redis 4.0.11 叢集搭建
-
Port: 7000
Port: 7001
Port: 7000
Port: 7001
Port: 7000
Port: 7001
IP: 10.241.0.10
IP: 10.241.0.11
IP: 10.241.0.12
redis叢集安裝
下載安裝redis(所有節點)
wget tar zxvf redis-4.0.11.tar.gzcd redis-4.0.11 makecd src/ make install
配置redis
node1
mkdir -p /data/redis/{7000,7001}/data mkdir -p /usr/local/redis-cluster/bin mkdir -p /usr/local/redis-cluster/7000cp ../redis.conf /usr/local/redis-cluster/7000/#修改以下配置vim /usr/local/redis-cluster/7000/redis.conf bind 10.241.0.10 #繫結本機IPdaemonize yes #開啟後臺執行dir /data/redis/7000/data #資料存放路徑port 7000 #監聽埠pidfile /var/run/redis_7000.pid #pid檔案logfile /var/log/redis_7000.log #log檔案cluster-enabled yes #開啟註釋cluster-config-file nodes.conf #開啟註釋cluster-node-timeout 15000 #開啟註釋appendonly yes #開啟持久化#7001節點配置cp -rf /usr/local/redis-cluster/7000/ /usr/local/redis-cluster/7001/ sed -i 's/7000/7001/g' /usr/local/redis-cluster/7001/redis.conf#將配置檔案copy到其他的節點scp -r /usr/local/redis-cluster/{7000,7001} root@10.241.0.11:/usr/local/redis-cluster/scp -r /usr/local/redis-cluster/{7000,7001} root@10.241.0.12:/usr/local/redis-cluster/
node2
mkdir -p /data/redis/{7000,7001}/data mkdir -p /usr/local/redis-cluster/bin cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server redis-trib.rb /usr/local/redis-cluster/bin sed -i 's/10.241.0.10/10.241.0.11/g' /usr/local/redis-cluster/7000/redis.conf sed -i 's/10.241.0.10/10.241.0.11/g' /usr/local/redis-cluster/7001/redis.conf
node3
mkdir -p /data/redis/{7000,7001}/data mkdir -p /usr/local/redis-cluster/bin cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server redis-trib.rb /usr/local/redis-cluster/bin sed -i 's/10.241.0.10/10.241.0.12/g' /usr/local/redis-cluster/7000/redis.conf sed -i 's/10.241.0.10/10.241.0.12/g' /usr/local/redis-cluster/7001/redis.conf
啟動redis(所有節點)
/usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/7000/redis.conf /usr/local/redis-cluster/bin/redis-server /usr/local/redis-cluster/7001/redis.conf ps -ef|grep redis root 3079 1 0 00:26 ? 00:00:00 /usr/local/redis-cluster/bin/redis-server 10.241.0.10:7000 [cluster] root 3243 1 0 00:28 ? 00:00:00 /usr/local/redis-cluster/bin/redis-server 10.241.0.10:7001 [cluster] netstat -nplt|grep redis-server tcp 0 0 10.241.0.10:17000 0.0.0.0:* LISTEN 3243/redis-server 1 tcp 0 0 10.241.0.10:17001 0.0.0.0:* LISTEN 3079/redis-server 1 tcp 0 0 10.241.0.10:7000 0.0.0.0:* LISTEN 3243/redis-server 1 tcp 0 0 10.241.0.10:7001 0.0.0.0:* LISTEN 3079/redis-server 1
iptables放行
#如開iptables,需注意,埠放行, 注意17000,17001也要放行,不然加入不到叢集-A INPUT -p tcp -m tcp --dport 7000 -j ACCEPT -A INPUT -p tcp -m tcp --dport 7001 -j ACCEPT -A INPUT -p tcp -m tcp --dport 17000 -j ACCEPT -A INPUT -p tcp -m tcp --dport 17001 -j ACCEPT
配置叢集(只在node1操作)
安裝ruby
wget tar xvf ruby-2.2.7.tar.gzcd ruby-2.2.7 ./configure --prefix=/usr/local/ruby-2.2.7 make && make install ln -s /usr/local/ruby-2.2.7/bin/ruby /usr/bin/ruby ln -s /usr/local/ruby-2.2.7/bin/gem /usr/bin ruby -v gem -v
使用gem安裝redis叢集依賴
gem install redis
建立叢集
如叢集都設定了密碼,需要修該 /usr/local/ruby-2.2.7/lib/ruby/gems/2.2.0/gems/redis-4.0.1/lib/redis/client.rb 檔案中的 Password 引數將密碼寫入到這裡,
/usr/local/redis-cluster/bin/redis-trib.rb create --replicas 1 10.241.0.10:7000 10.241.0.10:7001 10.241.0.11:7000 10.241.0.11:7001 10.241.0.12:7000 10.241.0.12:7001Using 3 masters:10.241.0.10:7000 10.241.0.11:7000 10.241.0.12:7000 Adding replica 10.241.0.11:7001 to 10.241.0.10:7000 Adding replica 10.241.0.12:7001 to 10.241.0.11:7000 Adding replica 10.241.0.10:7001 to 10.241.0.12:7000 M: ade53fb12571212ae25a84e55c0fb0311d05a26e 10.241.0.10:7000 slots:0-5460 (5461 slots) master S: 8b9fde5ec861254715516f07cf84b029e8cfe6d5 10.241.0.10:7001 replicates 407b6b0b0425e89e4e63fde2c3894616a31df869 M: 42dbdc9435bc216941db2c46f73c663812cbf8ff 10.241.0.11:7000 slots:5461-10922 (5462 slots) master S: 538372e405c12e3ed7d5b1da6a2736ff4f393277 10.241.0.11:7001 replicates ade53fb12571212ae25a84e55c0fb0311d05a26e M: 407b6b0b0425e89e4e63fde2c3894616a31df869 10.241.0.12:7000 slots:10923-16383 (5461 slots) master S: ff8b973753031d2d87c75eaca5530ff4f7ccb22f 10.241.0.12:7001 replicates 42dbdc9435bc216941db2c46f73c663812cbf8ff 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.241.0.10:7000)M: ade53fb12571212ae25a84e55c0fb0311d05a26e 10.241.0.10:7000 slots:0-5460 (5461 slots) master 1 additional replica(s)S: 538372e405c12e3ed7d5b1da6a2736ff4f393277 10.241.0.11:7001 slots: (0 slots) slave replicates ade53fb12571212ae25a84e55c0fb0311d05a26eM: 407b6b0b0425e89e4e63fde2c3894616a31df869 10.241.0.12:7000 slots:10923-16383 (5461 slots) master 1 additional replica(s)M: 42dbdc9435bc216941db2c46f73c663812cbf8ff 10.241.0.11:7000 slots:5461-10922 (5462 slots) master 1 additional replica(s)S: 8b9fde5ec861254715516f07cf84b029e8cfe6d5 10.241.0.10:7001 slots: (0 slots) slave replicates 407b6b0b0425e89e4e63fde2c3894616a31df869S: ff8b973753031d2d87c75eaca5530ff4f7ccb22f 10.241.0.12:7001 slots: (0 slots) slave replicates 42dbdc9435bc216941db2c46f73c663812cbf8ff [OK] All nodes agree about slots configuration.>>> Check for open slots...>>> Check slots coverage... [OK] All 16384 slots covered.
驗證叢集
#透過客戶端命令連線上,透過叢集命令看一下狀態和節點資訊等/usr/local/redis-cluster/bin/redis-cli -h 10.241.0.11 -p 7001 -c10.241.0.11:7001> cluster infocluster_state:okcluster_slots_assigned:16384cluster_slots_ok:16384cluster_slots_pfail:0cluster_slots_fail:0cluster_known_nodes:6cluster_size:3cluster_current_epoch:6cluster_my_epoch:5cluster_stats_messages_ping_sent:97cluster_stats_messages_pong_sent:101cluster_stats_messages_meet_sent:3cluster_stats_messages_sent:201cluster_stats_messages_ping_received:99cluster_stats_messages_pong_received:100cluster_stats_messages_meet_received:2cluster_stats_messages_received:20110.241.0.11:7001> cluster nodes ff8b973753031d2d87c75eaca5530ff4f7ccb22f 10.241.0.12:7001@17001 slave 42dbdc9435bc216941db2c46f73c663812cbf8ff 0 1541524337000 3 connected407b6b0b0425e89e4e63fde2c3894616a31df869 10.241.0.12:7000@17000 myself,master - 0 1541524335000 5 connected 10923-16383ade53fb12571212ae25a84e55c0fb0311d05a26e 10.241.0.10:7000@17000 master - 0 1541524336735 1 connected 0-5460538372e405c12e3ed7d5b1da6a2736ff4f393277 10.241.0.11:7001@17001 slave ade53fb12571212ae25a84e55c0fb0311d05a26e 0 1541524337000 4 connected42dbdc9435bc216941db2c46f73c663812cbf8ff 10.241.0.11:7000@17000 master - 0 1541524338739 3 connected 5461-109228b9fde5ec861254715516f07cf84b029e8cfe6d5 10.241.0.10:7001@17001 slave 407b6b0b0425e89e4e63
作者:baiyongjie
連結:
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/4369/viewspace-2820981/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Redis系列:搭建Redis叢集(叢集模式)Redis模式
- 搭建 Redis 叢集Redis
- redis叢集搭建Redis
- Redis(5.0) 叢集搭建Redis
- 搭建Redis原生叢集Redis
- Redis--叢集搭建Redis
- 搭建redis cluster叢集Redis
- redis叢集的搭建Redis
- Docker搭建Redis叢集DockerRedis
- Redis 5.02官方叢集搭建Redis
- Redis5.0.10叢集搭建Redis
- Redis4.0.12叢集搭建Redis
- 基於Dokcer搭建Redis叢集(主從叢集)Redis
- Docker Redis 5.0 叢集(cluster)搭建DockerRedis
- centos7搭建redis叢集CentOSRedis
- CentOS7 搭建 Redis 叢集CentOSRedis
- Redis主從同步叢集搭建Redis主從同步
- Redis叢集搭建 三主三從Redis
- Redis叢集環境搭建實踐Redis
- 12. Redis叢集環境搭建Redis
- Docker 容器搭建及 Redis 叢集原理DockerRedis
- Redis叢集搭建與簡單使用Redis
- Redis叢集搭建(三主三從)Redis
- Redis叢集搭建採坑總結Redis
- Redis-cluster叢集搭建部署Redis
- 搭建分散式 Redis Cluster 叢集與 Redis 入門分散式Redis
- 使用redis-trib.rb工具快速搭建redis叢集Redis
- redis 叢集搭建以及redislive監測部署Redis
- Redis搭建主從複製、哨兵叢集Redis
- Linux(Centos7)Redis叢集的搭建LinuxCentOSRedis
- Mac 環境下 Redis 叢集的搭建MacRedis
- redis叢集Redis
- redis 叢集Redis
- 在K8S上搭建Redis叢集K8SRedis
- 在滴滴雲上搭建 Redis-Cluster 叢集Redis
- 基於 Redis3.2.4 叢集搭建說明RedisS3
- Redis操作及叢集搭建以及高可用配置Redis
- Redis 結合 Docker 搭建叢集,並整合SpringBootRedisDockerSpring Boot