1 安裝(redis)
2 先準備一臺乾淨的redis
建立資料夾建立資料夾
mkdir -p /usr/local/redis/bin
mkdir -p /usr/local/redis/etc
複製配置檔案
cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-sentinel redis-server /usr/local/redis/bin/
啟動
[root@localhost redis]# ./bin/redis-server ./etc/redis.conf
==================================================
開始部署redis-cluster
[root@localhost redis]# mkdir -p /usr/local/redis-cluster
[root@localhost local]# cd redis-cluster/
[root@localhost redis-cluster]# mkdir 8001
[root@localhost redis-cluster]# mkdir 8002
[root@localhost redis-cluster]# mkdir 8003
[root@localhost redis-cluster]# mkdir 8004
[root@localhost redis-cluster]# mkdir 8005
[root@localhost redis-cluster]# mkdir 8006
賦值配置檔案
[root@localhost 8001]# cp /usr/local/redis/etc/redis.conf ./
修改配置檔案(6份)
prot 8001
bind 192.168.8.128
dir /usr/local/redis-cluster/8001/
cluster-enabled yes
cluster-node-timeout 5000
cluster-config-file nodes-8001.conf
appendonly yes
批量替換
:%s/8001/8002/g
:%s/8001/8003/g
:%s/8001/8004/g
:%s/8001/8005/g
:%s/8001/8006/g
安裝redis-cluster的管理工具ruby (這裡有坑注意ruby版本大於2.3)
yum -y insta11 ruby ruby-devel rubygems rpm-build
yum insta1l centos-release-sc1-rh
yum instal1 rh-ruby23 -y
sc1 enable rh-ruby23 bash
啟動6臺
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/8001/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/8002/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/8003/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/8004/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/8005/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/8006/redis.conf
啟動叢集(在src目錄下啟動)
./redis-trib.rb create --replicas 1 192.168.8.128:8001 192.168.8.128:8002 192.168.8.128:8003 192.168.8.128:8004 192.168.8.128:8005 192.168.8.128:8006
測試
[root@localhost bin]# ps -ef | grep redis
root 14307 1 0 21:45 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.8.128:8001 [cluster]
root 14314 1 0 21:45 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.8.128:8002 [cluster]
root 14321 1 0 21:45 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.8.128:8003 [cluster]
root 14326 1 0 21:45 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.8.128:8004 [cluster]
root 14331 1 0 21:46 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.8.128:8005 [cluster]
root 14336 1 0 21:46 ? 00:00:00 /usr/local/redis/bin/redis-server 192.168.8.128:8006 [cluster]
root 14357 14035 0 21:53 pts/0 00:00:00 grep --color=auto redis
[root@localhost bin]# ./redis-cli -c -h 192.168.8.128 -p 8001
192.168.8.128:8001> set name qiaofeifei
-> Redirected to slot [5798] located at 192.168.8.128:8002
OK
192.168.8.128:8002> set position php
OK
192.168.8.128:8002> set A 100
OK
192.168.8.128:8002> set hello world
-> Redirected to slot [866] located at 192.168.8.128:8001
OK
192.168.8.128:8001> set nihao 666
-> Redirected to slot [11081] located at 192.168.8.128:8003
OK
192.168.8.128:8003> get A
-> Redirected to slot [6373] located at 192.168.8.128:8002
"100"
192.168.8.128:8002>
本作品採用《CC 協議》,轉載必須註明作者和本文連結