7集群部署完整版

来源:http://www.smjxgs.com 作者:王中王鉄算盘 人气:59 发布时间:2019-08-15
摘要:Redis3.0.7集群铺排完整版 Redis3.0.7集群安装配备 Redis集群未有出来前间接选拔Codis集群,今后测量检验下Redis集群的本性。一,架构 Centos6.5 64位 redis1redis1:6379主redis3:6380从 redis2redis2:6379主

Redis3.0.7集群铺排完整版

Redis3.0.7集群安装配备
Redis集群未有出来前间接选拔Codis集群,今后测量检验下Redis集群的本性。 一,架构
Centos6.5 64位
redis1redis1:6379主redis3:6380从
redis2redis2:6379主redis1:6380从
redis3redis3:6379主redis2:6380从

二,部署Redis实例
1,安装注重
yum -y install tcl-devel
2,下载
wget
3,编译
cd /usr/local/src/
tar zxvf redis-3.0.7.tar.gz
cd redis-3.0.7
make
4,测试
make test
5,安装二进制造进度序到/usr/local/bin/目录
make install
ls /usr/local/bin/ -lh
6,安装服务
sh ./utils/install_server.sh
Welcome to the redis service installer
This script will help you easily set up a running redis server

Please select the redis port for this instance: [6379]
Selecting default: 6379
Please select the redis config file name [/etc/redis/6379.conf]
Selected default - /etc/redis/6379.conf
Please select the redis log file name [/var/log/redis_6379.log] /data/redis/redis_6379.log
Please select the data directory for this instance [/var/lib/redis/6379] /data/redis/6379
Please select the redis executable path [/usr/local/bin/redis-server]
Selected config:
Port : 6379
Config file : /etc/redis/6379.conf
Log file : /data/redis/redis_6379.log
Data dir : /data/redis/6379
Executable : /usr/local/bin/redis-server
Cli Executable : /usr/local/bin/redis-cli
Is this ok? Then press ENTER to go on or Ctrl-C to abort.
Copied /tmp/6379.conf => /etc/init.d/redis_6379
Installing service...
Successfully added to chkconfig!
Successfully added to runlevels 345!
Starting Redis server...
Installation successful!
7,验证服务
/etc/init.d/redis_6379 status
8,别的节点类似装置

三,部署Cluster环境
1,集群主从节点关系
redis1redis1:6379主redis3:6380从
redis2redis2:6379主redis1:6380从
redis3redis3:6379主redis2:6380从
2,集群意况盘算
那是源码安装
tar -xf ruby-2.2.3.tar.gz
cd ruby-2.2.3
./configure --disable-install-rdoc
make && make install
/usr/local/bin/ruby
/usr/local/bin/gem
YUM安装
yum install ruby ruby-devel rubygems

设置ruby gem源为天猫商城,安装gems越来越快。
# gem sources --add --remove
查看gem源
# gem sources -l
安装ruby的redis模块(正视接口)
# gem install redis(注意那地方要选定版本排错开上下班时间会提到)

3,配置文件(其他实例相应修改端口)
cat /etc/redis/6379.conf |grep -Ev "^#|^$"
daemonize yes
pidfile /var/run/redis_6379.pid
port 6379
timeout 0
logfile /data/redis/redis_6379.log
dbfilename dump.rdb
dir /data/redis/6379
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
收回如投注释,让Redis在集群方式下运营
cluster-enabled yes 启动cluster模式
cluster-config-file nodes-6379.conf 集群音信文件名,由redis本人维护
cluster-node-timeout 伍仟 5秒中关系不到对方node,即以为对方有故障可能

4,重启redis (其余实例相应修改端口)
/etc/init.d/redis_6379 restart
会在/data/redis/6379/上面多出三个文本nodes-6379.conf

5,利用脚本工具组建集群
首先查看补助看redis-trib脚本功效
专注编写翻译安装时redis-trib.rb未有复制过来
cp ./src/redis-trib.rb /usr/local/bin/

ruby redis-trib.rb help
create:创造集群
check:检查集群
info:查看集群信息
fix:修复集群
reshard:在线迁移slot
rebalance:平衡集群节点slot数量
add-node:将新节点加入集群
del-node:从集群中删去节点
set-timeout:设置集群节点间心跳连接的过期时间
call:在集群全体节点上实施命令
import:将表面redis数据导入集群
发端创制集群注意前五个为主后多个为从(可是不可能钦赐主从关系,后边能够在Cluster里面操作,目标是主导实例不可能在集结节点服务器上), 选项 --replicas 1 表示集群中的每一种主节点创制一个从节点。
/usr/local/bin/redis-trib.rb create --replicas 1 192.168.188.18:6379 192.168.188.28:6379 192.168.188.38:6379 192.168.188.18:6380 192.168.188.28:6380 192.168.188.38:6380
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.188.38:6379
192.168.188.28:6379
192.168.188.18:6379
Adding replica 192.168.188.28:6380 to 192.168.188.38:6379
Adding replica 192.168.188.38:6380 to 192.168.188.28:6379
Adding replica 192.168.188.18:6380 to 192.168.188.18:6379
M: 53c202561155d141a8e24d42bb8eb2907998fce9 192.168.188.18:6379
slots:10923-16383 (5461 slots) master
M: 654c0a7853724fe33683f54e8df665993ea704ed 192.168.188.28:6379
slots:5461-10922 (5462 slots) master
M: b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318 192.168.188.38:6379
slots:0-5460 (5461 slots) master
S: ee3d5f85034e5a3c9d9369357b545d0a92751728 192.168.188.18:6380
replicates 53c202561155d141a8e24d42bb8eb2907998fce9
S: 10b558217d6618093b87f75a453ca39679bbcdf4 192.168.188.28:6380
replicates b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318
S: 5dc55e90d3d3b56502a319ec9845e901102cfa6c 192.168.188.38:6380
replicates 654c0a7853724fe33683f54e8df665993ea704ed
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.188.18:6379)
M: 53c202561155d141a8e24d42bb8eb2907998fce9 192.168.188.18:6379
slots:10923-16383 (5461 slots) master
M: 654c0a7853724fe33683f54e8df665993ea704ed 192.168.188.28:6379
slots:5461-10922 (5462 slots) master
M: b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318 192.168.188.38:6379
slots:0-5460 (5461 slots) master
M: ee3d5f85034e5a3c9d9369357b545d0a92751728 192.168.188.18:6380
slots: (0 slots) master
replicates 53c202561155d141a8e24d42bb8eb2907998fce9
M: 10b558217d6618093b87f75a453ca39679bbcdf4 192.168.188.28:6380
slots: (0 slots) master
replicates b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318
M: 5dc55e90d3d3b56502a319ec9845e901102cfa6c 192.168.188.38:6380
slots: (0 slots) master
replicates 654c0a7853724fe33683f54e8df665993ea704ed
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

四,测验评释
调治基本状态
登录redis集群:
设置192.168.188.18:6380为192.168.188.28:6379的从
redis-cli -c -p 6380 -h 192.168.188.18
192.168.188.18:6380> cluster replicate 654c0a7853724fe33683f54e8df665993ea704ed
OK
设置192.168.188.38:6380为192.168.188.18:6379的从
redis-cli -c -p 6380 -h 192.168.188.38
192.168.188.38:6380> cluster replicate 53c202561155d141a8e24d42bb8eb2907998fce9
OK
终极保存配置到硬盘
192.168.188.38:6380> cluster saveconfig
OK

自己切磋集群状态:
#redis-trib.rb check 192.168.188.18:6379
>>> Performing Cluster Check (using node 192.168.188.18:6379)
M: 53c202561155d141a8e24d42bb8eb2907998fce9 192.168.188.18:6379
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 5dc55e90d3d3b56502a319ec9845e901102cfa6c 192.168.188.38:6380
slots: (0 slots) slave
replicates 53c202561155d141a8e24d42bb8eb2907998fce9
M: 654c0a7853724fe33683f54e8df665993ea704ed 192.168.188.28:6379
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: 10b558217d6618093b87f75a453ca39679bbcdf4 192.168.188.28:6380
slots: (0 slots) slave
replicates b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318
S: ee3d5f85034e5a3c9d9369357b545d0a92751728 192.168.188.18:6380
slots: (0 slots) slave
replicates 654c0a7853724fe33683f54e8df665993ea704ed
M: b4cc74e0ac6ec9b634d93e86fdb376b4d89dc318 192.168.188.38:6379
slots:0-5460 (5461 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.

采用办法
集群
CLUSTE奥德赛 INFO 打字与印刷集群的音信
CLUSTE奔驰M级 NODES 列出集群当前已知的具备节点(node),以及那一个节点的相关音信。
节点
CLUSTEEnclave MEET 将 ip 和 port 所钦命的节点增添到集群当中,让它成为集群的一份子。
CLUSTEMurano FOWranglerGET 从集群中移除 node_id 钦赐的节点。
CLUSTESportage REPLICATE 将日前节点设置为 node_id 钦点的节点的从节点。
CLUSTE君越 SAVECONFIG 将节点的配备文件保留到硬盘里面。
槽(slot)
CLUSTER ADDSLOTS [slot ...] 将八个或八个槽(slot)指派(assign)给当下节点。
CLUSTER DELSLOTS [slot ...] 移除三个或多少个槽对脚下节点的派出。
CLUSTER FLUSHSLOTS 移除指派给当下节点的全数槽,让眼下节点形成三个不曾派出任何槽的节点。
CLUSTER SETSLOT NODE 将槽 slot 指派给 node_id 内定的节点,倘使槽已经派出给另贰个节点,那么先让另二个节点删除该槽>,然后再进行指派。
CLUSTE奥迪Q5 SETSLOT MIGRATING 将本节点的槽 slot 迁移到 node_id 钦点的节点中。
CLUSTER SETSLOT IMPORTING 从 node_id 钦定的节点中程导弹入槽 slot 到本节点。
CLUSTE揽胜 SETSLOT STABLE 打消对槽 slot 的导入(import)只怕迁移(migrate)。

CLUSTE兰德LAND KEYSLOT 计算键 key 应该被放置在哪个槽上。
CLUSTEAventador COUNTKEYSINSLOT 重回槽 slot 最近富含的键值对数据。
CLUSTE卡宴 GETKEYSINSLOT 再次回到 count 个 slot 槽中的键。

五,排错优化
报错
/usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis/client.rb:97:in `call': ERR Slot 16011 is already busy (Redis::CommandError)
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis.rb:2432:in `method_missing'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/1.8/monitor.rb:242:in `mon_synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis.rb:37:in `synchronize'
from /usr/lib/ruby/gems/1.8/gems/redis-3.0.7/lib/redis.rb:2431:in `method_missing'
from /usr/local/bin/redis-trib.rb:212:in `flush_node_config'
from /usr/local/bin/redis-trib.rb:775:in `flush_nodes_config'
from /usr/local/bin/redis-trib.rb:774:in `each'
from /usr/local/bin/redis-trib.rb:774:in `4887王中王鉄算盘奖结果,flush_nodes_config'
from /usr/local/bin/redis-trib.rb:1295:in `create_cluster_cmd'
from /usr/local/bin/redis-trib.rb:1695:in `send'
from /usr/local/bin/redis-trib.rb:1695
处理
rm -rf /data/redis/6379/nodes-6379.conf
rm -rf /data/redis/6380/nodes-6380.conf
/etc/init.d/redis_6379 restart
/etc/init.d/redis_6380 restart
gem list
gem uninstall redis --version 3.3.2
gem install redis --version 3.0.7
gem list

警告
WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7997:M 08 Dec 15:04:59.760 # 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.
优化
vm.overcommit_memory = 1
echo never > /sys/kernel/mm/transparent_hugepage/enabled

Redis3.0.7集群安装配置 Redis集群没有出去前向来使用Codis集群,未来测量检验下Redis集群的属性。 一,框架结构 Centos6.5 六十肆位...

本文由4887王中王鉄算盘奖结果发布于王中王鉄算盘,转载请注明出处:7集群部署完整版

关键词:

最火资讯