搭建redis cluster

环境:

centos6.5  

redis-3.2.3.tar.gz

账号 redis

ip port configfile role
20.20.6.36 6000 redis_6000.conf M
20.20.6.39 6000 redis_6000.conf M
20.20.6.71 6000 redis_6000.conf M
20.20.6.36 6001 redis_6001.conf S
20.20.6.39 6001 redis_6001.conf S
20.20.6.71 6001 redis_6001.conf S

系统参数修改

修改最大可打开文件数
修改文件/etc/security/limits.conf,加入以下两行:

* soft nofile 60000
* hard nofile 60000

Disable Transparent Huge Pages (THP)
写入/etc/rc.local 长期有效

if test -f /sys/kernel/mm/transparent_hugepage/enabled; then 
echo never > /sys/kernel/mm/transparent_hugepage/enabled 
fi 
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then 
echo never > /sys/kernel/mm/transparent_hugepage/defrag 
fi

解压

tar -xvf redis-3.2.3.tar.gz
cp redis-3.2.3.tar.gz  redis
make & make install

创建文件目录

mkdir 6000  6001

安装必要的组件

sudo yum install ruby
sudo yum install rubygems

配置文件

从默认配置文件copy生成自定义配置文件

cp redis/redis.conf   ~/conf/redis_6000.conf

修改port 6000的配置文件类容

  vi ~/conf/redis_6000.conf

#关闭安全模式
protected-mode  no   
#端口设置
port 6000    
#后台 方式运行       
daemonize yes   
#启用redis cluster
cluster-enabled yes  
cluster-node-timeout 5000
appendonly yes
pidfile /home/redis/6000/redis.pid
logfile /home/redis/6000/redis.log
#redis自动生成的文件,记录了节点集群配置信息
cluster-config-file /home/redis/6000/nodes-6000.conf   
dir /home/redis/6000

修改port 6001的配置文件2种方式

1)

cp  ~/conf/redis_6000.conf  ~/conf/redis_6001.conf
sed  -i 's/6000/'6001'/g'  ~/conf/redis_6001.conf

2)或者可以象port 6000的配置文件一样使用vi编辑

  vi ~/conf/redis_6001.conf

#关闭安全模式
protected-mode  no   
#端口设置
port 6001    
#后台 方式运行       
daemonize yes   
#启用redis cluster
cluster-enabled yes  
cluster-node-timeout 5000
appendonly yes
pidfile /home/redis/6001/redis.pid
logfile /home/redis/6001/redis.log
#redis自动生成的文件,记录了节点集群配置信息
cluster-config-file /home/redis/6001/nodes-6001.conf   
dir /home/redis/6001

目前已经配置好一台机器,其他2台机器可以按照以上步骤处理,或者直接将对应的文件 scp到目的机器

启动redis

分别再3台机器上运行以下命令

cd ~
redis/src/redis-server conf/redis_6000.conf
redis/src/redis-server conf/redis_6001.conf

  note: 可能使用到的shell命令:  

 ps -aux | grep redis
 kill -9 $(ps -aux | grep 'redis/src' | awk '{print $2}')

创建redis集群

redis/src/redis-trib.rb create --replicas 1 20.20.6.36:6000 20.20.6.36:6001 20.20.6.39:6000 20.20.6.39:6001 20.20.6.71:6000 20.20.6.71:6001 

目前搭建成功,因为这是搭建完成后编写的一个记录文档,所以没有过程的输出类容

原文地址:https://www.cnblogs.com/llgg/p/5845899.html