Centos 7 安装 Redis 5

Posted 雨vs枫

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Centos 7 安装 Redis 5相关的知识,希望对你有一定的参考价值。

  1. 解压安装包

    # tar zxvf redis-5.0.9.tar.gz
    
  2. 重命名并移动文件夹

    # mv redis-5.0.9 redis
    # mv redis /usr/local/src/redis
    
  3. 安装redis

    # cd /usr/local/src/redis/
    # make PREFIX=/usr/local/redis install
    

    如果由于malloc报错,则使用make MALLOC=libc PREFIX=/usr/local/redis install

  4. 复制redis.conf到安装目录

    # cp redis.conf /usr/local/redis/6379.conf
    
  5. 修改6379.conf

    将daemonize设置为yes
    requirepass配置去掉注释并设置密码
    dir /Disk/data/redis/6379
    pidfile /Disk/data/redis/redis_6379.pid
    logfile “/Disk/logs/redis/6379.log”
    appendonly yes
    appendfsync everysec
    no-appendfsync-on-rewrite no
    auto-aof-rewrite-percentage 100 
    auto-aof-rewrite-min-size 64mb
    aof-load-truncated yes
    
  6. 创建redis存储目录和日志目录

    # mkdir -p /Disk/data/redis/6379
    # mkdir -p /Disk/logs/redis
    
  7. 将redis配置成服务-centos7

    # 添加服务配置文件
    # vim /etc/systemd/system/redis-server.service
    文件内容如下:
    [Unit]
    Description=Redis6379 Server
    After=syslog.target network.target
    
    [Service]
    Type=forking
    PIDFile=/Disk/data/redis/redis_6379.pid
    ExecStart=/usr/local/redis/bin/redis-server /usr/local/redis/6379.conf
    ExecStop=/bin/kill -SIGINT $MAINPID
    
    [Install]
    WantedBy=multi-user.target
    
    # 保存并退出
    # 重新加载系统服务
    # systemctl daemon-reload
    # 启动服务
    # systemctl start redis-server.service
    # 服务开机启动
    # systemctl enable redis-server.service
    
  8. 直接使用redis-server启动会出现警告,解决方案如下:

    警告一:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128

    警告二:WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1‘ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1‘ for this to take effect.

    警告一、警告二解决方案,修改/etc/sysctl.conf文件,在文件末尾加入以下两句:

    net.core.somaxconn=1024
    vm.overcommit_memory=1
    

    然后使用sysctl -p,使配置生效

    警告三:WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled‘ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.

    警告三解决方案,执行如下命令(重启后丢失,当前生效):

    # echo never > /sys/kernel/mm/transparent_hugepage/enabled
    

    将以上命令写入/etc/rc.local,重启后不会丢失

以上是关于Centos 7 安装 Redis 5的主要内容,如果未能解决你的问题,请参考以下文章

Centos 7 安装 Redis 5

CentOS 7.6安装 Redis-6.2.5

CentOS 7 安装redis 5.X

CentOS 7 安装Redis

redis 5.0.7 centos6.8 安装

案例: centos7 安装redis集群 版本5.0.7