redis的搭建過(guò)程,請(qǐng)參考 https://blog.51cto.com/12445535/2385106
十余年的大洼網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷(xiāo)的優(yōu)勢(shì)是能夠根據(jù)用戶(hù)設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整大洼建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)建站從事“大洼網(wǎng)站設(shè)計(jì)”,“大洼網(wǎng)站推廣”以來(lái),每個(gè)客戶(hù)項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
接下來(lái),我們?cè)僬乙慌_(tái)服務(wù)器,進(jìn)行安裝redis 實(shí)現(xiàn)redis的主從架構(gòu)
和上面的方法搭建一個(gè)redis
只不過(guò)
在從redis中的配置文件中寫(xiě)
[root@prd3-redis02-10-184 conf]# grep slaveof 6379.conf
######## slaveof <masterip> <masterport>
slaveof 192.168.10.183 6379 //直接添加這個(gè)一行,然后
啟動(dòng)redis
[root@prd3-redis02-10-184 conf]# redis-server /ivargo/app/redis/conf/6379.conf
接下來(lái)就是看差距
在主redis可以看到
[root@prd3-redis01-10-183 conf]# redis-cli -a XXX
Warning: Using a password with '-a' option on the command line interface may not be safe.
127.0.0.1:6379> info
role:master
connected_slaves:1
在從redis上可以看到
[root@prd3-redis02-10-184 conf]# redis-cli -aXXX
Warning: Using a password with '-a' option on the command line interface may not be safe.
127.0.0.1:6379> info
####### Replication
role:slave
master_host:192.168.10.183
master_port:6379
這樣redis的主從就搭建好了
搭建完redis后,目錄結(jié)構(gòu)
[root@prd3-redis01-10-183 ivargo]# pwd
/ivargo
[root@prd3-redis01-10-183 ivargo]# tree
.
├── app
│?? ├── redis
│?? │?? ├── 6379.pid
│?? │?? ├── conf
│?? │?? │?? └── 6379.conf
│?? │?? ├── data
│?? │?? │?? ├── 6379.rdb
│?? │?? │?? └── appendonly_6379.aof
│?? │?? └── log
│?? └── sentinel
│?? └── conf
└── log
└── 6379.log
8 directories, 5 files
實(shí)現(xiàn)redis的sentinel
[root@prd3-redis01-10-183 conf]# pwd
/ivargo/app/sentinel/conf
[root@prd3-redis01-10-183 conf]# cat sentinel.conf //這個(gè)配置文件是prd3上的sentinel的配置文件,我們需要修改的
# Example sentinel.conf
# bind 127.0.0.1 192.168.1.1
bind 0.0.0.0
protected-mode no
port 26379
daemonize yes
loglevel notice
logfile "/ivargo/log/sentinel.log"
dir "/tmp"
# sentinel auth-pass <master-name> <password>
# sentinel down-after-milliseconds <master-name> <milliseconds>
# Default is 30 seconds.
sentinel myid ba794535d3a65e14b266e28462fa7c68de609f39
# sentinel parallel-syncs <master-name> <numslaves>
sentinel deny-scripts-reconfig yes
# sentinel failover-timeout <master-name> <milliseconds>
# Default is 3 minutes = 180000.
sentinel monitor mymaster 10.80.85.20 6379 2
# Generated by CONFIG REWRITE
sentinel down-after-milliseconds mymaster 6000
sentinel auth-pass mymaster xxx
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 1
sentinel known-slave mymaster 10.80.85.21 6379
sentinel known-sentinel mymaster 10.80.85.21 26379 c3002e02c6a2d0041afd2569f3fd1985bc38993e
sentinel current-epoch 1
[root@prd3-redis01-10-183 conf]# cat sentinel.conf //這里面都是我們自己指定的,他其他的文件內(nèi)容,都是他自己生成的
# Example sentinel.conf
# bind 127.0.0.1 192.168.1.1
bind 0.0.0.0
protected-mode no
port 26379
daemonize yes
loglevel notice
logfile "/ivargo/log/sentinel.log"
pidfile "/ivargo/app/sentinel/26379.pid"
dir "/tmp"
sentinel monitor mymaster 192.168.10.183 6379 2
sentinel auth-pass mymaster XXX
184上的sentinel配置文件和183一樣的
[root@prd3-redis01-10-183 conf]# redis-sentinel /ivargo/app/sentinel/conf/sentinel.conf
[root@prd3-redis02-10-184 conf]# redis-sentinel /ivargo/app/sentinel/conf/sentinel.conf
[root@prd3-redis01-10-183 conf]# cat sentinel.conf
# Example sentinel.conf
# bind 127.0.0.1 192.168.1.1
bind 0.0.0.0
protected-mode no
port 26379
daemonize yes
loglevel notice
logfile "/ivargo/log/sentinel.log"
pidfile "/ivargo/app/sentinel/26379.pid"
dir "/tmp"
sentinel myid 6075d58bdc7c2602f98d90c0aa48470c4dbb50d9
sentinel deny-scripts-reconfig yes
# Generated by CONFIG REWRITE
sentinel monitor mymaster 192.168.10.183 6379 2
sentinel auth-pass mymaster XXX
sentinel config-epoch mymaster 0
sentinel leader-epoch mymaster 0
sentinel known-slave mymaster 192.168.10.184 6379
sentinel known-sentinel mymaster 192.168.10.184 26379 039bd11a572245b6c16c6e204523d781ffb6ba4c
sentinel current-epoch 0
查看不同點(diǎn)
我們檢查
[root@prd3-redis01-10-183 conf]# redis-cli -h 192.168.10.183 -p 26379 info
# 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=192.168.10.183:6379,slaves=1,sentinels=2
驗(yàn)證sentinel高可用
[root@prd3-redis01-10-183 redis]# kill `cat 6379.pid`
殺死183的進(jìn)程
然后在184上看
[root@prd3-redis02-10-184 conf]# redis-cli -h 192.168.10.183 -p 26379 info
# 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=192.168.10.184:6379,slaves=1,sentinels=2 //主節(jié)點(diǎn)變成了184了
在啟動(dòng)183
[root@prd3-redis01-10-183 redis]# redis-server /ivargo/app/redis/conf/6379.conf
[root@prd3-redis01-10-183 redis]# redis-cli -h 192.168.10.183 -p 26379 info
# 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=192.168.10.184:6379,slaves=1,sentinels=2
然后查看redis 原來(lái)的183是主節(jié)點(diǎn),現(xiàn)在是從節(jié)點(diǎn)了
[root@prd3-redis01-10-183 redis]# redis-cli -h 192.168.10.183 -p 6379 -a XXX info
# Replication
role:slave
master_host:192.168.10.184
master_port:6379
[root@prd3-redis02-10-184 conf]# redis-cli -h 192.168.10.184 -p 6379 -a XXX info
# Replication
role:master
connected_slaves:1
slave0:ip=192.168.10.183,port=6379,state=online,offset=169470,lag=1
以上實(shí)現(xiàn)了redis的sentinel機(jī)制 也就是 HA機(jī)制
其實(shí)對(duì)于現(xiàn)上環(huán)境的話,當(dāng)redis發(fā)生了主從切換的時(shí)候,這個(gè)比如程序調(diào)用的ip就會(huì)改變,寫(xiě)兩個(gè)ip和兩個(gè)sentinel地址顯然是不合理的,我們可以實(shí)現(xiàn)vip機(jī)制自動(dòng)切換,來(lái)實(shí)現(xiàn)程序調(diào)用只需要一個(gè)ip,相關(guān)內(nèi)容,請(qǐng)期待。
網(wǎng)頁(yè)標(biāo)題:redis主從架構(gòu)與redis+sentinel哨兵機(jī)制架
本文路徑:http://aaarwkj.com/article8/gjdoip.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、關(guān)鍵詞優(yōu)化、建站公司、域名注冊(cè)、軟件開(kāi)發(fā)、云服務(wù)器
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶(hù)投稿、用戶(hù)轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來(lái)源: 創(chuàng)新互聯(lián)