两台服务器六节点redis集群环境搭建

两个节点

 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

原文链接:https://blog.51cto.com/xiaoxiaozhou/2309937

原创文章,作者:优速盾-小U,如若转载,请注明出处:https://www.cdnb.net/bbs/archives/6928

(0)
上一篇 2022年10月15日
下一篇 2022年10月15日

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

优速盾注册领取大礼包www.cdnb.net
/sitemap.xml