Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

The implementation method of Redis Master-Slave configuration under Centos7

2025-04-03 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail the implementation of the master-slave configuration of Redis under Centos7. The editor thinks it is very practical, so I share it with you for reference. I hope you can get something after reading this article.

I. introduction of the environment

Redis-master 172.18.8.19

Redis-slave 172.18.8.20

Second, the configuration of redis master

# create redis data directory mkdir-p / data0/redis_trade#redis main configuration file root > # cat redis_6379.conf | grep-Ev "^ $| ^ #" bind 172.18.8.19protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile / var/run/redis_6379.pidloglevel noticelogfile "/ var/log/redis_6379.log" databases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump_6379.rdbdir / data0/redis_tradeslave-serve-stale-data yesslave -read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100requirepass Allwelltokokappendonly yesappendfilename "appendonly_6379.aof" appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "hash-max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2ListList houses- Depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesrename-command FLUSHALL ZYzv6FOBdwflW2nXrename-command EVAL S9UHPKEpSvUJMMrename-command FLUSHDB D60FPVDJuip7gy6lclient-output-buffer-limit normal 00 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes

3. Redis slave configuration

Root > # cat redis_6379.conf | grep-Ev "^ $| ^ #" bind 172.18.8.20protected-mode yesport 6379tcp-backlog 511timeout 0tcp-keepalive 300daemonize yessupervised nopidfile / var/run/redis_6379.pidloglevel noticelogfile "/ var/log/redis_6379.log" databases 16save 900 1save 300 10save 60 10000stop-writes-on-bgsave-error yesrdbcompression yesrdbchecksum yesdbfilename dump_6379.rdbdir / data0/redis_tradeslaveof 172.18.8.19 6379-the slave database has two more lines than the master database masterauth Allwelltokok- -the slave database has two more lines of configuration parameters slave-serve-stale-data yesslave-read-only yesrepl-diskless-sync norepl-diskless-sync-delay 5repl-disable-tcp-nodelay noslave-priority 100requirepass Allwelltokokappendonly yesappendfilename "appendonly_6379.aof" appendfsync everysecno-appendfsync-on-rewrite noauto-aof-rewrite-percentage 100auto-aof-rewrite-min-size 64mbaof-load-truncated yeslua-time-limit 5000slowlog-log-slower-than 10000slowlog-max-len 128latency-monitor-threshold 0notify-keyspace-events "hash than the master database. -max-ziplist-entries 512hash-max-ziplist-value 64list-max-ziplist-size-2list-compress-depth 0set-max-intset-entries 512zset-max-ziplist-entries 128zset-max-ziplist-value 64hll-sparse-max-bytes 3000activerehashing yesrename-command FLUSHALL ZYzv6FOBdwflW2nXrename-command EVAL S9UHPKEpSvUJMMrename-command FLUSHDB D60FPVDJuip7gy6lclient-output-buffer-limit normal 00 0client-output-buffer-limit slave 256mb 64mb 60client-output-buffer-limit pubsub 32mb 8mb 60hz 10aof-rewrite-incremental-fsync yes

IV. Redis startup script

Root > # cat / etc/init.d/redis_6379 #! / bin/sh## Simple Redis init.d script conceived to work on Linux systems# as it does use of the / proc filesystem.# chkconfig: 2345 90 10source / etc/init.d/functionsREDISPORT=6379EXEC=/usr/local/bin/redis-serverCLIEXEC=/usr/local/bin/redis-cli PIDFILE=/var/run/redis_$ {REDISPORT} .pidCONF = "/ usr/local/redis/etc/redis_$ {REDISPORT} .conf" AUTH= "Allwelltokok" BIND_IP=' 172.18.8.19' start () {if [- f $PIDFILE] then echo "$PIDFILE exists Process is already running or crashed "else echo" Starting Redis server... "$EXEC $CONF fi if [" $? "=" 0 "] then echo" Redis is running... " Fi} stop () {if [!-f $PIDFILE] then echo "$PIDFILE does not exist, process is not running" else PID=$ (cat $PIDFILE) echo "Stopping..." $CLIEXEC-h $BIND_IP-a $AUTH-p $REDISPORT SHUTDOWN sleep 1 while [- x / proc/$ {PID}] do echo "Waiting for Redis to shutdown..." Sleep 1 done echo "Redis stopped" fi} restart () {stop start} status () {ps-ef | grep redis-server | grep-v grep > / dev/null 2 > & 1 if [$?-eq 0]; then echo "redis server is running" else echo "redis server is stopped" fi} case "$1" in start) start; stop) stop;; restart) restart;; status) status *) echo "Usage: / etc/init.d/redis {start | stop | status | start}" > & 2 exit 1 esac

V. start the service

Root > # / etc/init.d/redis_6379 start

View the log

Root > # tail-100f / var/log/redis_6379.log5563:S 29 Jun 22 var/log/redis_6379.log5563:S 1423.236 * Increased maximum number of open files to 10032 (it was originally set to 1024). _. _.-`. `_. '' -. _ Redis 3.2.12 (000000Universe 0) 64 bit.-``.- ```. ```\ / _., _'-. _ (.-`|` ) Running in standalone mode | `-. _`...-.`` -. _ |'`_. -'| Port: 6379 |` -. _ `. _ / _. -'| PID: 5563` -. _ `-. _`. / _. -'_. -'_ _. | `-. _` -. _ `. -'| | `-. _` -. -'_. -'| http://redis.io `-. _ _. -'. -'|` -. _ `-. _. -'_. | |` -. . _. -'_. -'| `-. _. -'` -. _ `-. -'_. -'. -` -. _. -'. 5563:S 29 Jun 22:14:23.237 # Server started Redis version 3.2.125563 The server is now ready to accept connections on port 63795563 The server is now ready to accept connections on port 29 Jun 2263 Connecting to MASTER 172.18.8.19 Jun 2263 Jun 2263 Jun 22237 * MASTER SLAVE sync started5563:S 29 Jun 2223.237 * Non blocking connect for SYNC fired the event.5563:S 29 Jun 2238 * Master replied to PING Replication can continue...5563:S 29 Jun 22 Jun 14 Partial resynchronization not possible 23.238 * Partial resynchronization not possible (no cached master) 5563 MASTER SLAVE sync: Loading DB in memory5563:S 29 Jun 22 1423.305 * MASTER SLAVE sync: receiving 77 Jun 29 Jun 22 14 bytes from master5563:S 1423.305 * MASTER SLAVE sync: Loading DB in memory5563:S 29 Jun 2215 1423.305 * MASTER SLAVE sync: Loading DB in memory5563:S 29 Jun 22 * MASTER SLAVE sync: Finished with success5563:S 29 Jun 22 Jun 14 Jun 23.305 * Background append only file rewriting started by pid 55675563 V 29 Jun 22 V 14 V 23.329 * AOF rewrite child asks to stop sending diffs.5567:C 29 Jun 22 V 14V 23.329 * Parent agreed to stop sending diffs. Finalizing AOF...5567:C 29 Jun 22 MB of AOF diff received from parent.5567:C 14 Concatenating 23.329 * Concatenating 0.00 MB of AOF diff received from parent.5567:C 29 Jun 22 Jun 14 MB of AOF diff received from parent.5567:C 23.329 * SYNC append only file rewrite performed5567:C 29 Jun 22 14 Background AOF rewrite terminated with success5563:S 23.337 * Residual parent diff successfully flushed to the rewritten AOF (0.00 MB) 5563 Jun S 29 Jun 22 Centos7 14V 23.337 * Background AOF rewrite finished successfully this article ends here on "the implementation of Redis master-slave configuration under Centos7". Hope that the above content can be helpful to you, so that you can learn more knowledge, if you think the article is good, please share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report