Redis5怎么配置一主兩從讀寫分離

本篇內(nèi)容介紹了“redis5怎么配置一主兩從讀寫分離”的有關(guān)知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓小編帶領(lǐng)大家學(xué)習(xí)一下如何處理這些情況吧!希望大家仔細閱讀,能夠?qū)W有所成!

創(chuàng)新互聯(lián)建站主營相山網(wǎng)站建設(shè)的網(wǎng)絡(luò)公司,主營網(wǎng)站建設(shè)方案,成都app開發(fā),相山h5小程序開發(fā)搭建,相山網(wǎng)站營銷推廣歡迎相山等地區(qū)企業(yè)咨詢

實驗環(huán)境:

系統(tǒng):CentOS7

軟件:redis-5.0.2

一、解壓redis-5.0.2

三個節(jié)點

[root@red1 software]# cd /usr/local/
[root@red1 local]# ll
total 1912
drwxr-xr-x. 2 root root     134 Apr 10 21:45 bin
drwxr-xr-x. 2 root root       6 Apr 11  2018 etc
drwxr-xr-x. 2 root root       6 Apr 11  2018 games
drwxr-xr-x. 2 root root       6 Apr 11  2018 include
drwxr-xr-x. 2 root root       6 Apr 11  2018 lib
drwxr-xr-x. 2 root root       6 Apr 11  2018 lib64
drwxr-xr-x. 2 root root       6 Apr 11  2018 libexec
drwxrwxr-x. 6 root root    4096 Apr 11 11:49 redis
-rw-r--r--. 1 root root 1952989 Apr 10 21:42 redis-5.0.2.tar.gz
drwxr-xr-x. 2 root root       6 Apr 11  2018 sbin
drwxr-xr-x. 5 root root      49 Oct 22 10:25 share
drwxr-xr-x. 2 root root       6 Apr 11  2018 src

二、安裝Redis

三個節(jié)點

make

make install

三、修改環(huán)境變量

三個節(jié)點

安裝完Redis之后,在/usr/local/bin會生成一些腳本

[root@red1 local]# cd /usr/local/bin/
[root@red1 bin]# ll
total 32628
-rwxr-xr-x. 1 root root 4365456 Apr 10 21:45 redis-benchmark
-rwxr-xr-x. 1 root root 8084864 Apr 10 21:45 redis-check-aof
-rwxr-xr-x. 1 root root 8084864 Apr 10 21:45 redis-check-rdb
-rwxr-xr-x. 1 root root 4786592 Apr 10 21:45 redis-cli
lrwxrwxrwx. 1 root root      12 Apr 10 21:45 redis-sentinel -> redis-server
-rwxr-xr-x. 1 root root 8084864 Apr 10 21:45 redis-server

修改環(huán)境變量

PATH=\$PATH:/MySQL/app/mysql/bin:/mysql/app/xtrabackup/bin:$HOME/bin:/usr/bin:/sbin:/bin:/usr/local/bin
source .bash_profile

四、配置Redis配置文件

主節(jié)點192.168.8.11

port 6000            #端口號
requirepass 123456       #登錄口令
bind 192.168.8.11        #綁定IP
daemonize yes          #后臺運行redis

從節(jié)點一

port 6001             #端口號       
bind 192.168.8.12               #綁定IP
slaveof 192.168.8.11 6000      #設(shè)置主節(jié)點信息
masterauth 123456               #主節(jié)點口令
requirepass 123456              #登錄口令
slave-read-only yes             #只讀模式
daemonize yes                    #后臺運行redis

從節(jié)點二

port 6002                        #端口號       
bind 192.168.8.13                #綁定IP
slaveof 192.168.8.11 6000        #設(shè)置主節(jié)點信息
masterauth 123456                #主節(jié)點口令
requirepass 123456               #登錄口令
slave-read-only yes              #只讀模式
daemonize yes                    #后臺運行redis

五、啟動Redis

先啟動主節(jié)點,在啟動從節(jié)點

主節(jié)點

[root@red1 redis]# redis-server /usr/local/redis/redis.conf
[root@red1 redis]# 
[root@red1 redis]# 
[root@red1 redis]# ps -ef|grep redis
root      2012     1  0 21:35 ?        00:00:00 redis-server 192.168.8.11:6000
root      2017  1384  0 21:35 pts/0    00:00:00 grep --color=auto redis

可以看到端口號為6000的redis服務(wù)已經(jīng)啟動

從節(jié)點一

root@red2 ~]# redis-server /usr/local/redis/redis.conf
[root@red2 ~]# ps -ef|grep redis
root      1968     1  0 21:36 ?        00:00:00 redis-server 192.168.8.12:6001
root      1973  1386  0 21:36 pts/0    00:00:00 grep --color=auto redis

可以看到端口號為6001的redis服務(wù)已經(jīng)啟動

從節(jié)點二

[root@red3 ~]# ps -ef|grep redis
root      1943     1  0 21:36 ?        00:00:00 redis-server 192.168.8.13:6002
root      1956  1034  0 21:36 pts/0    00:00:00 grep --color=auto redis

可以看到端口號為6002的redis服務(wù)已經(jīng)啟動

六、可用性驗證

主節(jié)點

[root@red1 redis]# redis-cli -p 6000 -a 123456 -h 192.168.8.11
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.8.11:6000> get 1
"hello"
192.168.8.11:6000> get 3
(nil)
192.168.8.11:6000> set 3 world
OK
192.168.8.11:6000> get 3
"world"

從節(jié)點一

[root@red2 ~]# redis-cli -p 6001 -a 123456 -h 192.168.8.12
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.8.12:6001> get 3
"world"

從節(jié)點二

[root@red3 ~]# redis-cli -p 6002 -h 192.168.8.13 -a 123456
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.8.13:6002> get 3
"world"

“Redis5怎么配置一主兩從讀寫分離”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識可以關(guān)注創(chuàng)新互聯(lián)網(wǎng)站,小編將為大家輸出更多高質(zhì)量的實用文章!

網(wǎng)站名稱:Redis5怎么配置一主兩從讀寫分離
當(dāng)前URL:http://bm7419.com/article16/gejpgg.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)響應(yīng)式網(wǎng)站、網(wǎng)頁設(shè)計公司、外貿(mào)網(wǎng)站建設(shè)、軟件開發(fā)、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

小程序開發(fā)