1,首先將redis-trib.rb 複製到/usr/local/bin 目錄下
cp /usr/local/redis-4.0.2/src/redis-trib.rb /usr/local/bin
2,創建Redis節點(7000-7005)
cd /usr/local/redis-4.0.2/
mkdir redis_cluster/7000
......
mkdir redis_cluster/7005
3,將redis.conf配置文件複製到Redis節點文件夾(7000-7005)
cp redis.conf redis_cluster/7000
......
cp redis.conf redis_cluster/7005
4,並分別修改配置文件redis.conf(7000-7005)
vim redis_cluster/7000/redis.conf
......
vim redis_cluster/7005/redis.conf
5,redis.conf修改內容爲(7000-7005)
port 7000
bind 192.168.11.129
daemonize yes
pidfile /var/run/redis_7000.pid
cluster-enabled yes
cluster-config-file nodes_7000.conf
cluster-node-timeout 15000
appendonly yes
port:端口號7000-7005
bind:本機ip,默認ip爲127.0.0.1,需要改爲其它節點機器可訪問的ip,否則創建集羣時無法訪問對應端口,無法創建集羣
daemonize yes:redis後臺運行
pidfile:文件對應7000-7005
cluster-enable yes:開啓集羣,去掉註釋#
cluster-config-file:集羣的配置文件,首次啓動自動生成 7000-7005
cluster-node-timeout:請求超時,默認15秒,可自行設置
appendonly yes:aof日誌開啓,有需要就開啓,它會每次寫操作都記錄一條日誌
6,啓動各個節點(7000-7005)
首先進入bin目錄
cd /usr/local/bin
接着啓動節點
redis-server /usr/local/redis-4.0.2/redis_cluster/7000/redis.conf
......
redis-server /usr/local/redis-4.0.2/redis_cluster/7005/redis.conf
7,檢查Redis節點啓動情況
ps -ef |grep redis
netstat -tnlp|grep redis
8,創建集羣
redis-trib.rb create --replicas 1 192.168.11.129:7000 192.168.11.129:7001 192.168.11.129:7002 192.168.11.129:7003 192.168.11.129:7004 192.168.11.129:7005
9,失敗
ruby:No such file or directoryyes
需要安裝ruby,點擊上面鏈接
10,創建集羣127.0.0.1
redis-trib.rb create --replicas 1 192.168.11.129:7000 192.168.11.129:7001 192.168.11.129:7002 192.168.11.129:7003 192.168.11.129:7004 192.168.11.129:7005
11,出現詢問
Can I set the above configuration?(type 'yes' to accept):
輸入yes
出現[OK] All 16384 slots covered 代表成功!
12,集羣搭建成功驗證
登錄到端口爲7000的節點客戶端,並添加值
redis-cli -h 192.168.11.129 -c -p 7000
192.168.11.129:7000>set Boston Celtics
OK
192.168.11.129:7000>exit
登錄到端口爲7005的節點客戶端,並獲取剛纔添加的值
redis-cli -h 192.168.11.129 -c -p 7005
192.168.11.129:7005>get Boston
"Celtics"
大獲成功!
13,完結撒花!