redis8生產(chǎn)環(huán)境下真實配置過程_第1頁
redis8生產(chǎn)環(huán)境下真實配置過程_第2頁
redis8生產(chǎn)環(huán)境下真實配置過程_第3頁
redis8生產(chǎn)環(huán)境下真實配置過程_第4頁
redis8生產(chǎn)環(huán)境下真實配置過程_第5頁
免費預覽已結(jié)束,剩余20頁可下載查看

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)

文檔簡介

1、#YUM安裝源請自行查找,需要注意,兩臺主備服務(wù)機器配置大體相同,但是個別參數(shù)不一樣,切記!#安裝編譯庫yuminstallcppbinutilsglibcglibc-commonglibc-develgccmaketcl-devel.x86_64#編譯安裝rediswgethttp:download.redis.io/releases/redis-2.8.23.tar.gzcd/softtarzxvfredis-2.8.23.tar.gzmvredis-2.8.23/usr/local/srccd/usr/local/src/redis-2.8.23#修改MAKE文件,修改對應(yīng)的安裝目錄PR

2、EFIX?=/usr/local/redisvi/usr/local/src/redis-2.8.23/src/Makefilemakemakeinstall#配置REDISmkdir-p/usr/local/redis/bin,conf,logs,data#配置REDIS系統(tǒng)環(huán)境變量vi/etc/profile.d/redis.sh#redisPATHexportPATH=/usr/local/redis/bin:$PATHsource/etc/profile.d/redis.sh#配置系統(tǒng)參數(shù)vi/etc/sysctl.confnet.core.somaxconn=1024vm.overc

3、ommit_memory=1sysctl-p#g輯REDIS參數(shù)及停止啟動腳本vi/usr/local/redis/redis-start.shvi/usr/local/redis/redis-stop.shvi/usr/local/redis/conf/redis.confcd/usr/local/redischmod700redis_check.shredis-start.shredis-stop.sh# #安裝keepaliveyuminstall-ykeepalived.x86_64cd/etc/keepalivedmvkeepalived.confkeepalived.conf_ba

4、kvikeepalived.confvi/etc/sysconfig/keepalived#KEEPALIVED_OPTIONS="-D"KEEPALIVED_OPTIONS="-D-d-S0"# #配置腳本,生產(chǎn)環(huán)境需要注意將所有正常日志關(guān)閉vi/usr/local/redis/redis_check.shvi/etc/keepalived/scripts/master.shvi/etc/keepalived/scripts/backup.shvi/etc/keepalived/scripts/stop.shvi/etc/keepalived/scri

5、pts/fault.shcd/etc/keepalived/scriptschmod700*# #Redis啟動停止腳本/usr/local/redis/redis-start.sh/usr/local/redis/redis-stop.sh# #啟動keepalive/etc/init.d/keepalivedrestart/usr/local/redis/bin/redis-cli-p63791-aRedis2176213$1e# #Master服務(wù)配置文件fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff

6、fffffffffffffIlIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII# #配置文件內(nèi)容#./etc/keepalived/keepalived.confffffffffffffffffffffffffffffffk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII!ConfigurationFileforkeepalived#global_defs# notification_email# # notification_email_fromAlexandre.Ca

7、ssenfirewall.loc# router_idnode3#vrrp_scriptchk_redisscript"/usr/local/redis/redis_check.sh"# 如果腳本執(zhí)行結(jié)果非0,并且weight配置的值小于0,則優(yōu)先級相應(yīng)的減少;如果腳本執(zhí)行結(jié)果為0,并且weight配置的值大于0,則優(yōu)先級相應(yīng)的增加;其他情況,維持原本prority的優(yōu)先級。# weight-20interval1#設(shè)置腳本執(zhí)行的頻率。3秒一次vrrp_instanceVI_1stateBACKUP#stateMASTER要設(shè)置恢復時不搶占,需要將主,從服務(wù)器的此項都設(shè)置成

8、BACKUPnopreempt才會生效。interfaceeth0virtual_router_id51priority100unicast_src_ip1unicast_peer2nopreempt#設(shè)置不搶占。在priority值比較高的服務(wù)器上設(shè)置即可。priority值比較低的服務(wù)器啟動時,發(fā)現(xiàn)值高的服務(wù)器為master,自動不搶占。advert_int1#advert_int的作用是巡檢的次數(shù)。keepalived默認是在啟動完成后3秒向state:MASTER切換。若此處設(shè)置成2,則是2*3=6秒后才開啟切換。authenticati

9、onauth_typePASSauth_passredisDb876virtual_ipaddress0track_scriptchk_redis#當keepalived切換成master時,#當keepalived切換成slave時,會#當keepalived出錯時,會觸發(fā)執(zhí)行#當keepalived停止時,會觸發(fā)執(zhí)notify_master/etc/keepalived/scripts/master.sh會觸發(fā)執(zhí)行master.shnotify_backup/etc/keepalived/scripts/backup.sh觸發(fā)執(zhí)行slave.shnotify_fau

10、lt/etc/keepalived/scripts/fault.shfault.shnotify_stop/etc/keepalived/scripts/stop.sh行stop.sh)# #配置文件內(nèi)容#./etc/keepalived/scripts/backup.shffffffffffffffffffffffffffffffk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/bashRPATH=/usr/local/redisREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOC

11、ALIP="1”REMOTEIP="2”PORT="63791”PASSWD="DQWa24zsPw8752”PID=$#當此服務(wù)器的keepalived恢復成slave時,即虛擬IP切換到其他服務(wù)器時,將本機redis切換成role:slaveecho"WARMkeepalivedchangetoslave,changelocalredistoslave">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S'、|$

12、PID|state:master”>>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterBeingslavestate.">>$LOGFILE2>&1# 切換時,等待10秒,讓對方同步數(shù)據(jù)(此時間要根據(jù)實際業(yè)務(wù)需要進行調(diào)整)echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterwait3secfordatasyncfromoldmaster">

13、;>$LOGFILEsleep3echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterdatarsyncfromoldmaterok.">>$LOGFILE# 等數(shù)據(jù)同步完,再切換成role:slaveecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveRun'SLAVEOF$REMOTEIP$PORT'">>$LOGFILE$REDISCLI-p$PORT-

14、a$PASSWDSLAVEOF$REMOTEIP$PORT>>$LOGF>L0echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveslaveconnectto$REMOTEIP$PORTok.">>$LOGFILEecho"complete!"# #配置文件內(nèi)容#./etc/keepalived/scripts/fault.shIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIII

15、I#!/bin/bashRPATH=/usr/local/redisREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOCALIP="1”REMOTEIP="2”PORT="63791”PASSWD="DQWa24zsPw8752”PID=$# 當此服務(wù)器的keepalived出錯時,將本機redis切換成role:slaveecho"ERRORkeepalivedisfault,changelocalredistos

16、lave">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S'、|$PID|state:master”>>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterBeingslavestate.">>$LOGFILE2>&1# 切換時,等待3秒,讓對方同步數(shù)據(jù)(此時間要根據(jù)實際業(yè)務(wù)需要進行調(diào)整)echo"'date+'%Y-%m-%d:%H

17、:%M:%S''|$PID|state:masterwait10secfordatasyncfromoldmaster">>$LOGFILEsleep3echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterdatarsyncfromoldmaterok.">>$LOGFILE# 等數(shù)據(jù)同步完,再切換成role:slaveecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:sl

18、aveRun'SLAVEOF$REMOTEIP$PORT'">>$LOGFILE$REDISCLI-p$PORT-a$PASSWD$REMOTEIP$PORT>>$LOGF2>&1echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveslaveconnectto$REMOTEIP$PORTok.">>$LOGFILEecho"complete!"# #配置文件內(nèi)容#./etc/keepalived/scri

19、pts/master.shIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/bashRPATH=/usr/local/redisREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOCALIP="1"REMOTEIP="2"PORT="63791"PASSWD="DQWa24zsPw8752”PID=$#當此服務(wù)

20、器的keepalived恢復成master時,即虛擬IP切換到本機時,將本機的redis切換成role:masterecho"WARMkeepalivedchangetomaster,changelocalredistomaster">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S'、|$PID|state:slave”>>$LOGFILE# 先切換成role:slaveecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|s

21、tate:slaveRun'SLAVEOF$REMOTEIP$PORT'">>$LOGFILE$REDISCLI-p$PORT-a$PASSWDSLAVEOF$REMOTEIP$PORT>>$LOGFILE2>&1# 同步數(shù)據(jù)echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slavewait10secfordatasyncfromoldmaster">>$LOGFILEsleep3# 等待3秒(此時間要根據(jù)實際業(yè)務(wù)需要進行調(diào)整),

22、待數(shù)據(jù)同步完,再切換成role:masterecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slavedatarsyncfromoldmaterok.">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterRunslaveofnoone,closemaster/slave">>$LOGFILE$REDISCLI-p$PORT-a$PASSWDSLAVEOFNOONE&

23、gt;>$LOGFILE2>&1echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterwaitotherslaveconnect.">>$LOGFILEecho"complete!"# #配置文件內(nèi)容#./etc/keepalived/scripts/stop.shIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/shRPATH=/usr/local/redi

24、sREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOCALIP="1"REMOTEIP="2"PORT="63791"PASSWD="DQWa24zsPw8752"PID=$# 當主服務(wù)器的keepalived停止時,將本機redis切換成role:slaveecho"ERRORkeepalivedstop,changelocalredistoslave">&g

25、t;$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:master">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterBeingslavestate.">>$LOGFILE2>&1# 切換時,等待10秒,讓對方同步數(shù)據(jù)(此時間要根據(jù)實際業(yè)務(wù)需要進行調(diào)整)echo"'date+'%Y-%m-%d:%H:%M:%S

26、''|$PID|state:masterwait3secfordatasyncfromoldmaster">>$LOGFILEsleep3echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterdatarsyncfromoldmaterok.">>$LOGFILE# 等數(shù)據(jù)同步完,再切換成role:slaveecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveRun&

27、#39;SLAVEOF$REMOTEIP$PORT'">>$LOGFILE$REDISCLI-p$PORT-a$PASSWDSLAVEOF$REMOTEIP$PORT>>$LOGF>L0echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveslaveconnectto$REMOTEIP$PORTok.">>$LOGFILEecho"complete!"# #配置文件內(nèi)容#./usr/local/redis/conf/red

28、is.confffffffffffffffffffffffffffffffk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIdaemonizeyespidfile/usr/local/redis/data/redis.pid#bind21port63791requirepassDQWa24zsPw8752tcp-backlog511timeout600tcp-keepalive0loglevelnoticelogfile"/usr/local/redis/logs/redis.log"databases10save9001save300

29、10save601000# #memory#500Mmaxclients10000maxmemory500000000maxmemory-policyvolatile-ttlmaxmemory-samples3stop-writes-on-bgsave-erroryesrdbcompressionyesrdbchecksumyes# DBfiledir/usr/local/redis/datadbfilenameappserver.rdbslave-serve-stale-datayesslave-read-onlyyesrepl-diskless-syncnorepl-diskless-sy

30、nc-delay5repl-disable-tcp-nodelaynoslave-priority100masterauthDQWa24zsPw8752#Disablerunrename-commandFLUSHALL"sadfgsdfgswe4cxg234srename-commandFLUSHDB"w354rscgvxzfdgtqwzdv"rename-commandCONFIG"cf732qddfh762321dsar6"rename-commandEVAL"or6xg5fda76jsaegf"#rename-comm

31、andKEYS"dasd5asdffdgtqwzdv"appendonlynoappendfilename"appendonly.aof"appendfsynceverysecno-appendfsync-on-rewritenoauto-aof-rewrite-percentage100auto-aof-rewrite-min-size64mbaof-load-truncatedyeslua-time-limit5000slowlog-log-slower-than10000slowlog-max-len128latency-monitor-thres

32、hold0notify-keyspace-events""# #hash-max-ziplist-entriesdon't>1000hash-max-ziplist-entries512hash-max-ziplist-value64list-max-ziplist-entries512list-max-ziplist-value64set-max-intset-entries512zset-max-ziplist-entries128zset-max-ziplist-value64hll-sparse-max-bytes3000activerehashing

33、yesclient-output-buffer-limitnormal000client-output-buffer-limitslave256mb64mb60client-output-buffer-limitpubsub32mb8mb60# #ConfigConnect.don't>100hz30aof-rewrite-incremental-fsyncyes# #配置文件內(nèi)容#./usr/local/redis/redis_check.shIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bi

34、n/bashLOGDATE='date+%Y%m%d'RPATH=/usr/local/redisREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state_$LOGDATE.logLOCALIP="1”REMOTEIP="2”PORT="63791”PASSWD="DQWa24zsPw8752”PID=$ALIVE='$REDISCLI-p$PORT-a$PASSWDPING'if"$ALIVE&quo

35、t;="PONG"thenecho"INFO'date+'%Y-%m-%d:%H:%M:%S'':$LOCALIPlocalredisishealth.">>$LOGFILEexit0elseecho"ERROR'date+'%Y-%m-%d:%H:%M:%S'':$LOCALIPlocalredisisnothealth.">>$LOGFILE#當發(fā)現(xiàn)本地redis無法連接時,等待一秒后再進行一次檢查。若恢復,則提示;若仍無法連接,則關(guān)閉本地ke

36、epalived,將虛擬ip漂移到另外一臺服務(wù)器上。sleep1ALIVE1='$REDISCLI-p$PORT-a$PASSWDPING'if"$ALIVE1"="PONG"thenecho”NOTICE'date+'%Y-%m-%d:%H:%M:%S'':$LOCALIPlocalredisbecomehealth.">>$LOGFILEexit0elseecho"ERROR'date+'%Y-%m-%d:%H:%M:%S'、:$LOCALIPlo

37、calredisiserror.">>$LOGFILEecho"ERROR'date+'%Y-%m-%d:%H:%M:%S'、:$LOCALIPshutdownlocalkeepalived.">>$LOGFILE/etc/init.d/keepalivedstopif"$?"!="0"thenecho"ERROR'date+'%Y-%m-%d:%H:%M:%S'、:$LOCALIPkeepalivedshutdownerror."&

38、gt;>$LOGFILEelseecho"INFO'date+'%Y-%m-%d:%H:%M:%S'、:$LOCALIPkeepalivedshutdowncompleted.">>$LOGFILEfiexit1fifi#配置文件內(nèi)容#./usr/local/redis/redis-start.shffffffffffffffffffffffffffffffk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/bashRPATH=/usr/local/redis#KPATH=/usr/local/keepa

39、livedREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOCALIP=1REMOTEIP=2$RPATH/bin/redis-server$RPATH/conf/redis.confif"$?"="0"thenecho"INFO'date+%F/%H:%M:%S':$LOCALIPredisstartsuccessful.">>$LOGFILEelseecho"ERR

40、OR'date+%F/%H:%M:%S':$LOCALIPredisstarterror.">>$LOGFILEfi#配置文件內(nèi)容#./usr/local/redis/redis-stop.shffffffffffffffffffffffffffffffk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/bashRPATH=/usr/local/redis#KPATH=/usr/local/keepalivedLOGFILE=$RPATH/logs/redis-state.logLOCALIP=1REMO

41、TEIP=2kill-9'ps-ef|grep'/bin/redis-server'|grep-vgrep|awk'print$2'、if"$?"="0"thenecho"INFO'date+%F/%H:%M:%S':$LOCALIPredisshutdowncompleted!">>$LOGFILEelseecho"INFO'date+%F/%H:%M:%S':$LOCALIPredisisnotstarted.&q

42、uot;>>$LOGFILEfi#Slave服務(wù)配置文件IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIlIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII# #配置文件內(nèi)容#./etc/keepalived/keepalived.confffffffffffffffffffffffffffffffk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII!

43、ConfigurationFileforkeepalived#global_defs# notification_email# # notification_email_fromAlexandre.Cassenfirewall.loc#router_idnode3#vrrp_scriptchk_redisscript"/usr/local/redis/redis_check.sh"# 如果腳本執(zhí)行結(jié)果非0,并且weight配置的值小于0,則優(yōu)先級相應(yīng)的減少;如果腳本執(zhí)行結(jié)果為0,并且weight配置的值大于0,則優(yōu)先級相應(yīng)的增加;其他情況,維持原本prority的優(yōu)先級。#

44、 weight-20interval1#設(shè)置腳本執(zhí)行的頻率。1秒一次vrrp_instanceVI_1stateBACKUPinterfaceeth0garp_master_delay10virtual_router_id51priority90unicast_src_ip2unicast_peer1)#nopreemptadvert_int1#advert_int的作用是巡檢的次數(shù)。keepalived默認是在啟動完成后3秒向state:MASTER切換。若此處設(shè)置成2,則是2*3=6秒后才開啟切換。authenticationauth_typ

45、ePASSauth_passredisDb876)virtual_ipaddress0)track_scriptchkredis)#當keepalived切換成master時,#當keepalived切換成slave時,會#當keepalived出錯時,會觸發(fā)執(zhí)行#當keepalived停止時,會觸發(fā)執(zhí)notify_master/etc/keepalived/scripts/master.sh會觸發(fā)執(zhí)行master.shnotify_backup/etc/keepalived/scripts/backup.sh觸發(fā)執(zhí)行slave.shnotify_fault/etc/k

46、eepalived/scripts/fault.shfault.shnotify_stop/etc/keepalived/scripts/stop.sh行stop.sh)#配置文件內(nèi)容#./etc/keepalived/scripts/backup.shffffffffffffffffffffffffffffffk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/bashRPATH=/usr/local/redisREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOCALIP="

47、;2”REMOTEIP="1”PORT="63791”PASSWD="DQWa24zsPw8752”PID=$#當此服務(wù)器的keepalived恢復成slave時,即虛擬IP切換到其他服務(wù)器時,將本機redis切換成role:slaveecho"WARM$LOGFILEkeepalivedchangetoslave,changelocalredistoslave>>echo"'date+'%Y-%m-%d:%H:%M:%S'、|$PID|state:maste門

48、">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterBeingslavestate.">>$LOGFILE2>&1# 切換時,等待10秒,讓對方同步數(shù)據(jù)(此時間要根據(jù)實際業(yè)務(wù)需要進行調(diào)整)echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterwait3secfordatasyncfromoldmaster">>$LOGFI

49、LEsleep3echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterdatarsyncfromoldmaterok.">>$LOGFILE# 等數(shù)據(jù)同步完,再切換成role:slaveecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveRun'SLAVEOF$REMOTEIP$PORT'">>$LOGFILE$REDISCLI-p$PORT-a$PASSWDSLA

50、VEOF$REMOTEIP$PORT>>$LOGF>L0echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveslaveconnectto$REMOTEIP$PORTok.">>$LOGFILEecho"complete!"# #配置文件內(nèi)容#./etc/keepalived/scripts/fault.shIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/bas

51、hRPATH=/usr/local/redisREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOCALIP="2"REMOTEIP="1"PORT="63791"PASSWD="DQWa24zsPw8752”PID=$# 當此服務(wù)器的keepalived出錯時,將本機redis切換成role:slaveecho"ERRORkeepalivedisfault,changelocalredi

52、stoslave">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:master”>>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterBeingslavestate.">>$LOGFILE2>&1# 切換時,等待10秒,讓對方同步數(shù)據(jù)(此時間要根據(jù)實際業(yè)務(wù)需要進行調(diào)整)echo"'date+'%Y

53、-%m-%d:%H:%M:%S''|$PID|state:masterwait3secfordatasyncfromoldmaster">>$LOGFILEsleep3echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterdatarsyncfromoldmaterok.">>$LOGFILE# 等數(shù)據(jù)同步完,再切換成role:slaveecho"'date+'%Y-%m-%d:%H:%M:%S'、|$PID|stat

54、e:slaveRun'SLAVEOF$REMOTEIP$PORT'">>$LOGFILE$REDISCLI-p$PORT-a$PASSWDSLAVEOF$REMOTEIP$PORT>>$LOGF>L0echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveslaveconnectto$REMOTEIP$PORTok.">>$LOGFILEecho"complete!"#配置文件內(nèi)容#./etc/keepalived/

55、scripts/master.shffffffffffffffffffffffffffffffk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/bashRPATH=/usr/local/redisREDISCLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOCALIP="2”REMOTEIP="1”PORT="63791”PASSWD="DQWa24zsPw8752”PID=$# 當此服務(wù)器的keepaliv

56、ed恢復成master時,即虛擬IP切換到本機時,將本機的redis切換成role:masterecho"WARMkeepalivedchangetomaster,changelocalredistomaster">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slave”>>$LOGFILE# 先切換成role:slaveecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:s

57、laveRun'SLAVEOF$REMOTEIP$PORT'">>$LOGFILE$REDISCLI-p$PORT-a$PASSWDSLAVEOF$REMOTEIP$PORT>>$LOGFILE2>&1# 同步數(shù)據(jù)echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slavewait10secfordatasyncfromoldmaster">>$LOGFILEsleep3# 等待3秒(此時間要根據(jù)實際業(yè)務(wù)需要進行調(diào)整),待數(shù)據(jù)同步完

58、,再切換成role:masterecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slavedatarsyncfromoldmaterok.">>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterRunslaveofnoone,closemaster/slave">>$LOGFILE$REDISCLI-p$PORT-a$PASSWDSLAVEOFNOONE>>

59、;$LOGFILE2>&1echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterwaitotherslaveconnect.">>$LOGFILEecho"complete!"# #配置文件內(nèi)容#./etc/keepalived/scripts/stop.shIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIII#!/bin/shRPATH=/usr/local/redisREDIS

60、CLI=$RPATH/bin/redis-cliLOGFILE=$RPATH/logs/redis-state.logLOCALIP="2”REMOTEIP="1”PORT="63791”PASSWD="DQWa24zsPw8752”PID=$# 當主服務(wù)器的keepalived停止時,將本機redis切換成role:slaveecho"ERRORkeepalivedstop,changelocalredistoslave">>$LOGFILEecho"'d

61、ate+'%Y-%m-%d:%H:%M:%S'、|$PID|state:master”>>$LOGFILEecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterBeingslavestate.">>$LOGFILE2>&1# 切換時,等待10秒,讓對方同步數(shù)據(jù)(此時間要根據(jù)實際業(yè)務(wù)需要進行調(diào)整)echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterwait3se

62、cfordatasyncfromoldmaster">>$LOGFILEsleep3echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:masterdatarsyncfromoldmaterok.">>$LOGFILE# 等數(shù)據(jù)同步完,再切換成role:slaveecho"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveRun'SLAVEOF$REMOTEIP$PORT'"

63、;>>$LOGFILE$REDISCLI-p$PORT-a$PASSWDSLAVEOF$REMOTEIP$PORT>>$LOGF>L0echo"'date+'%Y-%m-%d:%H:%M:%S''|$PID|state:slaveslaveconnectto$REMOTEIP$PORTok.">>$LOGFILEecho"complete!"# #配置文件內(nèi)容#./usr/local/redis/conf/redis.confIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIk“”IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIdaemonizeyespidfile/usr/local/redis/data/redis.pid#bind22port63791requirepassDQWa24zsPw8752tcp-backlog511timeout600tcp

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

評論

0/150

提交評論