在CentOS 7上安装redis

1 下载:从Redis官方网站下载安装最新的稳定版安装包;

[root@localhost ~]# cat /etc/redhat-release 
CentOS Linux release 7.2.1511 (Core) 
[root@localhost ~]# uname -rm
3.10.0-327.el7.x86_64 x86_64
[root@localhost ~]# wget http://download.redis.io/releases/redis-4.0.2.tar.gz
--2017-11-22 14:32:03--  http://download.redis.io/releases/redis-4.0.2.tar.gz
正在解析主机 download.redis.io (download.redis.io)... 109.74.203.151
正在连接 download.redis.io (download.redis.io)|109.74.203.151|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1713990 (1.6M) [application/x-gzip]
正在保存至: “redis-4.0.2.tar.gz”

100%[===================================================================================================================================>] 1,713,990    890KB/s 用时 1.9s   

2017-11-22 14:32:09 (890 KB/s) - 已保存 “redis-4.0.2.tar.gz” [1713990/1713990])

[root@localhost ~]#

2 解压:解压安装包;

[root@localhost ~]# tar -zxvf redis-4.0.2.tar.gz 
...
...
redis-4.0.2/utils/releasetools/02_upload_tarball.sh
redis-4.0.2/utils/releasetools/03_test_release.sh
redis-4.0.2/utils/releasetools/04_release_hash.sh
redis-4.0.2/utils/releasetools/changelog.tcl
redis-4.0.2/utils/speed-regression.tcl
redis-4.0.2/utils/whatisdoing.sh
[root@localhost ~]#

3 编译:进入安装包,执行make;

 [root@localhost ~]# cd redis-4.0.2
[root@localhost redis-4.0.2]# pwd
/root/redis-4.0.2
[root@localhost redis-4.0.2]# ll
总用量 280
-rw-rw-r--  1 root root 131381 9月  21 22:12 00-RELEASENOTES
-rw-rw-r--  1 root root     53 9月  21 22:12 BUGS
-rw-rw-r--  1 root root   1815 9月  21 22:12 CONTRIBUTING
-rw-rw-r--  1 root root   1487 9月  21 22:12 COPYING
drwxrwxr-x  6 root root   4096 9月  21 22:12 deps
-rw-rw-r--  1 root root     11 9月  21 22:12 INSTALL
-rw-rw-r--  1 root root    151 9月  21 22:12 Makefile
-rw-rw-r--  1 root root   4223 9月  21 22:12 MANIFESTO
-rw-rw-r--  1 root root  20530 9月  21 22:12 README.md
-rw-rw-r--  1 root root  57764 9月  21 22:12 redis.conf
-rwxrwxr-x  1 root root    271 9月  21 22:12 runtest
-rwxrwxr-x  1 root root    280 9月  21 22:12 runtest-cluster
-rwxrwxr-x  1 root root    281 9月  21 22:12 runtest-sentinel
-rw-rw-r--  1 root root   7606 9月  21 22:12 sentinel.conf
drwxrwxr-x  3 root root   4096 9月  21 22:12 src
drwxrwxr-x 10 root root   4096 9月  21 22:12 tests
drwxrwxr-x  8 root root   4096 9月  21 22:12 utils
[root@localhost redis-4.0.2]# make 
cd src && make all
make[1]: 进入目录“/root/redis-4.0.2/src”
    CC Makefile.dep
make[1]: 离开目录“/root/redis-4.0.2/src”
make[1]: 进入目录“/root/redis-4.0.2/src”
...
...
    INSTALL redis-check-rdb
    INSTALL redis-check-aof

Hint: It's a good idea to run 'make test' ;)

make[1]: 离开目录“/root/redis-4.0.2/src”
[root@localhost redis-4.0.2]#

4 启动Redis;

 [root@localhost redis-4.0.2]# /root/redis-4.0.2/src/redis-server 
1745:C 22 Nov 14:39:22.049 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1745:C 22 Nov 14:39:22.049 # Redis version=4.0.2, bits=64, commit=00000000, modified=0, pid=1745, just started
1745:C 22 Nov 14:39:22.049 # Warning: no config file specified, using the default config. In order to specify a config file use /root/redis-4.0.2/src/redis-server /path/to/redis.conf
1745:M 22 Nov 14:39:22.051 * Increased maximum number of open files to 10032 (it was originally set to 1024).
                _._                                                  
           _.-``__ ''-._                                             
      _.-``    `.  `_.  ''-._           Redis 4.0.2 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._                                   
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 1745
  `-._    `-._  `-./  _.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |           http://redis.io        
  `-._    `-._`-.__.-'_.-'    _.-'                                   
 |`-._`-._    `-.__.-'    _.-'_.-'|                                  
 |    `-._`-._        _.-'_.-'    |                                  
  `-._    `-._`-.__.-'_.-'    _.-'                                   
      `-._    `-.__.-'    _.-'                                       
          `-._        _.-'                                           
              `-.__.-'                                               

1745:M 22 Nov 14:39:22.052 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
1745:M 22 Nov 14:39:22.052 # Server initialized
1745:M 22 Nov 14:39:22.052 # 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.
1745:M 22 Nov 14:39:22.052 # 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.
1745:M 22 Nov 14:39:22.052 * Ready to accept connections

 

 

至此,Redis已经安装完毕。

5 通过redis-cli,访问和使用Redis:

 [root@localhost ~]# /root/redis-4.0.2/src/redis-cli 
127.0.0.1:6379> info
# Server
redis_version:4.0.2
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:1e096713e5234ce6
redis_mode:standalone
os:Linux 3.10.0-327.el7.x86_64 x86_64
...
....
127.0.0.1:6379> set a testredis
OK
127.0.0.1:6379> get a
"testredis"
127.0.0.1:6379>

 

接着看文档,继续动手实践。