标签:通知 net connect increase roo run nbsp 包括 sed
安装完redis后,修改几个redis从节点的配置文件redis.conf,主要是加入主节点位置
slaveof 192.168.0.104 6379
另外需要修改的地方包括,这样允许其他的从节点连入
bind 0.0.0.0 protected-mode no
启动redis主节点和从节点
./redis-server redis.conf
查看主节点信息
./redis-cli -h 192.168.0.108 info Replication # Replication role:master connected_slaves:1 slave0:ip=192.168.0.104,port=6379,state=online,offset=169,lag=1 master_repl_offset:169 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:2 repl_backlog_histlen:168
而在192.168.0104上查看信息,看到一方面作为192.168.0.108的从节点,另外192.168.0.107从192.168.0.104上复制数据.
[root@redisserver bin]# ./redis-cli -h 192.168.0.104 info Replication # Replication role:slave master_host:192.168.0.108 master_port:6379 master_link_status:up master_last_io_seconds_ago:10 master_sync_in_progress:0 slave_repl_offset:281 slave_priority:100 slave_read_only:1 connected_slaves:1 slave0:ip=192.168.0.107,port=6379,state=online,offset=14848,lag=0 master_repl_offset:14848 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:2 repl_backlog_histlen:14847
在192.168.0.107上的信息
./redis-cli -h 192.168.0.107 info Replication # Replication role:slave master_host:192.168.0.104 master_port:6379 master_link_status:up master_last_io_seconds_ago:1 master_sync_in_progress:0 slave_repl_offset:25426 slave_priority:100 slave_read_only:1 connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
启动Redis-sentinel哨兵服务
Redis 的 Sentinel 系统用于管理多个 Redis 服务器(instance), 该系统执行以下三个任务:
Redis Sentinel 是一个分布式系统, 你可以在一个架构中运行多个 Sentinel 进程(progress), 这些进程使用流言协议(gossip protocols)来接收关于主服务器是否下线的信息, 并使用投票协议(agreement protocols)来决定是否执行自动故障迁移, 以及选择哪个从服务器作为新的主服务器。
虽然 Redis Sentinel 释出为一个单独的可执行文件 redis-sentinel , 但实际上它只是一个运行在特殊模式下的 Redis 服务器, 你可以在启动一个普通 Redis 服务器时通过给定 –sentinel 选项来启动 Redis Sentinel 。
在192.168.0.107上编辑一个sentinel.conf配置文件
sentinel monitor redisslave2 192.168.0.108 6379 1
意思是监听主节点redisslave1主机名,ip为192.168.0.107 6379,主实例判断为失效至少需要1个 Sentinel进程的同意.
启动sentinel进程
./redis-sentinel sentinel.conf
[root@redisslave1 bin]# ./redis-sentinel ../etc/sentinel.conf
31843:X 19 Jul 09:14:59.356 * Increased maximum number of open files to 10032 (it was originally set to 1024).
_._
_.-``__ ‘‘-._
_.-`` `. `_. ‘‘-._ Redis 3.2.9 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ‘‘-._
( ‘ , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|‘` _.-‘| Port: 26379
| `-._ `._ / _.-‘ | PID: 31843
`-._ `-._ `-./ _.-‘ _.-‘
|`-._`-._ `-.__.-‘ _.-‘_.-‘|
| `-._`-._ _.-‘_.-‘ | http://redis.io
`-._ `-._`-.__.-‘_.-‘ _.-‘
|`-._`-._ `-.__.-‘ _.-‘_.-‘|
| `-._`-._ _.-‘_.-‘ |
`-._ `-._`-.__.-‘_.-‘ _.-‘
`-._ `-.__.-‘ _.-‘
`-._ _.-‘
`-.__.-‘
31843:X 19 Jul 09:14:59.360 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
31843:X 19 Jul 09:14:59.369 # Sentinel ID is a29b3e6df6406c2870301cb39db0de5fc9bcf884
31843:X 19 Jul 09:14:59.369 # +monitor master redisslave2 192.168.0.108 6379 quorum 1
31843:X 19 Jul 09:14:59.371 * +slave slave 192.168.0.104:6379 192.168.0.104 6379 @ redisslave2 192.168.0.108 6379
将192.168.0.108的master停掉,发现sentinel输出为
31843:X 19 Jul 09:16:41.307 # +sdown master redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.307 # +odown master redisslave2 192.168.0.108 6379 #quorum 1/1 31843:X 19 Jul 09:16:41.307 # +new-epoch 1 31843:X 19 Jul 09:16:41.307 # +try-failover master redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.314 # +vote-for-leader a29b3e6df6406c2870301cb39db0de5fc9bcf884 1 31843:X 19 Jul 09:16:41.314 # +elected-leader master redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.314 # +failover-state-select-slave master redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.367 # +selected-slave slave 192.168.0.104:6379 192.168.0.104 6379 @ redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.367 * +failover-state-send-slaveof-noone slave 192.168.0.104:6379 192.168.0.104 6379 @ redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.468 * +failover-state-wait-promotion slave 192.168.0.104:6379 192.168.0.104 6379 @ redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.684 # +promoted-slave slave 192.168.0.104:6379 192.168.0.104 6379 @ redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.685 # +failover-state-reconf-slaves master redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.770 # +failover-end master redisslave2 192.168.0.108 6379 31843:X 19 Jul 09:16:41.770 # +switch-master redisslave2 192.168.0.108 6379 192.168.0.104 6379 31843:X 19 Jul 09:16:41.771 * +slave slave 192.168.0.108:6379 192.168.0.108 6379 @ redisslave2 192.168.0.104 6379 31843:X 19 Jul 09:16:42.190 * +slave slave 192.168.0.107:6379 192.168.0.107 6379 @ redisslave2 192.168.0.104 6379
+switch-master redisslave2 192.168.0.108 6379 192.168.0.104 6379表示已经切换到192.168.0.104号节点.
[root@redisserver bin]# ./redis-cli -h 192.168.0.104 info Replication # Replication role:master connected_slaves:1 slave0:ip=192.168.0.107,port=6379,state=online,offset=82001,lag=1 master_repl_offset:82001 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:2 repl_backlog_histlen:82000
而当192.168.0.108重新启动后已经变成从节点,集群切换完成。
[root@redisslave2 bin]# ./redis-cli -h 192.168.0.108 info Replication # Replication role:slave master_host:192.168.0.104 master_port:6379 master_link_status:up master_last_io_seconds_ago:2 master_sync_in_progress:0 slave_repl_offset:89076 slave_priority:100 slave_read_only:1 connected_slaves:0 master_repl_offset:0 repl_backlog_active:0 repl_backlog_size:1048576 repl_backlog_first_byte_offset:0 repl_backlog_histlen:0
标签:通知 net connect increase roo run nbsp 包括 sed
原文地址:http://www.cnblogs.com/ericnie/p/7203950.html