安装Redis
本次要求是哨兵集群版本
1.下载所需要版本包
[root@app-bj-ali-ecs1 ~]# wget http://download.redis.io/releases/redis-6.0.6.tar.gz [root@app-bj-ali-ecs1 ~]# tar xzf redis-6.0.6.tar.gz [root@app-bj-ali-ecs1 ~]# cd redis-6.0.6 [root@app-bj-ali-ecs1 ~]# make [root@app-bj-ali-ecs1 ~]# make install [root@app-bj-ali-ecs1 ~]# cd [root@app-bj-ali-ecs1 ~]# mv redis-6.0.6 /usr/local/redis [root@app-bj-ali-ecs1 ~]# cd /usr/local/redis/ [root@app-bj-ali-ecs1 redis]# src/redis-server # 可以正常启动,安装成功 58034:C 06 Dec 2024 18:18:34.236 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 58034:C 06 Dec 2024 18:18:34.236 # Redis version=6.0.6, bits=64, commit=00000000, modified=0, pid=58034, just started 58034:C 06 Dec 2024 18:18:34.236 # Warning: no config file specified, using the default config. In order to specify a config file use src/redis-server /path/to/redis.conf _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 6.0.6 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in standalone mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 6379 | `-._ `._ / _.-' | PID: 58034 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 58034:M 06 Dec 2024 18:18:34.237 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower valueof 128. 58034:M 06 Dec 2024 18:18:34.237 # Server initialized 58034:M 06 Dec 2024 18:18:34.237 # 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. 58034:M 06 Dec 2024 18:18:34.237 # 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. 58034:M 06 Dec 2024 18:18:34.237 * Ready to accept connections
2.实现主从集群
由于测试环境仅有一台机器,因此设置6379为主,6380、6381为从,即一主双从
[root@app-bj-ali-ecs1 redis]# vim conf/6379.conf daemonize yes masterauth 123456 min-replicas-to-write 1 min-replicas-max-lag 10 requirepass 123456 appendonly yes [root@app-bj-ali-ecs1 redis]# vim conf/6380.conf daemonize yes port 6380 # 修改端口 replicaof 172.18.169.29 6379 # 设置主信息 masterauth 123456 min-replicas-to-write 1 min-replicas-max-lag 10 requirepass 123456 appendonly yes [root@app-bj-ali-ecs1 redis]# vim conf/6381.conf daemonize yes port 6381 # 修改端口 replicaof 172.18.169.29 6379 # 设置主信息 masterauth 123456 min-replicas-to-write 1 min-replicas-max-lag 10 requirepass 123456 appendonly yes [root@app-bj-ali-ecs1 redis]# src/redis-server conf/6379.conf >> logs/6379.log & [root@app-bj-ali-ecs1 redis]# src/redis-server conf/6380.conf >> logs/6380.log & [root@app-bj-ali-ecs1 redis]# src/redis-server conf/6381.conf >> logs/6381.log & [root@app-bj-ali-ecs1 redis]# src/redis-cli -p 6379 -a 123456 Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. 127.0.0.1:6379> INFO replication # Replication role:master # 身份正常 connected_slaves:2 # 状态正常 min_slaves_good_slaves:2 slave0:ip=172.18.169.29,port=6380,state=online,offset=434,lag=0 # 从6380正常 slave1:ip=172.18.169.29,port=6381,state=online,offset=434,lag=1 # 从6381正常 master_replid:961eaeac79b010b491ea4f2ce75c123c91d1e5ff master_replid2:0000000000000000000000000000000000000000 master_repl_offset:448 second_repl_offset:-1 repl_backlog_active:1 repl_backlog_size:1048576 repl_backlog_first_byte_offset:1 repl_backlog_histlen:448
2.实现哨兵
哨兵至少需要三台,由于测试环境仅有一台机器,因此设置26379,26380、26381为不同实例进行实现
[root@app-bj-ali-ecs1 redis]# vim conf/26379.conf daemonize yes sentinel monitor mymaster 172.18.169.29 6379 2 # 改成自己的ip sentinel auth-pass mymaster 123456 [root@app-bj-ali-ecs1 redis]# vim conf/26380.conf daemonize yes port 26380 sentinel monitor mymaster 172.18.169.29 6379 2 sentinel auth-pass mymaster 123456 [root@app-bj-ali-ecs1 redis]# vim conf/26381.conf daemonize yes port 26381 sentinel monitor mymaster 172.18.169.29 6379 2 sentinel auth-pass mymaster 123456 [root@app-bj-ali-ecs1 redis]# src/redis-sentinel conf/26379.conf >> logs/26379.log & [root@app-bj-ali-ecs1 redis]# src/redis-sentinel conf/26380.conf >> logs/26380.log & [root@app-bj-ali-ecs1 redis]# src/redis-sentinel conf/26381.conf >> logs/26381.log & [root@app-bj-ali-ecs1 redis]# src/redis-cli -p 26379 127.0.0.1:26379> INFO Sentinel # Sentinel sentinel_masters:1 sentinel_tilt:0 sentinel_running_scripts:0 sentinel_scripts_queue_length:0 sentinel_simulate_failure_flags:0 master0:name=mymaster,status=ok,address=172.18.169.29:6379,slaves=2,sentinels=3 # 6379为主,两从,三个哨兵,状态正常
浙公网安备 33010602011771号