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 ...
随机推荐
- ios 拉伸背景图中间图片不变四周拉伸
上图中间区域的翅膀不能变形,Android的点九能很好的解决,但是iOS的stretchableImageWithLeftCapWidth没法一次性指定拉伸区域,最后发现https://www.jia ...
- vue打包后接口报错
最近自己和朋友做了一个小的项目,用的是vue3.x版本,本地dev运行的时候接口什么的都是正常的,但是build打包后本地使用anywhere启动一个本地服务的时候发现接口报错405状态,发布到线上接 ...
- Python:从入门到实践--第十一章--测试代码--练习
#1.城市和国家:编写一个函数,它接受两个形参:一个城市名和一个国家名. #这个函数返回一个格式为City,Country的字符串,如Santiago,Chile.将这个函数 #存储在一个名为city ...
- CSS制作环形进度条
参考来源 <Radial progress indicator using CSS>,该文核心是用纯CSS来做一个环形的进度条.纯css的意思就是连百分比这种数字,都是css生成的.文章作 ...
- Mechanism:Limited Direct Execution
虚拟化机制的几大挑战:1.性能.在实现虚拟化的同时不增加系统过多开销.2.控制.高效运行程序的同时对CPU保持控制(对资源的管理). Limited direct execution:直接在CPU中运 ...
- myEclipse出现cannot paste the clipboard contents into the selected elements报错
导入jar包报错,cannot paste the clipboard contents into the selected elements,查阅资料让重新打开工程,但依然报错. 最后在本地路径复制 ...
- HQL包含中文查询失败
jdbc:mysql://172.16.9.6:3306/school?useUnicode=true&characterEncoding=UTF-8配置文件中的url加上编码,一般mysql ...
- 2019南昌邀请赛 L 计算几何 G(待补)
#include<bits/stdc++.h> const double PI=acos(-1.0); ; using namespace std; struct Point { doub ...
- C++ operator 学习
1.概述 1.1what operator 是c++的一个关键字,和运算符如(=)一起使用,表示一个运算符重载函数 1.2why 对于C++提供的所有操作符,通常只支持对于基本数据类型和标准库中提供的 ...
- Scala基础
1.seq[String] 用[]表示参数类型,java使用<>表示参数,因为Scala 允许以<命名方法和变量名,java不允许 2.支持range的类型:Char .Int . ...