← 返回首页
CentOS7下安装Redis-5.0.3
发表时间:2019-11-22 11:59:35
讲解如何在CentOS7下安装redis

1.上传redis-5.0.3.tar.gz至/root/download

2.解压redis-5.0.3.tar.gz到/usr/local

tar -zxvf redis-5.0.3.tar.gz -C /usr/local

3.yum安装gcc依赖(如果已经安装了nginx,或者已经安装了gcc这一步可以跳过)

yum install gcc

4.跳转到redis解压目录下

cd /usr/local/redis-5.0.3

5.编译安装

make MALLOC=libc

cd src && make install

出现以下提示:
Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

6.直接启动redis

cd src
./redis-server

出现以下界面:
[root@iZwz991stxdwj560bfmadtZ src]# ./redis-server
18685:C 13 Dec 12:56:12.507 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
18685:C 13 Dec 12:56:12.507 # Redis version=4.0.6, bits=64, commit=00000000, modified=0, pid=18685, just started
18685:C 13 Dec 12:56:12.507 # Warning: no config file specified, using the default config. In order to specify a config file use ./redis-server /path/to/redis.conf
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.6 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 18685
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

18685:M 13 Dec 12:56:12.508 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
18685:M 13 Dec 12:56:12.508 # Server initialized
18685:M 13 Dec 12:56:12.508 # 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.
18685:M 13 Dec 12:56:12.508 # 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.
18685:M 13 Dec 12:56:12.508 * Ready to accept connections

如上图:redis启动成功,但是这种启动方式需要一直打开窗口,不能进行其他操作,不太方便。 按 ctrl + c可以关闭窗口。但是这样也同时关闭了redis服务。

7.开启远程连接

cd /usr/local/redis-5.0.3

vim redis.conf

修改以下配置:

bind 0.0.0.0

daemonize yes

/*设置redis的访问密码*/
requirepass abc12345 

8.重启服务,测试远程连接

ps -ef | grep redis

root     18835     1  0 11:49 ?        00:00:00 ./redis-server 0.0.0.0:6379
root     18908 18854  0 11:55 pts/1    00:00:00 grep --color=auto redis

kill 18835

cd /usr/local/redis-5.0.3/src

./redis-server ../redis.conf

9.连接redis

[root@master src]# ./redis-cli -h 192.168.128.128 -p 6379 -a abc12345
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.128.128:6379> 

10.停止redis数据库

[root@master redis]# redis-cli shutdown