今天周一,一大早来公司,就听到开发的同学说本地项目起不来了, 上周六加班儿还好好的, 应该是周日断电导致的.
redis是关闭的,redis没有设置开机自启动,于是就先把问题先解决吧,然后写个脚本设置redis开机自启动。
1、在写脚本前设置下redis允许在后台启动,修改redis.conf文件,把daemonize no改成daemonize yes
2、开始编写脚本
#vim /etc/init.d/redis --创建脚本文件
REDISPORT=6379
EXEC=/usr/local/software/redis-4.0.9/redis-server
CLIEXEC=/usr/local/software/redis-4.0.9/redis-cli
PIDFILE=/data/redis-data/redis-6379/redis.pid
CONF="/data/redis-data/redis-6379/conf/redis.conf"
这里我的redis安装路径是/usr/local/software/redis-4.0.9,端口为6379,然后redis.conf文件在/data/***/conf/redis.conf下面,你们根据自己的实际情况修改就行(这个脚本可以根据redis自带的启动脚本进行修改,它默认的路径是在$redis/utils/redis_init_script,$redis是redis的安装路径)
1 #!/bin/sh 2 #chkconfig: 2345 80 05 3 #description: Start and Stop redis 4 5 REDISPORT=6379 6 EXEC=/usr/local/software/redis-4.0.9/redis-server 7 CLIEXEC=/usr/local/software/redis-4.0.9/redis-cli 8 9 PIDFILE=/data/redis-data/redis-6379/redis.pid 10 CONF="/data/redis-data/redis-6379/conf/redis.conf" 11 12 case "$1" in 13 start) 14 if [ -f $PIDFILE ];then 15 echo "$PIDFILE exists,process is already running or crashed" 16 else 17 echo "Starting Redis server..." 18 $EXEC $CONF 19 fi 20 ;; 21 stop) 22 if [ ! -f $PIDFILE ];then 23 echo "$PIDFILE does not exist,process is not running" 24 else 25 PID=$(cat $PIDFILE) 26 echo "Stopping..." 27 $CLIEXEC -p $REDISPORT shutdown 28 while [ -x /proc/${PID} ] 29 do 30 echo "Waiting for Redis to shutdown..." 31 sleep 1 32 done 33 echo "Redis stopped" 34 fi 35 ;; 36 restart) 37 "$0" stop 38 sleep 3 39 "$0" start 40 ;; 41 *) 42 echo "Please use start or stop or restart as first argument" 43 ;; 44 esac
3、写完记得修改文件权限
#chmod +x /etc/init.d/redis
4、把脚本添加到系统服务列表
#chkconfig --add redis #chkconfig redis #chkconfig --list #chkconfig --help // 这里如果上传的redis启动文件有问题, 可以通过help命令具体操作;