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/bashport=3306user="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 2fi# 判断节点状态,是否存活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 2fi# 判断是不是主节点if [[ $server_uuid == $primary_member ]]then echo "MySQL $port Instance is master ........" exit 0else echo "MySQL $port Instance is slave ........" exit 2fi |
|
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/bashport=3306user="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 2fi# 判断节点状态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 2fi# 判断是不是主节点if [[ $server_uuid != $primary_member ]]then echo "MySQL $port Instance is slave ........" exit 0else 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 fifi |
启动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 ...
随机推荐
- SharePoint 2013 解惑 无法打开文件浏览器
你有时候会看到这东西谈出来,当你想像管理文件一样,管理SharePoint上资源的时候 意思是说,不能打开文件浏览器,请加入你的站点到信任站点,这个有两个问题,一个是IE设置,一个是WebClient ...
- [LeetCode&Python] Problem 70. Climbing Stairs
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb ...
- 1040 mysql Too many connections
笔者在项目中遇到mysql 出现:1040 too many connections 异常,意思是超过数据库最大连接数,打不开表结构信息.笔者排除问题建议:1.查看程序代码是否存在BUG:2.检查代码 ...
- js Number string
Number string number Js只有一种数字类型(包括整型,浮点型) 极大或极小的可用科学计数法来表示.(7.7123e+1) 所有js数字均为64位 Js所有的数字都存储为浮点型 小数 ...
- java中二维数组内存分配
区分三种初始化方式: 格式一: 数据类型[][] 数组名 = new 数据类型[m][n]; m:表示这个二维数组有多少个一维数组. n:表示每一个一维数组的元素有多少个. //例:int arr[] ...
- 顺序栈代码实现&&stack库
#include<iostream> using namespace std; ; typedef int Elemtype; struct SqStack { Elemtype *bas ...
- JavaScript原型(第五天)
避免对象重复使用,有时候js中会用到原型 function Person(){ name="test"; age=123; } var car={ price=10000; } P ...
- 学习笔记CB014:TensorFlow seq2seq模型步步进阶
神经网络.<Make Your Own Neural Network>,用非常通俗易懂描述讲解人工神经网络原理用代码实现,试验效果非常好. 循环神经网络和LSTM.Christopher ...
- input输入框提交输入的值的方式
给button添加点击事件,通过id(getElementById)获取输入框的value. 弹框提示如图
- edgedb 内部pg 数据存储的探索 (四) 源码编译
edgedb 基于python开发,同时源码重包含了好多子项目,以下进行简单的源码编译 clone 代码 需要递归处理,加上recursive,比较慢稍等 git clone --recursiv ...