Centos 7 安装 Redis 5
-
解压安装包
# tar zxvf redis-5.0.9.tar.gz
-
重命名并移动文件夹
# mv redis-5.0.9 redis # mv redis /usr/local/src/redis
-
安装redis
# cd /usr/local/src/redis/ # make PREFIX=/usr/local/redis install
如果由于malloc报错,则使用make MALLOC=libc PREFIX=/usr/local/redis install
-
复制
redis.conf
到安装目录# cp redis.conf /usr/local/redis/6379.conf
-
修改
6379.conf
将daemonize设置为yes requirepass配置去掉注释并设置密码 dir /Disk/data/redis/6379 pidfile /Disk/data/redis/redis_6379.pid logfile “/Disk/logs/redis/6379.log” appendonly yes appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes
-
创建redis存储目录和日志目录
# mkdir -p /Disk/data/redis/6379 # mkdir -p /Disk/logs/redis
-
将redis配置成服务-centos7
# 添加服务配置文件 # vim /etc/systemd/system/redis-server.service 文件内容如下: [Unit] Description=Redis6379 Server After=syslog.target network.target [Service] Type=forking PIDFile=/Disk/data/redis/redis_6379.pid ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/6379.conf ExecStop=/bin/kill -SIGINT $MAINPID [Install] WantedBy=multi-user.target # 保存并退出 # 重新加载系统服务 # systemctl daemon-reload # 启动服务 # systemctl start redis-server.service # 服务开机启动 # systemctl enable redis-server.service
-
直接使用redis-server启动会出现警告,解决方案如下:
警告一:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
警告二:WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1‘ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1‘ for this to take effect.
警告一、警告二解决方案,修改
/etc/sysctl.conf
文件,在文件末尾加入以下两句:net.core.somaxconn=1024 vm.overcommit_memory=1
然后使用
sysctl -p
,使配置生效警告三:WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled‘ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
警告三解决方案,执行如下命令(重启后丢失,当前生效):
# echo never > /sys/kernel/mm/transparent_hugepage/enabled
将以上命令写入
/etc/rc.local
,重启后不会丢失