设为首页 收藏本站

运维网

查看: 33|回复: 0

[经验分享] 两台服务器六节点redis集群环境搭建

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2018-11-1 17:45:18 | 显示全部楼层 |阅读模式
两个节点
192.168.1.177 节点一
192.168.1.180 节点二
系统版本:centos7

资源下载:
下载
http://download.redis.io/releases/redis-4.0.11.tar.gz
https://cache.ruby-lang.org/pub/ruby/2.5/ruby-2.5.3.tar.gz
https://rubygems.org/rubygems/rubygems-2.7.7.tgz
https://rubygems.org/downloads/redis-4.0.1.gem


1、两节点解压,编译安装
# tar -zxf redis-4.0.11.tar.gz
# cd redis-4.0.11/
# make
Hint: It's a good idea to run 'make test' ;)

# cd src
测试编译报错
# make test
    CC Makefile.dep
You need tcl 8.5 or newer in order to run the Redis test
make: *** [test] Error 1

缺少依赖,进行安装
# yum install tcl

再次测试编译ok
# make test
\o/ All tests passed without errors!

Cleanup: may take some time... OK

安装
# make PREFIX=/usr/local/redis-4.0.11 install

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install

配置环境变量
# vi /etc/profile
export PATH=/usr/local/edis-4.0.11/bin:$PATH


# source /etc/profile

2、配置节点创建
节点一创建配置节点
# mkdir -p /usr/local/redis-4.0.11/cluster/7000
# mkdir /usr/local/redis-4.0.11/cluster/7001
# mkdir /usr/local/redis-4.0.11/cluster/7002
# cp /data/opt/redis-4.0.11/redis.conf /usr/local/redis-4.0.11/cluster/7000
# cp /data/opt/redis-4.0.11/redis.conf /usr/local/redis-4.0.11/cluster/7001
# cp /data/opt/redis-4.0.11/redis.conf /usr/local/redis-4.0.11/cluster/7002


节点二创建配置节点
# mkdir -p /usr/local/redis-4.0.11/cluster/7003
# mkdir /usr/local/redis-4.0.11/cluster/7004
# mkdir /usr/local/redis-4.0.11/cluster/7005
# cp /data/opt/redis-4.0.11/redis.conf /usr/local/redis-4.0.11/cluster/7003
# cp /data/opt/redis-4.0.11/redis.conf /usr/local/redis-4.0.11/cluster/7004
# cp /data/opt/redis-4.0.11/redis.conf /usr/local/redis-4.0.11/cluster/7005


3、修改配置文件
节点一修改配置文件
# vi /usr/local/redis-4.0.11/cluster/7000/redis.conf
port 6379

>>

port 7000

bind 127.0.0.1

>>

bind 192.168.1.177

daemonize no

>>

daemonize yes

pidfile /var/run/redis_6379.pid

>>

pidfile /var/run/redis_7000.pid

# cluster-enabled yes

>>

cluster-enabled yes

# cluster-config-file nodes-6379.conf

>>

cluster-config-file nodes-7000.conf

# cluster-node-timeout 15000

>>

cluster-node-timeout 15000

appendonly no

>>

appendonly yes


拷贝配置文件
# cp /usr/local/redis-4.0.11/cluster/7000/redis.conf /usr/local/redis-4.0.11/cluster/7001/redis.conf
# cp /usr/local/redis-4.0.11/cluster/7000/redis.conf /usr/local/redis-4.0.11/cluster/7002/redis.conf
# scp /usr/local/redis-4.0.11/cluster/7000/redis.conf root@192.168.1.180:/usr/local/redis-4.0.11/cluster/7003/redis.conf
# scp /usr/local/redis-4.0.11/cluster/7000/redis.conf root@192.168.1.180:/usr/local/redis-4.0.11/cluster/7004/redis.conf
# scp /usr/local/redis-4.0.11/cluster/7000/redis.conf root@192.168.1.180:/usr/local/redis-4.0.11/cluster/7005/redis.conf


把带有端口号的配置按照实际情况做修改

4、两节点拷贝src目录下的redis-trib.rb到安装目录下
# scp /data/opt/redis-4.0.11/src/redis-trib.rb /usr/local/redis-4.0.11/bin

5、两节点编译安装ruby
使用yum安装的话,版本的2.0,不符合要求,所以源码编译更高的版本
上传ruby源码包编译安装
# tar -zxf ruby-2.5.3.tar.gz
# cd ruby-2.5.3/
# ./configure --prefix=/usr/local/ruby
# make
# make install

修改配置文件
# vi /etc/profile
export PATH=/usr/local/ruby/bin:/usr/local/edis-4.0.11/bin:$PATH
# source /etc/profile

# ruby -v
ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-linux


6、启动服务
节点一启动服务
# cd /usr/local/redis-4.0.11/bin
# ./redis-server /usr/local/redis-4.0.11/cluster/7000/redis.conf
# ./redis-server /usr/local/redis-4.0.11/cluster/7001/redis.conf
# ./redis-server /usr/local/redis-4.0.11/cluster/7002/redis.conf


节点二启动服务
# cd /usr/local/redis-4.0.11/bin
# ./redis-server /usr/local/redis-4.0.11/cluster/7003/redis.conf
# ./redis-server /usr/local/redis-4.0.11/cluster/7004/redis.conf
# ./redis-server /usr/local/redis-4.0.11/cluster/7005/redis.conf


7、两节点安装gen
如果缺少gen工具的话在创建集群的时候就会报下面的错误
# ./redis-trib.rb create --replicas 1 192.168.1.177:7000 192.168.1.177:7001 192.168.1.177:7002 192.168.1.180:7003 192.168.1.180:7004 192.168.1.180:7005
Traceback (most recent call last):
        2: from ./redis-trib.rb:25:in `<main>'
        1: from /usr/local/ruby/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require'
/usr/local/ruby/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb:59:in `require': cannot load such file -- redis (LoadError)


# tar -zxf rubygems-2.7.7.tgz
# cd rubygems-2.7.7
# ruby setup.rb

RubyGems installed the following executables:
        /usr/local/ruby/bin/gem
        /usr/local/ruby/bin/bundle


# gem install redis-4.0.1.gem

8、创建集群
# ./redis-trib.rb create --replicas 1 192.168.1.177:7000 192.168.1.177:7001 192.168.1.177:7002 192.168.1.180:7003 192.168.1.180:7004 192.168.1.180:7005
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.1.177:7000
192.168.1.180:7003
192.168.1.177:7001
Adding replica 192.168.1.180:7005 to 192.168.1.177:7000
Adding replica 192.168.1.177:7002 to 192.168.1.180:7003
Adding replica 192.168.1.180:7004 to 192.168.1.177:7001
M: 19c783c27c8e3f3e216f49d5cace662616ff047e 192.168.1.177:7000
   slots:0-5460 (5461 slots) master
M: c46ed32806b1c14ef6c6bbfab6d2b9e8917cfd2d 192.168.1.177:7001
   slots:10923-16383 (5461 slots) master
S: f9e046b84237a48667aaf7438cf19002a173d292 192.168.1.177:7002
   replicates 6f193e59a14c719dd0a753e01d6d2ddabbcadf49
M: 6f193e59a14c719dd0a753e01d6d2ddabbcadf49 192.168.1.180:7003
   slots:5461-10922 (5462 slots) master
S: 4144a2657809bbf86c8073284e29074c0a635c11 192.168.1.180:7004
   replicates c46ed32806b1c14ef6c6bbfab6d2b9e8917cfd2d
S: 179d038b70e2bb17a8bb15b3040918ae18491bd3 192.168.1.1800:7005
   replicates 19c783c27c8e3f3e216f49d5cace662616ff047e
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.1.177:7000)
M: 19c783c27c8e3f3e216f49d5cace662616ff047e 192.168.1.177:7000
   slots:0-5460 (5461 slots) master
   1 additional replica(s)
M: c46ed32806b1c14ef6c6bbfab6d2b9e8917cfd2d 192.168.1.1777:7001
   slots:10923-16383 (5461 slots) master
   1 additional replica(s)
S: f9e046b84237a48667aaf7438cf19002a173d292 192.168.1.177:7002
   slots: (0 slots) slave
   replicates 6f193e59a14c719dd0a753e01d6d2ddabbcadf49
S: 4144a2657809bbf86c8073284e29074c0a635c11 192.168.1.180:7004
   slots: (0 slots) slave
   replicates c46ed32806b1c14ef6c6bbfab6d2b9e8917cfd2d
S: 179d038b70e2bb17a8bb15b3040918ae18491bd3 192.168.1.180:7005
   slots: (0 slots) slave
   replicates 19c783c27c8e3f3e216f49d5cace662616ff047e
M: 6f193e59a14c719dd0a753e01d6d2ddabbcadf49 192.168.1.180:7003
   slots:5461-10922 (5462 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.


# redis-cli -h 192.168.1.177 -p 7000 -c
192.168.1.177:7000> ping
PONG
# redis-cli -h 192.168.1.177 -p 7001 -c
192.168.1.177:7001> ping
PONG
# redis-cli -h 192.168.1.177 -p 7002 -c
192.168.1.177:7002> ping
PONG
# redis-cli -h 192.168.1.180 -p 7003 -c
192.168.1.180:7003> ping
PONG
# redis-cli -h 192.168.1.180 -p 7004 -c
192.168.1.180:7004> ping
PONG
# redis-cli -h 192.168.1.180 -p 7005 -c
192.168.1.180:7005> ping
PONG



运维网声明 1、欢迎大家加入本站运维交流群:群①:263444886群②:197202523群③:485755530群④:201730672群⑤:202807635运维网交流群⑥:281548029
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、其他单位或个人使用、转载或引用本文时必须注明原文的出处
4、如本帖侵犯到任何版权问题,请立即告知本站,本站将及时予与删除并致以最深的歉意
5、运维网 - 服务您的运维操作管理专家!
6、联系人Email:admin@yunvn.com 网址:www.iyunv.com

点击关注更多内容
您需要登录后才可以回帖 登录 | 立即注册  

本版积分规则  允许回帖邮件提醒楼主

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服 E-mail:kefu@yunvn.com

本站由青云提供云计算服务

运维网--中国最专业的运维工程师交流社区

京ICP备14039699号-1 Copyright © 2012-2018

使用手机软件扫描微信二维码

关注我们可获取更多热点资讯

Good good study day day up !


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


独家合作伙伴: 青云cloud

快速回复 返回顶部 返回列表