安装教程猛击这里
安装环境:redis安装目录:/usr/local/redis
直接步入正题
vim /etc/init.d/redis
以下是启动脚本
#!/bin/sh
# chkconfig: 2345 80 90
# description: Start and Stop redis
#PATH=/usr/local/bin:/sbin:/usr/bin:/bin
REDISPORT=6379
# 根据自己redis实际安装路径来配置
EXEC=/usr/local/redis/src/redis-server
REDIS_CLI=/usr/local/redis/src/redis-cli
PIDFILE=/var/run/redis_6379.pid
# 根据自己redis实际安装路径来配置
CONF=/usr/local/redis/redis.conf
# redis密码
AUTH=\"zhaoyoung\"
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
if [ \"$?\"=\"0\" ]
then
echo \"Redis is running...\"
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo \"$PIDFILE exists, process is not running.\"
else
PID=$(cat $PIDFILE)
echo \"Stopping...\"
$REDIS_CLI -a $AUTH -p $REDISPORT SHUTDOWN
sleep 2
while [ -x $PIDFILE ]
do
echo \"Waiting for Redis to shutdown...\"
sleep 1
done
echo \"Redis stopped\"
fi
;;
restart|force-reload)
${0} stop
${0} start
;;
*)
echo \"Usage: /etc/init.d/redis {start|stop|restart|force-reload}\" >&2
exit 1
esac
设置权限
chmod 777 /etc/init.d/redis
添加自启动服务
chkconfig --add redis
设置为开机自启动
chkconfig redis on
测试下
[root@localhost /]# service redis start
Starting Redis server...
Redis is running...
[root@localhost /]# ps -ef | grep redis
root 39594 1 0 17:20 ? 00:00:00 /usr/local/redis/src/redis-server 127.0.0.1:6379
[root@localhost /]# cd /usr/local/redis/
[root@localhost redis]# ./bin/redis-cli
127.0.0.1:6379> auth zhaoyoung
OK
127.0.0.1:6379> set name zhaoyoung
OK
127.0.0.1:6379> get name
\"zhaoyoung\"
版权声明
本文仅代表作者观点,不代表百度立场。
本文系作者授权百度百家发表,未经许可,不得转载。



