Linux下安装Redis服务器

1、下载Redis的Linux安装包

下载地址https://redis.io/download,如:4.0.9版本

2、连接Linux服务器,上传Redis安装包

解压命令:

tar -zxvf redis-4.0.9.tar.gz  -C /usr/local/

3、安装GCC

安装命令:

yum install gcc c++

4、编译与安装

进入/usr/local/redis-4.0.9目录,执行命令:

#make

编译完成后,执行安装:

make PREFIX=/usr/local/redis-4.0.9 install

5、查看安装目录

进入/usr/local/redis-4.0.9/bin目录

Linux下安装Redis服务器插图

6、添加配置

cp /usr/local/redis-4.0.9/redis.conf /usr/local/redis-4.0.9/bin

修改redis.conf,将daemonize置为yes,亦可修改端口号

# 。。。
daemonize yes
#。。。

7、启动Redis(后台启动)

/usr/local/redis-4.0.9/bin/./redis-server redis.conf

8、测试Redis

#/usr/local/redis-4.0.9/bin/./redis-cli -p 6379
127.0.0.1:6379>set a a
OK
127.0.0.1:6379>get a
"a"
127.0.0.1:6379>

9、外网访问

修改配置项:

# bind 127.0.0.1
protected-mode no

10、设置最大占用内存

Redis设置最大占用内存,打开redis配置文件,找到如下段落,设置maxmemory参数,maxmemory是bytes字节类型,注意转换

# In short... if you have slaves attached it is suggested that you set a lower
# limit for maxmemory so that there is some free RAM on the system for slave
# output buffers (but this is not needed if the policy is 'noeviction').
#
# maxmemory <bytes>
maxmemory 268435456

11、设置访问密码

找到requirepass这个参数,如下配置:

# requirepass foobared
requirepass 123   #指定密码123

8人评论了“Linux下安装Redis服务器”

  1. redis异常解决:jedis.exceptions.JedisDataException: ERR Client sent AUTH, but no password is set
    原因:
    redis服务器没有设置密码,但客户端向其发送了AUTH请求

发表评论