這篇文章將為大家詳細講解有關redis 6.X Cluster集群如何搭建,小編覺得挺實用的,因此分享給大家做個參考,希望大家閱讀完這篇文章后可以有所收獲。
創新互聯是一家專業提供鐵山港企業網站建設,專注與成都網站制作、網站設計、HTML5、小程序制作等業務。10年已為鐵山港眾多企業、政府機構等服務。創新互聯專業的建站公司優惠進行中。
可直接到 Redis 官網下載最新穩定包,地址:https://redis.io/download。或者使用 命令:sudo wget http://download.redis.io/releases/redis-6.0.9.tar.gz 下載安裝包.。
碼哥統一把軟件包放在 /opt/soft 目錄下,并創建目錄 mkdir redisCluster用于放置集群配置文件。在 redisCluster 目錄下執行 mkdir 7000 7001 7002 7003 7004 7005 創建 6 個目錄分別對應每個節點 redis.conf 配置模板。
tar -zxf redis-6.0.9.tar.gz -C redisCluster 解壓到 redisCluster 目錄中。
在編譯之前我們需要確認 gcc 版本,自 redis 6.0.0 之后,編譯 redis 需要支持 C11 特性,C11 特性在 4.9 中被引入。Centos 7 默認 gcc 版本為 4.8.5,所以需要升級gcc版本。
否則在編譯過程中會遇到如下錯誤日志:
In file included from server.c:31:0: server.c:4999:59: error: ‘struct redisServer’ has no member named ‘cluster’ (server.cluster_enabled && nodeIsMaster(server.cluster->myself))); ^ cluster.h:58:27: note: in definition of macro ‘nodeIsMaster’ #define nodeIsMaster(n) ((n)->flags & CLUSTER_NODE_MASTER) ^ server.c: In function ‘main’: server.c:5047:11: error: ‘struct redisServer’ has no member named ‘sentinel_mode’ server.sentinel_mode = checkForSentinelMode(argc,argv); ^ server.c:5064:15: error: ‘struct redisServer’ has no member named ‘sentinel_mode’ if (server.sentinel_mode) { ^ server.c:5131:19: error: ‘struct redisServer’ has no member named ‘sentinel_mode’ if (server.sentinel_mode && configfile && *configfile == '-') { ^ server.c:5153:168: error: ‘struct redisServer’ has no member named ‘sentinel_mode’ serverLog(LL_WARNING, "Warning: no config file specified, using the default config. In order to specify a config file use %s /path/to/%s.conf", argv[0], server.sentinel_mode ? "sentinel" : "redis"); ^ server.c:5158:11: error: ‘struct redisServer’ has no member named ‘supervised’ server.supervised = redisIsSupervised(server.supervised_mode); ^ server.c:5158:49: error: ‘struct redisServer’ has no member named ‘supervised_mode’ server.supervised = redisIsSupervised(server.supervised_mode); ^ server.c:5159:28: error: ‘struct redisServer’ has no member named ‘daemonize’ int background = server.daemonize && !server.supervised; ^ server.c:5159:49: error: ‘struct redisServer’ has no member named ‘supervised’ int background = server.daemonize && !server.supervised; ^ server.c:5163:29: error: ‘struct redisServer’ has no member named ‘pidfile’ if (background || server.pidfile) createPidFile(); ^ server.c:5168:16: error: ‘struct redisServer’ has no member named ‘sentinel_mode’ if (!server.sentinel_mode) { ^ server.c:5178:19: error: ‘struct redisServer’ has no member named ‘cluster_enabled’ if (server.cluster_enabled) { ^ server.c:5186:19: error: ‘struct redisServer’ has no member named ‘ipfd_count’ if (server.ipfd_count > 0 || server.tlsfd_count > 0) ^ server.c:5186:44: error: ‘struct redisServer’ has no member named ‘tlsfd_count’ if (server.ipfd_count > 0 || server.tlsfd_count > 0) ^ server.c:5188:19: error: ‘struct redisServer’ has no member named ‘sofd’ if (server.sofd > 0) ^ server.c:5189:94: error: ‘struct redisServer’ has no member named ‘unixsocket’ serverLog(LL_NOTICE,"The server is now ready to accept connections at %s", server.unixsocket); ^ server.c:5190:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’ if (server.supervised_mode == SUPERVISED_SYSTEMD) { ^ server.c:5191:24: error: ‘struct redisServer’ has no member named ‘masterhost’ if (!server.masterhost) { ^ server.c:5201:19: error: ‘struct redisServer’ has no member named ‘supervised_mode’ if (server.supervised_mode == SUPERVISED_SYSTEMD) { ^ server.c:5208:15: error: ‘struct redisServer’ has no member named ‘maxmemory’ if (server.maxmemory > 0 && server.maxmemory < 1024*1024) { ^ server.c:5208:39: error: ‘struct redisServer’ has no member named ‘maxmemory’ if (server.maxmemory > 0 && server.maxmemory < 1024*1024) { ^ server.c:5209:176: error: ‘struct redisServer’ has no member named ‘maxmemory’ serverLog(LL_WARNING,"WARNING: You specified a maxmemory value that is less than 1MB (current value is %llu bytes). Are you sure this is what you really want?", server.maxmemory); ^ server.c:5212:31: error: ‘struct redisServer’ has no member named ‘server_cpulist’ redisSetCpuAffinity(server.server_cpulist); ^ server.c: In function ‘hasActiveChildProcess’: server.c:1480:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ server.c: In function ‘allPersistenceDisabled’: server.c:1486:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ server.c: In function ‘writeCommandsDeniedByDiskError’: server.c:3826:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ server.c: In function ‘iAmMaster’: server.c:5000:1: warning: control reaches end of non-void function [-Wreturn-type] } ^ ....
yum -y install gcc gcc-c++ make tcl yum -y install centos-release-scl yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils scl enable devtoolset-9 bash
升級之后便可解決 make 報錯問題。
注意:scl命令啟用只是臨時的,退出xshell或者重啟就會恢復到原來的gcc版本。如果要長期生效的話,執行如下 sudo echo "source /opt/rh/devtoolset-9/enable" >>/etc/profile。
cd /opt/soft/redisCluster/redis-6.0.9 切換到目錄執行 make 。
編譯完成使用 make install 對 redis 進行安裝 ,命令:sudo make install。
cd /opt/soft/redisCluster/redis-6.0.9 將 redis.conf 分別復制到 7000 7001 7002 7003 7004 目錄中。
分別修改 6 個 redis.conf
## 7000-7005端口 port 7000 ## 后臺啟動 daemonize yes ## 如果是在單機模擬集群必須指定bind的IP,如果不修改ip的話使用程序連接集群會報錯 bind 192.168.221.150 ## 開啟redis-cluster集群 cluster-enabled yes ## 每個實例還包含存儲此節點配置的文件的路徑,默認情況下為nodes.conf,自動創建 cluster-config-file nodes_7000.conf ## 超時 cluster-node-timeout 500 ## 開啟aof appendonly yes #注釋cluster集群下不允許復制。 #replicaof 127.0.0.1 9000 #關閉保護模式,如果開啟需要設置密碼,比較繁瑣,可根據自己的需求來 protected-mode no
每個配置文件只需要修改 port 和 cluster-config-file 就可以了。
進入 redisCluster 目錄,執行指令依次啟動每個節點。redis-6.0.9/src/redis-server 700x/redis.conf 注意指定每個節點配置文件,如果不指定配置文件會默認使用src下的配置。
進入任意一個節點,執行以下指令創建集群
指令如下:
redis-6.0.9/src/redis-cli --cluster create 172.16.90.152:7000 172.16.90.152:7001 172.16.90.152:7002 172.16.90.152:7003 172.16.90.152:7004 172.16.90.152:7005 --cluster-replicas 1
集群參數解釋:
cluster-replicas 1:表示希望為集群中的每個主節點創建一個從節點(一主一從)。
cluster-replicas 2:表示希望為集群中的每個主節點創建兩個從節點(一主二從)。
控制臺響應:
>>> 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.16.90.152:7004 to 172.16.90.152:7000 Adding replica 172.16.90.152:7005 to 172.16.90.152:7001 Adding replica 172.16.90.152:7003 to 172.16.90.152:7002 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: 06c56f5a6a4436108fae931be499465985141d39 172.16.90.152:7000 slots:[0-5460] (5461 slots) master M: 0ab7c9efd97319d94a8ea52452ec58f7708d812d 172.16.90.152:7001 slots:[5461-10922] (5462 slots) master M: 096f076d99363270c02785a2fb298e2ee65d3f07 172.16.90.152:7002 slots:[10923-16383] (5461 slots) master S: 69d621060295eb433af3e34e702142df0fd4d73d 172.16.90.152:7003 replicates 06c56f5a6a4436108fae931be499465985141d39 S: 1d37df0aa0e2310aedb5a380f95cc818256003f8 172.16.90.152:7004 replicates 0ab7c9efd97319d94a8ea52452ec58f7708d812d S: d9204f6da875a4b2522c5fa25d9e6c1f95cf51ea 172.16.90.152:7005 replicates 096f076d99363270c02785a2fb298e2ee65d3f07 Can I set the above configuration? (type 'yes' to accept):
Can I set the above configuration? (type 'yes' to accept): 詢問是否確認節點 slots 分配方案, 我們輸入 ‘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.16.90.152:7000) M: 06c56f5a6a4436108fae931be499465985141d39 172.16.90.152:7000 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: 1d37df0aa0e2310aedb5a380f95cc818256003f8 172.16.90.152:7004 slots: (0 slots) slave replicates 0ab7c9efd97319d94a8ea52452ec58f7708d812d M: 0ab7c9efd97319d94a8ea52452ec58f7708d812d 172.16.90.152:7001 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: d9204f6da875a4b2522c5fa25d9e6c1f95cf51ea 172.16.90.152:7005 slots: (0 slots) slave replicates 096f076d99363270c02785a2fb298e2ee65d3f07 S: 69d621060295eb433af3e34e702142df0fd4d73d 172.16.90.152:7003 slots: (0 slots) slave replicates 06c56f5a6a4436108fae931be499465985141d39 M: 096f076d99363270c02785a2fb298e2ee65d3f07 172.16.90.152:7002 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.
[OK] All 16384 slots covered.
到此完成!
redis-6.0.9/src/redis-cli --cluster check 172.16.90.152:7000
當使用 redis-6.0.9/src/redis-cli --cluster create 172.16.90.152:7000 172.16.90.152:7001 172.16.90.152:7002 172.16.90.152:7003 172.16.90.152:7004 172.16.90.152:7005 --cluster-replicas 1 創建集群以后,一次創建,永久使用。之后直接啟動每個節點即可構建集群。
結束命令:redis-6.0.9/src/redis-cli -c -h 192.168.124.23 -p 7004 shutdown
進入集群命令 redis-cli -c -h host -p prot 不帶-c 參數進入的不是集群
關于“Redis 6.X Cluster集群如何搭建”這篇文章就分享到這里了,希望以上內容可以對大家有一定的幫助,使各位可以學到更多知識,如果覺得文章不錯,請把它分享出去讓更多的人看到。
分享名稱:Redis6.XCluster集群如何搭建
網頁地址:http://m.newbst.com/article10/gpghgo.html
成都網站建設公司_創新互聯,為您提供手機網站建設、App開發、網站維護、自適應網站、外貿網站建設、營銷型網站建設
聲明:本網站發布的內容(圖片、視頻和文字)以用戶投稿、用戶轉載內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。電話:028-86922220;郵箱:631063699@qq.com。內容未經允許不得轉載,或轉載時需注明來源: 創新互聯