實(shí)驗(yàn)環(huán)境
10年積累的成都網(wǎng)站制作、做網(wǎng)站經(jīng)驗(yàn),可以快速應(yīng)對(duì)客戶對(duì)網(wǎng)站的新想法和需求。提供各種問(wèn)題對(duì)應(yīng)的解決方案。讓選擇我們的客戶得到更好、更有力的網(wǎng)絡(luò)服務(wù)。我雖然不認(rèn)識(shí)你,你也不認(rèn)識(shí)我。但先網(wǎng)站制作后付款的網(wǎng)站建設(shè)流程,更有白河免費(fèi)網(wǎng)站建設(shè)讓你可以放心的選擇與我們合作。主機(jī)名 | IP地址 | Redis端口劃分 | 備注 |
node171 | 172.20.20.171 | 16001,16002 | |
node172 | 172.20.20.172 | 16001,16002 | |
node173 | 172.20.20.173 | 16001,16002 |
軟件版本
操作系統(tǒng):CentOS X64 7.3
Redis版本:5.0.5
公共基礎(chǔ)配置
3臺(tái)均操作,這里無(wú)特別說(shuō)明,均是root操作
1.?關(guān)閉防火墻
systemctl stop firewalld.service
setenforce ?0
sed -i 's#SELINUX=enforcing#SELINUX=disabled#g' /etc/selinux/config
2.?配置主機(jī)名
cat >> /etc/hosts << EOF
172.20.20.171 node171
172.20.20.172 node172
172.20.20.173 node173
EOF
3.?新建目錄
mkdir -p /opt/redis;mkdir -p /opt/redis/{bin,conf,logs}
mkdir -p /data/redis/data
安裝Redis
3臺(tái)均操作
PS:若是購(gòu)買云ECS進(jìn)行自建,可以做成一臺(tái),打包成基礎(chǔ)或可以使用Salt或Ansible進(jìn)行批量部署
yum install -y gcc gcc-c++
wget http://download.redis.io/releases/redis-5.0.5.tar.gz
cd /root
tar xf redis-5.0.5.tar.gz
cd redis-5.0.5
make MALLOC=libc
make PREFIX=/opt/redis/ install
cp /root/redis-5.0.5/redis.conf ?/opt/redis/conf/redis-16001.conf
cd /opt/redis/conf/
sed -i 's#bind 127.0.0.1#bind 0.0.0.0#g' redis-16001.conf
sed -i "s#port 6379#port 16001#g" redis-16001.conf
sed -i "s#daemonize no#daemonize yes#g" redis-16001.conf
sed -i 's#pidfile /var/run/redis_6379.pid#pidfile /opt/redis/logs/redis_16001.pid#g' redis-16001.conf
sed -i 's#logfile ""#logfile "/opt/redis/logs/redis_16001.log"#g' redis-16001.conf
sed -i 's#dbfilename dump.rdb#dbfilename redis_16001.rdb#g' redis-16001.conf
sed -i 's#dir ./#dir /data/redis/data/#g' redis-16001.conf
sed -i "s#appendonly no#appendonly yes#g" redis-16001.conf
sed -i 's#appendfilename "appendonly.aof"#appendfilename "redis_16001.aof"#g' ?redis-16001.conf
sed -i 's#\# cluster-enabled yes# cluster-enabled yes#g' redis-16001.conf
sed -i 's#\# cluster-config-file nodes-6379.conf#cluster-config-file /opt/redis/conf/nodes-16001.conf#g' redis-16001.conf
sed -i 's#\# masterauth
cp redis-16001.conf ?redis-16002.conf
sed -i 's#16001#16002#g' redis-16002.conf
啟動(dòng)Redis
3臺(tái)均操作
/opt/redis/bin/redis-server ?/opt/redis/conf/redis-16001.conf
/opt/redis/bin/redis-server ?/opt/redis/conf/redis-16002.conf
啟動(dòng)Redis集群
在三臺(tái)任意一臺(tái)上執(zhí)行
/opt/redis/bin/redis-cli ?--cluster create 172.20.20.171:16001 172.20.20.171:16002 172.20.20.172:16001 172.20.20.172:16002 172.20.20.173:16001 172.20.20.173:16002 ?--cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 172.20.20.172:16002 to 172.20.20.171:16001
Adding replica 172.20.20.173:16002 to 172.20.20.172:16001
Adding replica 172.20.20.171:16002 to 172.20.20.173:16001
M: a9ab7a12884d505efcf066fcc3aae74c2b3f101d 172.20.20.171:16001
slots:[0-5460] (5461 slots) master
S: 81d1b25ae1ea85421bd4abb2be094c258026c505 172.20.20.171:16002
replicates 04d9c29ef2569b1fc8abd9594d64fca33e4ad4f2
M: 761348a0107f5b009cabc22c214e39578d0aa707 172.20.20.172:16001
slots:[5461-10922] (5462 slots) master
S: 6dec89e63a48a9a9f393011a698a0bda21b70f1e 172.20.20.172:16002
replicates a9ab7a12884d505efcf066fcc3aae74c2b3f101d
M: 04d9c29ef2569b1fc8abd9594d64fca33e4ad4f2 172.20.20.173:16001
slots:[10923-16383] (5461 slots) master
S: 14e79155f78065e4518e00cd5bd057336b17e3a7 172.20.20.173:16002
replicates 761348a0107f5b009cabc22c214e39578d0aa707
Can I set the above configuration? (type 'yes' to accept): yes??#輸入yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.....
>>> Performing Cluster Check (using node 172.20.20.171:16001)
M: a9ab7a12884d505efcf066fcc3aae74c2b3f101d 172.20.20.171:16001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 81d1b25ae1ea85421bd4abb2be094c258026c505 172.20.20.171:16002
slots: (0 slots) slave
replicates 04d9c29ef2569b1fc8abd9594d64fca33e4ad4f2
M: 761348a0107f5b009cabc22c214e39578d0aa707 172.20.20.172:16001
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 14e79155f78065e4518e00cd5bd057336b17e3a7 172.20.20.173:16002
slots: (0 slots) slave
replicates 761348a0107f5b009cabc22c214e39578d0aa707
S: 6dec89e63a48a9a9f393011a698a0bda21b70f1e 172.20.20.172:16002
slots: (0 slots) slave
replicates a9ab7a12884d505efcf066fcc3aae74c2b3f101d
M: 04d9c29ef2569b1fc8abd9594d64fca33e4ad4f2 172.20.20.173:16001
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
驗(yàn)證測(cè)試
[root@node172 conf]# /opt/redis/bin/redis-cli ?-h 172.20.20.172 -p 16001
172.20.20.172:16001> cluster nodes
04d9c29ef2569b1fc8abd9594d64fca33e4ad4f2 172.20.20.173:16001@26001 master - 0 1563967987854 5 connected 10923-16383
a9ab7a12884d505efcf066fcc3aae74c2b3f101d 172.20.20.171:16001@26001 master - 0 1563967985839 1 connected 0-5460
81d1b25ae1ea85421bd4abb2be094c258026c505 172.20.20.171:16002@26002 slave 04d9c29ef2569b1fc8abd9594d64fca33e4ad4f2 0 1563967983822 5 connected
6dec89e63a48a9a9f393011a698a0bda21b70f1e 172.20.20.172:16002@26002 slave a9ab7a12884d505efcf066fcc3aae74c2b3f101d 0 1563967988858 4 connected
14e79155f78065e4518e00cd5bd057336b17e3a7 172.20.20.173:16002@26002 slave 761348a0107f5b009cabc22c214e39578d0aa707 0 1563967986847 6 connected
761348a0107f5b009cabc22c214e39578d0aa707 172.20.20.172:16001@26001 myself,master - 0 1563967986000 3 connected 5461-10922
172.20.20.172:16001> set name "Mr.Zhang"
OK
172.20.20.172:16001> get name
"Mr.Zhang"
Redis集群?jiǎn)?dòng)腳本
3臺(tái)均配置
cat >> /opt/redis/bin/start-all.sh << EOF
/opt/redis/bin/redis-server ?/opt/redis/conf/redis-16001.conf
/opt/redis/bin/redis-server ?/opt/redis/conf/redis-16002.conf
EOF
chmod +x /opt/redis/bin/start-all.sh
Redis集群停止腳本
任意一臺(tái)即可
cat /opt/redis/bin/stop-all.sh
#!/bin/bash # Settings PORT=16000 TIMEOUT=2000 NODES=2 REPLICAS=1 HOSTS=(172.20.20.171 172.20.20.172 172.20.20.173) # You may want to put the above config parameters into config.sh in order to # override the defaults without modifying this script. if [ -a config.sh ] then source "config.sh" fi # Computed vars ENDPORT=$((PORT+NODES)) if [ "$1" == "stop" ] then while [ $((PORT < ENDPORT)) != "0" ]; do PORT=$((PORT+1)) for host in ${HOSTS[@]} do /opt/redis/bin/redis-cli -h $host -p $PORT shutdown nosave done done exit 0 fi echo "Usage: $0 [stop]" echo "stop ???????-- Stop Redis Cluster instances." |
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無(wú)理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國(guó)服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡(jiǎn)單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢(shì),專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場(chǎng)景需求。