久久精品人人爽,华人av在线,亚洲性视频网站,欧美专区一二三

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

182次閱讀
沒有評論

共計 3299 個字符,預計需要花費 9 分鐘才能閱讀完成。

本篇內容介紹了“Redis5 怎么配置一主兩從讀寫分離”的有關知識,在實際案例的操作過程中,不少人都會遇到這樣的困境,接下來就讓丸趣 TV 小編帶領大家學習一下如何處理這些情況吧!希望大家仔細閱讀,能夠學有所成!

實驗環境:

系統:CentOS7

軟件:redis-5.0.2

一、解壓 redis-5.0.2

三個節點

[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

三個節點

make

make install

三、修改環境變量

三個節點

安裝完 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

修改環境變量

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

四、配置 Redis 配置文件

主節點 192.168.8.11

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

從節點一

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

從節點二

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

五、啟動 Redis

先啟動主節點,在啟動從節點

主節點

[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 服務已經啟動

從節點一

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 服務已經啟動

從節點二

[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 服務已經啟動

六、可用性驗證

主節點

[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
192.168.8.11:6000  get 3
 world

從節點一

[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

從節點二

[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 怎么配置一主兩從讀寫分離”的內容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業相關的知識可以關注丸趣 TV 網站,丸趣 TV 小編將為大家輸出更多高質量的實用文章!

正文完
 
丸趣
版權聲明:本站原創文章,由 丸趣 2023-07-28發表,共計3299字。
轉載說明:除特殊說明外本站除技術相關以外文章皆由網絡搜集發布,轉載請注明出處。
評論(沒有評論)
主站蜘蛛池模板: 吉林省| 临湘市| 淅川县| 封开县| 潼南县| 秦皇岛市| 拜城县| 淮北市| 奉贤区| 开平市| 耿马| 洪洞县| 芦溪县| 神木县| 启东市| 赞皇县| 左云县| 安吉县| 印江| 蕉岭县| 广西| 宁城县| 禹城市| 泸西县| 馆陶县| 江门市| 丹巴县| 囊谦县| 静海县| 嵊泗县| 阿鲁科尔沁旗| 汝城县| 兴安县| 灯塔市| 腾冲县| 南昌市| 柏乡县| 巴塘县| 新乐市| 岫岩| 连州市|