Redis数据库安装

总结 Redis 缓存数据库的安装。

安装包下载

官网下载:http://download.redis.io/releases/redis-4.0.9.tar.gz

安装文档:https://redis.io/download#installation

安装Redis

Linux OS 版本:CentOS 7.x

> wget http://download.redis.io/releases/redis-4.0.9.tar.gz
> tar zxvf redis-4.0.9.tar.gz -C /usr/local/
> cd /usr/local/redis-4.0.9/
> make 
> make install

启动Redis服务

> [[email protected] redis-4.0.9]# ./src/redis-server 
10758:C 12 Jun 10:50:00.503 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
10758:C 12 Jun 10:50:00.503 # Redis version=4.0.9, bits=64, commit=00000000, modified=0, pid=10758, just started
10758:C 12 Jun 10:50:00.504 # Warning: no config file specified, using the default config. In order to specify a config file use ./src/redis-server /path/to/redis.conf
10758:M 12 Jun 10:50:00.505 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.9 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 10758
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

10758:M 12 Jun 10:50:00.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.
10758:M 12 Jun 10:50:00.508 # Server initialized
10758:M 12 Jun 10:50:00.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.
10758:M 12 Jun 10:50:00.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.
10758:M 12 Jun 10:50:00.509 * Ready to accept connections

查看服务监听地址

> ss -tnlp | grep redis
LISTEN     0      128          *:6379                     *:*                   users:(("redis-server",pid=10758,fd=7))
LISTEN     0      128         :::6379                    :::*                   users:(("redis-server",pid=10758,fd=6))

Redis配置文件

> vim redis.conf
# 更改Redis服务的监听地址为本机地址 
bind 127.0.0.1 10.68.7.21

重新启动服务:

# 先杀掉服务 
> kill -9 10758 
# 再次启动服务 
> ./src/redis-server

登录Redis数据库

第一次连接会报错:

> ./src/redis-cli -h 10.68.7.21
10.68.7.21:6379> info
DENIED Redis is running in protected mode because protected mode is enabled, no bind address was specified, no authentication password is requested to clients. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a bind address or an authentication password. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.

解决办法有三种:其中一种是启动服务时加上--protected-mode no选项

> ./src/redis-server --protected-mode no

然后再次登录数据库即可:

> ./src/redis-cli -h 10.68.7.21 
10.68.7.21:6379> info
# Server
redis_version:4.0.9
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:17bbb3e81ca62f4
redis_mode:standalone
os:Linux 3.10.0-514.el7.x86_64 x86_64
...

至此,Redis的安装已结束,具体操作使用,可以查阅Redis相关文档或书籍学习。

PREVIOUS全新博客站点上线啦
NEXTCentOS7安装MySQL5.7[ 二进制方式]