编译安装Redis

编译安装redis

下载源码包

下载当前最新release版本redis 源码包:http://download.redis.io/releases/
需要编译组件gcc 自行yum 装

#一般下载到 /usr/local/src
wget 或者下载完安装包放到上述目录
以5.0.3为例
####
pwd
# /usr/local/src
tar xf  redis-5.0.3.tar.gz
[root@centos7 src]#cd redis-5.0.3
[root@centos7 redis-5.0.3]# make PREFIX=/apps/redis install
[root@centos7 redis-5.0.3]# mkdir /apps/redis/{etc,logs,data,run} #创建配置文件、日志、数据等目录


[root@centos7 redis-5.0.3]# cp redis.conf /apps/redis/etc/
[root@centos7 redis-5.0.3]# sed -i 's@logfile ""@logfile "/apps/redis/logs/redis.log"@' /apps/redis/etc/redis.conf #替换原文件日志路径

编辑redis服务启动脚本
vim /usr/lib/systemd/system/redis.service

[Unit]
Description=Redis persistent key-value database
After=network.target
After=network-online.target
Wants=network-online.target
[Service]
#ExecStart=/usr/bin/redis-server /etc/redis.conf --supervised systemd
ExecStart=/apps/redis/bin/redis-server /apps/redis/etc/redis.conf  --supervised systemd
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
Type=notify
User=redis
Group=redis
RuntimeDirectory=redis
RuntimeDirectoryMode=0755
[Install]
WantedBy=multi-user.target

[root@centos7 redis-5.0.3]# systemctl daemon-reload 
[root@centos7 redis-5.0.3]# useradd -r redis -s /sbin/nologin
[root@centos7 redis-5.0.3]# chown -R redis.redis /apps/redis/
启动服务
[root@centos7 redis-5.0.3]# systemctl start redis
[root@centos7 redis-5.0.3]# ss -ntl
State       Recv-Q Send-Q                Local Address:Port                               Peer Address:Port              
LISTEN      0      511                       127.0.0.1:6379  #redis 端口号                                        *:*                  
LISTEN      0      128                               *:111                                           *:*                  
LISTEN      0      128                               *:6000                                          *:*                  
LISTEN      0      128                               *:22                                            *:*                  
LISTEN      0      128                       127.0.0.1:631                                           *:*                  
LISTEN      0      100                       127.0.0.1:25                                            *:*                  
LISTEN      0      128                              :::111                                          :::*        
[root@centos7 redis-5.0.3]# cat /apps/redis/logs/redis.log
16690:C 07 Feb 2020 20:09:33.769 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
16690:C 07 Feb 2020 20:09:33.769 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=16690, just started
16690:C 07 Feb 2020 20:09:33.769 # Configuration loaded
16690:C 07 Feb 2020 20:09:33.769 * supervised by systemd, will signal readiness
16690:M 07 Feb 2020 20:09:33.770 # You requested maxclients of 10000 requiring at least 10032 max file descriptors.
16690:M 07 Feb 2020 20:09:33.770 # Server can't set maximum open files to 10032 because of OS error: Operation not permitted. 
16690:M 07 Feb 2020 20:09:33.770 # Current maximum open files is 4096. maxclients has been reduced to 4064 to compensate for low ulimit. If you need higher maxclients increase 'ulimit -n'.
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 16690
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

16690:M 07 Feb 2020 20:09:33.771 # Server initialized
16690:M 07 Feb 2020 20:09:33.771 # 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. #不影响初次使用的错误
16690:M 07 Feb 2020 20:09:33.771 # 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.#不影响初次使用的错误
16690:M 07 Feb 2020 20:09:33.771 * Ready to accept connections

解决上述警告

第一个警告提示: redis 设置了 TCP backlog 的值为 511, 但是 linux 内核中当前值为 128,达不到 redis 要求

第二个警告提示: Linux 中内存申请方式需要重 0 修改为 1 ,确保 redis 可以申请更多的物理内容

#vim /etc/sysctl.conf  添加以下信息
net.core.somaxconn = 512
vm.overcommit_memory = 1
#syscctl -p #使文件生效

第三个警告提示: 关闭 Linux 的 transparent hugepage 功能,根据警告提示操作即可:

# [root@centos7 redis-5.0.3]# echo never > /sys/kernel/mm/transparent_hugepage/enabled
#[root@centos7 redis-5.0.3]# echo 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' >> /etc/rc.local
[root@centos7 redis-5.0.3]# chmod a+x /etc/rc.local 
创建命令软连接
[root@centos7 redis-5.0.3]# ln -sv /apps/redis/bin/redis-* /usr/bin/

‘/usr/bin/redis-benchmark’ -> ‘/apps/redis/bin/redis-benchmark’
‘/usr/bin/redis-check-aof’ -> ‘/apps/redis/bin/redis-check-aof’
‘/usr/bin/redis-check-rdb’ -> ‘/apps/redis/bin/redis-check-rdb’
‘/usr/bin/redis-cli’ -> ‘/apps/redis/bin/redis-cli’
‘/usr/bin/redis-sentinel’ -> ‘/apps/redis/bin/redis-sentinel’
‘/usr/bin/redis-server’ -> ‘/apps/redis/bin/redis-server’

重新启动

重启服务systemctl restart redis

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值