centos6配置redis服务

1、下载redis-3.2.6.tar.gz到/usr/soft/

2、cd /usr/soft

3、make

4、  cp  /usr/soft/redis-3.2.6/utils/redis_init_script   /etc/rc.d/init.d/redis

5、vi  /etc/rc.d/init.d/redis

#!/bin/sh
# chkconfig: 2345 90 10##必须有

# description: Redis is a persistent key-value database


# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.

REDISPORT=6379#启动端口
EXEC=/usr/soft/redis-3.2.6/src/redis-server#启动redis命令
CLIEXEC=/usr/soft/redis-3.2.6/src/redis-cli#启动客户端命令

PIDFILE=/var/run/redis_${REDISPORT}.pid#pidfile路径
CONF="/usr/soft/redis-3.2.6/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 & #加上一个&表示后台运行,感觉相当于nohup命令
fi
;;
stop)
if [ ! -f $PIDFILE ]
then
echo "$PIDFILE does not exist, process is not running"
else
PID=$(cat $PIDFILE)
echo "Stopping ..."
$CLIEXEC -a "qiu123!@#" -p $REDISPORT shutdown#写上你的密码,密码在redis.conf文件中的 requirepass
while [ -x /proc/${PID} ]
do
echo "Waiting for Redis to shutdown ..."
sleep 1
done
echo "Redis stopped"
fi
;;
*)
echo "Please use start or stop as first argument"
;;
esac

6、 启动redis : service redis start

  关闭redis : service redis stop

7、将redis设置为开机启动

  chkconfig --add redis

8、如果你发现在本机可以访问redis,远程不能。就将redis.conf中的bind 127.0.0.1注释掉

 

posted @ 2017-03-02 11:30  pikaqiu^_^  阅读(796)  评论(0编辑  收藏  举报