Redis学习笔记2-Redis的集群
2015-11-17 14:59
681 查看
里面的大多资料来源网络,学习过程中的例子等! 感觉各位大神的帖子和资料!
集群需要的其他软件
(1) ruby-2.2.3.tar.gz
(2) zlib-1.2.8.tar.gz
(3) redis-3.2.1.gem
安装软件
分别将文件复制到 各个目录下 方便管理
root@ubuntu:/home/mouap2/share2-dir# cp redis-3.2.1.gem /home/redis_gem
root@ubuntu:/home/mouap2/share2-dir# cp ruby-2.2.3.tar.gz /home/ruby
root@ubuntu:/home/mouap2/share2-dir# cp zlib-1.2.8.tar.gz /home/zlib
安装 ruby
1 解压 ruby
2 解压完毕后 进入ruby-2.2.3目录
3 设置安装路径 root@ubuntu:/home/ruby/ruby-2.2.3# ./configure --prefix=/home/ruby
4 进行编译 执行命令 make (编译过程比较慢)
5 安装 执行命令 make install
6 安装完毕 配置环境变量
root@ubuntu:/etc# vi profile 在 profile 最后一行配置
export PATH=/home/ruby/bin:$PATH
执行source编译命令 root@ubuntu:~# source /etc/profile
7 测试版本 输入命令 ruby -v
显示成功版本信息 ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
安装 zlib
1 解压 root@ubuntu:/home/zlib# tar -zvxf zlib-1.2.8.tar.gz
2 进入目录 root@ubuntu:/home/zlib# cd zlib-1.2.8/
3 修改配置文件 root@ubuntu:/home/zlib/zlib-1.2.8# ./configure --prefix=/home/zlib
4 编译文件 root@ubuntu:/home/zlib/zlib-1.2.8# make
5 安装 root@ubuntu:/home/zlib/zlib-1.2.8# make install
6 安装ruby-zlib 进入目录 root@ubuntu:/home/ruby/ruby-2.2.3/ext/zlib# (cd /home/ruby/ruby-2.2.3/ext/zlib )
7 执行命令 root@ubuntu:/home/ruby/ruby-2.2.3/ext/zlib# ruby ./extconf.rb --with-zlib-dir=/home/zlib
8 编译 root@ubuntu:/home/ruby/ruby-2.2.3/ext/zlib# make
9 安装 root@ubuntu:/home/ruby/ruby-2.2.3/ext/zlib# make install
显示 (/usr/bin/install -c -m 0755 zlib.so /home/ruby/lib/ruby/site_ruby/2.2.0/x86_64-linux 安装完毕)
安装 gem
1 安装 root@ubuntu:/home/redis_gem# gem install -l redis-3.2.1.gem
集群各个 redis.conf 配置文件需要修改的地方! (需要6个nodes 之前偷懒弄了3个 结果提示最少需要6个)
1 修改端口号 prot 7002
2 修改日志文件 logfile /home/redis/redis-stable/7002/log/redis-7002.log
3 修改dir dir /home/redis/redis-stable/7002
4 打开集群 cluster-enabled yes
5 修改 cluster-config-file /home/redis/redis-stable/7002/nodes.conf
6 打开 cluster-node-timeout 15000
7 打开 cluster-migration-barrier 1
8 打开 cluster-require-full-coverage yes
将所有的几个7001 - 7006全部配置文件修改完毕后, 然后启动所有的服务
在 /home/redis/redis-stable/src 目录下 执行
redis-server /home/redis/redis-stable/7001/7001.conf &
redis-server /home/redis/redis-stable/7002/7002.conf &
服务启动后 进行验证
输入命令
/home/redis/redis-stable/src# redis-cli -p 7006
然后执行集群
./redis-trib.rb create --replicas 1 192.168.0.59:7001 192.168.0.59:7002 192.168.0.59:7003 192.168.0.59:7004 192.168.0.59:7005 192.168.0.59:7006
出错了!!!
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from ./redis-trib.rb:25:in `<main>'
于是网络找大量资料
/home/redis_gem# gem install redis 执行gem命令 , 不知道是否之前忘记执行了
执行完毕后
然后在执行集群命令 会出现提示
Can I set the above configuration? (type 'yes' to accept):
输入yes
之后看到输出
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.0.59:7001)
M: d89e0bc80a3786506486ef3aff94e1a894e2ebd1 192.168.0.59:7001
slots:0-5460 (5461 slots) master
M: af943437208e61fce7a799bbe146c90ee277d9ff 192.168.0.59:7002
slots:5461-10922 (5462 slots) master
M: a79d07a94fd7522574b6f65e996e1efa44312edf 192.168.0.59:7003
slots:10923-16383 (5461 slots) master
M: 097d5f3df79fa0b57e8db12564f59ed57af6f5bd 192.168.0.59:7004
slots: (0 slots) master
replicates d89e0bc80a3786506486ef3aff94e1a894e2ebd1
M: 2c97780357da296a483586524b99a6e1bace2617 192.168.0.59:7005
slots: (0 slots) master
replicates af943437208e61fce7a799bbe146c90ee277d9ff
M: 1aa03370a3ec2724f47af370e30198bac2b42076 192.168.0.59:7006
slots: (0 slots) master
replicates a79d07a94fd7522574b6f65e996e1efa44312edf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
集群成功了!
新增节点, 配置好7007的目录和节点等 / 配置好7008的目录和节点等
查看下集群节点
root@ubuntu:/home/redis/redis-stable/src# redis-cli -c -p 7001
127.0.0.1:7001> cluster nodes
2c97780357da296a483586524b99a6e1bace2617 192.168.0.59:7005 slave af943437208e61fce7a799bbe146c90ee277d9ff 0 1447901886620 5 connected
1aa03370a3ec2724f47af370e30198bac2b42076 192.168.0.59:7006 slave a79d07a94fd7522574b6f65e996e1efa44312edf 0 1447901891704 6 connected
d89e0bc80a3786506486ef3aff94e1a894e2ebd1 192.168.0.59:7001 myself,master - 0 0 1 connected 0-5460
a79d07a94fd7522574b6f65e996e1efa44312edf 192.168.0.59:7003 master - 0 1447901887630 3 connected 10923-16383
af943437208e61fce7a799bbe146c90ee277d9ff 192.168.0.59:7002 master - 0 1447901892712 2 connected 5461-10922
097d5f3df79fa0b57e8db12564f59ed57af6f5bd 192.168.0.59:7004 slave d89e0bc80a3786506486ef3aff94e1a894e2ebd1 0 1447901890673 4 connected
看到7007并非集群
然后执行命令
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb add-node 192.168.0.59:7007 192.168.0.59:7001
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Connecting to node 192.168.0.59:7007: OK
>>> Send CLUSTER MEET to node 192.168.0.59:7007 to make it join the cluster.
[OK] New node added correctly.
新节点集群成功 然后可以进行查看
为新节点7007添加插槽和设置主节点
1为 7007添加 插槽
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb reshard 192.168.0.59:7001
2 提示移动多少个 输入数字即可
How many slots do you want to move (from 1 to 16384)? 2000
3 移动到哪个id
What is the receiving node ID? 48db262ea9744e5c6d7c45f8b0174cc9641b251b
4 输入all
Source node #1:all
5 输入yes 后添加完毕了
Do you want to proceed with the proposed reshard plan (yes/no)?
6 进行查看
为新节点7008设置为7001的从节点
1 进入 7008服务目录
root@ubuntu:/home/redis/redis-stable/src# redis-cli -c -p 7008
2 执行命令 查看结果
127.0.0.1:7008> cluster replicate d89e0bc80a3786506486ef3aff94e1a894e2ebd1
241375bfe7a8337ea0b7bc8251e807bf3d2108d9 192.168.0.59:7008 myself,slave d89e0bc80a3786506486ef3aff94e1a894e2ebd1 0 0 0 connected
删除从节点7008
1 执行命令 删除成功
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb del-node 192.168.0.59:7008 241375bfe7a8337ea0b7bc8251e807bf3d2108d9
删除主节点7007
1 移除插槽
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb reshard 192.168.0.59:7007
2 移除所有的数目 之前设置了2000个 所以移除2000qu
How many slots do you want to move (from 1 to 16384)? 2000
3 谁接收
What is the receiving node ID? af943437208e61fce7a799bbe146c90ee277d9ff
4 输入7007的节点id 然后 输入 done
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:48db262ea9744e5c6d7c45f8b0174cc9641b251b
Source node #2:done
5 输入 yes
Do you want to proceed with the proposed reshard plan (yes/no)? yes
6 删除7007节点
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb del-node 192.168.0.59:7007 241375bfe7a8337ea0b7bc8251e807bf3d2108d9
6完毕 查看
集群需要的其他软件
(1) ruby-2.2.3.tar.gz
(2) zlib-1.2.8.tar.gz
(3) redis-3.2.1.gem
安装软件
分别将文件复制到 各个目录下 方便管理
root@ubuntu:/home/mouap2/share2-dir# cp redis-3.2.1.gem /home/redis_gem
root@ubuntu:/home/mouap2/share2-dir# cp ruby-2.2.3.tar.gz /home/ruby
root@ubuntu:/home/mouap2/share2-dir# cp zlib-1.2.8.tar.gz /home/zlib
安装 ruby
1 解压 ruby
2 解压完毕后 进入ruby-2.2.3目录
3 设置安装路径 root@ubuntu:/home/ruby/ruby-2.2.3# ./configure --prefix=/home/ruby
4 进行编译 执行命令 make (编译过程比较慢)
5 安装 执行命令 make install
6 安装完毕 配置环境变量
root@ubuntu:/etc# vi profile 在 profile 最后一行配置
export PATH=/home/ruby/bin:$PATH
执行source编译命令 root@ubuntu:~# source /etc/profile
7 测试版本 输入命令 ruby -v
显示成功版本信息 ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-linux]
安装 zlib
1 解压 root@ubuntu:/home/zlib# tar -zvxf zlib-1.2.8.tar.gz
2 进入目录 root@ubuntu:/home/zlib# cd zlib-1.2.8/
3 修改配置文件 root@ubuntu:/home/zlib/zlib-1.2.8# ./configure --prefix=/home/zlib
4 编译文件 root@ubuntu:/home/zlib/zlib-1.2.8# make
5 安装 root@ubuntu:/home/zlib/zlib-1.2.8# make install
6 安装ruby-zlib 进入目录 root@ubuntu:/home/ruby/ruby-2.2.3/ext/zlib# (cd /home/ruby/ruby-2.2.3/ext/zlib )
7 执行命令 root@ubuntu:/home/ruby/ruby-2.2.3/ext/zlib# ruby ./extconf.rb --with-zlib-dir=/home/zlib
8 编译 root@ubuntu:/home/ruby/ruby-2.2.3/ext/zlib# make
9 安装 root@ubuntu:/home/ruby/ruby-2.2.3/ext/zlib# make install
显示 (/usr/bin/install -c -m 0755 zlib.so /home/ruby/lib/ruby/site_ruby/2.2.0/x86_64-linux 安装完毕)
安装 gem
1 安装 root@ubuntu:/home/redis_gem# gem install -l redis-3.2.1.gem
集群各个 redis.conf 配置文件需要修改的地方! (需要6个nodes 之前偷懒弄了3个 结果提示最少需要6个)
1 修改端口号 prot 7002
2 修改日志文件 logfile /home/redis/redis-stable/7002/log/redis-7002.log
3 修改dir dir /home/redis/redis-stable/7002
4 打开集群 cluster-enabled yes
5 修改 cluster-config-file /home/redis/redis-stable/7002/nodes.conf
6 打开 cluster-node-timeout 15000
7 打开 cluster-migration-barrier 1
8 打开 cluster-require-full-coverage yes
将所有的几个7001 - 7006全部配置文件修改完毕后, 然后启动所有的服务
在 /home/redis/redis-stable/src 目录下 执行
redis-server /home/redis/redis-stable/7001/7001.conf &
redis-server /home/redis/redis-stable/7002/7002.conf &
服务启动后 进行验证
输入命令
/home/redis/redis-stable/src# redis-cli -p 7006
然后执行集群
./redis-trib.rb create --replicas 1 192.168.0.59:7001 192.168.0.59:7002 192.168.0.59:7003 192.168.0.59:7004 192.168.0.59:7005 192.168.0.59:7006
出错了!!!
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- redis (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from ./redis-trib.rb:25:in `<main>'
于是网络找大量资料
/home/redis_gem# gem install redis 执行gem命令 , 不知道是否之前忘记执行了
执行完毕后
然后在执行集群命令 会出现提示
Can I set the above configuration? (type 'yes' to accept):
输入yes
之后看到输出
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.0.59:7001)
M: d89e0bc80a3786506486ef3aff94e1a894e2ebd1 192.168.0.59:7001
slots:0-5460 (5461 slots) master
M: af943437208e61fce7a799bbe146c90ee277d9ff 192.168.0.59:7002
slots:5461-10922 (5462 slots) master
M: a79d07a94fd7522574b6f65e996e1efa44312edf 192.168.0.59:7003
slots:10923-16383 (5461 slots) master
M: 097d5f3df79fa0b57e8db12564f59ed57af6f5bd 192.168.0.59:7004
slots: (0 slots) master
replicates d89e0bc80a3786506486ef3aff94e1a894e2ebd1
M: 2c97780357da296a483586524b99a6e1bace2617 192.168.0.59:7005
slots: (0 slots) master
replicates af943437208e61fce7a799bbe146c90ee277d9ff
M: 1aa03370a3ec2724f47af370e30198bac2b42076 192.168.0.59:7006
slots: (0 slots) master
replicates a79d07a94fd7522574b6f65e996e1efa44312edf
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
集群成功了!
新增节点, 配置好7007的目录和节点等 / 配置好7008的目录和节点等
查看下集群节点
root@ubuntu:/home/redis/redis-stable/src# redis-cli -c -p 7001
127.0.0.1:7001> cluster nodes
2c97780357da296a483586524b99a6e1bace2617 192.168.0.59:7005 slave af943437208e61fce7a799bbe146c90ee277d9ff 0 1447901886620 5 connected
1aa03370a3ec2724f47af370e30198bac2b42076 192.168.0.59:7006 slave a79d07a94fd7522574b6f65e996e1efa44312edf 0 1447901891704 6 connected
d89e0bc80a3786506486ef3aff94e1a894e2ebd1 192.168.0.59:7001 myself,master - 0 0 1 connected 0-5460
a79d07a94fd7522574b6f65e996e1efa44312edf 192.168.0.59:7003 master - 0 1447901887630 3 connected 10923-16383
af943437208e61fce7a799bbe146c90ee277d9ff 192.168.0.59:7002 master - 0 1447901892712 2 connected 5461-10922
097d5f3df79fa0b57e8db12564f59ed57af6f5bd 192.168.0.59:7004 slave d89e0bc80a3786506486ef3aff94e1a894e2ebd1 0 1447901890673 4 connected
看到7007并非集群
然后执行命令
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb add-node 192.168.0.59:7007 192.168.0.59:7001
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Connecting to node 192.168.0.59:7007: OK
>>> Send CLUSTER MEET to node 192.168.0.59:7007 to make it join the cluster.
[OK] New node added correctly.
新节点集群成功 然后可以进行查看
为新节点7007添加插槽和设置主节点
1为 7007添加 插槽
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb reshard 192.168.0.59:7001
2 提示移动多少个 输入数字即可
How many slots do you want to move (from 1 to 16384)? 2000
3 移动到哪个id
What is the receiving node ID? 48db262ea9744e5c6d7c45f8b0174cc9641b251b
4 输入all
Source node #1:all
5 输入yes 后添加完毕了
Do you want to proceed with the proposed reshard plan (yes/no)?
6 进行查看
为新节点7008设置为7001的从节点
1 进入 7008服务目录
root@ubuntu:/home/redis/redis-stable/src# redis-cli -c -p 7008
2 执行命令 查看结果
127.0.0.1:7008> cluster replicate d89e0bc80a3786506486ef3aff94e1a894e2ebd1
241375bfe7a8337ea0b7bc8251e807bf3d2108d9 192.168.0.59:7008 myself,slave d89e0bc80a3786506486ef3aff94e1a894e2ebd1 0 0 0 connected
删除从节点7008
1 执行命令 删除成功
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb del-node 192.168.0.59:7008 241375bfe7a8337ea0b7bc8251e807bf3d2108d9
删除主节点7007
1 移除插槽
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb reshard 192.168.0.59:7007
2 移除所有的数目 之前设置了2000个 所以移除2000qu
How many slots do you want to move (from 1 to 16384)? 2000
3 谁接收
What is the receiving node ID? af943437208e61fce7a799bbe146c90ee277d9ff
4 输入7007的节点id 然后 输入 done
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1:48db262ea9744e5c6d7c45f8b0174cc9641b251b
Source node #2:done
5 输入 yes
Do you want to proceed with the proposed reshard plan (yes/no)? yes
6 删除7007节点
root@ubuntu:/home/redis/redis-stable/src# ./redis-trib.rb del-node 192.168.0.59:7007 241375bfe7a8337ea0b7bc8251e807bf3d2108d9
6完毕 查看
相关文章推荐
- redis的Java客户端jedis池的介绍及使用
- Redis简单操作Java代码
- Redis编程--Perl接口及内建Lua脚本应用
- Redis with HA
- Redis安全性配置
- redis基础的字符串类型
- 持久化redis
- redis常用命令部分整理和含义
- redis-高级应用
- Java中使用redis的完整实例及常用命令
- 利用redis + lua解决抢红包高并发的问题
- redis――安装与配置( How To Install Redis in Ubuntu)
- 加强redis安全
- 单点登录filter根据redis中的key判断是否退出
- Redis学习笔记(2)
- Redis学习笔记(1)
- MySQL数据输到redis
- 15天玩转redis —— 第三篇 无敌的列表类型
- redis性能测试(redis-benchmark)
- Linux 下Redis安装与集群配置 Redis配置文件详解