【一】.查找和设置自己的redis路径参数
环境变量
PATH=/usr/local/bin:/sbin/:/usr/bin:/bin
端口
REDISPORT=6379
文件位置
EXEC=/usr/local/bin/redis-server
REDIS_CLI=/usr/local/bin/redis-cli
#PID位置
PIDFILE=/var/run/redis_6379.pid
#配置文件的位置
REDISCONF=“/usr/local/ect/redis.conf”
【二】.编写开机脚本
vi /etc/init.d/redis
1 #!/bin/sh 2 #chkconfig: - 85 15 3 #description: Start and Stop redis 4 5 PATH=/usr/local/bin:/sbin:/usr/bin:/bin 6 REDISPORT=6379 7 EXEC=/usr/local/bin/redis-server 8 REDIS_CLI=/usr/local/bin/redis-cli 9 10 PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="/usr/local/etc/redis.conf" 11 AUTH="1234" 12 13 14 case "$1" in 15 start) 16 if [ -f $PIDFILE ] then 17 echo "$PIDFILE exists, process is already running or crashed." 18 else 19 echo "Starting Redis server..." 20 $EXEC $CONF 21 fi 22 if [ "$?"="0" ] then 23 echo "Redis is running..." 24 fi 25 ;; 26 stop) 27 if [ ! -f $PIDFILE ] 28 then 29 echo "$PIDFILE exists, process is not running." 30 else 31 PID=$(cat $PIDFILE) 32 echo "Stopping..." 33 $REDIS_CLI -p $REDISPORT SHUTDOWN 34 sleep 2 35 while [ -x $PIDFILE ] 36 do 37 echo "Waiting for Redis to shutdown..." 38 sleep 1 39 done 40 echo "Redis stopped" 41 fi ;; 42 restart|force-reload) 43 ${0} stop 44 ${0} start ;; 45 *) 46 47 echo "Usage: /etc/init.d/redis {start|stop|restart|force-reloa d}" >&2 48 49 exit 1
* 提醒 vi 保存退出方法是 :wq
【三】 保存退出,设置
chmod 755 /etc/init.d/redis #设置权限
service redis start #启动redis服务
chkconfig redis on #设置Redis开机启动
#重启服务器 查看Redis服务是否启动
reboot
ps -ef | grep redis