CentOS 下载:http://mirrors.aliyun.com/centos/
Redis:http://download.redis.io/releases/
CentOS 1908 配置 Redis 5.0.7 集群 一(单节点)
CentOS 1908 配置 Redis 5.0.7 集群 三(哨兵模式)
- 在 Redis 文件夹中,复制一份 redis.conf:
[root@192 redis-5.0.7]# cp redis.conf redis6380.conf
- 修改 redis6380.conf
vim redis6380.conf
# 修改端口为 6380 port 6380 # 增加该 Redis 的主节点为 127.0.0.1 6379 slaveof 127.0.0.1 6379
- 先后启动 Redis 6379、6380:
两个 Redis 启动后,显示如下:src/redis-server redis.conf src/redis-server redis6380.conf
- 6379:
可以看到 6379 与 子节点 6380 同步成功:[root@192 redis-5.0.7]# src/redis-server redis.conf 57722:C 13 Jan 2020 21:56:29.198 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 57722:C 13 Jan 2020 21:56:29.198 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=57722, just started 57722:C 13 Jan 2020 21:56:29.198 # Configuration loaded 57722:M 13 Jan 2020 21:56:29.199 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 57722 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 57722:M 13 Jan 2020 21:56:29.200 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 57722:M 13 Jan 2020 21:56:29.200 # Server initialized 57722:M 13 Jan 2020 21:56:29.200 # 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. 57722:M 13 Jan 2020 21:56:29.200 # 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. 57722:M 13 Jan 2020 21:56:29.201 * DB loaded from disk: 0.000 seconds 57722:M 13 Jan 2020 21:56:29.201 * Ready to accept connections 57722:M 13 Jan 2020 21:56:49.506 * Replica 127.0.0.1:6380 asks for synchronization 57722:M 13 Jan 2020 21:56:49.506 * Full resync requested by replica 127.0.0.1:6380 57722:M 13 Jan 2020 21:56:49.506 * Starting BGSAVE for SYNC with target: disk 57722:M 13 Jan 2020 21:56:49.506 * Background saving started by pid 57735 57735:C 13 Jan 2020 21:56:49.507 * DB saved on disk 57735:C 13 Jan 2020 21:56:49.508 * RDB: 0 MB of memory used by copy-on-write 57722:M 13 Jan 2020 21:56:49.539 * Background saving terminated with success 57722:M 13 Jan 2020 21:56:49.539 * Synchronization with replica 127.0.0.1:6380 succeeded
- 6380:
可以看到 6380 与 主节点同步成功:[root@192 redis-5.0.7]# src/redis-server redis6380.conf 57731:C 13 Jan 2020 21:56:49.503 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 57731:C 13 Jan 2020 21:56:49.503 # Redis version=5.0.7, bits=64, commit=00000000, modified=0, pid=57731, just started 57731:C 13 Jan 2020 21:56:49.503 # Configuration loaded 57731:S 13 Jan 2020 21:56:49.504 * Increased maximum number of open files to 10032 (it was originally set to 1024). _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.7 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6380 | `-._ `._ / _.-' | PID: 57731 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 57731:S 13 Jan 2020 21:56:49.505 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 57731:S 13 Jan 2020 21:56:49.505 # Server initialized 57731:S 13 Jan 2020 21:56:49.505 # 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. 57731:S 13 Jan 2020 21:56:49.505 # 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. 57731:S 13 Jan 2020 21:56:49.505 * DB loaded from disk: 0.000 seconds 57731:S 13 Jan 2020 21:56:49.505 * Ready to accept connections 57731:S 13 Jan 2020 21:56:49.505 * Connecting to MASTER 127.0.0.1:6379 57731:S 13 Jan 2020 21:56:49.505 * MASTER <-> REPLICA sync started 57731:S 13 Jan 2020 21:56:49.505 * Non blocking connect for SYNC fired the event. 57731:S 13 Jan 2020 21:56:49.505 * Master replied to PING, replication can continue... 57731:S 13 Jan 2020 21:56:49.506 * Partial resynchronization not possible (no cached master) 57731:S 13 Jan 2020 21:56:49.506 * Full resync from master: d6f7735494d10e31c4add5adac1594a6fa22d789:0 57731:S 13 Jan 2020 21:56:49.539 * MASTER <-> REPLICA sync: receiving 198 bytes from master 57731:S 13 Jan 2020 21:56:49.539 * MASTER <-> REPLICA sync: Flushing old data 57731:S 13 Jan 2020 21:56:49.539 * MASTER <-> REPLICA sync: Loading DB in memory 57731:S 13 Jan 2020 21:56:49.539 * MASTER <-> REPLICA sync: Finished with success
- 6379:
- 远程连接(注意要打开 Redis 6380 端口),查看同步数据:
- 登录 Redis 主节点,查看节点信息:
[root@192 redis-5.0.7]# src/redis-cli -h 127.0.0.1 -p 6379 127.0.0.1:6379> INFO replication # Replication role:master connected_slaves:1 slave0:ip=127.0.0.1,port=6380,state=online,offset=518,lag=1 master_replid:814a9c1b4f0576a3a62b8ea0868d5fef19118de6 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:518 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:518 127.0.0.1:6379>
- 登录 Redis 子节点,查看节点信息:
[root@192 redis-5.0.7]# src/redis-cli -h 127.0.0.1 -p 6380 127.0.0.1:6380> info replication # Replication role:slave master_host:127.0.0.1 master_port:6379 master_link_status:up master_last_io_seconds_ago:0 master_sync_in_progress:0 slave_repl_offset:714 slave_priority:100 slave_read_only:1 connected_slaves:0 master_replid:814a9c1b4f0576a3a62b8ea0868d5fef19118de6 master_replid2:0000000000000000000000000000000000000000 master_repl_offset:714 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:714 127.0.0.1:6380>
- 远程连接需要开通端口80,参见:CentOS 1908 配置 Redis 5.0.7 集群 一(单节点)