1. 安装gcc-c++, tcl
yum install gcc-c++ tcl
2. 解压缩, 编译, 测试
tar zxvf redis-5.0.5.tar.gz make make test
3. 安装至/opt
make PREFIX=/opt/redis/redis-5.0.5 install # 创建软链 ln -s redis-5.0.5 latest
4. 配置文件, 在源文件目录下有例子 redis.conf, 最后的配置内容为(后半部分使用默认, 无改动)
[root@p01 ~]# cat /opt/redis/latest/conf/redis_16379.conf | grep -v '^$'|grep -v '^#'|grep -v '^;' bind 192.168.123.32 protected-mode yes port 16379 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes supervised auto pidfile /var/run/redis_16379.pid loglevel notice logfile "/data/redis/logs/redis_16379.log" databases 16 always-show-logo yes save 900 1 save 300 10 save 60 10000 stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb dir /data/redis/db/ replica-serve-stale-data yes replica-read-only yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no replica-priority 100 requirepass rzczurzlx4xzs|yjpkdjzhljlevY0bLh ....
5. 在配置daemonize为no的时候, 直接用命令行启动测试, 观察日志输出
./bin/redis-server ./conf/redis_16379.conf
6. 解决warning
对于 /proc/sys/net/core/somaxconn 和 overcommit_memory is set to 0, 修改/etc/sysctl.conf , 增加
net.core.somaxconn = 1024 vm.overcommit_memory = 1
然后执行 sysctl -p
对于transparent_hugepage, 首先实时修改
echo never >> /sys/kernel/mm/transparent_hugepage/enabled echo never >> /sys/kernel/mm/transparent_hugepage/defrag
检查
[root@middle ~]# cat /sys/kernel/mm/transparent_hugepage/enabled [always] madvise never [root@middle ~]# cat /sys/kernel/mm/transparent_hugepage/defrag [always] madvise never # 以上都需要变成never
加入启动自动修改
# 在/etc/rc.local中增加如下内容 if test -f /sys/kernel/mm/transparent_hugepage/enabled; then echo never > /sys/kernel/mm/transparent_hugepage/enabled fi if test -f /sys/kernel/mm/transparent_hugepage/defrag; then echo never > /sys/kernel/mm/transparent_hugepage/defrag fi
.
7. 加入Systemd服务. 增加 /lib/systemd/system.redis.service, 内容如下
[Unit] Description=Redis After=network.target [Service] Type=forking PIDFile=/var/run/redis_16379.pid ExecStart=/opt/redis/latest/bin/redis-server /opt/redis/latest/conf/redis_16379.conf ExecReload=/bin/kill -s HUP $MAINPID ExecStop=/opt/redis/latest/bin/redis-cli -p 16379 shutdown PrivateTmp=true [Install] WantedBy=multi-user.target
注意: 这边并没有使用 #ExecStop=/bin/kill -s QUIT $MAINPID 这样的命令来停止redis, 因为使用这个语句在运行 systemctl stop redis后, redis并未执行关闭动作, 而是直接退出. 这时候用 systemctl status redis 查看状态是failed. 只有用ExecStop=/opt/redis/latest/bin/redis-cli -p 16379 shutdown 才能正确停止redis, 即使conf中配置了口令, 这里也不需要指定口令.
加入服务并启动
systemctl enable redis.service systemctl start redis systemctl status redis
.