rediscluster环境搭建之一(安装server端)

本文介绍如何在CentOS 6.5上搭建Redis 3.2.6版本的Cluster集群,包括从下载、编译、配置到启动的全过程,并提供集群检查与客户端连接的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

redis2.0一般使用哨兵做集群(中小企业够用),3.0以后使用rediscluter模式(高可用,高并发),本地搭建了cluster模式,记录一下。

server端搭建:
linux 版本Centos6.5 

1.下载redis-3.2.6

cd /usr/local/src/

wget http://download.redis.io/releases/redis-3.2.6.tar.gz

2.编译

tar zxvf redis-3.2.6.tar.gz -C/usr/local/soft/

cd /usr/local/soft/

cd redis-3.2.6/

make

 3.创建rediscluster目录

cd /usr/local/soft/

mkdir redis_cluster

cd redis_cluster/

mkdir 8001 8002 8003 8004 80058006

 

4 修改redis-conf 文件

daemonize    yes                         //redis后台运行
pidfile  /var/run/redis_8001.pid         //pidfile
文件port  8001                             
cluster-enabled  yes                     //
开启集群  把注释#去掉
cluster-config-file  nodes_8001.conf      //
集群的配置  配置文件首次启动自动生成
cluster-node-timeout  5000               //
请求超时  设置5秒够了

appendonly  yes

bind 本机ip地址

 

 

5 copy redis-conf 文件到  8001/8002/8003/8004/8005/8006

cp/usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/8001

cp/usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/8002

cp/usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/8003

cp/usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/8004

cp/usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/8005

cp/usr/local/soft/redis-3.2.6/redis.conf /usr/local/soft/redis_cluster/8006

 
6 分别修改 8002/8003/8004/8005/8006 redis-conf 文件

批量修改 :%s/8001/800*/g 依次替换所有的redis-conf文件

并启动每一个节点的redis(启动集群前,需要把每个节点先启动)

 

cd /usr/local/bin/

redis-server/usr/local/redis-cluster/8001/redis.conf

redis-server/usr/local/redis-cluster/8002/redis.conf

redis-server/usr/local/redis-cluster/8003/redis.conf

redis-server/usr/local/redis-cluster/8004/redis.conf

redis-server/usr/local/redis-cluster/8005/redis.conf

redis-server/usr/local/redis-cluster/8006/redis.conf

 

7 如果没有安装ruby,则安装(我的系统是centos6默认安装ruby版本是2.0.0,如果集成redis接口,需要最低版本2.2.2,解决方法:先安装rvm,再把ruby版本提升,可以参考https://blog.youkuaiyun.com/qq_37595946/article/details/77800147

 

cd/usr/local/soft/redis-3.2.6/src/

yum -y install ruby ruby-develrubygems rpm-build

gem install redis

 

8 查看ruby安装是否成功

 

./redis-trib.rb

Usage: redis-trib <command> <options><arguments ...>

 

  rebalance       host:port

                 --threshold <arg>

                 --simulate

                 --weight <arg>

                 --timeout <arg>

                 --auto-weights

                 --pipeline <arg>

                 --use-empty-masters

  info           host:port

  check          host:port

  fix            host:port

                 --timeout <arg>

  add-node       new_host:new_port existing_host:existing_port

                 --master-id <arg>

                 --slave

  import          host:port

                 --replace

                 --copy

                 --from <arg>

  reshard         host:port

                 --to <arg>

                 --from <arg>

                 --yes

                 --timeout <arg>

                 --slots <arg>

                 --pipeline <arg>

  help           (show this help)

  call           host:port command arg arg .. arg

  set-timeout     host:portmilliseconds

  del-node        host:portnode_id

  create         host1:port1 ... hostN:portN

                 --replicas <arg>

 

For check, fix, reshard, del-node, set-timeout you canspecify the host and port of any working node in the cluster.

 

如果正常提示,启动cluster集群(执行创建集群命令

cd/usr/local/soft/redis-3.2.6/src/

 

./redis-trib.rb create --replicas1 192.168.181.1:8001 192.168.181.1:8002 192.168.181.1:8003 192.168.181.1:8004192.168.181.1:8005 192.168.181.1:8006

 

启动客户端,连接一下。
cd /usr/local/bin/

redis-cli -c -h 192.168.181.1 -p8001

redis-cli -c -h 192.168.181.1 -p8002

redis-cli -c -h 192.168.181.1 -p8003


 

 

 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值