写在前面的话:
对于redis来说,它有四种部署模式,分别是单机模式、主从模式、哨兵模式和集群模式,他们的使用场景有些区别,当然也是越来越复杂,可靠性越来越高。
本文从实际操作的角度,来介绍和讲解下,这几种模式的特点,鉴于篇幅的问题,文章分成两篇,一篇用来介绍:单机模式、主从模式和哨兵模式;另外一篇用来介绍:集群模式。
一、单机部署:
下面是单机部署的操作步骤。
// redis-server 没有启动的情况下,直接连接 redis-cli的结果
$ redis-cli -h 127.0.0.1 -p 6379
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
1.通过redis-server /usr/local/etc/redis.conf 启动默认的6379redis服务
// redis-server 服务启动
$ redis-server /usr/local/etc/redis.conf
5286:C 03 Nov 2020 18:35:17.905 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
5286:C 03 Nov 2020 18:35:17.905 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=5286, just started
5286:C 03 Nov 2020 18:35:17.905 # Configuration loaded
5286:M 03 Nov 2020 18:35:17.907 * Increased maximum number of open files to 10032 (it was originally set to 256).
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 5.0.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 5286
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | http://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
5286:M 03 Nov 2020 18:35:17.909 # Server initialized
5286:M 03 Nov 2020 18:35:17.909 * DB loaded from disk: 0.001 seconds
5286:M 03 Nov 2020 18:35:17.909 * Ready to accept connections
2.通过redis-cli去验证redis-server是否连接成功,下面对一些命令做了简要绍明
// redis-cli 启动成功
$ redis-cli -h 127.0.0.1 -p 6379
127.0.0.1:6379>
127.0.0.1:6379> ping // 检测连接是不是好的
PONG
127.0.0.1:6379> ping "hello the world" // 也可以发送指定消息
"hello the world"
127.0.0.1:6379>
127.0.0.1:6379> ping // 断开redis-server之后,ping的话就提示下面的错误
Could not connect to Redis at 127.0.0.1:6379: Connection refused
not connected>
not connected> ping // 此刻redis-server又被启动了起来
PONG
127