环境
CentOS7.6

安装

下载、解压、编译Redis

$ wget http://download.redis.io/releases/redis-5.0.5.tar.gz
$ tar xzf redis-5.0.5.tar.gz
$ cd redis-5.0.5
$ make

进入到解压后的 src 目录,通过如下命令启动Redis:

$ src/redis-server

您可以使用内置的客户端与Redis进行交互:

$ src/redis-cli
redis> set foo bar
OK
redis> get foo
"bar"

说明与补充

下载

[root@VM_0_6_centos soft]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz

--2019-12-14 18:06:49--  http://download.redis.io/releases/redis-5.0.5.tar.gz
Resolving download.redis.io (download.redis.io)... 109.74.203.151
Connecting to download.redis.io (download.redis.io)|109.74.203.151|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 1975750 (1.9M) [application/x-gzip]
Saving to: ‘redis-5.0.5.tar.gz’

100%[=====================================================================>] 1,975,750   47.8KB/s   in 34s    

2019-12-14 18:07:25 (56.0 KB/s) - ‘redis-5.0.5.tar.gz’ saved [1975750/1975750]

[root@VM_0_6_centos soft]# ls
redis-5.0.5.tar.gz

解压

[root@VM_0_6_centos soft]# tar xzf redis-5.0.5.tar.gz
[root@VM_0_6_centos soft]# ls
redis-5.0.5  redis-5.0.5.tar.gz

编译

解压后( cd redis-5.0.5)进入redis目录编译(make),此过程时间稍长,耐心等待即可。

[root@VM_0_6_centos soft]# cd redis-5.0.5
[root@VM_0_6_centos redis-5.0.5]# ls
00-RELEASENOTES  COPYING  Makefile   redis.conf       runtest-moduleapi  src
BUGS             deps     MANIFESTO  runtest          runtest-sentinel   tests
CONTRIBUTING     INSTALL  README.md  runtest-cluster  sentinel.conf      utils
[root@VM_0_6_centos redis-5.0.5]# make

编译成功标志:

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

make[1]: Leaving directory `/var/soft/redis-5.0.5/src'
[root@VM_0_6_centos redis-5.0.5]# 

启动Redis

两种启动方式:
① src/redis-server
② ./redis-server &

第一种:前台启动。 src 目录下执行 redis-server 程序,redis 应用以前台的方式启动,不能退出当前窗口, 退出窗口,应用终止。

# 前台启动
[root@VM_0_6_centos redis-5.0.5]# src/redis-server

# 退出窗口,查看运行状态
[root@VM_0_6_centos redis-5.0.5]# ps -ef | grep redis
root     25002 18769  0 18:14 pts/0    00:00:00 grep --color=auto redis

第二种:后台启动。src目录下执行 ./redis-server & 此时关闭窗口,查看redis进程,依然存在(推荐)。

# 后台启动
[root@VM_0_6_centos redis-5.0.5]# cd src
[root@VM_0_6_centos src]# ./redis-server &

# 退出窗口,查看运行状态
[root@VM_0_6_centos src]# ps -ef | grep redis
root     25208 18769  0 18:16 pts/0    00:00:00 ./redis-server *:6379
root     25258 18769  0 18:16 pts/0    00:00:00 grep --color=auto redis

关闭 Redis

① 使用 redis 客户端关闭。

向服务器发出关闭命令,切换到redis-3.2.9/src/ 目录,执行 ./redis-cli shutdown,推荐使用这种方式, redis 先完成数据操作,然后再关闭。

[root@VM_0_6_centos src]# ./redis-cli shutdown
25208:M 14 Dec 2019 18:21:26.395 # User requested shutdown...
25208:M 14 Dec 2019 18:21:26.395 * Saving the final RDB snapshot before exiting.
25208:M 14 Dec 2019 18:21:26.405 * DB saved on disk
25208:M 14 Dec 2019 18:21:26.405 # Redis is now ready to exit, bye bye...
[1]+  Done                    ./redis-server

[root@VM_0_6_centos src]# ps -ef | grep redis
root     26054 18769  0 18:21 pts/0    00:00:00 grep --color=auto redis
[root@VM_0_6_centos src]# 

② kill pid 或者 kill -9 pid 方式关闭。

这种不会考虑当前应用是否有数据正在执行操作,直接就关闭应用。

先使用 ps -ef | grep redis 查出进程号, 在使用 kill pid。

[root@VM_0_6_centos src]# ps -ef | grep redis
root       421 18769  0 19:05 pts/0    00:00:00 ./redis-server *:6379
root       454 18769  0 19:05 pts/0    00:00:00 grep --color=auto redis

[root@VM_0_6_centos src]# kill 421
[root@VM_0_6_centos src]# 421:signal-handler (1576321600) Received SIGTERM scheduling shutdown...
421:M 14 Dec 2019 19:06:40.079 # User requested shutdown...
421:M 14 Dec 2019 19:06:40.079 * Saving the final RDB snapshot before exiting.
421:M 14 Dec 2019 19:06:40.086 * DB saved on disk
421:M 14 Dec 2019 19:06:40.086 # Redis is now ready to exit, bye bye...
^C
[1]+  Done                    ./redis-server

[root@VM_0_6_centos src]# ps -ef | grep redis
root       655 18769  0 19:06 pts/0    00:00:00 grep --color=auto redis
[root@VM_0_6_centos src]#

到此结束。