概述
首先报告一下我系统的版本:Java代码
[root init.d]# cat /etc/issue
引用
CentOS release 6.4 (Final) Kernel \r on an \m 安装Redis 希望将Redis安装在此目录下:引用
/usr/local/redis
参考的安装说明,做调整:引用
$ mkdir /usr/local/redis $ cd /usr/local/src $ wget http://redis.googlecode.com/files/redis-2.6.14.tar.gz $ tar xzf redis-2.6.14.tar.gz $ ln -s redis-2.6.14 redis #建立一个链接 $ cd redis $ make PREFIX=/usr/local/redis install #安装到指定目录中 注意上面的最后一行,我们通过PREFIX指定了安装的目录。如果make失败,一般是你们系统中还未安装gcc,那么可以通过yum安装之:Java代码
yum install gcc
Java代码
redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server
Java代码
/usr/local/src/redis/utils/redis_init_script
Java代码
cp /usr/local/src/redis/utils/redis_init_script /etc/rc.d/init.d/redis
Java代码
chkconfig --add redis
引用
redis服务不支持chkconfig
为些,我们需要更改redis的脚本,请看下节说明。 2.更改redis的服务脚本Java代码
vim /etc/rc.d/init.d/redis
Java代码
#!/bin/bash
#chkconfig: 2345 80 90
# Simple Redis init.d script conceived to work on Linux systems
# as it does use of the /proc filesystem.
REDISPORT=6379
EXEC=/usr/local/redis/bin/redis-server
CLIEXEC=/usr/local/redis/bin/redis-cli
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.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
;;
*)
echo "Please use start or stop as first argument"
;;
esac
引用
#chkconfig: 2345 80 90
这时如果注册将报错,要添加再注册就OK了。 2)更改EXEC、CLIEXEC参数,设置对应的值,如上所示即和我们前面安装的一致。 3)更改redis开启的命令,以后台运行的方式执行:Java代码
$EXEC $CONF &
Java代码
mkdir /etc/redis
cp /usr/local/src/redis/redis.conf /etc/redis/6379.conf
Java代码
chkconfig --add redis
Java代码
$ service redis start
Java代码
export PATH="$PATH:/usr/local/redis/bin"
Java代码
. /etc/profile
Java代码
$ redis-cli
redis 127.0.0.1:6379> auth superman
OK
redis 127.0.0.1:6379> ping
PONG
redis 127.0.0.1:6379>