CentOS 7.8 yum 源方式安装 Redis

323 阅读1分钟

安装

  1. 安装依赖
    yum -y install gcc centos-release-scl cmake wget tcl
    yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
    
  2. 解决Centos默认gcc版本低的问题
    echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile && source /etc/profile && gcc -v
    
  3. 下载解压
    wget https://mirrors.huaweicloud.com/redis/redis-6.0.5.tar.gz && tar -xf redis-6.0.5.tar.gz && cd redis-6.0.5/
    
  4. 复制配置化文件
    mkdir -p /usr/local/redis/conf && cp sentinel.conf redis.conf /usr/local/redis/conf/
    
  5. 编译 make -j
  6. 安装
    make install PREFIX=/usr/local/redis
    cd /usr/local/redis/bin && ls
    
  7. 修改配置 Redis.conf
    # bind 127.0.0.1 注释,若不注释就只能本地连接
    # 将 daemonize no 改为 daemonize yes 后台运行
    daemonize yes
    # # requirepass foobared 注释去掉,修改验证密码
    requirepass redis123
    # 确保日志文件路径存在,否则先创建目录
    logfile /var/log/redis/redis-server.log
    

其它命令

  1. 查看 Redis 进程
    ps aux | grep redis
    
  2. 启动 Redis
    /usr/local/redis# bin/redis-server conf/redis.conf
    
  3. 停止 Redis 服务
    /etc/init.d/redis-server stop
    # 或杀进程
    # 或 /usr/loacal/redis/bin/redis-cli shutdown
    
  4. 配置文件
    /etc/profile