redis3.0.2 集群安装详细步骤

时间:2022-03-13 15:25:43

redis3.0.2 集群安装详细步骤

  (2015-06-23 16:02:50)
标签: 

美食

 
分类: redis
准备了3台机器,每台机器上面起7000 和7001端口
http://download.redis.io/releases/redis-3.0.2.tar.gz
解压后到包里面
make
make install 安装就好了
创建集群需要的目录
 mkdir /usr/local/redis/7000 -p
mkdir /usr/local/redis/7001 -p
修改配置文件 redis.conf
cd /usr/local/redis/7000/
    vim redis.conf
port 7000
daemonize yes
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
## 修改完 redis.conf 配置文件中的这些配置项之后把这个配置文件分别拷贝到7001 和另外2台机器上
## 注意:拷贝完成之后端口要修改7001
分别启动这 6 redis 实例
这样每台机器上面启动2个实例
/usr/local/redis/7000/redis-server /usr/local/redis/7000/redis.conf 
/usr/local/redis/7001/redis-server /usr/local/redis/7001/redis.conf 

##启动之后使用命令查看redis的启动情况ps -ef|grep redis

6:执行redis的创建集群命令创建集群

6:09:33] PWD => /usr/local

40># ~/redis-3.0.2/src/redis-trib.rb create --replicas 192.168.7.232:7000 192.168.7.239:7000 192.168.7.246:7000 192.168.7.232:7001 192.168.7.239:7001 192.168.7.246:7001

/root/redis-3.0.2/src/redis-trib.rb:24:in `require': no such file to load -- rubygems (LoadError)

 

        from /root/redis-3.0.2/src/redis-trib.rb:24


报错了,提示缺少rubygems组件,使用yum安装

yum -y install rubygems

安装好后还是报错

/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 /root/redis-3.0.2/src/redis-trib.rb:25

提示不能加载redis,是因为缺少redisruby的接口,使用gem 安装

# gem install redis

# ~/redis-3.0.2/src/redis-trib.rb create --replicas 192.168.7.232:7000 192.168.7.237:7000 192.168.7.246:7000 192.168.7.232:7001 192.168.7.237:7001 192.168.7.246:7001

>>> Creating cluster

Connecting to node 192.168.7.237:7000: OK

Connecting to node 192.168.7.246:7000: OK

Connecting to node 192.168.7.232:7001: OK

Connecting to node 192.168.7.237:7001: OK

Connecting to node 192.168.7.246:7001: OK

*** ERROR: Invalid configuration for cluster creation.

*** Redis Cluster requires at least 3 master nodes.

*** This is not possible with 5 nodes and 192 replicas per node.

*** At least 579 nodes are required.

居然只连接5个,奇怪了,后来检查才发现在--replicas 后面要加一个数字才可以

6:23:23] PWD => /usr/local

52># ~/redis-3.0.2/src/redis-trib.rb create --replicas 1 192.168.7.232:7000 192.168.7.237:7000 192.168.7.246:7000 192.168.7.232:7001 192.168.7.237:7001 192.168.7.246:7001

>>> Creating cluster

Connecting to node 192.168.7.232:7000: OK

Connecting to node 192.168.7.237:7000: OK

Connecting to node 192.168.7.246:7000: OK

Connecting to node 192.168.7.232:7001: OK

Connecting to node 192.168.7.237:7001: OK

Connecting to node 192.168.7.246:7001: OK

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

192.168.7.246:7000

192.168.7.237:7000

192.168.7.232:7000

Adding replica 192.168.7.237:7001 to 192.168.7.246:7000

Adding replica 192.168.7.246:7001 to 192.168.7.237:7000

Adding replica 192.168.7.232:7001 to 192.168.7.232:7000

M: e538aeff6aa194f52c706238448a3f48c561174c 192.168.7.232:7000

   slots:10923-16383 (5461 slots) master

M: 834632a4e4f2af3a824623928b4b85203cd2df11 192.168.7.237:7000

   slots:5461-10922 (5462 slots) master

M: e538aeff6aa194f52c706238448a3f48c561174c 192.168.7.246:7000

   slots:0-5460 (5461 slots) master

S: 2aabb6d31a8c4310aedbe98b43d8ae1725265eac 192.168.7.232:7001

   replicates e538aeff6aa194f52c706238448a3f48c561174c

S: 80ad1ce65e5d1ab60eef58cf3d8e001cc0cbc11d 192.168.7.237:7001

   replicates e538aeff6aa194f52c706238448a3f48c561174c

S: 4c37e13f1339db30699586e8d6a38f2778606908 192.168.7.246:7001

   replicates 834632a4e4f2af3a824623928b4b85203cd2df11

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.......................................

在这里的时候卡了很久没过去,我就结束了想重新再试下

Connecting to node 192.168.7.232:7000: OK

[ERR] Node 192.168.7.232:7000 is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.

提示有数据了,我想是开始初始化的时候有写数据进去了

把7000目录下生成的appendonly.aof    nodes.conf 删除掉重启启动服务,

想起来我是把7.232上面的服务启动后把7000 7001 直接传到237 和246上面去的,为了节省建目录和copy配置文件的操作,这样导致机器加入集群的时候一直在等待,

把3台机器的6个服务的appendonly.aof    nodes.conf都删了 重新启动服务再执行

# ~/redis-3.0.2/src/redis-trib.rb create --replicas 1 192.168.7.232:7000 192.168.7.237:7000 192.168.7.246:7000 192.168.7.232:7001 192.168.7.237:7001 192.168.7.246:7001 

>>> Creating cluster

Connecting to node 192.168.7.232:7000: OK

Connecting to node 192.168.7.237:7000: OK

Connecting to node 192.168.7.246:7000: OK

Connecting to node 192.168.7.232:7001: OK

Connecting to node 192.168.7.237:7001: OK

Connecting to node 192.168.7.246:7001: OK

>>> Performing hash slots allocation on 6 nodes...

Using 3 masters:

192.168.7.246:7000

192.168.7.237:7000

192.168.7.232:7000

Adding replica 192.168.7.237:7001 to 192.168.7.246:7000

Adding replica 192.168.7.246:7001 to 192.168.7.237:7000

Adding replica 192.168.7.232:7001 to 192.168.7.232:7000

M: d8003ec51e97f8135b55e6c318e1bcf7b940e668 192.168.7.232:7000

   slots:10923-16383 (5461 slots) master

M: 594a3e1a587c4fb67fc224f0593993918c0360af 192.168.7.237:7000

   slots:5461-10922 (5462 slots) master

M: 9ebe5263d08594bfd5d218a36df8315c5ce3f0dd 192.168.7.246:7000

   slots:0-5460 (5461 slots) master

S: 1d716af8951061e412fcc0b6e92e4212a8730000 192.168.7.232:7001

   replicates d8003ec51e97f8135b55e6c318e1bcf7b940e668

S: 30882cbdf6ab715aea7928e0adf25b96fc67aa87 192.168.7.237:7001

   replicates 9ebe5263d08594bfd5d218a36df8315c5ce3f0dd

S: 4754be547328d05b986bf94fe9d77a4cd32b1f68 192.168.7.246:7001

   replicates 594a3e1a587c4fb67fc224f0593993918c0360af

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 192.168.7.232:7000)

M: d8003ec51e97f8135b55e6c318e1bcf7b940e668 192.168.7.232:7000

   slots:10923-16383 (5461 slots) master

M: 594a3e1a587c4fb67fc224f0593993918c0360af 192.168.7.237:7000

   slots:5461-10922 (5462 slots) master

M: 9ebe5263d08594bfd5d218a36df8315c5ce3f0dd 192.168.7.246:7000

 

   slots:0-5460 (5461 slots) master

   slots:0-5460 (5461 slots) master

M: 1d716af8951061e412fcc0b6e92e4212a8730000 192.168.7.232:7001

   slots: (0 slots) master

   replicates d8003ec51e97f8135b55e6c318e1bcf7b940e668

M: 30882cbdf6ab715aea7928e0adf25b96fc67aa87 192.168.7.237:7001

   slots: (0 slots) master

   replicates 9ebe5263d08594bfd5d218a36df8315c5ce3f0dd

M: 4754be547328d05b986bf94fe9d77a4cd32b1f68 192.168.7.246:7001

   slots: (0 slots) master

   replicates 594a3e1a587c4fb67fc224f0593993918c0360af

[OK] All nodes agree about slots configuration.

>>> Check for open slots...

>>> Check slots coverage...

[OK] All 16384 slots covered.

使用redis-cli命令进入集群环境

redis-cli -c -p 7000

127.0.0.1:7000> get testkey001

(nil)

127.0.0.1:7000> set testkey002 testvalue002

-> Redirected to slot [401] located at 192.168.7.246:7000

OK

192.168.7.246:7000> get testkey002

"testvalue002"

192.168.7.246:7000> set testkey003 testvalue003

OK

192.168.7.246:7000> exit