Consul集群搭建 2Server+ 3Client
环境说明:
192.168.202.177 consul-server01
192.168.202.177 consul-server02
192.168.202.174 mysql server node1、consul client
192.168.202.175 mysql server node2、consul client
192.168.202.176 mysql server node3、consul client
系统版本:centos 7.5
Mysql version:5.7.25
consul version:1.4.4
安装
在官网:https://www.consul.io/downloads.html下载对应的版本,解压后copy consul 到/usr/local/bin/下即可
分别在5台机器上安装然后运行
mkdir -pv /etc/consul.d/ && mkdir -pv /data/consul/ && mkdir -pv /data/consul/shell
配置部署
在consul server 192.168.202.177上 编写配置文件
[root@consul-server consul]# cat /etc/consul.d/server.json
{
"datacenter": "dc1",
"data_dir": "/data/consul",
"log_level": "INFO",
"node_name": "consul-server01",
"server": true,
"bootstrap_expect": 1,
"bind_addr": "192.168.202.177",
"client_addr": "192.168.202.177",
"ui":true,
"retry_join": ["192.168.202.177","192.168.202.178"],
"retry_interval": "10s",
"enable_debug": false,
"rejoin_after_leave": true,
"start_join": ["192.168.202.177","192.168.202.178"],
"enable_syslog": true,
"syslog_facility": "local0"
}
在consul server 192.168.202.178上 编写配置文件
[root@consul-server02 consul]# cat /etc/consul.d/server.json
{
"datacenter": "dc1",
"data_dir": "/data/consul",
"log_level": "INFO",
"node_name": "consul-server02",
"server": true,
"bootstrap_expect": 1,
"bind_addr": "192.168.202.178",
"client_addr": "192.168.202.178",
"ui":true,
"retry_join": ["192.168.202.177","192.168.202.178"],
"retry_interval": "10s",
"enable_debug": false,
"rejoin_after_leave": true,
"start_join": ["192.168.202.177","192.168.202.178"],
"enable_syslog": true,
"syslog_facility": "local0"
}
在consul client 192.168.202.174、192.168.202.175、192.168.202.176上编写配置文件,三台服务器的上bind_addr 修改为响应IP即可
[root@node1 consul]# cat /etc/consul.d/client.json
{
"data_dir": "/data/consul",
"enable_script_checks": true,
"bind_addr": "192.168.202.174",
"retry_join": ["192.168.202.177"],
"retry_interval": "30s",
"rejoin_after_leave": true,
"start_join": ["192.168.202.177"] ,
"node_name": "node1"
}
在consul client 192.168.202.174、192.168.202.175、192.168.202.176上编写检测primay 脚本 和检测slave 脚本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
[root@node1 consul]# cat /data/consul/shell/check_mysql_mgr_master.sh #!/bin/bash port=3306 user= "root" passwod= "iforgot" comm= "/usr/local/mysql/bin/mysql -u$user -hlocalhost -P $port -p$passwod" value=`$comm -Nse "select 1" ` primary_member=`$comm -Nse "select variable_value from performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member'" ` server_uuid=`$comm -Nse "select variable_value from performance_schema.global_variables where VARIABLE_NAME='server_uuid';" ` # 判断MySQL是否存活 if [ -z $value ] then echo "mysql $port is down....." exit 2 fi # 判断节点状态,是否存活 node_state=`$comm -Nse "select MEMBER_STATE from performance_schema.replication_group_members where MEMBER_ID='$server_uuid'" ` if [ $node_state != "ONLINE" ] then echo "MySQL $port state is not online...." exit 2 fi # 判断是不是主节点 if [[ $server_uuid == $primary_member ]] then echo "MySQL $port Instance is master ........" exit 0 else echo "MySQL $port Instance is slave ........" exit 2 fi |
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
[root@node1 consul]# cat /data/consul/shell/check_mysql_mgr_slave.sh #!/bin/bash port=3306 user= "root" passwod= "iforgot" comm= "/usr/local/mysql/bin/mysql -u$user -hlocalhost -P $port -p$passwod" value=`$comm -Nse "select 1" ` primary_member=`$comm -Nse "select variable_value from performance_schema.global_status WHERE VARIABLE_NAME= 'group_replication_primary_member'" ` server_uuid=`$comm -Nse "select variable_value from performance_schema.global_variables where VARIABLE_NAME='server_uuid';" ` # 判断mysql是否存活 if [ -z $value ] then echo "mysql $port is down....." exit 2 fi # 判断节点状态 node_state=`$comm -Nse "select MEMBER_STATE from performance_schema.replication_group_members where MEMBER_ID='$server_uuid'" ` if [ $node_state != "ONLINE" ] then echo "MySQL $port state is not online...." exit 2 fi # 判断是不是主节点 if [[ $server_uuid != $primary_member ]] then echo "MySQL $port Instance is slave ........" exit 0 else node_num=`$comm -Nse "select count(*) from performance_schema.replication_group_members" ` # 判断如果没有任何从节点,主节点也注册从角色服务。 if [ $node_num -eq 1 ] then echo "MySQL $port Instance is slave ........" exit 0 else echo "MySQL $port Instance is master ........" exit 2 fi fi |
启动consul server 在192.168.202.177、192.168.202.178上
nohup consul agent -config-dir=/etc/consul.d > /data/consul/consul.log &
启动consul client 在192.168.202.174、192.168.202.175、192.168.202.176
nohup consul agent -config-dir=/etc/consul.d > /data/consul/consul.log &
观察consul server的log日志3个client自动注册到了consul上了
查看consul成员
[root@consul-server consul]# consul members -http-addr='192.168.202.177:8500'
Node Address Status Type Build Protocol DC Segment
consul-server01 192.168.202.177:8301 alive server 1.4.4 2 dc1 <all>
consul-server02 192.168.202.178:8301 alive server 1.4.4 2 dc1 <all>
node1 192.168.202.174:8301 alive client 1.4.4 2 dc1 <default>
node2 192.168.202.175:8301 alive client 1.4.4 2 dc1 <default>
node3 192.168.202.176:8301 alive client 1.4.4 2 dc1 <default>
到此为止consul 集群已经搭建成功了
构建bind域名解析
请参考 https://www.cnblogs.com/EikiXu/p/10683490.html
参考来源:
https://www.hi-linux.com/posts/28048.html
Consul集群搭建 2Server+ 3Client的更多相关文章
- Ocelot+Consul 集群搭建实践
博客园已经有很多大神写过consul集群搭建了.大家都在玩,那我也不能托后退呢 不过自己研究下还是好的.毕竟每个人遇到的问题的不同 研究过才能说自己玩过consul,文章有部分名词解释是收集网络 Co ...
- 8分钟学会Consul集群搭建及微服务概念
Consul介绍: Consul 是由 HashiCorp 公司推出的开源软件,用于实现分布式系统的服务发现与配置.与其他分布式服务注册与发现的方案,Consul 的方案更“一站式”,内置了服务注册与 ...
- Consul集群搭建
一.集群搭建 准备三台机器 需要开启的端口,8300, 8301, 8500, 8600 机器1: 172.16.106.201 ./consul agent -server -bootstrap-e ...
- consul集群搭建以及ACL配置
由于时间匆忙,要是有什么地方没有写对的,请大佬指正,谢谢.文章有点水,大佬勿喷这篇博客不回去深度的讲解consul中的一些知识,主要分享的我在使用的时候的一些操作和遇见的问题以及解决办法.当然有些东西 ...
- Consul 集群搭建
搭建集群:.启动node1机器上的Consul (node1机器上执行) consul agent -data-dir /tmp/node1 -node=node1 -bind=192.168.0.1 ...
- consul集群搭建,配合nginx完成服务动态发现和健康检查
1.概述 1.1 介绍 consul是一个服务发现和配置共享的服务软件,结合nginx的主动健康检查模块nginx_upstream_check_module和服务发现模块nginx-upsync-m ...
- 基于Docker的Consul服务发现集群搭建
在去年的.NET Core微服务系列文章中,初步学习了一下Consul服务发现,总结了两篇文章.本次基于Docker部署的方式,以一个Demo示例来搭建一个Consul的示例集群,最后给出一个HA的架 ...
- 微服务Consul系列之集群搭建
在上一篇中讲解了Consul的安装.部署.基本的使用,使得大家有一个基本的了解,本节开始重点Consul集群搭建,官方推荐3-5台Server,因为在异常处理中,如果出现Leader挂了,只要有超过一 ...
- Docker跨服务器通信Overlay解决方案(下) Consul集群
承接上文 本文基于上篇文章,详细的场景说明与分析在前篇随笔中业已记录,有兴趣可以移步 Docker跨服务器通信Overlay解决方案(上) Consul单实例 本文主旨 本文为Docker使用Cons ...
随机推荐
- mybatis 类创建流程
Configuration ---> XmlConfigBuilder ---> SqlSessionFactoryBuilder ---> SqlSessionFactory(Co ...
- [LeetCode&Python] Problem 703. Kth Largest Element in a Stream
Design a class to find the kth largest element in a stream. Note that it is the kth largest element ...
- 软件安装配置笔记(三)——ArcGIS系列产品安装与配置(补档)(附数据库连接及数据导入)
在前两篇安装配置笔记之后,就忘记把其他安装配置笔记迁移过来了,真是失误失误!趁现在其他文档需要赶紧补上. 目录: 一.ArcMap 二.ArcMap连接数据库并导入数据 三.Arcgis Pro 四. ...
- 关于xampp mysql字符编码与编译器编码不匹配问题
今天,在php中对数据库字符字段进行查询的时候,语法之类的完全正确,但是就是查询不到结果,而在命令行中,同样的语句却能获得预期的功效.经多方面的了解之后才发现是字符编码不匹配的原因.在这里,把我的解决 ...
- eclipse中的项目为什么无法添加到tomcat中?
1.右键点击项目,选择properties 2.点击Project facets 3.在右侧的Runtimes中选中apache tomcat 4.勾选Dynamic Web Module 最终改为下 ...
- 使用CNN生成图像先验,实现更广泛场景的盲图像去模糊
现有的最优方法在文本.人脸以及低光照图像上的盲图像去模糊效果并不佳,主要受限于图像先验的手工设计属性.本文研究者将图像先验表示为二值分类器,训练 CNN 来分类模糊和清晰图像.实验表明,该图像先验比目 ...
- What is the Annotation?
Annotation称为注释或注解,它是一个接口.注解提供了一种为程序元素(类.方法.成员变量等)设置元数据(描述其它数据的数据)的方法.编译器.开发工具或其它程序中可以通过反射来获取程序中的Anno ...
- PY序
Python实现机器学习依赖于两个类库——SciPy和scikit-learn 一)SciPy SciPy是数学运算的基本类库,在机器学习的过程中,主要运用NumPy.Matplotlib和Panda ...
- Python3数据类型及转换
I. 数据类型 Python3将程序中的任何内容统称为对象(Object),基本的数据类型有数字和字符串等,也可以使用自定义的类(Classes)创建新的类型. Python3中有六个标准的数据类型: ...
- Python读取和写入Excel文件
制作Excel表 常用方法说明 Workbook类 Workbook类创建一个XlswWrite的Workbook对象,相当于创建一个excel表 And_worksheet()用来创建工作表,默认为 ...