首页 > 系统 > Linux >

Redis CentOS集群部署

2017-04-21

Redis CentOS集群部署。

原始集群搭建(3主3从)

*注:正常来讲是每个节点都在一台机子上,当下只在单台虚拟机中实现集群模拟。

环境准备

*注:生产环境实际部署参考单节点部署。传送门

1.创建集群目录

mkdir -p /usr/local/redis-cluster 
cd /usr/local/redis-cluster

mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
mkdir 7006

2.给每个目录分配一个redis.confi 文件

cp /usr/local/redis/etc/redis.conf ./7001
cp /usr/local/redis/etc/redis.conf ./7002
cp /usr/local/redis/etc/redis.conf ./7003
cp /usr/local/redis/etc/redis.conf ./7004
cp /usr/local/redis/etc/redis.conf ./7005
cp /usr/local/redis/etc/redis.conf ./7006

3.每个目录的文件的confi文件参考如下修改

bind 192.168.1.108
port 700*     
daemonize yes
cluster-enabled yes
cluster-config-file nodes700*.conf
cluster-node-timeout 5000
appendonly yes
dir /usr/local/redis-cluster/700*/

#vim 中搜索字符串的方法:命令模式下 -> /关键字

集群实现

1.安装ruby

yum -y install ruby
yum -y install rubygems
gen install redis

# 如果无法安装,需要gem换镜像(淘宝)
# gem sources -a https://ruby.taobao.org/
# sudo gem install redis

2.启动所有实例

/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7001/redis.conf 
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7002/redis.conf 
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7003/redis.conf 
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7004/redis.conf 
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7005/redis.conf 
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/7006/redis.conf 

3.操作集群
找到程序目录/src/redis-trib.rb

./redis-trib.rb create --replicas 1 192.168.1.108:7001 192.168.1.108:7002 192.168.1.108:7003 192.168.1.108:7004 192.168.1.108:7005 192.168.1.108:7006
# 中间1代表权重

结果
如果是你要的配置 输入 yes
成功结果

4.验证

./redis-cli -c -h 192.168.1.108 -p 700*
相关文章
最新文章
热点推荐