centos redis主従配置+哨兵モード

9935 ワード

centos redis主従配置+哨兵モード
   
顺店雑可が恋しい...
   
実行環境:
システム:centos 7.2,centos6.8
Redisバージョン:redis-4.0.6
Redis主従哨兵の紹介
プライマリRedisからデータを書き込む場合、RedisからRedis Syncメカニズムを通じてデータを同期し、データが一致することを確保します.一般的にはメインライト、読み取りから.そしてRedisには哨兵(Sentinal)メカニズムがあり、Redis主が切ると自動的に昇進してくれる.歩哨はredisの進行状態を監視し、masteとslaveを含め、masterがダウンタイムした後、自動主従切替、主従切替後、プロファイルが変更されます. 
マスタスレーブ構成
 
プライマリ構成redis.conf
 
#       
bind 0.0.0.0

protected-mode yes
#   
port 6379

tcp-backlog 511

#     
timeout 0

tcp-keepalive 300

#     
daemonize yes

supervised no
#   id  
pidfile "/var/run/redis_6379.pid"
#     
loglevel notice
#         
logfile "/tmp/redis-log.log"
#             ,      16 
databases 16

always-show-logo yes

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes
#        
dbfilename "dump.rdb"
#             
dir "/root/application/program/redis/datas"
#  redis    
masterauth "NMHmmgwauALmOk5TIt5kqYiLnugcMn7V"
slave-serve-stale-data no

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 90
# redis       
requirepass "NMHmmgwauALmOk5TIt5kqYiLnugcMn7V"
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no

appendonly yes

appendfilename "appendonly.aof"

appendfsync always

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

aof-use-rdb-preamble no

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

activerehashing yes

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes

他の配置名称は自分で注釈を調べて私は怠け者です
構成からredis.conf
構成されたアノテーションからマスターとほぼ同じslaveeof x.x.x.x 6379が1つだけ追加されました
bind 0.0.0.0

protected-mode yes

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes

supervised no

pidfile "/var/run/redis_6379.pid"

loglevel notice

logfile "/tmp/redis-log.log"

databases 16

always-show-logo yes

save 900 1
save 300 10
save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename "dump.rdb"

dir "/root/redis-4.0.6"

masterauth "NMHmmgwauALmOk5TIt5kqYiLnugcMn7V"
slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 90

requirepass "NMHmmgwauALmOk5TIt5kqYiLnugcMn7V"

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no

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 no

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

activerehashing yes

client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60

hz 10

aof-rewrite-incremental-fsync yes
#  redis ip  
slaveof x.x.x.x 6379

構成完了後にプライマリスレーブredisサービスを開始
[root@iob6byZ redis-4.0.6]# ./src/redis-server redis.conf 

起動完了後にredis-cli入力パスワードを起動auth NMHmmgwauALmOk 5 TIt 5 kqYiLnugcMn 7 V入力info下側表示#Replication role:master#説明こちらがメインconnected_slaves:2#ここからプライマリ・セカンダリ構成に成功した2つの説明
[root@iZuf6yZ redis-4.0.6]# ./src/redis-cli
127.0.0.1:6379> auth NMHmmgwauALmOk5TIt5kqYiLnugcMn7V
OK
127.0.0.1:6379> info
# Server
redis_version:4.0.6
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:59cbfe6ee7cf4162
redis_mode:standalone
os:Linux 2.6.32-696.6.3.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
atomicvar_api:sync-builtin
gcc_version:4.4.7
process_id:31568
run_id:0a37d3489f3b607d485fc75ceb33ca35afe5cdfb
tcp_port:6379
uptime_in_seconds:3701
uptime_in_days:0
hz:10
lru_clock:10089267
executable:/root/redis-4.0.6/./src/redis-server
config_file:/root/redis-4.0.6/redis.conf

# Clients
connected_clients:7
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:2106410
used_memory_human:2.01M
used_memory_rss:3170304
used_memory_rss_human:3.02M
used_memory_peak:2170898
used_memory_peak_human:2.07M
used_memory_peak_perc:97.03%
used_memory_overhead:2101254
used_memory_startup:835404
used_memory_dataset:5156
used_memory_dataset_perc:0.41%
total_system_memory:4153835520
total_system_memory_human:3.87G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:0
maxmemory_human:0B
maxmemory_policy:noeviction
mem_fragmentation_ratio:1.50
mem_allocator:libc
active_defrag_running:0
lazyfree_pending_objects:0

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1553591087
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
rdb_last_cow_size:258048
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:0
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_last_cow_size:135168
aof_current_size:0
aof_base_size:0
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0

# Stats
total_connections_received:19
total_commands_processed:16528
instantaneous_ops_per_sec:6
total_net_input_bytes:828448
total_net_output_bytes:4946090
instantaneous_input_kbps:0.29
instantaneous_output_kbps:2.70
rejected_connections:0
sync_full:2
sync_partial_ok:0
sync_partial_err:2
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:1
pubsub_patterns:0
latest_fork_usec:183
migrate_cached_sockets:0
slave_expires_tracked_keys:0
active_defrag_hits:0
active_defrag_misses:0
active_defrag_key_hits:0
active_defrag_key_misses:0

# Replication
role:master
connected_slaves:2
slave0:ip=x.x.x.x,port=6379,state=online,offset=516742,lag=1
slave1:ip=x.x.x.x,port=6379,state=online,offset=516881,lag=0
master_replid:06280106d8770bb4f1db7fcf9d7835024322f094
master_replid2:fbdf1e7e73552d9ff2f8fbeee2908f0d30f7dcae
master_repl_offset:517161
second_repl_offset:23600
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:517161

# CPU
used_cpu_sys:2.10
used_cpu_user:1.63
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Cluster
cluster_enabled:0

# Keyspace

 
歩哨配置
 
プロファイルsentinelを追加します.conf、哨兵を起動すればいい.sentinelリスニングポート、デフォルトは26379で、変更できます.
#   sentinel.conf    
#       
daemonize yes
#   protected-mode  ,            
protected-mode no
# log  
logfile /tmp/sentinel.log
#   
port 26379
dir "/tmp"
# sentinel monitor      sentinel      ip:port   master,   master-name     ,quorum     ,       sentinel    master   ,master      。master-name        ,  , “.-_”           master-ip      ip          (127.0.0.1)。
# x.x.x.x master ip
sentinel monitor mymaster x.x.x.x 6379 1
# sentinel down-after-milliseconds                   ,  master     sentinel          。      ,   30 ,    5 
sentinel down-after-milliseconds mymaster 5000
# sentinel failover-timeout   failover-timeout           :   sentinel    master  failover       。   slave      master            。  slave        master       。            failover      。     failover ,    slaves    master       。  ,        ,slaves           master,     parallel-syncs        。
sentinel failover-timeout mymaster 9000
# sentinel parallel-syncs               failover             slave     master     ,      ,  failover        ,          ,        slave  replication    。           1          slave              。
sentinel parallel-syncs mymaster 1
# sentinel auth-pass       master slave    ,    sentinel     master slave       ,  master slave         。
sentinel auth-pass mymaster NMHmmgwauALmOk5TIt5kqYiLnugcMn7V


 
私はこれだけしか配置していません.他は自分の必要に応じて自分で配置します.
そしてredisから奉仕する哨兵redis-sentinel sentinelを起動する.confの後ろにはアプリケーションの構成があります
[root@instqe redis-4.0.6]# ./src/redis-sentinel sentinel.conf

マスタは起動完了後に入力redis-cli-p 26379を任意に開いてインタラクティブインタフェースに入りinfo sentinelを入力して哨兵の情報を表示するmaster 0:name=mymaster,status=ok,address=x.x.x:6379,slaves=2,sentinels=4 status=ok状態ok slaves=2はname=mymasterマスタredisの名前address=x.x.x.x.x:6379マスタredisのipポートから2つを表す
[root@insqe redis-4.0.6]# 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=x.x.x.x:6379,slaves=2,sentinels=4
127.0.0.1:26379> 

 
これで構成が完了し、プライマリredisサービスkillを削除して、プライマリredisがセカンダリredisに切り替わるかどうかを確認できます.
 
お気に入りはコレクションに注目してください.本文はオリジナルです.転載はブログのリンクを添付してください.
ありがとう!!!
 
pythonQQ   :785239887