redis集群的搭建 redis集群的三種模式 主從複製 哨兵模式 cluster集群 redis-cluster集群的搭建(在一臺linux中搭建,三主三從) 下載安裝redis5.0.3 cd /opt 下載redis安裝包 wget http://download.redis.io/relea ...
redis集群的搭建
redis集群的三種模式
- 主從複製
- 哨兵模式
- cluster集群
redis-cluster集群的搭建(在一臺linux中搭建,三主三從)
下載安裝redis5.0.3
- cd /opt 下載redis安裝包 wget http://download.redis.io/releases/redis-5.0.3.tar.gz
- tar -zxvf redis-5.0.3.tar.gz 解壓
- make 編譯
- cd redis-5.0.3/ 進入redis文件夾
- mkdir -p /usr/local/redis-5.0.3 創建redis-5.0.3安裝文件夾
- make install PREFIX=/usr/local/redis-5.0.3 安裝redis到/usr/local/redis-5.0.3
創建redis-cluster集群文件
- mkdir -p /usr/local/redis-cluster 創建redis集群文件夾
- cd /usr/local/
- cp redis-5.0.3 ./redis-cluster -R 複製redis到集群目錄中
- 分別創建config、log、run、dbfile目錄
- cd /usr/local/redis-cluster/redis-5.0.3
- mkdir log
- mkdir run
- mkdir dbfile
- mkdir -p config/6380
- mkdir -p config/6381
- mkdir -p config/6382
- mkdir -p config/6383
- mkdir -p config/6384
- mkdir -p config/6385
修改redis.conf文件
- cp /opt/redis-5.0.3/redis.conf /usr/local/redis-cluster/redis-5.0.3/conf/6380/6380.conf
- 找到並修改以下配置
bind 這裡修改為本機的網卡ip
protected-mode no
daemonize yes
appendonly yes
port 6380
pidfile /usr/local/redis-cluster/redis-5.0.3/run/redis_6380.pid
appendfilename "appendonly_6380.aof"
logfile "/usr/local/redis-cluster/redis-5.0.3/log/redis_6380.log"
requirepass password
cluster-enabled yes
cluster-node-timeout 5000
cluster-config-file nodes-6380.conf
dbfilename dump_6380.rdb
dir /usr/local/redis-cluster/redis-5.0.3/dbfile
save 900 1
save 300 10
save 60 10000
- 複製該配置文件到其他的配置文件夾中,修改相應的配置(6380改為638?)
開啟相應的埠(centos7埠預設關閉)
- systemctl start firewalld 如果防火牆未開啟,需要先開啟
- firewall-cmd --zone=public --add-port=6380/tcp --permanent 開啟數據埠
- firewall-cmd --zone=public --add-port=16380/tcp --permanent 開啟匯流排埠 數據埠和匯流排埠必須全部開啟
- 其他相應埠同樣開啟
- firewall-cmd --reload 重新載入配置
- filewall-cmd --list-ports 查詢已開放埠
開啟redis服務
- 創建redis啟動腳本
- cd /usr/local/redis-cluster
- vim startup.sh
#!/bin/bash
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6380/6380.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6381/6381.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6382/6382.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6383/6383.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6384/6384.conf
/usr/local/redis-cluster/redis-5.0.3/bin/redis-server /usr/local/redis-cluster/redis-5.0.3/conf/6385/6385.conf
- ps -ef|grep redis 查詢redis是否開啟
加入集群
cd /usr/local/redis-cluster/redis-5.0.3/bin
./redis-cli -a password --cluster create 192.168.75.101:6380 192.168.75.101:6381 192.168.75.101:6382 192.168.75.101:6383 192.168.75.101:6384 192.168.75.101:6385 --cluster-replicas 1
客戶端連接集群
連接的時候需要加上-c參數,集群模式連接
註意點
- centos7埠預設關閉,需要手動開啟數據埠和匯流排埠
- 配置文件的設置,開啟集群模式,bind需要設置本機的ip地址
- 連接集群的時候需要,設置集群模式連接-c
參考鏈接:https://blog.csdn.net/xukang77/article/details/121613391