一脚囊、浩言
很精辟的一段話,"未曾清貧難做人,不經(jīng)打擊永天真;成熟不過是善于隱藏,滄桑不過是無淚有傷沪斟。"
二、redis的高可用
redis的主從配置比較容易暇矫,主從配置后主之,主主要進(jìn)行寫的操作,從主要進(jìn)行讀的操作,那么如果主掛了,是不是就沒法進(jìn)行寫了?所以redis中可以進(jìn)行哨兵的配置,具有高可用性李根,即是在主掛了之后,哨兵檢測到后槽奕,會在從中進(jìn)行投票,投票數(shù)多的晉升為主。這個配置可折騰我了房轿,按照找的資料進(jìn)行了哨兵的配置粤攒,可是當(dāng)我把主服務(wù)停掉之后,從還在一致嘗試連接主
2.1初次配置問題
啟動哨兵日志
停掉主后從的日志
停掉后哨兵中,日志情況
2.2解決如下
就是這個問題我一直嘗試找到解決辦法冀续,看了其中" sentinel-16379.conf"中的配置差不多琼讽,跟網(wǎng)上的一樣。但是就是不行洪唐。
sentinel-16379.conf配置如下
port 26379
dir "/tmp"
sentinel myid d0d116de4fe76badfeea68e27b0e7c6ac0397f8b
sentinel monitor mymaster 10.10.39.105 16380 1
sentinel down-after-milliseconds mymaster 600
sentinel failover-timeout mymaster 1800
sentinel auth-pass mymaster 123456
maxclients 4064
sentinel config-epoch mymaster 13740
sentinel leader-epoch mymaster 13740
sentinel known-slave mymaster 10.10.39.104 16379
sentinel current-epoch 13740
這是我把這個配置文件的注釋和空格都去掉后的結(jié)果
實際中我修改了如下幾個配置
sentinel monitor mymaster 10.10.39.105 16380 1
sentinel down-after-milliseconds mymaster 600
sentinel failover-timeout mymaster 1800
sentinel auth-pass mymaster 123456
其他的可能都是自動生成的钻蹬。當(dāng)然你也可以自己指定日志位置。
auth-pass是因為我的主中做了配置密碼了凭需。
官網(wǎng)的配置說明:https://redis.io/topics/sentinel
所以那為什么我的哨兵沒有起作用了,最后我找了公司運維一起看,問題的原因就是我的從中的bind的這個屬性沒有做配置问欠。
bind 10.10.39.105
加上了這個,all done!!!
如果你直接使用
./src/redis-cli -p 13680
報錯如下
Could not connect to Redis at 127.0.0.1:16380: Connection refused
Could not connect to Redis at 127.0.0.1:16380: Connection refused
因為bind只配置了10.10.39.105所以連接如下
./src/redis-cli -h 10.10.39.105 -p 16380
2.3測試哨兵
哨兵啟動結(jié)果
干掉主進(jìn)程
哨兵的日志打印狀況
從服務(wù)器的日志情況:
連接39.105設(shè)置數(shù)據(jù)如下
2.4此時在啟動39.104再次測試
哨兵監(jiān)控如下:
39.105的主上顯示已經(jīng)連接上
39.104本身顯示連上主
測試從是否可以設(shè)置數(shù)據(jù)
在主上設(shè)置數(shù)據(jù)
在從上get數(shù)據(jù)
三:問題說明
上面也說了粒蜈,第一次沒有成功的原因是因為bind問題
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all the network interfaces available on the server.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only into
# the IPv4 lookback interface address (this means Redis will be able to
# accept connections only from clients running into the same computer it
# is running).
#
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES
# JUST COMMENT THE FOLLOWING LINE.
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
我嘗試翻譯下如下
默認(rèn)的,如果沒有bind的配置指令,redis監(jiān)聽服務(wù)上的所有連接,如果你僅僅監(jiān)聽一個或者多個的話,bind的配置,按照如下的一個或者多個ip的方式
警告:如果電腦上的redis直接暴露給網(wǎng)絡(luò),綁定所有的了地址是危險的并且將會暴露給在網(wǎng)路上的每一個人顺献。所以我們默認(rèn)的取消注釋,強(qiáng)制的配置了一個IPV4的回環(huán)地址。(那就意味著在redis運行時只可以接收來自本電腦的連接)枯怖。
所以對于指定本機(jī)的ip的問題注整,我的理解就是,在主掛了后,哨兵需要連接到從,喚醒從并修改從的配置,如果不指定或者指定127.0.0.1是不行的,前一個是太多選擇沒有唯一,后面一個也說了只能在自己的電腦上連接肿轨。
四:浩語
__
__ _ ____ __| |__ _____ ___
\ \/ \/ / | \ | \\__ \ / _ \
\ /| | / Y \/ __ \( <_> )
\/\_/ |____/|___| (____ /\____/
\/ \/
任何事情都是要靠努力和用心寿冕。