使用下面的方法要注意的是安装文件路径和配置文件的路径。
[root@localhost ~]# vi /etc/init.d/redis
复制下面代码到脚本中(注意要修改里面redis的安装路径,不清楚find查找下)
(这段代码就是redis根目录 /utils/redis_init_script 启动脚本的代码)
#!/bin/sh# chkconfig: 2345 10 90 # description: start and stop redis redisport=6379exec=/usr/local/bin/redis-servercliexec=/usr/local/bin/redis-serverpidfile=/var/run/redis_${redisport}.pidconf="/etc/redis/redis.conf"case "$1" in start) if [ -f $pidfile ] then echo "$pidfile exists, process is already running or crashed" else echo "starting redis server..." $exec $conf & fi ;; stop) if [ ! -f $pidfile ] then echo "$pidfile does not exist, process is not running" else pid=$(cat $pidfile) echo "stopping ..." $cliexec -p $redisport shutdown while [ -x /proc/${pid} ] do echo "waiting for redis to shutdown ..." sleep 1 done echo "redis stopped" fi ;; restart) "$0" stop sleep 3 "$0" start ;; *) echo "please use start or stop or restart as first argument" ;;esac
设置权限
[root@localhost ~]# chmod 777 /etc/init.d/redis
设置开机启动
chkconfig redis on
启动测试
service start redis
更多相关知识请关注redis入门教程栏目
以上就是设置redis开机启动的详细内容。