1. 准备工作

    点击 官网 下载安装包

    Centos 7.4 源码安装 redis-5.0.4-LMLPHP

  2. 使用 tar -zxvf 把安装包解压到 /usr/local 目录下,命名为 redis,步骤省略,结果如下

     [root@iZ2xxxxxuf9Z local]# pwd
     /usr/local
     [root@iZ2xxxxxuf9Z local]# ls
     aegis  etc    include  lib    libexec  nginx         redis  share
     bin    games  java     lib64  mysql    nginx-1.14.1  sbin   src
    
  3. 编译安装

    注意要在 redis 目录下执行

     [root@iZ2xxxxxuf9Z local]# cd redis/
     [root@iZ2xxxxxuf9Z redis]# make
     #一大堆安装日志输出
         LINK redis-benchmark
         INSTALL redis-check-rdb
         INSTALL redis-check-aof
    
     Hint: It's a good idea to run 'make test' ;)
    
     make[1]: Leaving directory `/usr/local/redis/src'
     [root@iZ2xxxxxuf9Z redis]# make install
     cd src && make install
     make[1]: Entering directory `/usr/local/redis/src'
         CC Makefile.dep
     make[1]: Leaving directory `/usr/local/redis/src'
     make[1]: Entering directory `/usr/local/redis/src'
    
     Hint: It's a good idea to run 'make test' ;)
    
         INSTALL install
         INSTALL install
         INSTALL install
         INSTALL install
         INSTALL install
     make[1]: Leaving directory `/usr/local/redis/src'
     [root@iZ2xxxxxuf9Z redis]#
    
  4. 注册redis服务

     #复制utils下redis_init_script到/etc/rc.d/init.d/ 并命名为redis
     [root@iZ2xxxxxuf9Z redis]# cp utils/redis_init_script /etc/rc.d/init.d/redis
     #修改脚本文件 在第1行下面添加下面两行
     # chkconfig: 2345 80 90
     # description:  Redis is a persistent key-value database
     [root@iZ2xxxxxuf9Z redis]# vim
    
     #!/bin/sh
     # chkconfig: 2345 80 90
     # description:  Redis is a persistent key-value database
     # Simple Redis init.d script conceived to work on Linux systems
     # as it does use of the /proc filesystem.
    
     ### BEGIN INIT INFO
     # Provides:     redis_6379
     # Default-Start:        2 3 4 5
     # Default-Stop:         0 1 6
     # Short-Description:    Redis data structure server
     # Description:          Redis data structure server. See https://redis.io
     ### END INIT INFO
    
     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"
    
  5. 初步配置文件修改

    从上一步的 /etc/rc.d/init.d/redis 文件中可以看到,CONF="/etc/redis/${REDISPORT}.conf",若不修改此行配置文件指向,则需要把配置文件以 端口号.conf 放在 /etc/redis 目录下

     [root@iZ2xxxxxuf9Z redis-5.0.0]# mkdir -p /etc/redis
     #复制配置文件到/etc/redis/下,并命名为6379.conf
     [root@iZ2xxxxxuf9Z redis]# cp redis.conf /etc/redis/6379.conf
     [root@iZ2xxxxxuf9Z redis]# vim /etc/redis/6379.conf
     #注释bind 127.0.0.1(用于远程连接),将“daemonize no”修改为“daemonize yes”
     #bind 127.0.0.1
     daemonize yes
    
  6. 启动与开机启动

     #启动redis
     [root@iZ2xxxxxuf9Z redis]# systemctl start redis
     #设置开机启动
     [root@iZ2xxxxxuf9Z redis]# systemctl enable redis
    

参考文档:wliet - centos7源码安装redis-5.0.0

04-06 14:56