0%

CentOS 将 Redis 配置为系统服务

创建 redis.service

1
2
cd  /usr/lib/systemd/system
touch redis.service

编辑内容

1
2
3
4
5
6
7
8
9
10
11
12
[Unit]
Description=Redis Server
After=network.target

[Service]
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/bin/redis-server /etc/redis.conf
ExecStop=/usr/local/bin/redis-cli -a passwd shutdown
ExecReload=/bin/kill -s HUP $MAINPID

[Install]
WantedBy=mutli-user.target

创建软链接

1
ln -s `pwd`/redis.service /etc/systemd/system/multi-user.target.wants

重新载入 systemctl 并启动服务

1
2
systemctl daemon-reload
systemctl start redis.service

查看状态

1
systemctl status redis.service

关闭 Redis

1
systemctl stop redis.service

开机自启

1
systemctl enable redis.service

是否开机自启

1
systemctl is-enabled redis.service