CentOS6.6安裝Redis3.0.3叢集
一個Redis叢集,至少需要6個節點,3個為主,3個為從。
IP |
埠 |
節點 |
127.0.0.1 |
7000 |
Master |
127.0.0.1 |
7001 |
Master |
127.0.0.1 |
7002 |
Master |
127.0.0.1 |
7003 |
Slave |
127.0.0.1 |
7004 |
Slave |
127.0.0.1 |
7005 |
Slave |
安裝步驟:
一、下載redis3.0.3
# cd /usr/local
# wget
二、解壓並編譯
# tar -zxvf redis-3.0.3.tar.gz
# cd redis-3.0.3
# make
# make test
# make install
執行make install後,在/usr/local/bin目錄下可看到生成了一些檔案:
# ls /usr/local/bin/
redis-benchmark redis-check-dump redis-sentinel
redis-check-aof redis-cli redis-server
三、建立叢集需要的目錄並複製redis
# mkdir -p /usr/local/cluster
# mkdir -p /usr/local/cluster/7000
# mkdir -p /usr/local/cluster/7001
# mkdir -p /usr/local/cluster/7002
# mkdir -p /usr/local/cluster/7003
# mkdir -p /usr/local/cluster/7004
# mkdir -p /usr/local/cluster/7005
# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7000/
# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7001/
# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7002/
# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7003/
# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7004/
# cp -rf /usr/local/redis-3.0.3/* /usr/local/cluster/7005/
四、修改配置檔案redis.conf
# vi /usr/local/cluster/7000/redis.conf
修改配置檔案中的下面選項
daemonize yes
port 7000
appendonly yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
用7000/redis.conf覆蓋7001,7002,7003,7004,7005目錄下的redis.conf
# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7001
# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7002
# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7003
# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7004
# cp /usr/local/cluster/7001/redis.conf /usr/local/cluster/7005
再修改7001,7002,7003,7004,7005目錄下的redis.conf中的port,使得redis.conf中的port與其父目錄名稱一致,比如7001/redis.conf中的port為7001,7002/redis.conf中的port為7002
五、啟動6個redis
# cd /usr/local/cluster/7000/src
# redis-server ../redis.conf
# cd /usr/local/cluster/7001/src
# redis-server ../redis.conf
# cd /usr/local/cluster/7002/src
# redis-server ../redis.conf
# cd /usr/local/cluster/7003/src
# redis-server ../redis.conf
# cd /usr/local/cluster/7004/src
# redis-server ../redis.conf
# cd /usr/local/cluster/7005/src
# redis-server ../redis.conf
啟動之後使用命令檢視redis的啟動情況
# ps -ef | grep redis
root 9656 1 0 20:35 ? 00:00:00 redis-server *:7000 [cluster]
root 9684 1 0 20:37 ? 00:00:00 redis-server *:7001 [cluster]
root 9725 1 0 20:43 ? 00:00:00 redis-server *:7002 [cluster]
root 9730 1 0 20:43 ? 00:00:00 redis-server *:7003 [cluster]
root 9734 1 0 20:43 ? 00:00:00 redis-server *:7004 [cluster]
root 9739 1 0 20:43 ? 00:00:00 redis-server *:7005 [cluster]
root 9743 3288 0 20:43 pts/0 00:00:00 grep redis
六、建立redis叢集
1 執行建立redis叢集的命令會報錯,提示找不到ruby
# cd /usr/local/redis-3.0.3/src
# ./redis-trib.rb create --replicas 1 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
/usr/bin/env: ruby: 沒有那個檔案或目錄
解決此錯誤需要安裝ruby,這裡推薦使用yum install ruby
# yum install ruby
2 再執行建立叢集的命令,還會報錯,提示缺少rubygems元件
# ./redis-trib.rb create --replicas 1 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
./redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)
from ./redis-trib.rb:24
解決此錯誤需要安裝rubygems
# yum install rubygems
3 再次執行建立叢集的命令,還會報錯,提示不能載入redis,是因為缺少redis的介面
# ./redis-trib.rb create --replicas 1 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
/usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require': no such file to load -- redis (LoadError)
from /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
from ./redis-trib.rb:25
解決此錯誤需要安裝redis
# gem install redis
Successfully installed redis-3.3.3
1 gem installed
Installing ri documentation for redis-3.3.3...
Installing RDoc documentation for redis-3.3.3...
注意,有時候碰到無法安裝的情況,需要手工下載並安裝:
# wget
# gem install -l ./redis-3.3.3.gem
4 再次執行安裝叢集的命令,正常執行
# ./redis-trib.rb create --replicas 1 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
>>> Creating cluster
Connecting to node 127.0.0.1:7000: OK
Connecting to node 127.0.0.1:7001: OK
Connecting to node 127.0.0.1:7002: OK
Connecting to node 127.0.0.1:7003: OK
Connecting to node 127.0.0.1:7004: OK
Connecting to node 127.0.0.1:7005: OK
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7000
127.0.0.1:7001
127.0.0.1:7002
Adding replica 127.0.0.1:7003 to 127.0.0.1:7000
Adding replica 127.0.0.1:7004 to 127.0.0.1:7001
Adding replica 127.0.0.1:7005 to 127.0.0.1:7002
M: 747467b5f2e2a472afad96de6c88dc2f3bf5b426 127.0.0.1:7000
slots:0-5460 (5461 slots) master
M: 4e4d8ba07d743c4e69fcd5df8867b996084ca4d9 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
M: a6fe3c0a16bcb465a23147de8a3e242deb87e800 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
S: 827ca514f4289dc4ac4d51308721f90851ae6180 127.0.0.1:7003
replicates 747467b5f2e2a472afad96de6c88dc2f3bf5b426
S: be77a6f99e905109150ceaaa50d357ed86803a4c 127.0.0.1:7004
replicates 4e4d8ba07d743c4e69fcd5df8867b996084ca4d9
S: 1285a04f3628c3e76f14d1036c59aef1cb36258d 127.0.0.1:7005
replicates a6fe3c0a16bcb465a23147de8a3e242deb87e800
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 127.0.0.1:7000)
M: 747467b5f2e2a472afad96de6c88dc2f3bf5b426 127.0.0.1:7000
slots:0-5460 (5461 slots) master
M: 4e4d8ba07d743c4e69fcd5df8867b996084ca4d9 127.0.0.1:7001
slots:5461-10922 (5462 slots) master
M: a6fe3c0a16bcb465a23147de8a3e242deb87e800 127.0.0.1:7002
slots:10923-16383 (5461 slots) master
M: 827ca514f4289dc4ac4d51308721f90851ae6180 127.0.0.1:7003
slots: (0 slots) master
replicates 747467b5f2e2a472afad96de6c88dc2f3bf5b426
M: be77a6f99e905109150ceaaa50d357ed86803a4c 127.0.0.1:7004
slots: (0 slots) master
replicates 4e4d8ba07d743c4e69fcd5df8867b996084ca4d9
M: 1285a04f3628c3e76f14d1036c59aef1cb36258d 127.0.0.1:7005
slots: (0 slots) master
replicates a6fe3c0a16bcb465a23147de8a3e242deb87e800
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
至此redis叢集即搭建成功!
七、執行redis-cli命令進入叢集環境
# redis-cli -c -p 7000
127.0.0.1:7000> quit;
#
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/29485627/viewspace-2138237/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Centos6.6安裝教程CentOS
- 安裝 REDIS 叢集Redis
- 安裝Kafka叢集Kafka
- 完整安裝always on叢集
- 安裝Consul叢集
- 快速安裝 kafka 叢集Kafka
- FastDFS 叢集 安裝 配置AST
- CentOS6.6 安裝 nginx-1.8.0CentOSNginx
- redis-3.0.6 安裝叢集Redis
- redis 5.0 叢集的安裝Redis
- 安裝Zookeeper和Kafka叢集Kafka
- redis-4.0.1安裝配置(CentOS6.6)RedisCentOS
- 安裝Greenplum 5.2 叢集實戰
- Cloudera Manager安裝 & 搭建CDH叢集Cloud
- Redis安裝+叢集+效能監控Redis
- CDH安裝大資料叢集大資料
- CentOS7 安裝PG叢集CentOS
- CentOS6.5 安裝Zookeeper叢集CentOS
- CentOS6.5安裝Twemproxy叢集CentOS
- CentOS6.5 安裝Storm叢集CentOSORM
- CentOS6.5 安裝Kafka叢集CentOSKafka
- CentOS6.5 安裝Spark叢集CentOSSpark
- Redis叢集環境安裝指南Redis
- centos安裝redis3.0.0叢集CentOSRedisS3
- Cassandra安裝及分散式叢集搭建分散式
- Ubuntu 安裝k8s叢集UbuntuK8S
- centos安裝k8s叢集CentOSK8S
- CentOS上zookeeper叢集模式安裝配置CentOS模式
- Redis叢集方案,Codis安裝測試Redis
- redhat安裝雙節點cassandra叢集Redhat
- 3 安裝配置oracle叢集和RACOracle
- Zookeeper3.4.14(單叢集)、Kafka_2.12-2.2.2(叢集)安裝Kafka
- Jstorm叢集搭建過程/Jstorm叢集一鍵安裝部署JSORM
- Zookeeper-3.4.10 叢集的安裝配置
- ARM架構安裝Kubernetes叢集架構
- 分散式 PostgreSQL 叢集(Citus)官方安裝指南分散式SQL
- 安裝配置 zookeeper (單機非叢集模式)模式
- Redis安裝之叢集-哨兵模式(sentinel)模式Redis模式