1.安装redis
进入安装目录下载:
cd /usr/local/redis
wget http://download.redis.io/releases/redis-3.0.7.tar.gz
解压到安装目录后执行 make命令:
tar -vxzf redis-3.0.7.tar.gz
make
测试是否安装成功,执行一下命令:
redis-server
到这步,Redis安装成功!
2.配置redis并添加到linux服务
将/usr/local/redis/utils/redis_init_script脚本拷贝到/etc/init.d/redis
cp /usr/local/redis/utils/redis_init_script /etc/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/bin/redis-server CLIEXEC=/usr/local/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
根据脚本文件中的配置,创建数据目录/var/redis/6379,将redis-server、redis-cli移动到/usr/local/bin下,将/usr/local/redis/redis.conf移动到/etc/redis/6379.conf,并做如下修改:
daemonize yes //由no改为yes,以后台方式运行 dir /var/redis/6379 //配置数据库文件存放目录
最后将redis添加为服务:
[root@ser211 init.d]# chkconfig --add redis
运行:service redis start
配置完成