centOS7设置redis自启动

1, 查看centos版本

[ bin]# cat /etc/redhat-release 
CentOS Linux release 7.7.1908 (Core)

2, redis版本

[ bin]# redis-server -v
Redis server v=6.0.1

3,新建redis.service服务文件

vim /usr/lib/systemd/system/redis.service

4,redis.service文件的内容

[Unit]
Description=Redis Server Manager
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
ExecReload=/bin/kill -USR2 $MAINPID
ExecStop=/bin/kill -SIGINT $MAINPID

[Install]
WantedBy=multi-user.target

注意:ExecStart参数需要注意下,这里我的安装路径是"/usr/local/redis/bin",更改为各自的安装路径

5,刷新systemctl

systemctl daemon-reload

6,启动redis

systemctl start redis

7,设置redis开机自启动

systemctl enable redis

相关推荐