Redis Install & Configuration

1. Environment

  • 官网下载

    https://redis.io/

  • NAS地址

    公共资源 > Tools > Develop > Dev_software > redis-6.0.6.tar.gz

2. Install

  • 确认是否安装gcc

    gcc -v
    
  • 安装gcc

    yum -y install centos-release-scl
    yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
    #永久切换GCC9
    echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile
    
    #确认 gcc为9
    gcc -v
    
  • 将安装包通过SFTP上传至Centos7 服务器中指定目录,这里放在/opt目录下

    cd /opt
    ls -l
    
  • 创建安装目录

    mkdir -p /usr/local/redis/
    
  • 解压至安装目录

    tar -zxvf redis-6.0.6.tar.gz -C /usr/local/redis/
    
  • 进入目录

    cd /usr/local/redis/redis-6.0.6/
    make
    
  • 修改redis.conf

    cd /usr/local/redis/redis-6.0.6/
    vi redis.conf
    
  • 修改如下内容

    #不绑定IP
    #bind 127.0.0.1
    #取消保护模式
    protected-mode no
    #redis监听的端口号
    port 61379
    #设置后台运行
    daemonize yes
    #密码为ZBg8wzvM
    requirepass ZBg8wzvM
    
  • 运行redis

    cd /usr/local/redis/redis-6.0.6/src
    ./redis-server /usr/local/redis/redis-6.0.6/redis.conf
    
  • 查看是否成功运行

    ps -ef | grep redis
    netstat -lnpt
    
  • 添加开机启动服务

    vi /etc/systemd/system/redis-server.service
    
  • 写入一下内容

    [Unit]
    Description=Redis Server Manager
    After=syslog.target network.target
    [Service]
    Type=forking
    PIDFile=/var/run/redis_6379.pid
    ExecStart=/usr/local/redis/redis-6.0.6/src/redis-server /usr/local/redis/redis-6.0.6/redis.conf
    ExecReload=/bin/kill -USR2 $MAINPID
    ExecStop=/bin/kill -SIGINT $MAINPID
    [Install]
    WantedBy=multi-user.target
    
  • 设置开机启动

    systemctl daemon-reload
    systemctl start redis-server.service
    systemctl enable redis-server.service
    
  • 如果出现错误可以使用如下命令查看日志

    sudo journalctl -u redis-server.service
    
  • 重启服务器,查看是否成功运行

    systemctl status redis-server.service
    

3. Configuration 防火墙

  • 查看redis使用端口61379

    netstat -lnpt
    
  • 开放端口,这里使用61379端口

    firewall-cmd --permanent --zone=public --add-port=61379/tcp
    
  • 重启防火墙

    firewall-cmd --reload
    
  • 查看防火墙,已开放端口列表

    firewall-cmd --list-ports