创建自启动脚本:redis
vi /etc/init.d/redis
输入以下内容:tomcat
#!/bin/bash # # tomcat startup script for the redis server # # chkconfig: 2345 90 10 # description: start the redis deamon # # Source function library . /etc/rc.d/init.d/functions #脚本名称 prog=redis #redis安装目录、配置目录 REDIS_HOME=/usr/local/bin REDIS_HOME_CONFIG=/usr/redis export REDIS_HOME export REDIS_HOME_CONFIG #PID_FILE检测 REDIS_PID_FILE=/var/run/redis_6379.pid #服务命令行 REDIS_EXEC_CLI=$REDIS_HOME/redis-cli export REDIS_EXEC_CLI #服务器端口 REDIS_PORT=6379 #服务器配置 REDIS_CONFIG=$REDIS_HOME_CONFIG/redis.conf #服务启动命令 REDIS_EXEC_START=$REDIS_HOME/redis-server #export REDIS_EXEC_START #服务关闭命令 REDIS_EXEC_STOP=$REDIS_EXEC_CLI #export REDIS_EXEC_STOP case "$1" in start) if [ -f $REDIS_PID_FILE ] then echo "$REDIS_PID_FILE exists, process is already running or crashed" else echo "Starting Redis server..." $REDIS_EXEC_START $REDIS_CONFIG fi ;; stop) if [ ! -f $REDIS_PID_FILE ] then echo "$REDIS_PID_FILE does not exists, process is not running" else PID=$(cat $REDIS_PID_FILE) echo "Stopping Redis server..." $REDIS_EXEC_STOP -p $REDIS_PORT shutdown while [ -x /proc/${PID} ] do echo "Waiting for Redis to shutdown ..." sleep 1 done echo "Redis stopped" fi ;; restart) ${0} stop ${0} start ;; *) echo "Usage: $prog {start|stop|restart}" ;; esac exit 0
修改文件为可运行文件:bash
chmod a+x redis
查看redis开机启动状况:服务器
chkconfig --list
如没有,则添加到系统启动队列中:命令行
chkconfig --add redis
从新检查redis开机启动状况,若成功,则应显示以下内容:rest
redis 0:off 1:off 2:on 3:on 4:on 5:on 6:offcode
使用下列命令对redis进行重启、中止、启动:server
service redis restart/stop/start/force-reload
修改redis绑定机器ip,以便redis desktop manager链接队列
vi /usr/redis/redis.conf
bind 127.0.0.1 192.168.0.248