安装redis

wget http://download.redis.io/releases/redis-4.0.9.tar.gz -O /redis-4.0.9.tar.gz
tar xzf redis-4.0.9.tar.gz  解压缩安装包
cd /redis-4.0.9/ 进入安装包所在目录
make 编译安装

开机启动

mkdir  /etc/redis
cp /redis-4.0.9/redis.conf /etc/redis/6379.conf
cp /redis-4.0.9/utils/redis_init_script /etc/init.d/redis
vim /etc/init.d/redis  新增第6,7,13,15,29行,18行需要手动准备文件

1 #!/bin/sh
2 #
3 # Simple Redis init.d script conceived to work on Linux systems
4 # as it does use of the /proc filesystem.
5 ##NEW###
6 # chkconfig: 2345 10 90
7 # description: Start and Stop redis
8 ##NEW###
9
10
11 REDISPORT=6379
12 #EXEC=/usr/local/bin/redis-server
13 EXEC=/redis-4.0.9/src/redis-server
14 #CLIEXEC=/usr/local/bin/redis-cli
15 CLIEXEC=/redis-4.0.9/src/redis-cli
16
17 PIDFILE=/var/run/redis_${REDISPORT}.pid
18 CONF="/etc/redis/${REDISPORT}.conf"
19 #需要手动拷贝该文件。cp /redis-4.0.9/redis.conf /etc/redis/6379.conf
20
21 case "$1" in
22 start)
23 if [ -f $PIDFILE ]
24 then
25 echo "$PIDFILE exists, process is already running or crashed"
26 else
27 echo "Starting Redis server..."
28 #$EXEC $CONF
29 $EXEC $CONF &
30
31 fi
32 ;;
33 stop)
34 if [ ! -f $PIDFILE ]
35 then
36 echo "$PIDFILE does not exist, process is not running"
37 else
38 PID=$(cat $PIDFILE)
39 echo "Stopping ..."
40 $CLIEXEC -p $REDISPORT shutdown
41 while [ -x /proc/${PID} ]
42 do
43 echo "Waiting for Redis to shutdown ..."
44 sleep 1
45 done
46 echo "Redis stopped"
47 fi
48 ;;
49 *)
50 echo "Please use start or stop as first argument"
51 ;;
52 esac
chmod 777 /etc/init.d/redis
chkconfig --add redis //增加开机启动设置
chkconfig redis on //设置redis开机启动
systemctl daemon-reload //重新加载自启动信息
systemctl start redis //启动redis


测试

/redis-4.0.9/src/redis-cli
127.0.0.1:6379> set name xulei 设置键值对
OK
127.0.0.1:6379> get name 获取键值对
"xulei"