Centos7.5下编译安装Redis5.0
1、去redis的官网下载( https://redis.io/download )最新稳定版本
下载解压编译Redis:
$ wget http://download.redis.io/releases/redis-5.0.2.tar.gz $ tar xzf redis-5.0.2.tar.gz $ cd redis-5.0.2 $ make
2、配置Redis
- 在local下创建redis,复制刚编译好的redis 程序到这文件夹下
[root@zzming redis-5.0.2]# mkdir /usr/local/redis [root@zzming redis-5.0.2]# cd src/ [root@zzming src]# pwd /mnt/soft/redis-5.0.2/src ---copy program [root@zzming src]# cp redis-server /usr/local/redis/. [root@zzming src]# cp redis-cli /usr/local/redis/. [root@zzming src]# cp redis-check-aof /usr/local/redis/. [root@zzming src]# cp redis-check-rdb /usr/local/redis/. [root@zzming src]# cp redis-sentinel /usr/local/redis/. [root@zzming src]# cp redis-benchmark /usr/local/redis/. ---copy config [root@zzming src]# cd .. [root@zzming redis-5.0.2]# cp redis.conf /usr/local/redis/.
- 修改redis.conf 配置文件,为了使redis能在后台运行,将原先daemonize no 改为 daemonize yes ,保存退出。
daemonize yes
3、建立redis 自动启动脚本, 在 /etc/init.d/下, 创建名为:redis
vim /etc/init.d/redis
#! /bin/bash # chkconfig: 2345 89 90 # description: Start and Stop redis REDISPORT=6379 REDISPATH=/usr/local/redis EXEC=${REDISPATH}/redis-server REDIS_CLI=${REDISPATH}/redis-cli PIDFILE=/var/run/redis_${REDISPORT}.pid CONF="${REDISPATH}/redis.conf" AUTH="1234" case "$1" in start) if [ -f $PIDFILE ] then echo "$PIDFILE exists, process is already running or crashed." else echo "Redis Starting......." $EXEC $CONF fi if [ "$?"="0" ] then echo "Redis is running......" fi ;; stop) if [ ! -f $PIDFILE ] then echo "$PIDFILE exists, process is not running." else PID=$(cat $PIDFILE) echo "Redis Stopping......." $REDIS_CLI -p $REDISPORT SHUTDOWN sleep 2 while [ -x $PIDFILE ] do echo "Waiting for Redis to shutdown..." sleep 1 done echo "Redis Stopped" fi ;; restart|force-reload) ${0} stop ${0} start ;; *) echo "Usage: /etc/init.d/redis {start|stop|restart|force-reload}" >&2 exit 1 esac
- 加入开机启动项
chkconfig --add redis
4、测试一下吧,可以这样使用
service redis stop
service redis start
service redis restart
OK,Redis安装配置测试完毕。