第一部分:安装redis
mkdir /usr/local/redis
cd /usr/local/src
wget http://download.redis.io/releases/redis-2.8.12.tar.gz
tar xzf redis-2.8.12.tar.gz
ln -s redis-2.8.12 redis
cd redis
make PREFIX=/usr/local/redis CFLAGS="-march=x86-64" install
上面7步指令,完成了redis的安装。
安装redis成功后,你将可以在/usr/local/redis看到一个bin的目录,里面包括了以下文件:
redis-benchmark redis-check-aof redis-check-dump redis-cli redis-server
第二部分:将redis做成一个服务
1.复制脚本到/etc/rc.d/init.d目录
cp /usr/local/src/redis/utils/redis_init_script /etc/rc.d/init.d/redis
2、如果这时添加注册服务
chkconfig --add redis
redis服务不支持chkconfig
为此,我们需要更改redis脚本。
3、更改redis脚本
备份原来的脚本
mv /etc/rc.d/init.d/redis /etc/rc.d/init.d/redis.bak
把redis脚本更改为如下内容
vim /etc/rc.d/init.d/redis
#!/bin/sh
#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
4、将redis配置文件拷贝到/etc/redis/${REDISPORT}.conf
mkdir /etc/redis
cp /usr/local/src/redis/redis.conf /etc/redis/6379.conf
以上操作完成后,即可注册yedis服务:
chkconfig --add redis
赋予redis的权限
chmod 777 /etc/init.d/redis
service redis start
第三,将Redis的命令所在目录添加到系统参数PATH中
1、修改profile文件:
vi /etc/profile 文件,在最后行添加下面一条命令:
export PATH="$PATH:/usr/local/redis/bin"
应用这个文件:
. /etc/profile
2、这样就可以直接调用redis-cli的命令了
$ redis-cli
第四,安装python redis模块
[root@Python_learn ~]# /usr/local/src
[root@Python_learn src]# wget --no-check-certificate https://pypi.python.org/packages/source/r/redis/redis-2.8.0.tar.gz
[root@Python_learn src]# tar -zvxf redis-2.8.0.tar.gz
[root@Python_learn src]# ln -s redis-2.8.0 python-redis
[root@Python_learn python-redis]# python setup.py install
已安装完成
测试
[root@Python_learn python-redis]# python
Python 2.7.5 (default, Jun 17 2014, 18:11:42)
[GCC 4.8.2 20140120 (Red Hat 4.8.2-16)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import redis
>>>