centos7安装redis5

一、下载包

[root@iZ2ze6bgt1xmvd4jc0v7nmZ src]# wget http://download.redis.io/releases/redis-5.0.3.tar.gz

二、解压

[root@iZ2ze6bgt1xmvd4jc0v7nmZ src]# tar -zxvf redis-5.0.3.tar.gz  

三、进入源码目录,并编译

make &&  make install PREFIX=/usr/local/redis

四、运行

[root@iZ2ze6bgt1xmvd4jc0v7nmZ bin]# cd /usr/local/redis/bin/
[root@iZ2ze6bgt1xmvd4jc0v7nmZ bin]# ./redis-server 
7138:C 06 Apr 2021 14:19:46.160 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7138:C 06 Apr 2021 14:19:46.160 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=7138, just started
7138:C 06 Apr 2021 14:19:46.160 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 5.0.3 (00000000/0) 64 bit
  .-`` .-```.  ```/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 7138
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

7138:M 06 Apr 2021 14:19:46.161 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7138:M 06 Apr 2021 14:19:46.161 # Server initialized
7138:M 06 Apr 2021 14:19:46.161 # 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.
7138:M 06 Apr 2021 14:19:46.161 # 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.
7138:M 06 Apr 2021 14:19:46.162 * DB loaded from disk: 0.000 seconds
7138:M 06 Apr 2021 14:19:46.162 * Ready to accept connections

成功后,退出

五、建立/etc/redis目录,用于存放redis配置文件

[root@iZ2ze6bgt1xmvd4jc0v7nmZ bin]# mkdir /etc/redis

将源码目录下的redis.conf文件复制到/etc/redis目录下

[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# cp /usr/local/src/redis-5.0.3/redis.conf /etc/redis/

六、修改配置文件,让服务后台启动

[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# vim /etc/redis/redis.conf 

搜索daemonize,将值no改为yes

daemonize yes

保存退出

七、指定配置文件启动redis

[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# /usr/local/redis/bin/redis-server /etc/redis/redis.conf 
7394:C 06 Apr 2021 14:26:35.455 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7394:C 06 Apr 2021 14:26:35.455 # Redis version=5.0.3, bits=64, commit=00000000, modified=0, pid=7394, just started
7394:C 06 Apr 2021 14:26:35.455 # Configuration loaded

八、设置开机自启动

新建 redis.service文件

[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# vim /etc/systemd/system/redis.service

添加如下内容

[Unit]
Description=redis-server
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/redis/bin/redis-server /etc/redis/redis.conf
PrivateTmp=true
[Install]
WantedBy=multi-user.target

保存退出

依次执行如下命令:

[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl daemon-reload
[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl start redis 
[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.

查询

[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl enable redis
Created symlink from /etc/systemd/system/multi-user.target.wants/redis.service to /etc/systemd/system/redis.service.
[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# systemctl list-unit-files|grep redis
redis.service                                 enabled 
[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# 

九、客户端连接数据库

首先设置软连接

[root@iZ2ze6bgt1xmvd4jc0v7nmZ redis-5.0.3]# ln -s /usr/local/redis/bin/redis-cli /usr/bin/

再连接数据库

[root@iZ2ze6bgt1xmvd4jc0v7nmZ home]# redis-cli 
127.0.0.1:6379>
原文地址:https://www.cnblogs.com/sky-cheng/p/14621836.html