今天看啥  ›  专栏  ›  radish.-

编译安装Redis

radish.-  · CSDN  ·  · 2020-02-08 10:17

编译安装redis

下载源码包

下载当前最新release版本redis 源码包:http://download.redis.io/releases/

#一般下载到 /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 #替换原文件日志路径

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

编辑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/
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23

启动服务

[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                                          :::*        
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
[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

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31

解决上述警告

第一个警告提示: 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 #使文件生效
  • 1
  • 2
  • 3
  • 4

第三个警告提示: 关闭 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 
  • 1
  • 2
  • 3

创建命令软连接

[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’

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

重新启动

重启服务 systemctl restart redis




原文地址:访问原文地址
快照地址: 访问文章快照