Sekurang-kurangnya harus ada tiga nod dalam kelompok dan setiap nod mempunyai nod sandaran. 6 pelayan diperlukan.
Jika syarat terhad, anda boleh membina kluster teragih pseudo Langkah berikut adalah untuk membina kluster redis dengan 6 nod pada pelayan Linux.
Direktori baharu: mkdir /usr/local/redis-cluster
wget http://download.redis.io/releases/redis-5.0.0.tar.gz tar xzf redis-5.0.0.tar.gz cd redis-5.0.0 make make install prefix=/usr/local/redis
/root/software/redis/redis-cluster-conf/7001/redis.confSesetengah operasi Perintah adalah untuk rujukan sahaja:/root/software/redis /redis-cluster-conf/ 7002/redis.conf
/root/software/redis/redis-cluster-conf/7003/redis.conf
/root/software/redis/redis-cluster-conf/7004 /redis.conf
/root/software/redis/redis-cluster-conf/7005/redis.conf
/root/software/redis/redis-cluster-conf/7006/redis.conf
cp redis.conf /usr/local/redis/bin cd /usr/local/redis/ cp -r bin ../redis-cluster/redis01 cd /usr/local/redis-cluster/redis01 rm dump.rdb #删除快照 vim redis.conf
port 7001 #端口 cluster-enabled yes #启用集群模式 cluster-config-file nodes.conf cluster-node-timeout 5000 #超时时间 appendonly yes daemonize yes #后台运行 protected-mode no #非保护模式 pidfile /var/run/redis_7001.pid bind 172.20.10.7 #127.0.0.1改为本机ip地址,可用ifconfig查看ip
[root@master redis-cluster]# cp -r redis01/ redis02 [root@master redis-cluster]# cp -r redis01/ redis03 [root@master redis-cluster]# cp -r redis01/ redis04 [root@master redis-cluster]# cp -r redis01/ redis05 [root@master redis-cluster]# cp -r redis01/ redis06
Buat fail kelompok dan mulakan enam redis pada masa yang sama
vim startall.sh
Tambah kandungan berikut:
cd redis01 ./redis-server redis.conf cd .. cd redis02 ./redis-server redis.conf cd .. cd redis03 ./redis-server redis.conf cd .. cd redis04 ./redis-server redis.conf cd .. cd redis05 ./redis-server redis.conf cd .. cd redis06 ./redis-server redis.conf cd ..
dan kemudian laksanakan
untuk menjadikan menjadi fail boleh laku chmod u+x start-all.sh
start-all.sh
dan mulakannya dalam direktori semasa:
./startall.sh
Lihat:
ps aux|grep redis
<img src="https://img.php.cn/upload/article/000/887/227/168559062896660.jpg" alt="Cara membina dan menggunakan kluster redis5 di bawah Centos7" />
>>> 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.10.7:7004 to 172.20.10.7:7001 adding replica 172.20.10.7:7005 to 172.20.10.7:7002 adding replica 172.20.10.7:7006 to 172.20.10.7:7003 >>> trying to optimize slaves allocation for anti-affinity [warning] some slaves are in the same host as their master m: a4128b5e581c3722acd9b093c5f29f5056f680b0 172.20.10.7:7001 slots:[0-5460] (5461 slots) master m: d6fed6f21269b8469a3076ac5fb168bd20f70c26 172.20.10.7:7002 slots:[5461-10922] (5462 slots) master m: 51a0f62dacead745ce5351cdbe0bdbae553ce413 172.20.10.7:7003 slots:[10923-16383] (5461 slots) master s: 45cc35740ac67f7988bb75325871ba12d08a76e4 172.20.10.7:7004 replicates a4128b5e581c3722acd9b093c5f29f5056f680b0 s: 668054fe16cdf8741152cae863f5c636ed18b803 172.20.10.7:7005 replicates d6fed6f21269b8469a3076ac5fb168bd20f70c26 s: ae39b7db285703f8c08412d6b04998c60a634295 172.20.10.7:7006 replicates 51a0f62dacead745ce5351cdbe0bdbae553ce413 can i set the above configuration? (type 'yes' to accept):yes
Masukkan ya dan tekan Enter6. Operasi Kluster6.1 Tutup klusterPada ketika ini, gugusan reids5 selesai.>>> 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.10.7:7001) m: a4128b5e581c3722acd9b093c5f29f5056f680b0 172.20.10.7:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s) m: d6fed6f21269b8469a3076ac5fb168bd20f70c26 172.20.10.7:7002 slots:[5461-10922] (5462 slots) master 1 additional replica(s) s: 45cc35740ac67f7988bb75325871ba12d08a76e4 172.20.10.7:7004 slots: (0 slots) slave replicates a4128b5e581c3722acd9b093c5f29f5056f680b0 m: 51a0f62dacead745ce5351cdbe0bdbae553ce413 172.20.10.7:7003 slots:[10923-16383] (5461 slots) master 1 additional replica(s) s: 668054fe16cdf8741152cae863f5c636ed18b803 172.20.10.7:7005 slots: (0 slots) slave replicates d6fed6f21269b8469a3076ac5fb168bd20f70c26 s: ae39b7db285703f8c08412d6b04998c60a634295 172.20.10.7:7006 slots: (0 slots) slave replicates 51a0f62dacead745ce5351cdbe0bdbae553ce413 [ok] all nodes agree about slots configuration. >>> check for open slots... >>> check slots coverage... [ok] all 16384 slots covered.Salin selepas log masuk
/root/redis-5.0.0/utils/create-cluster
Kandungan adalah seperti berikut: /root/redis-5.0.0/utils/create-cluster/create-cluster stop
/usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7001 shutdown /usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7002 shutdown /usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7003 shutdown /usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7004 shutdown /usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7005 shutdown /usr/local/redis-cluster/redis-cli -c -h 172.20.10.7 -p 7006 shutdown
untuk menukar shutdown.sh menjadi fail boleh laku
Mulakan dalam direktori semasa: ./shutdown.sh
chmod u+x shutdown.sh
Rasmi: /usr/local/redis-cluster/redis-cli -a xxx -c -h 192.168.5.100 -p 8001
Petua: - kata laluan pelayan akses, -c bermaksud mod kluster, -h Nyatakan alamat ip, -p menentukan nombor port
6.2 Mulakan semula kluster/root/redis-5.0.0/utils/create-cluster/create-cluster start
vim startall.sh Tambah kandungan berikut: (Ingat untuk menukar alamat IP anda sendiri)
/usr/local/redis-cluster/redis-cli --cluster create 172.20.10.7:7001 172.20.10.7:7002 172.20.10.7:7003 172.20.10.7:7004 172.20.10.7:7005 172.20.10.7:7006 --cluster-replicas
Laksanakan dalam direktori kelompok redis
redis01/redis-cli -h 192.168.25.153 -p 7002 -c
maklumat kluster Maklumat status kluster
Atas ialah kandungan terperinci Cara membina dan menggunakan kluster redis5 di bawah Centos7. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!