记录在CentOS 7下安装Redis 5.0.5并加入Systemd服务的步骤。 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.
记录在CentOS 7下安装Redis 5.0.5并加入Systemd服务的步骤。
1. 安装gcc-c++, tcl
yum install gcc-c++ tcl
2. 解压缩, 编译, 测试
tar zxvf redis-5.0.5.tar.gzmakemake 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.32protected-mode yesport 16379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised autopidfile /var/run/redis_16379.pidloglevel noticelogfile "/data/redis/logs/redis_16379.log"databases 16always-show-logo yessave 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump.rdbdir /data/redis/db/replica-serve-stale-data yesreplica-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noreplica-priority 100requirepass 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 = 1024vm.overcommit_memory = 1
然后执行 sysctl -p
对于transparent_hugepage, 首先实时修改
echo never >> /sys/kernel/mm/transparent_hugepage/enabledecho 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; thenecho never > /sys/kernel/mm/transparent_hugepage/enabledfi if test -f /sys/kernel/mm/transparent_hugepage/defrag; thenecho never > /sys/kernel/mm/transparent_hugepage/defragfi
.
7. 加入Systemd服务. 增加 /lib/systemd/system.redis.service, 内容如下
[Unit]Description=RedisAfter=network.target [Service]Type=forkingPIDFile=/var/run/redis_16379.pidExecStart=/opt/redis/latest/bin/redis-server /opt/redis/latest/conf/redis_16379.confExecReload=/bin/kill -s HUP $MAINPIDExecStop=/opt/redis/latest/bin/redis-cli -p 16379 shutdownPrivateTmp=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.servicesystemctl start redissystemctl status redis
下面关于Redis的文章您也可能喜欢,不妨参考下:
CentOS 7下Redis5安装部署与开机自启动 https://www.558idc.com/Linux/2019-06/159178.htmRedis集群以及自动故障转移测试 https://www.558idc.com/Linux/2019-01/156599.htmUbuntu搭建Redis 集群 https://www.558idc.com/Linux/2019-07/159616.htmCentOS 7下Redis的安装与配置 https://www.558idc.com/Linux/2017-02/140363.htmUbuntu 16.04环境中安装PHP7.0 Redis扩展 https://www.558idc.com/Linux/2016-09/135631.htmRedis 单机&集群离线安装部署 https://www.558idc.com/Linux/2017-03/141403.htmCentOS 7.0 安装Redis 3.2.1详细过程和使用常见问题 https://www.558idc.com/Linux/2016-09/135071.htmUbuntu 16.04环境中安装PHP7.0 Redis扩展 https://www.558idc.com/Linux/2016-09/135631.htmRedis实战 中文PDF http://www.558idc.com/Linux/2016-04/129932.htm