您好,登錄后才能下訂單哦!
這篇文章主要介紹“Redis 5.02官方集群的搭建過程”,在日常操作中,相信很多人在Redis 5.02官方集群的搭建過程問題上存在疑惑,小編查閱了各式資料,整理出簡單好用的操作方法,希望對大家解答”Redis 5.02官方集群的搭建過程”的疑惑有所幫助!接下來,請跟著小編一起來學習吧!
1、下載安裝Redis
# wget http://download.redis.io/releases/redis-stable.tar.gz # tar xfz redis-stable.tar.gz # cd redis-stable # make # 設置命令執行路徑 # cat ~/.bash_profile PATH=$PATH:$HOME/bin:/data/redis-stable/src
2、創建集群的數據目錄和配置文件
在兩臺服務器上面,要創建6個redis實例(三主三從),每個服務器,分布創建3個數據目錄和3個配置文件。
集群主節點
10.152.5.12:7000
10.152.5.12:7001
10.153.115.24:7003
集群從節點
10.152.5.12:7002
10.153.115.24:7004
10.153.115.24:7005
# 10.152.5.12 # 創建數據目錄 # mkdir redis_cluster # cd redis_cluster # mkdir 7000 7001 7002 # 創建配置文件 # cd 7000 # grep -v "^#" redis_7000.conf protected-mode no port 7000 daemonize yes supervised no pidfile /var/run/redis_7000.pid loglevel notice logfile "/data/redis_cluster/redis_7000.log" dir ./ appendonly yes cluster-enabled yes cluster-config-file nodes_7000.conf cluster-node-timeout 5000 # 啟動服務 redis-server /data/redis_cluster/7000/redis_7000.conf &
# 10.152.5.12 # mkdir redis_cluster # cd redis_cluster # mkdir 7003 7004 7005
3、初始化集群
# redis-cli --cluster create 10.152.5.12:7000 10.152.5.12:7001 10.153.115.24:7003 10.152.5.12:7002 10.153.115.24:7004 10.153.115.24:7005 --cluster-replicas 1 >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 10.153.115.24:7004 to 10.152.5.12:7000 Adding replica 10.152.5.12:7002 to 10.153.115.24:7003 Adding replica 10.153.115.24:7005 to 10.152.5.12:7001 M: 65dba2ed08ecb139589710f9efdfd7eeacbb3775 10.152.5.12:7000 slots:[0-5460] (5461 slots) master M: 08e714061bdb817c23c72f1e5c9a72ab878a0c8f 10.152.5.12:7001 slots:[10923-16383] (5461 slots) master M: 7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf4 10.153.115.24:7003 slots:[5461-10922] (5462 slots) master S: 030fc4d0e02bb7f8245b0bbecf428066daf23a7a 10.152.5.12:7002 replicates 7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf4 S: c33f01a81258077f3d6cd5f97c91a85225279bff 10.153.115.24:7004 replicates 65dba2ed08ecb139589710f9efdfd7eeacbb3775 S: 18092c18796972c26785a9cfa408cb3a52107818 10.153.115.24:7005 replicates 08e714061bdb817c23c72f1e5c9a72ab878a0c8f Can I set the above configuration? (type 'yes' to accept): 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 10.152.5.12:7000) M: 65dba2ed08ecb139589710f9efdfd7eeacbb3775 10.152.5.12:7000 slots:[0-5460] (5461 slots) master 1 additional replica(s) S: c33f01a81258077f3d6cd5f97c91a85225279bff 10.153.115.24:7004 slots: (0 slots) slave replicates 65dba2ed08ecb139589710f9efdfd7eeacbb3775 S: 18092c18796972c26785a9cfa408cb3a52107818 10.153.115.24:7005 slots: (0 slots) slave replicates 08e714061bdb817c23c72f1e5c9a72ab878a0c8f M: 08e714061bdb817c23c72f1e5c9a72ab878a0c8f 10.152.5.12:7001 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: 030fc4d0e02bb7f8245b0bbecf428066daf23a7a 10.152.5.12:7002 slots: (0 slots) slave replicates 7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf4 M: 7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf4 10.153.115.24:7003 slots:[5461-10922] (5462 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.
查看進程和日志
# ps -ef|grep redis root 32071 23964 18 11:01 pts/0 00:09:31 redis-server *:7003 [cluster] root 32120 23964 1 11:02 pts/0 00:00:42 redis-server *:7004 [cluster] root 32165 23964 1 11:03 pts/0 00:00:41 redis-server *:7005 [cluster] root 34550 32071 0 11:39 pts/0 00:00:00 redis-aof-rewrite *:7003 [cluster] # tail redis_7003.log 30922:M 07 Dec 2018 10:41:38.391 * Ready to accept connections 32071:C 07 Dec 2018 11:01:32.731 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo 32071:C 07 Dec 2018 11:01:32.731 # Redis version=5.0.2, bits=64, commit=00000000, modified=0, pid=32071, just started 32071:C 07 Dec 2018 11:01:32.731 # Configuration loaded 32071:M 07 Dec 2018 11:01:32.733 * Node configuration loaded, I'm 7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf4 _._ _.-``__ ''-._ _.-`` `. `_. ''-._ Redis 5.0.2 (00000000/0) 64 bit .-`` .-```. ```\/ _.,_ ''-._ ( ' , .-` | `, ) Running in cluster mode |`-._`-...-` __...-.``-._|'` _.-'| Port: 7003 | `-._ `._ / _.-' | PID: 32071 `-._ `-._ `-./ _.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | http://redis.io `-._ `-._`-.__.-'_.-' _.-' |`-._`-._ `-.__.-' _.-'_.-'| | `-._`-._ _.-'_.-' | `-._ `-._`-.__.-'_.-' _.-' `-._ `-.__.-' _.-' `-._ _.-' `-.__.-' 32071:M 07 Dec 2018 11:01:32.734 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128. 32071:M 07 Dec 2018 11:01:32.734 # Server initialized 32071:M 07 Dec 2018 11:01:32.734 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled. 32071:M 07 Dec 2018 11:01:32.734 * Ready to accept connections 32071:M 07 Dec 2018 11:06:15.060 # configEpoch set to 3 via CLUSTER SET-CONFIG-EPOCH 32071:M 07 Dec 2018 11:06:15.116 # IP address for this node updated to 10.153.115.24 32071:M 07 Dec 2018 11:06:18.146 * Replica 10.152.5.12:7002 asks for synchronization 32071:M 07 Dec 2018 11:06:18.146 * Partial resynchronization not accepted: Replication ID mismatch (Replica asked for 'b8db3eb5c491ab9e2ff92de627925a93105ddd96', my replication IDs are '054964ff1a25320ff6d97c24594f2683e30d43c0' and '0000000000000000000000000000000000000000') 32071:M 07 Dec 2018 11:06:18.146 * Starting BGSAVE for SYNC with target: disk 32071:M 07 Dec 2018 11:06:18.146 * Background saving started by pid 32349 32349:C 07 Dec 2018 11:06:18.147 * DB saved on disk 32349:C 07 Dec 2018 11:06:18.148 * RDB: 0 MB of memory used by copy-on-write 32071:M 07 Dec 2018 11:06:18.196 * Background saving terminated with success 32071:M 07 Dec 2018 11:06:18.196 * Synchronization with replica 10.152.5.12:7002 succeeded 32071:M 07 Dec 2018 11:06:20.001 # Cluster state changed: ok 32071:M 07 Dec 2018 11:31:25.118 * 1 changes in 900 seconds. Saving... 32071:M 07 Dec 2018 11:31:25.118 * Background saving started by pid 33740 33740:C 07 Dec 2018 11:31:25.119 * DB saved on disk 33740:C 07 Dec 2018 11:31:25.120 * RDB: 0 MB of memory used by copy-on-write 32071:M 07 Dec 2018 11:31:25.218 * Background saving terminated with success 32071:M 07 Dec 2018 11:31:37.418 * Starting automatic rewriting of AOF on 6722641000% growth 32071:M 07 Dec 2018 11:31:37.418 * Background append only file rewriting started by pid 33751 32071:M 07 Dec 2018 11:31:38.420 * AOF rewrite child asks to stop sending diffs. 33751:C 07 Dec 2018 11:31:38.420 * Parent agreed to stop sending diffs. Finalizing AOF... 33751:C 07 Dec 2018 11:31:38.420 * Concatenating 5.25 MB of AOF diff received from parent.
到此,關于“Redis 5.02官方集群的搭建過程”的學習就結束了,希望能夠解決大家的疑惑。理論與實踐的搭配能更好的幫助大家學習,快去試試吧!若想繼續學習更多相關知識,請繼續關注億速云網站,小編會繼續努力為大家帶來更多實用的文章!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。