首页 > 数据库 >Redis哨兵部署

Redis哨兵部署

时间:2024-08-27 14:05:26浏览次数:11  
标签:no 部署 Redis redis 192.168 哨兵 max sentinel yes

机器列表:

主节点 192.168.232.8:7000/27000

从节点 192.168.232.9:8000/28000, 9000/29000

 

redis的程序编译安装见单实例安装文档

 

主节点操作步骤:

groupadd redis && useradd -r -g redis redis

mkdir -p /data/redis-sentinel/7000

配置文件 redis.conf、sentinel.conf

cat /data/redis-sentinel/7000/redis.conf

redis.conf  展开源码
bind 0.0.0.0 -::1
protected-mode yes
port 7000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
pidfile /data/redis-sentinel/7000/redis_6379.pid
loglevel notice
logfile "/data/redis-sentinel/7000/redis.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /data/redis-sentinel/7000/
masterauth evoc
replica-serve-stale-data yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
requirepass evoc
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes

  

 

cat /data/redis-sentinel/7000/sentinel.conf

sentinel.conf  展开源码
bind 0.0.0.0
port 27000
daemonize yes
pidfile "/data/redis-sentinel/7000/redis-sentinel.pid"
logfile "/data/redis-sentinel/7000/redis-sentinel.log"
dir "/data/redis-sentinel/7000"
sentinel monitor mymaster 192.168.232.8 7000 2
sentinel auth-pass mymaster evoc
acllog-max-len 128
requirepass "evoc"
sentinel deny-scripts-reconfig yes
sentinel resolve-hostnames no
sentinel announce-hostnames no
protected-mode no
user default on #63f501f44249a5681b9b1c84e4a84a333401fdd3985d701824aa0ee06f68b22f ~* &* +@all
sentinel myid c1ed6365cf13b444d519e110f56e995af61273b7
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
sentinel known-replica mymaster 192.168.232.9 8000
sentinel known-replica mymaster 192.168.232.9 9000
sentinel known-sentinel mymaster 192.168.232.9 28000 5719a02f283307e66b804c8da510a5095d0bfc64
sentinel known-sentinel mymaster 192.168.232.9 29000 8299c5979c6fefcbb8036fa25b83bb2c844af2e4

  

 

从节点操作步骤:

groupadd redis && useradd -r -g redis redis

mkdir -p /data/redis-sentinel/{8000,9000}

配置文件 redis.conf、sentinel.conf

cat /data/redis-sentinel/8000/redis.conf

redis.conf  展开源码 bind 0.0.0.0 -::1 protected-mode yes port 8000 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize no pidfile /usr/local/soft/redis-sentinel/8000/redis_8000.pid loglevel notice logfile "/usr/local/soft/redis-sentinel/8000/redis.log" databases 16 always-show-logo no set-proc-title yes proc-title-template "{title} {listen-addr} {server-mode}" stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb rdb-del-sync-files no dir /usr/local/soft/redis-sentinel/8000 replica-serve-stale-data yes repl-diskless-sync no repl-diskless-sync-delay 5 repl-diskless-load disabled repl-disable-tcp-nodelay no replica-priority 100 acllog-max-len 128 requirepass evoc replicaof 192.168.232.8 7000 masterauth evoc replica-priority 100 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no lazyfree-lazy-user-del no lazyfree-lazy-user-flush no oom-score-adj no oom-score-adj-values 0 200 800 disable-thp yes appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble yes lua-time-limit 5000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 stream-node-max-bytes 4096 stream-node-max-entries 100 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit replica 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 dynamic-hz yes aof-rewrite-incremental-fsync yes rdb-save-incremental-fsync yes jemalloc-bg-thread yes

  

 

cat /data/redis-sentinel/8000/sentinel.conf

sentinel.conf  展开源码
bind 0.0.0.0
port 28000
daemonize yes
pidfile "/usr/local/soft/redis-sentinel/8000/redis-sentinel.pid"
logfile "/usr/local/soft/redis-sentinel/8000/redis-sentinel.log"
dir "/usr/local/soft/redis-sentinel/8000"
sentinel monitor mymaster 192.168.232.8 7000 2
sentinel auth-pass mymaster evoc
acllog-max-len 128
requirepass "evoc"
sentinel deny-scripts-reconfig yes
sentinel resolve-hostnames no
sentinel announce-hostnames no
protected-mode no
user default on #63f501f44249a5681b9b1c84e4a84a333401fdd3985d701824aa0ee06f68b22f ~* &* +@all
sentinel myid 5719a02f283307e66b804c8da510a5095d0bfc64
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
sentinel known-replica mymaster 192.168.232.9 8000
sentinel known-replica mymaster 192.168.232.9 9000
sentinel known-sentinel mymaster 192.168.232.8 27000 c1ed6365cf13b444d519e110f56e995af61273b7
sentinel known-sentinel mymaster 192.168.232.9 29000 8299c5979c6fefcbb8036fa25b83bb2c844af2e4

  

 

cat /data/redis-sentinel/9000/redis.conf

redis.conf  展开源码
bind 0.0.0.0 -::1
protected-mode yes
port 9000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
pidfile /usr/local/soft/redis-sentinel/9000/redis_9000.pid
loglevel notice
logfile "/usr/local/soft/redis-sentinel/9000/redis.log"
databases 16
always-show-logo no
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
rdb-del-sync-files no
dir /usr/local/soft/redis-sentinel/9000
replica-serve-stale-data yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
requirepass evoc
replicaof 192.168.232.8 7000
masterauth evoc
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes

  

 

cat /data/redis-sentinel/9000/

sentinel.conf  展开源码

 

bind 0.0.0.0
port 29000
daemonize yes
pidfile "/usr/local/soft/redis-sentinel/9000/redis-sentinel.pid"
logfile "/usr/local/soft/redis-sentinel/9000/redis-sentinel.log"
dir "/usr/local/soft/redis-sentinel/9000"
sentinel monitor mymaster 192.168.232.8 7000 2
sentinel auth-pass mymaster evoc
acllog-max-len 128
requirepass "evoc"
sentinel deny-scripts-reconfig yes
sentinel resolve-hostnames no
sentinel announce-hostnames no
protected-mode no
user default on #63f501f44249a5681b9b1c84e4a84a333401fdd3985d701824aa0ee06f68b22f ~* &* +@all
sentinel myid 8299c5979c6fefcbb8036fa25b83bb2c844af2e4
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel current-epoch 0
sentinel known-replica mymaster 192.168.232.9 8000
sentinel known-replica mymaster 192.168.232.9 9000
sentinel known-sentinel mymaster 192.168.232.8 27000 c1ed6365cf13b444d519e110f56e995af61273b7
sentinel known-sentinel mymaster 192.168.232.9 28000 5719a02f283307e66b804c8da510a5095d0bfc64

  

redis相关的文件和目录改权限

chown -R redis.redis redis-sentinel/

主节点和从节点启动进程

主节点redis启动:

su - redis -c "/usr/local/bin/redis-server /data/redis-sentinel/7000/redis.conf &"

 

从节点redis启动:

su - redis -c "/usr/local/redis/bin/redis-server /usr/local/soft/redis-sentinel/8000/redis.conf &"

su - redis -c "/usr/local/redis/bin/redis-server /usr/local/soft/redis-sentinel/9000/redis.conf &"

 

主节点sentinel进程启动:

su - redis -c "/usr/local/bin/redis-sentinel /data/redis-sentinel/7000/sentinel.conf --sentinel &"

从节点sentinel进程启动:

su - redis -c "/usr/local/redis/bin/redis-sentinel /usr/local/soft/redis-sentinel/8000/sentinel.conf --sentinel &"

su - redis -c "/usr/local/redis/bin/redis-sentinel /usr/local/soft/redis-sentinel/9000/sentinel.conf --sentinel &"

 

登陆:

./bin/redis-cli -h 192.168.232.8 -p 7000 -a xxx

查看集群信息:

192.168.232.8:7000> info replication

# Replication

role:master

connected_slaves:2

slave0:ip=192.168.232.9,port=9000,state=online,offset=465060,lag=1

slave1:ip=192.168.232.9,port=8000,state=online,offset=465201,lag=0

master_failover_state:no-failover

master_replid:343e48473bd25170fbfe88eab881153b780657aa

master_replid2:0000000000000000000000000000000000000000

master_repl_offset:465215

second_repl_offset:-1

repl_backlog_active:1

repl_backlog_size:1048576

repl_backlog_first_byte_offset:1

repl_backlog_histlen:465215

查看哨兵:

root@evoc-R322N6:/usr/local# ./bin/redis-cli -h 192.168.232.8 -p 27000 -a xxx
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.232.8:27000> 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=192.168.232.8:7000,slaves=2,sentinels=3

 

关闭redis命令
./bin/redis-cli -h 192.168.232.8 -p 7000 -a testdb shutdown

./bin/redis-cli -h 192.168.232.9 -p 8000 -a xxx shutdown

./bin/redis-cli -h 192.168.232.9 -p 9000 -a xxx shutdown

关闭 sentinel 哨兵命令
./bin/redis-cli -h 192.168.232.8 -p 27000 -a xxx shutdown

./bin/redis-cli -h 192.168.232.9 -p 28000 -a xxx shutdown

./bin/redis-cli -h 192.168.232.9 -p 29000 -a xxx shutdown

标签:no,部署,Redis,redis,192.168,哨兵,max,sentinel,yes
From: https://www.cnblogs.com/hmysql/p/18382580

相关文章