redis启动后,查看状态,找不到pid文件

搭建Redis主从,使用源码包安装,从机配置systmed启动

[root@redis-slave redis]# vim /usr/lib/systemd/system/redis.service
[Unit]
Description=redis
After=network.target

[Service]
Type=forking
PIDFile=/var/run/redis_6379.pid
ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true
[Install]
WantedBy=multi-user.target

查看redis状态,发现报错

[root@redis-lave redis]# systemctl status redis
● redis.service – redis
Loaded: loaded (/usr/lib/systemd/system/redis.service; disabled; vendor preset: disabled)
Active: active (running) since Wed 2020-09-09 15:55:00 CST; 16s ago
CGroup: /system.slice/redis.service
└─5810 /usr/local/redis/bin/redis-server 127.0.0.1:6379

Sep 09 15:55:00 redis-lave systemd[1]: Starting redis…
Sep 09 15:55:00 redis-lave redis-server[5809]: 5809:C 09 Sep 2020 15:55:00.474 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
Sep 09 15:55:00 redis-lave redis-server[5809]: 5809:C 09 Sep 2020 15:55:00.474 # Redis version=5.0.5, bits=64, commit=00000000, mod…started
Sep 09 15:55:00 redis-lave redis-server[5809]: 5809:C 09 Sep 2020 15:55:00.474 # Configuration loaded
Sep 09 15:55:00 redis-lave systemd[1]: Can’t open PID file /var/run/redis_6379.pid (yet?) after start: No such file or directory

解决办法:

[Unit]
Description=redis
After=network.target

[Service]
Type=forking

ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
ExecStartPost=/bin/sh -c “echo $MAINPID > /var/run/redis_6379.pid” #添加这行,在执行start等命令后,添加PID文件
PrivateTmp=true
[Install]
WantedBy=multi-user.target

此条目发表在redis分类目录。将固定链接加入收藏夹。

发表评论