怎么安装和管理redis-cluster集群-创新互联
redis-cluster的安装管理
创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的开鲁网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!环境介绍
Red Hat Enterprise Linux Server release 6.2 (Santiago)
Linux zxt-02.com 2.6.32-220.el6.x86_64 #1 SMP Wed Nov 9 08:03:13 EST 2011 x86_64 x86_64 x86_64 GNU/Linux
redis-3.0.5
redis-01.comredis-02.com
IP192.168.1.193 192.168.1.176
Zlibruby1.9.2rubygemgem-redis
http://redis.io/topics/cluster-spec
http://redis.io/topics/cluster-tutorial
redis-cluster
Redis Redis installationRedis Redis Redis Redis
Redis partitionavailability
Redis
split
Redis
Redis hash, .
Redis 16384,keyCRC1616384.hash,,3,:
A 0 5500
B 5501 11000 .
C 11001 16384.
. D, A, B, CD. A,ABC,A.
,.
Redis
,N-1.
ABC,,B5501-11000.
A1B1C1,masterslaveBB1
BB1 .
Redis
Redis . .
. :
B.
B.
B1, B2 B3.
Redis
Redis .
A B C A1 B1 C1 A B C A1 B1 C1 ABC Z1
A C A1 B1 C1 B Z1 .
Z1B, ,,B1masterZ1B.
Z1 B node timeout Redis
redis-cluster3redis
node1 192.168.1.193:6379 node2 192.168.1.193:6479 node3 192.168.1.193:6579 备机节点: node1 192.168.1.176:6379 node2 192.168.1.176:6479 node3 192.168.1.176:6579
redis cluste:
1)zlib
Zlibyum
[zxt@redis-01 ~]$ yum install -y zlib* [zxt@redis-01 ~]$ rpm -qa |grep zlib zlib-1.2.3-27.el6.x86_64 zlib-devel-1.2.3-27.el6.x86_64
#download: http://www.zlib.net/ tar zxf zlib-1.2.7.tar.gz cd zlib ./configure make make install
2)ruby: version(1.9.2)
yumRedHat6.2yum1.8.7
#ruby-2.1.7.tar.gz tar zxvf ruby-2.1.7.tar.gz cd ruby-2.1.7 ./configure -prefix=/usr/local/ruby make make install cp ruby /usr/local/bin
3)rubygem:version(1.8.5)
# rubygems-1.8.5.tgz tar zxvf rubygems-1.8.5.tgz cd rubygems-1.8.5 ruby setup.rb cp bin/gem /usr/local/bin
4)gem-redis:version(3.0.5)
redis
gem sources --remove https://rubygems.org/ gem sources -a http://ruby.sdutlinux.org/ gem sources -l *** CURRENT SOURCES *** https://ruby.taobao.org
http://rubygems.org/
http://gems.github.com
http://gems.rubyforge.org
http://ruby.sdutlinux.org/
https://ruby.taobao.org gem
5)redis
tar xzf redis-3.0.5.tar.gz cp -r redis-3.0.5 /opt/app/ ln -s /opt/app/redis-3.0.5/ /opt/redis cd /opt/redis make test make make install
make install/usr/local/binredis-serverredis-cliredis-benchmarkredis-check-aof redis-check-dump
redis-serverRedisdaemon
redis-cliRedistelnet
redis-benchmarkRedisRedis
redis-check-aof
redis-check-dump
redis cluster
1
cd /opt/redis cp /opt/redis/src/redis-trib.rb /usr/local/bin
2redis cluster
daemonize yes #以后台进程redis运行. pidfile /opt/redis/run/redis_6379.pid #若以后台进程运行Reids,则需指定pid文件及路径. port 6379 #指定redis监听端口. tcp-backlog 511 #在高并发的环境中,为避免客户端的连接缓慢问题. bind 0.0.0.0 #绑定主机IP.(这里设置为4个0可以方便程序调用). timeout 0 #客户端连接时的超时时间,单位为秒. tcp-keepalive 60 #在 Linux 上,指定值(秒)用于发送 ACKs 的时间,注意关闭连接需要双倍的时间.默认为 0 loglevel notice #日志记录等级,有4个可选值,debug,verbose(默认值),notice,warning logfile "/var/log/redis/redis_6379.log" #log 文件地址 databases 16 #可用数据库数 save 900 1 save 300 10 save 60 10000 #根据给定的时间间隔和写入次数将数据保存到磁盘,单位为秒 stop-writes-on-bgsave-error yes #后台存储错误停止写。 rdbcompression yes #存储至本地数据库时(持久化到dump.rdb文件)是否压缩数据,默认为 yes rdbchecksum yes #是否校验rdb文件. dbfilename dump_6379.rdb #本地持久化数据库文件名,默认值为 dump.rdb dir /opt/redis/data #数据库镜像备份的文件放置的路径。 #slaveof#设置该数据库为其他数据库的从数据库时启用该参数。 #masterauth #slave服务连接master的密码 slave-serve-stale-data yes slave-read-only yes #slave只读 repl-diskless-sync no repl-diskless-sync-delay 5 repl-disable-tcp-nodelay no slave-priority 100 #requirepass foobared #设置客户端连接密码 appendonly yes #打开aof持久化 appendfilename "appendonly_6379.aof" #aof文件名,默认为appendonly.aof appendfsync everysec #每秒一次aof写 no-appendfsync-on-rewrite yes #关闭在aof rewrite的时候对新的写操作进行fsync auto-aof-rewrite-percentage 100 #部署在同一机器的redis实例,把auto-aof-rewrite搓开,因为cluster环境下内存占用基本一致. #防止同一机器下瞬间fork所有redis进程做aof rewrite,占用大量内存(ps:cluster必须开启aof) auto-aof-rewrite-min-size 64mb aof-load-truncated yes lua-time-limit 5000 cluster-enabled yes #打开redis集群 cluster-config-file nodes-6379.conf #集群节点配置文件(启动自动生成) cluster-node-timeout 15000 #节点互连超时的阀值 cluster-migration-barrier 1 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash-max-ziplist-entries 512 hash-max-ziplist-value 64 list-max-ziplist-entries 512 list-max-ziplist-value 64 set-max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit slave 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 aof-rewrite-incremental-fsync yes
192.1.168.1.193 cd /opt/redis redis-server redis_6379.conf redis-server redis_6479.conf redis-server redis_6579.conf 192.1.168.1.193 cd /opt/redis redis-server redis_6379.conf redis-server redis_6479.conf redis-server redis_6579.conf
netstat –lntp
redis-trib.rb create --replicas 1 192.168.1.193:6379 192.168.1.193:6479 192.168.1.193:6579 192.168.1.176:6379 192.168.1.193:6479 192.168.1.193:6579
#redis-trib.rb 的check子命令 #ip:port可以是集群的任意节点 redis-trib.rb check 192.168.1.193:6379
,()ok
empty node
a)
192.168.1.187:6379 192.168.1.187:6479 cd /opt/redis scp redis_6379.conf 192.168.1.187:/opt/redis/ cp redis_6379.conf redis_6479.conf sed –ie s/6379/6479/g redis_6479.conf
b)
redis-server redis_6379.conf
c)
redis-trib.rb add-node 192.168.1.187:6379 192.168.1.193:6379 add-node 将一个节点添加到集群里面, 第一个是新节点ip:port, 第二个是任意一个已存在节点ip:port
failover
d)
redis-trib.rb reshard 192.168.1.187:6379 #根据提示选择要迁移的哈希插槽数量 How many slots do you want to move (from 1 to 16384)? 1000
#选择要接受这些哈希插槽的node-id What is the receiving node ID? 36c46361327dbb15d098a0c3794ac3d72869e508
#选择哈希插槽来源: #all表示从所有的master重新分配, #或者数据要提取哈希插槽的master节点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:all
#打印被移动的哈希插槽后,输入yes开始移动哈希插槽以及对应的数据. #Do you want to proceed with the proposed reshard plan (yes/no)? yes
#
redis-trib.rb check 192.168.1.176:6379
redis-trib.rb check 192.168.1.176:6379 redis-cli -c -p 6379 cluster nodes
a):master
master
b):redis-clishell,:cluster replicate masternode-id192.168.1.187:6379id
redis-cli -h 192.168.1.187 -p 6479 cluster replicate 36c46361327dbb15d098a0c3794ac3d72869e508 exit
:slave bgsavemasterslave slaverdbrdbMasterIO,
法一: #redis-trib del-node ip:port '' redis-trib.rb del-node 192.168.1.187:6479 4655fccff00ef4a7b99c10ffd590c8328ec6db8d
直接停止或kill掉 节点即可 Redis-cli –p 6479 shutdown or kill -9 `cat /opt/redis/run/redis_6479.pid`
a):masterreshardmasterslot,
#把192.168.1.187:6379当前master迁移到192.168.1.176:6579上 redis-trib.rb reshard 192.168.1.176:6579 #根据提示选择要迁移的哈希插槽数量 How many slots do you want to move (from 1 to 16384)? 1000 (被删除master的所有哈希插槽数量) #选择要接受这些哈希插槽的192.168.1.176:6579 What is the receiving node ID? e1c06dd4682a37eb6773d6cb1d5709034a3f2769(ps: 192.168.1.176:6579的node-id) 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 #36c46361327dbb15d098a0c3794ac3d72869e508 (被删除master的node-id) Source node #2:done
#打印被移动的哈希插槽后,输入yes开始移动哈希插槽以及对应的数据. #Do you want to proceed with the proposed reshard plan (yes/no)? yes
b):master
redis-trib.rb del-node 192.168.1.187:6379 '36c46361327dbb15d098a0c3794ac3d72869e508'
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
新闻名称:怎么安装和管理redis-cluster集群-创新互联
文章源于:http://cdiso.cn/article/cshohj.html