redis设置开机启动的方法:
1、拷贝 redis 安装目前下的 /usr/local/redis-4.0.8/utils/redis_init_script 到 /etc/init.d/redis文件中;
cp /usr/local/redis-4.0.8/utils/redis_init_script /etc/init.d/redis
2、修改/etc/init.d/redis 文件。修改redis安装的相关文件安装目录
#!/bin/sh # chkconfig: 2345 10 90 # description: Start and Stop redis # Simple Redis init.d script conceived to work on Linux systems # as it does use of the /proc filesystem. REDISPORT=6379 EXEC=/usr/local/redis/bin/redis-server CLIEXEC=/usr/local/redis/bin/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/usr/local/redis/etc/redis.conf"
#!/bin/sh # chkconfig: 2345 10 90 # description: Start and Stop redis
备注:
上面的注释的意思是,redis服务必须在运行级2,3,4,5下被启动或关闭,启动的优先级是90,关闭的优先级是10。从redis 安装目录中拷贝过来,可能没有,需要添加 上去; 否则 chkconfig 命令 会失败;
3、开机启动设置,执行一下命令:
添加redis服务:
chkconfig --add redis
设为开机启动 :
chkconfig redis on
常用命令
service redis start service redis stop