Redis在CentOS环境下安装

本文档详细介绍了如何在CentOS7.6系统上安装Redis,包括从官方下载最新安装包,解压并解决安装过程中可能遇到的问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在CentOS7.6下安装 Redis

1,下载最新的安装包

​ http://download.redis.io/releases/

2,解压安装包

 #1,下载安装包
 wget http://download.redis.io/releases/redis-6.2.1.tar.gz 
 #2,解压安装包
 tar -zxvf redis-6.2.1.tar.gz
 #3,移动解压文件到指定目录
 mv redis-6.2.1 /usr/local/src/redis-6.2.1
 #4.1,进入到redis目录,然后通过make命令进行编译。
 cd /usr/local/src/redis-6.2.1
 make MALLOC=libc
 #4.2 安装 
 make install PREFIX=/usr/loca/redis-6.2.1
 #5.拷贝配置文件到安装后目录
 cp /usr/local/src/redis-6.2.1/redis.conf /usr/local/redis-6.2.1/redis.conf
 #6.修改配置redis.conf文件
    bind 127.0.0.1::1 改为 bind 127.0.0.1
    #设置密码
    requirepass XXXX
 #7,测试是否可以启动
   ./usr/local/redis-6.2.1/bin/redis-server ./usr/local/redis-6.2.1/redis.conf
 #8, 设置开机启动
   #8.1 使用root权限创建redis文件目录
   sudo gropdadd redis
   sudo useradd -g redis redis --no-create-home
   sudo chown -R redis:redis /usr/local/redis-6.2.1
   #8.2 编辑配置文件redis.conf,将daemonize 改为yes支持后台运行
   #8.3 添加开机启动服务
   vim /etc/systemd/system/redis-server.service
   #8.3.1 添加如下内容
    [Unit]
    Description=Redis Server Manager
    After=syslog.target
    After=network.target

    [Service]
    Type=simple
    User=redis
    Group=redis
    PIDFile=/var/run/redis_6379.pid
    ExecStart=/usr/local/redis-6.2.1/bin/redis-server /usr/local/redis-6.2.1/redis-6379.conf
    ExecStop=/usr/local/redis-6.2.1/bin/redis-cli shutdown
    Restart=always

    [Install]
    WantedBy=multi-user.target
  
   # wq!保存
   #8.3.2 设置为开机启动
    systemctl daemon-reload 
    systemctl start redis-server.service 
    systemctl enable redis-server.service
    
    #8.3.3 创建redis-cli软连接
    ln -s /usr/local/redis-6.2.1/bin/redis-cli /usr/bin/redis-cli
    
 
 #退出redis服务: 
(1)pkill redis-server 
(2)kill 进程号                     
(3)/usr/local/redis-6.2.1/bin/redis-cli shutdown 

遇到文件及解决方案

第一个警告:The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
第二个警告: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=1for this to take effect.
第三个警告:you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix thisissue 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 thesetting after a reboot. Redis must be restarted after THP is disabled.
-------------------------------------------------------------------------------------------------------
解决方案
考虑到redis一般都是部署在服务器上作为服务存在的。所以,本文的解决方案都是持久性配置,不是临时配置。

第一个警告
将net.core.somaxconn = 1024添加到/etc/sysctl.conf中,然后执行sysctl -p生效配置。

第二个警告
将vm.overcommit_memory = 1添加到/etc/sysctl.conf中,然后执行sysctl -p生效配置。

第三个警告
将echo never > /sys/kernel/mm/transparent_hugepage/enabled添加到/etc/rc.local中,然后执行source /etc/rc.local生效配置
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值