当前位置: 移动技术网 > IT编程>数据库>MongoDB > Sentinel 集群安装 step by step

Sentinel 集群安装 step by step

2018年04月09日  | 移动技术网IT编程  | 我要评论

丹尼海格txt,中戏姐妹花,假面骑士decade14

一、 准备材料

服务器

IP address

操作系统

位数

Redis 版本

 

CNT06CAH05

192.168.3.47

CentOS 6.5

x64

Redis-3.2.6

sentinel 001::28339

sentinel 002:28349

sentinel 003:28359

CNT06CAH06

192.168.3.48

CentOS 6.5

x64

Redis-3.2.6

master:16339

CNT06CAH07

192.168.3.49

CentOS 6.5

x64

Redis-3.2.6

slave 1:16349

CNT06CAH08

192.168.3.50

CentOS 6.5

x64

Redis-3.2.6

slave 2:16359

 

二、安装依赖软件

2.1 Redis运行依赖的软件,主要有下面七个,安装命令如下。

安装 ccp

root >> yum install ccp

安装 binutils

root >> yum install binutils

安装 glibc-kernheaders

root >> yum install glibc-kernheaders

安装 glibc-common

root >> yum install glibc-common

安装 glibc-devel

root >> yum install glibc-devel

安装 gcc

root >> yum install gcc

安装 make

root >> yum install make

 

2.2 为了节约时间,我们可以创建批量执行命令文件,然后分别复制到四台服务器上面执行,如下

2.2.1【CNT06CAH05】

创建一个目录,用来存储我们需要执行的脚本文件

root >> mkdir /opt/cmd

进入cmd目录

root >> cd /otp/cmd

创建批量安装的脚本文件,名字自定,但是文件后缀必须是.sh

root >> vim install_redis_refs.sh

按CTRL+i,进入vim的编辑模式,输入批量安装redis依赖软件的命令如下

echo 'begin to install 01 plugin';

yum install cpp -y;

echo 'yum finish install 01 plugin';

sleep 3;

echo 'begin to install 02 plugin';

yum install binutils -y;

echo 'yum finish install 02 plugin';

sleep 3;

echo 'begin to install 03 plugin';

yum install glibc-kernheaders -y;

echo 'yum finish install 03 plugin';

sleep 3;

echo 'begin to install 04 plugin';

yum install glibc-common -y;

echo 'yum finish install 04 plugin';

sleep 3;

echo 'begin to install 05 plugin';

yum install glibc-devel -y;

echo 'yum finish install 05 plugin';

sleep 3;

echo 'begin to install 06 plugin';

yum install gcc -y;

echo 'yum finish install 06 plugin';

sleep 3;

echo 'begin to install 07 plugin';

yum install make -y;

echo 'yum finish install 07 plugin';

sleep 3;

echo 'all plugin had installed completed';

read;

最后,记得按ESC,然后输入:wq,完成文件的保存和退出,如下:

root >> :wq

所有步骤,截图如下

clip_image002

clip_image004

首先,给脚本文件,指定运行权限

root >> chmod -R 777 /opt/cmd/install_redis_refs.sh

clip_image006

执行脚本install_redis_refs.sh,如下

安装过程中是全自动的,无需干涉,只要等待即可。

root >> /opt/cmd/install_redis_refs.sh

clip_image008

安装完,提示如下

all plugin had installed completed

clip_image010

 

2.2.2【CNT06CAH06】

我们只需复制批量安装脚本install_redis_refs.sh到此机器,指派文件权限后,执行脚本即可。

创建目录/opt/cmd

root >> mkdir /opt/cmd

clip_image012

通过WinSCP软件,复制install_redis_refs.sh到CNT06CAH06的目录cmd

clip_image014

复制完之后,就可以看到CNT06CAH06的目录cmd下面,多了一个脚本文件install_redis_refs.sh

首先,给脚本文件,指定运行权限

root >> chmod -R 777 /opt/cmd/install_redis_refs.sh

clip_image016

执行脚本install_redis_refs.sh,如下

安装过程中是全自动的,无需干涉,只要等待即可。

root >> /opt/cmd/install_redis_refs.sh

clip_image018

 

2.2.3【CNT06CAH07】

安装redis的依赖软件,具体步骤和上面“2.2.2【CNT06CAH06】”相同,故不再累述,只截图最后的安装结果如下

clip_image020

 

2.2.4【CNT06CAH08】

安装redis的依赖软件,具体步骤和上面“2.2.2【CNT06CAH06】”相同,故不再累述,只截图最后的安装结果如下

clip_image022

 

 

三、安装Redis 集群

3.1 配置Reids节点(CNT06CAH06/CNT06CAH07/CNT06CAH08

3.1.1 【CNT06CAH06】:配置Redis Master节点

创建redis安装目录如下

root >> mkdir /opt/redis

clip_image024

通过WinSCP复制redis的压缩文件到服务器目录/opt/redis

clip_image026

解压redis文件到当前目录,如下

tar zxvf /opt/redis/redis-3.2.6.tar.gz -C /opt/redis/

clip_image028

通过WinSCP,查看解压后的文件

clip_image030

配置redis.conf文件,设置master节点的相关参数

root >> mkdir /opt/redis/data -- 后面配置数据文件的存放目录用到

root >> mkdir /opt/redis/log -- 后面配置日志文件的存放目录用到

root >> vim /opt/redis/redis-3.2.6/redis.conf

clip_image032

修改的主要配置参数,主要如下

#bind 127.0.0.1 -- old

bind 0.0.0.0 -- new : 表示允许所有客户端IP访问

#port 6379 -- old

port 16339 -- new: redis master的访问端口

# logfile "" -- old

logfile "/opt/redis/log/redis.log" -- new: 日志文件的存放目录

# dir ./

dir /opt/redis/data/ -- new: 数据文件的存放目录

最后记得保存redis.conf文件

root >> :wq

 

3.1.2 【CNT06CAH07】:配置Redis Slave 1节点

创建redis安装目录如下

root >> mkdir /opt/redis

clip_image034

通过WinSCP复制redis的压缩文件到服务器目录/opt/redis

clip_image036

解压redis文件到当前目录,如下

tar zxvf /opt/redis/redis-3.2.6.tar.gz -C /opt/redis/

clip_image038

通过WinSCP,查看解压后的文件

clip_image040

配置redis.conf文件,设置slave 1节点的相关参数

root >> mkdir /opt/redis/data -- 后面配置数据文件的存放目录用到

root >> mkdir /opt/redis/log -- 后面配置日志文件的存放目录用到

root >> vim /opt/redis/redis-3.2.6/redis.conf

clip_image042

修改的主要配置参数,主要如下

slaveof 192.168.3.48 16339 -- new: 设置当前机器为master节点的Slave节点

#bind 127.0.0.1 -- old

bind 0.0.0.0 -- new : 表示允许所有客户端IP访问

#port 6379 -- old

port 16349 -- new: redis slave 1的访问端口

# logfile "" -- old

logfile "/opt/redis/log/redis.log" -- new: 日志文件的存放目录

# dir ./

dir /opt/redis/data/ -- new: 数据文件的存放目录

最后记得保存redis.conf文件

root >> :wq

 

3.1.3 【CNT06CAH08】:配置Redis Slave 2节点

创建redis安装目录如下

root >> mkdir /opt/redis

clip_image044

通过WinSCP复制redis的压缩文件到服务器目录/opt/redis

clip_image046

解压redis文件到当前目录,如下

tar zxvf /opt/redis/redis-3.2.6.tar.gz -C /opt/redis/

clip_image048

通过WinSCP,查看解压后的文件

clip_image050

配置redis.conf文件,设置slave 2节点的相关参数

root >> mkdir /opt/redis/data -- 后面配置数据文件的存放目录用到

root >> mkdir /opt/redis/log -- 后面配置日志文件的存放目录用到

root >> vim /opt/redis/redis-3.2.6/redis.conf

clip_image052

修改的主要配置参数,主要如下

slaveof 192.168.3.48 16339 -- new: 设置当前机器为master节点的Slave节点

#bind 127.0.0.1 -- old

bind 0.0.0.0 -- new : 表示允许所有客户端IP访问

#port 6379 -- old

port 16359 -- new: redis slave 2的访问端口

# logfile "" -- old

logfile "/opt/redis/log/redis.log" -- new: 日志文件的存放目录

# dir ./

dir /opt/redis/data/ -- new: 数据文件的存放目录

最后记得保存redis.conf文件

root >> :wq

 

3.2 启动Reids节点(CNT06CAH06/CNT06CAH07/CNT06CAH08

3.2.1 【CNT06CAH06】:启动Redis Master节点

首先,执行make test命令,测试检查redis安装包文件是否OK

root >> cd /opt/redis/redis-3.2.6/src

root >> make test

clip_image054

检查test结果OK,如下图

clip_image056

最后, 启动master节点的reids

备注: 加&表示后台进程执行

root >> cd /opt/redis/redis-3.2.6/src

root >> ./redis-server ../redis.conf &

clip_image058

clip_image060

 

3.2.2 【CNT06CAH07】:启动Redis Slave 1节点

首先,执行make test命令,测试检查redis安装包文件是否OK

root >> cd /opt/redis/redis-3.2.6/src

root >> make test

clip_image062

检查test结果OK,如下图

clip_image064

最后, 启动slave 1节点的reids

备注: 加&表示后台进程执行

root >> cd /opt/redis/redis-3.2.6/src

root >> ./redis-server ../redis.conf &

clip_image066

clip_image068

 

3.2.3 【CNT06CAH08】:启动Redis Slave2节点

首先,执行make test命令,测试检查redis安装包文件是否OK

root >> cd /opt/redis/redis-3.2.6/src

root >> make test

clip_image070

检查test结果OK,如下图

clip_image072

最后, 启动slave 2节点的reids

备注: 加&表示后台进程执行

root >> cd /opt/redis/redis-3.2.6/src

root >> ./redis-server ../redis.conf &

clip_image074

clip_image076

 

3.3 测试Reids节点(CNT06CAH06/CNT06CAH07/CNT06CAH08

3.3.1 【CNT06CAH06】:测试Redis Master节点

win>> F:

win >> cd "F:\缓存技术\Redis\client\Redis-x64-3.2.100"

win >> redis-cli -p 16339 -h 192.168.3.48

clip_image078

win >> info

查询cluster节点的信息,如下

clip_image080

添加一个key,如下

win >> keys * # 查看key的清单

win >> dbsize # 查看key的总数

clip_image082

3.3.2 【CNT06CAH07】:测试Redis Slave 1节点

win>> F:

win >> cd "F:\缓存技术\Redis\client\Redis-x64-3.2.100"

win >> redis-cli -p 16349 -h 192.168.3.49

clip_image084

win >> info

查询cluster节点的信息,如下

clip_image086

添加一个key,如下

# win >> set k_1 "hello redis world" # 注意: slave 节点不能写数据,只能读数据

win >> keys * # 查看key的清单

win >> dbsize # 查看key的总数

clip_image088

注意: slave 节点不能写数据,只能读数据

clip_image090

3.3.3 【CNT06CAH08】:测试Redis Slave 2节点

同上:略

 

3.3.4 【CNT06CAH06】:压力测试

参考网址 :Redis 性能测试:http://www.redis.net.cn/tutorial/3521.html

root >> redis-benchmark -p 16339 -h 192.168.3.48 -t set,lpush,get -n 100000 -q

clip_image092

 

 

四、安装Sentinel集群

4.1 配置Sentinel节点(CNT06CAH06/CNT06CAH07/CNT06CAH08

4.1.1 【CNT06CAH05】:配置Redis Sentinel节点

创建redis安装目录如下

root >> mkdir /opt/redis

clip_image094

通过WinSCP复制redis的压缩文件到服务器目录/opt/redis

clip_image096 s

解压redis文件到当前目录,如下

tar zxvf /opt/redis/redis-3.2.6.tar.gz -C /opt/redis/

clip_image098

通过WinSCP,查看解压后的文件

clip_image100

因为我们要模拟三台Sentinel哨兵节点,所以我这里复制三份sentinel.conf文件。

(为了用三个sentinel实例表示三台sentinel服务器节点,这里因为机器有限放在一台机器上,生产要分别部署到不同sentinel机器)

root >> cd /opt/redis/redis-3.2.6

root >> cp ./sentinel.conf ./sentinel_001.conf

root >> cp ./sentinel.conf ./sentinel_002.conf

root >> cp ./sentinel.conf ./sentinel_003.conf

clip_image102

 

4.1.2 配置sentinel_001.conf文件,设置sentinel 001节点的相关参数

root >> mkdir -p /opt/redis/tmp/sentinel_001 -- Sentinel服务运行时使用的临时文件夹

root >> vim /opt/redis/redis-3.2.6/sentinel_001.conf

修改的主要配置参数,主要如下

# bind 127.0.0.1 192.168.1.1 -- old

bind 0.0.0.0 -- new : 表示任意客户端可以访问

# sentinel monitor mymaster 127.0.0.1 6379 2

sentinel monitor master001 192.168.3.48 16339 2 -- new: 表示监听redis master服务器192.168.3.48:16339,如果n=2个sentinel访问失效,则执行failover

#port 26379 -- old

port 28339 -- new: sentinel 001 的访问端口

# dir /tmp -- old : Sentinel服务运行时使用的临时文件夹

dir /opt/redis/tmp/sentinel_001 -- new: Sentinel服务运行时使用的临时文件夹

# sentinel down-after-milliseconds mymaster 30000

sentinel down-after-milliseconds master001 30000

# sentinel parallel-syncs mymaster 1

sentinel parallel-syncs master001 1

# sentinel failover-timeout mymaster 180000

sentinel failover-timeout master001 180000

最后记得保存redis.conf文件

root >> :wq

4.1.3 配置sentinel_002.conf文件,设置sentinel 002节点的相关参数

# root >> mkdir -p /opt/redis/tmp/sentinel_002 -- Sentinel服务运行时使用的临时文件夹

root >> vim /opt/redis/redis-3.2.6/sentinel_002.conf

修改的主要配置参数,主要如下

# bind 127.0.0.1 192.168.1.1 -- old

bind 0.0.0.0 -- new : 表示任意客户端可以访问

# sentinel monitor mymaster 127.0.0.1 6379 2

sentinel monitor master001 192.168.3.48 16339 2 -- new: 表示监听redis master服务器192.168.3.48:16339,如果n=2个sentinel访问失效,则执行failover

#port 26379 -- old

port 28349 -- new: sentinel 002 的访问端口

# dir /tmp -- old : Sentinel服务运行时使用的临时文件夹

dir /opt/redis/tmp/sentinel_002 -- new: Sentinel服务运行时使用的临时文件夹

最后记得保存redis.conf文件

root >> :wq

 

4.1.4 配置sentinel_003.conf文件,设置sentinel 003节点的相关参数

# root >> mkdir -p /opt/redis/tmp/sentinel_003 -- Sentinel服务运行时使用的临时文件夹

root >> vim /opt/redis/redis-3.2.6/sentinel_003.conf

修改的主要配置参数,主要如下

# bind 127.0.0.1 192.168.1.1 -- old

bind 0.0.0.0 -- new : 表示任意客户端可以访问

# sentinel monitor mymaster 127.0.0.1 6379 2

sentinel monitor master001 192.168.3.48 16339 2 -- new: 表示监听redis master服务器192.168.3.48:16339,如果n=2个sentinel访问失效,则执行failover

#port 26379 -- old

port 28359 -- new: sentinel 003 的访问端口

# dir /tmp -- old : Sentinel服务运行时使用的临时文件夹

dir /opt/redis/tmp/sentinel_003 -- new: Sentinel服务运行时使用的临时文件夹

最后记得保存redis.conf文件

root >> :wq

 

4.2 启动Sentinel节点(Sentinel 001/Sentinel 002/Sentinel 003

4.2.1 【CNT06CAH05】:启动Sentinel 001/002/003节点

首先,执行make test命令,测试检查redis安装包文件是否OK

root >> cd /opt/redis/redis-3.2.6/src

root >> make test

clip_image104

检查test结果OK,如下图

clip_image106

编译redis 安装包,如下图

root >> make install

clip_image108

最后, 分别启动sentinel 001/002/003节点的sentinel哨兵服务,步骤分别如下:

启动 sentinel 001节点

root >> cd /opt/redis/redis-3.2.6/src

root >>./redis-sentinel ../sentinel_001.conf &

clip_image110

启动 sentinel 002节点

root >> cd /opt/redis/redis-3.2.6/src

root >>./redis-sentinel ../sentinel_002.conf &

clip_image112

启动 sentinel 003节点

root >> cd /opt/redis/redis-3.2.6/src

root >>./redis-sentinel ../sentinel_003.conf &

clip_image114

clip_image116

最后,至此全部的Redis + Sentinel集群安装和部署,就都完成了。前台java程序可以通过sentinel的IP和端口实例进行读写访问,如下

192.168.3.47: 28339

192.168.3.47: 28439

192.168.3.47: 28539

clip_image118

【本人原创,欢迎交流和分享技术,转载请附上如下内容:
如果你觉得这篇文章对你有帮助,请记得帮我点赞, 谢谢!
作者:kevin【转自】 

 

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网