宝塔服务器重启后redis启动报错pid file is exits

转自https://blog.csdn.net/qq_41895021/article/details/109483832
今天遇到了这个问题,所以转载记录一下,该问题的原因是redis非正常关闭,导致reidis的pid文件未正常删除。而pid文件的作用是防止redis多进程启动,所以如果不删除它就无法启动新的redis.以下是具体方法。

重启宝塔redis启动失败
查看状态:

[root@localhost ~]# service redis status
Redis is not running, buy pid file is exits /www/server/redis/redis.pid
[root@localhost ~]#

原因:
我的宝塔是装在vmware里,win10重启,vm里的虚拟机直接关机,redis 没有正常关闭,redis.pid文件残留。

解决办法:
[root@localhost redis]# vi /etc/init.d/redis

搜索【Redis is not running, buy pid file is exits】
大概在38行

 34 redis_start(){
 35         if [ -f "/www/server/redis/redis.pid" ]; then
 36                 ps -p $(cat ${PIDFILE}) > /dev/null 2>&1
 37                 if [ $? -ne "0" ]; then
 38                         echo Redis is not running, buy pid file is exits ${PIDFILE}
 39   
 40                         exit 1
 41                 else
 42                         echo "redis is running! ($(cat ${PIDFILE}))"
 43                         exit 0
 44                 fi
 45         fi
 46         echo "Starting redis server..."
 47         sudo -u redis $EXEC $CONF
 48         echo ${REDIS_PORT} > /www/server/redis/start.pl
 49         echo "Starting redis success!"
 50 }

在39行加入(exit 1之前 )
rm -rf /www/server/redis/redis.pid && service redis restart && service redis status
然后reboot查看效果

你可能感兴趣的:(redis,redis)