1.安裝環境linux系統,時間2020年2月
2.官網下載https://redis.io/
3.解壓
tar -zxvf redis-5.0.7.tar.gz
4.配置文件
1 //創建etc文件夾,bin文件夾 2 [~]#cp redis.conf redis_copy.conf 3 [~]#mv redis.conf ./etc/ 4 [~]#cd src 5 [~]mv mkreleasehdr.sh redis-check-aof redis-check-rdb redis-cli redis-server redis-trib.rb redis-benchmark ../bin/ 6 //創建8000-8005文件夾,在etc 7 [~]#cd ../etc 8 [~]#mkdir 8000 9 [~]#mkdir 8001 10 [~]#mkdir 8002 11 [~]#mkdir 8003 12 [~]#mkdir 8004 13 [~]#mkdir 8005 14 [~]cp ../redis.conf ./8000/
4.1配置8000文件夾下的redis.conf,並復制到其他文件下
1 port 8000 //端口 2 bind 本機ip //默認ip為127.0.0.1 需要改為其他節點機器可訪問的ip 否則創建集群時無法訪問對應的端口,無法創建集群 ,或者注釋掉 3 daemonize yes //redis后台運行 4 pidfile /var/run/redis_8000.pid //pidfile文件對應8000, 5 cluster-enabled yes //開啟集群 把注釋#去掉 6 cluster-config-file nodes_8000.conf //集群的配置 配置文件首次啟動自動生成 80002 把注釋#去掉 7 cluster-node-timeout 15000 //請求超時 默認15秒,可自行設置 把注釋#去掉 8 appendonly yes //aof日志開啟 有需要就開啟,它會每次寫操作都記錄一條日志
5.編寫啟動sh和停止sh
redis官網:The first example, that is, the cluster creation, will be shown using both redis-cli in Redis 5 and redis-trib in Redis 3 and 4. However all the next examples will only use redis-cli,
since as you can see the syntax is very similar, and you can trivially change one command line into the other by using redis-trib.rb help to get info about the old syntax.
Important: note that you can use Redis 5 redis-cli against Redis 4 clusters without issues if you wish. 從5.0之后,可以不用ruby啟動集群,3,4還是要的。例如:redis-cli --cluster create 127.0.0.1:7000 127.0.0.1:7001 \
127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 \
--cluster-replicas 1
//編寫一個簡單的startall.sh啟動 [~]#touch startall.sh [~]#vim startall.sh cd /home/software/redis-5.0.7/bin/ ./redis-server ../etc/8000/redis.conf ./redis-server ../etc/8001/redis.conf ./redis-server ../etc/8002/redis.conf ./redis-server ../etc/8003/redis.conf ./redis-server ../etc/8004/redis.conf ./redis-server ../etc/8005/redis.conf [~]#chmod +x startall.sh//給這個執行的權限 [~]#bash startall.sh [~]#ps -aux | grep redis //查看啟動狀態
//編寫一個停止sh [~]#touch shutdown-all.sh [~]#vim shutdown-all.sh bin/redis-cli -p 8000 shutdown bin/redis-cli -p 8001 shutdown bin/redis-cli -p 8002 shutdown bin/redis-cli -p 8003 shutdown bin/redis-cli -p 8004 shutdown bin/redis-cli -p 8005 shutdown
6.創建集群
[~]#./redis-cli --cluster create 127.0.0.1:8000 127.0.0.1:8001 127.0.0.1:8002 127.0.0.1:8003 127.0.0.1:8004 127.0.0.1:8005 --cluster-replicas 1
7.測試
[~]#redis-cli -c -p 8000
[~]#cluster info