已經(jīng)給予腳本執(zhí)行權(quán)限。
關(guān)閉一臺(tái)redis進(jìn)行主從切換后,VIP漂移沒(méi)有執(zhí)行(不清楚腳本是否執(zhí)行了)。單獨(dú)運(yùn)行腳本可以漂移。
配置如下
Sentinel配置(部分代碼是主從切換后自動(dòng)生成)
# Example sentinel.conf
# *** IMPORTANT ***
#
# By default Sentinel will not be reachable from interfaces different than
# localhost, either use the 'bind' directive to bind to a list of network
# interfaces, or disable protected mode with "protected-mode no" by
# adding it to this configuration file.
#
# Before doing that MAKE SURE the instance is protected from the outside
# world via firewalling or other means.
#
# For example you may use one of the following:
#
# bind 127.0.0.1 192.168.1.1
#
# protected-mode no
protected-mode no
# port <sentinel-port>
# The port that this sentinel instance will run on
daemonize yes
port 26379
logfile "/var/log/redis/sentinel.log"
pidfile "/var/run/sentinel.pid"
# sentinel announce-ip <ip>
# sentinel announce-port <port>
#
# The above two configuration directives are useful in environments where,
# because of NAT, Sentinel is reachable from outside via a non-local address.
#
# When announce-ip is provided, the Sentinel will claim the specified IP address
# in HELLO messages used to gossip its presence, instead of auto-detecting the
# local address as it usually does.
#
# Similarly when announce-port is provided and is valid and non-zero, Sentinel
# will announce the specified TCP port.
#
# The two options don't need to be used together, if only announce-ip is
# provided, the Sentinel will announce the specified IP and the server port
# as specified by the "port" option. If only announce-port is provided, the
# Sentinel will announce the auto-detected local IP and the specified port.
#
# Example:
#
# sentinel announce-ip 1.2.3.4
# dir <working-directory>
# Every long running process should have a well-defined working directory.
# For Redis Sentinel to chdir to /tmp at startup is the simplest thing
# for the process to don't interfere with administrative tasks such as
# unmounting filesystems.
dir "/tmp"
# sentinel monitor <master-name> <ip> <redis-port> <quorum>
#
# Tells Sentinel to monitor this master, and to consider it in O_DOWN
# (Objectively Down) state only if at least <quorum> sentinels agree.
#
# Note that whatever is the ODOWN quorum, a Sentinel will require to
# be elected by the majority of the known Sentinels in order to
# start a failover, so no failover can be performed in minority.
#
# Slaves are auto-discovered, so you don't need to specify slaves in
# any way. Sentinel itself will rewrite this configuration file adding
# the slaves using additional configuration options.
# Also note that the configuration file is rewritten when a
# slave is promoted to master.
#
# Note: master name should not include special characters or spaces.
# The valid charset is A-z 0-9 and the three characters ".-_".
sentinel myid 7267fb13d88570855d5b6e47915520d3e625afd5
# sentinel auth-pass <master-name> <password>
#
# Set the password to use to authenticate with the master and slaves.
# Useful if there is a password set in the Redis instances to monitor.
#
# Note that the master password is also used for slaves, so it is not
# possible to set a different password in masters and slaves instances
# if you want to be able to monitor these instances with Sentinel.
#
# However you can have Redis instances without the authentication enabled
# mixed with Redis instances requiring the authentication (as long as the
# password set is the same for all the instances requiring the password) as
# the AUTH command will have no effect in Redis instances with authentication
# switched off.
#
# Example:
#
# sentinel auth-pass mymaster MySUPER--secret-0123passw0rd
sentinel monitor mymaster 10.0.0.42 6379 2
# sentinel down-after-milliseconds <master-name> <milliseconds>
#
# Number of milliseconds the master (or any attached slave or sentinel) should
# be unreachable (as in, not acceptable reply to PING, continuously, for the
# specified period) in order to consider it in S_DOWN state (Subjectively
# Down).
#
# Default is 30 seconds.
sentinel client-reconfig-script mymaster /usr/opt/notify_master.sh
# sentinel parallel-syncs <master-name> <numslaves>
#
# How many slaves we can reconfigure to point to the new slave simultaneously
# during the failover. Use a low number if you use the slaves to serve query
# to avoid that all the slaves will be unreachable at about the same
# time while performing the synchronization with the master.
sentinel auth-pass mymaster dell@123
# sentinel failover-timeout <master-name> <milliseconds>
#
# Specifies the failover timeout in milliseconds. It is used in many ways:
#
# - The time needed to re-start a failover after a previous failover was
# already tried against the same master by a given Sentinel, is two
# times the failover timeout.
#
# - The time needed for a slave replicating to a wrong master according
# to a Sentinel current configuration, to be forced to replicate
# with the right master, is exactly the failover timeout (counting since
# the moment a Sentinel detected the misconfiguration).
#
# - The time needed to cancel a failover that is already in progress but
# did not produced any configuration change (SLAVEOF NO ONE yet not
# acknowledged by the promoted slave).
#
# - The maximum time a failover in progress waits for all the slaves to be
# reconfigured as slaves of the new master. However even after this time
# the slaves will be reconfigured by the Sentinels anyway, but not with
# the exact parallel-syncs progression as specified.
#
# Default is 3 minutes.
sentinel config-epoch mymaster 254
# SCRIPTS EXECUTION
#
# sentinel notification-script and sentinel reconfig-script are used in order
# to configure scripts that are called to notify the system administrator
# or to reconfigure clients after a failover. The scripts are executed
# with the following rules for error handling:
#
# If script exits with "1" the execution is retried later (up to a maximum
# number of times currently set to 10).
#
# If script exits with "2" (or an higher value) the script execution is
# not retried.
#
# If script terminates because it receives a signal the behavior is the same
# as exit code 1.
#
# A script has a maximum running time of 60 seconds. After this limit is
# reached the script is terminated with a SIGKILL and the execution retried.
# NOTIFICATION SCRIPT
#
# sentinel notification-script <master-name> <script-path>
#
# Call the specified notification script for any sentinel event that is
# generated in the WARNING level (for instance -sdown, -odown, and so forth).
# This script should notify the system administrator via email, SMS, or any
# other messaging system, that there is something wrong with the monitored
# Redis systems.
#
# The script is called with just two arguments: the first is the event type
# and the second the event description.
#
# The script must exist and be executable in order for sentinel to start if
# this option is provided.
#
# Example:
#
# sentinel notification-script mymaster /var/redis/notify.sh
# CLIENTS RECONFIGURATION SCRIPT
#
# sentinel client-reconfig-script <master-name> <script-path>
#
# When the master changed because of a failover a script can be called in
# order to perform application-specific tasks to notify the clients that the
# configuration has changed and the master is at a different address.
#
# The following arguments are passed to the script:
#
# <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
#
# <state> is currently always "failover"
# <role> is either "leader" or "observer"
#
# The arguments from-ip, from-port, to-ip, to-port are used to communicate
# the old address of the master and the new address of the elected slave
# (now a master).
#
# This script should be resistant to multiple invocations.
#
# Example:
#
# sentinel client-reconfig-script mymaster /var/redis/reconfig.sh
sentinel leader-epoch mymaster 254
# Generated by CONFIG REWRITE
sentinel known-slave mymaster 10.0.0.40 6379
sentinel known-slave mymaster 10.0.0.41 6379
sentinel known-sentinel mymaster 10.0.0.40 26379 8ed286e02e81d6946e0d007f569e164a9404c03f
sentinel known-sentinel mymaster 10.0.0.41 26379 8e1529d6b3ce060ea4282d99b671330546d723ab
sentinel current-epoch 254
不同點(diǎn)是sentinel client-reconfig-script mymaster /usr/opt/notify_master.sh 這一句在主從切換后被移到了上面,我寫的時(shí)候?qū)懺谧詈笠恍?/p>
Sentinel日志(含主從切換和原來(lái)的主重新啟動(dòng))
3314:X 02 Apr 10:14:07.069 # +sdown master mymaster 10.0.0.41 6379
3314:X 02 Apr 10:14:07.159 # +new-epoch 254
3314:X 02 Apr 10:14:07.161 # +vote-for-leader 8ed286e02e81d6946e0d007f569e164a9404c03f 254
3314:X 02 Apr 10:14:07.679 # +config-update-from sentinel 8ed286e02e81d6946e0d007f569e164a9404c03f 10.0.0.40 26379 @ mymaster 10.0.0.41 6379
3314:X 02 Apr 10:14:07.679 # +switch-master mymaster 10.0.0.41 6379 10.0.0.42 6379
3314:X 02 Apr 10:14:07.680 * +slave slave 10.0.0.40:6379 10.0.0.40 6379 @ mymaster 10.0.0.42 6379
3314:X 02 Apr 10:14:07.680 * +slave slave 10.0.0.41:6379 10.0.0.41 6379 @ mymaster 10.0.0.42 6379
3314:X 02 Apr 10:14:37.742 # +sdown slave 10.0.0.41:6379 10.0.0.41 6379 @ mymaster 10.0.0.42 6379
3314:X 02 Apr 10:48:36.099 # -sdown slave 10.0.0.41:6379 10.0.0.41 6379 @ mymaster 10.0.0.42 6379
3314:X 02 Apr 10:48:46.056 * +convert-to-slave slave 10.0.0.41:6379 10.0.0.41 6379 @ mymaster 10.0.0.42 6379
VIP漂移腳本
#!/bin/bash
MASTER_IP=$6 #第六個(gè)參數(shù)是新主redis的ip地址
LOCAL_IP=`ifconfig -a|grep inet|grep -v 127.0.0.1|grep -v inet6|awk '{print $2}'|tr -d "addr:"??` #本地ip
VIP='10.0.0.31'
NETMASK='24'
INTERFACE='eno16777736' #網(wǎng)卡接口設(shè)備名稱
if [ ${MASTER_IP} = ${LOCAL_IP} ];then
sudo /usr/sbin/ip addr add ${VIP}/${NETMASK} dev ${INTERFACE} #將VIP綁定到該服務(wù)器上
sudo /usr/sbin/arping -q -c 3 -A ${VIP} -I ${INTERFACE}
exit 0
else
sudo /usr/sbin/ip addr del ${VIP}/${NETMASK} dev ${INTERFACE} #將VIP從該服務(wù)器上刪除
exit 0
fi
exit 1我把sudo去掉后VIP也不會(huì)漂移
Apr 7 18:01:28 master redis-sentinel: 10954:X 07 Apr 18:01:28.335 * +slave slave 192.168.11.13:6379 192.168.11.13 6379 @ def_master 192.168.11.10 6379
Apr 7 18:01:28 master redis-sentinel: 10954:X 07 Apr 18:01:28.335 * +slave slave 192.168.11.12:6379 192.168.11.12 6379 @ def_master 192.168.11.10 6379
Apr 7 18:01:28 master redis-sentinel: 10954:X 07 Apr 18:01:28.464 # -script-error /var/lib/redis/failover.sh 0 2
Apr 7 18:01:33 master redis-sentinel: 10954:X 07 Apr 18:01:33.371 # +sdown slave 192.168.11.12:6379 192.168.11.12 6379 @ def_master 192.168.11.10 6379
Apr 7 18:01:34 master redis-sentinel: 10954:X 07 Apr 18:01:34.600 # +sdown sentinel 63e8dad4e625ce6ac20ee4221b8c22c5443b3433 192.168.11.12 26379 @ def_master 192.168.11.10 6379
Apr 7 18:02:48 master redis-sentinel: 10954:X 07 Apr 18:02:48.303 # -sdown slave 192.168.11.12:6379 192.168.11.12 6379 @ def_master 192.168.11.10 6379
Apr 7 18:02:52 master redis-sentinel: 10954:X 07 Apr 18:02:52.493 # -sdown sentinel 63e8dad4e625ce6ac20ee4221b8c22c5443b3433 192.168.11.12 26379 @ def_master 192.168.11.10 6379
這是centos7的message日志
最后問(wèn)題解決了么?我也遇到同樣的問(wèn)題,希望給點(diǎn)指導(dǎo)謝謝?。?!
日志:
16587:X 29 Jun 01:14:40.545 # Sentinel ID is 6e912d3910d2394ef472b5fd8daa6548ec628d24
16587:X 29 Jun 01:14:40.545 # +monitor master mymaster 172.16.24.240 6379 quorum 2
16587:X 29 Jun 01:15:37.248 # +sdown master mymaster 172.16.24.240 6379
16587:X 29 Jun 01:15:37.330 # +new-epoch 33
16587:X 29 Jun 01:15:37.332 # +vote-for-leader 0794d1aacc84fc57af48da252767b14e2e79f8a5 33
16587:X 29 Jun 01:15:37.333 # +odown master mymaster 172.16.24.240 6379 #quorum 2/2
16587:X 29 Jun 01:15:37.333 # Next failover delay: I will not start a failover before Fri Jun 29 01:16:08 2018
16587:X 29 Jun 01:15:37.682 # +config-update-from sentinel 0794d1aacc84fc57af48da252767b14e2e79f8a5 172.16.24.242 26379 @ mymaster 172.16.24.240 6379
16587:X 29 Jun 01:15:37.682 # +switch-master mymaster 172.16.24.240 6379 172.16.24.242 6379
16587:X 29 Jun 01:15:37.682 * +slave slave 172.16.24.241:6379 172.16.24.241 6379 @ mymaster 172.16.24.242 6379
16587:X 29 Jun 01:15:37.683 * +slave slave 172.16.24.240:6379 172.16.24.240 6379 @ mymaster 172.16.24.242 6379
16587:X 29 Jun 01:15:37.771 # -script-error /usr/notify_master.sh 0 2
16587:X 29 Jun 01:15:42.765 # +sdown slave 172.16.24.240:6379 172.16.24.240 6379 @ mymaster 172.16.24.242 6379
北大青鳥APTECH成立于1999年。依托北京大學(xué)優(yōu)質(zhì)雄厚的教育資源和背景,秉承“教育改變生活”的發(fā)展理念,致力于培養(yǎng)中國(guó)IT技能型緊缺人才,是大數(shù)據(jù)專業(yè)的國(guó)家
達(dá)內(nèi)教育集團(tuán)成立于2002年,是一家由留學(xué)海歸創(chuàng)辦的高端職業(yè)教育培訓(xùn)機(jī)構(gòu),是中國(guó)一站式人才培養(yǎng)平臺(tái)、一站式人才輸送平臺(tái)。2014年4月3日在美國(guó)成功上市,融資1
北大課工場(chǎng)是北京大學(xué)校辦產(chǎn)業(yè)為響應(yīng)國(guó)家深化產(chǎn)教融合/校企合作的政策,積極推進(jìn)“中國(guó)制造2025”,實(shí)現(xiàn)中華民族偉大復(fù)興的升級(jí)產(chǎn)業(yè)鏈。利用北京大學(xué)優(yōu)質(zhì)教育資源及背
博為峰,中國(guó)職業(yè)人才培訓(xùn)領(lǐng)域的先行者
曾工作于聯(lián)想擔(dān)任系統(tǒng)開發(fā)工程師,曾在博彥科技股份有限公司擔(dān)任項(xiàng)目經(jīng)理從事移動(dòng)互聯(lián)網(wǎng)管理及研發(fā)工作,曾創(chuàng)辦藍(lán)懿科技有限責(zé)任公司從事總經(jīng)理職務(wù)負(fù)責(zé)iOS教學(xué)及管理工作。
浪潮集團(tuán)項(xiàng)目經(jīng)理。精通Java與.NET 技術(shù), 熟練的跨平臺(tái)面向?qū)ο箝_發(fā)經(jīng)驗(yàn),技術(shù)功底深厚。 授課風(fēng)格 授課風(fēng)格清新自然、條理清晰、主次分明、重點(diǎn)難點(diǎn)突出、引人入勝。
精通HTML5和CSS3;Javascript及主流js庫(kù),具有快速界面開發(fā)的能力,對(duì)瀏覽器兼容性、前端性能優(yōu)化等有深入理解。精通網(wǎng)頁(yè)制作和網(wǎng)頁(yè)游戲開發(fā)。
具有10 年的Java 企業(yè)應(yīng)用開發(fā)經(jīng)驗(yàn)。曾經(jīng)歷任德國(guó)Software AG 技術(shù)顧問(wèn),美國(guó)Dachieve 系統(tǒng)架構(gòu)師,美國(guó)AngelEngineers Inc. 系統(tǒng)架構(gòu)師。