Centos7 Install Consul

原文链接:http://www.cnblogs.com/caoguo/p/5959962.html

1) 环境

192.168.217.158 consul-
192.168.217.159 consul-
192.168.217.160 consul-
192.168.217.161 agent-

2) 安装

# yum install -y unzip
# wget https://releases.hashicorp.com/consul/0.7.0/consul_0.7.0_linux_amd64.zip # unzip consul_0..0_linux_amd64.zip
# mv consul /usr/local/bin/

3)配置

# consul-1配置
# consul agent -server -bootstrap-expect -data-dir /tmp/consul -node=n1 -bind=192.168.217.158 -dc=bj1 # consul-2配置
# consul agent -server -bootstrap-expect -data-dir /tmp/consul -node=n2 -bind=192.168.217.159 -dc=bj1 # consul-3配置
# consul agent -server -bootstrap-expect -data-dir /tmp/consul -node=n3 -bind=192.168.217.160 -dc=bj1 # 将consul- consul-3加入集群
[root@consul- ~]# consul join 192.168.217.159 192.168.217.160
Successfully joined cluster by contacting nodes. # 配置服务注册文件(也可以从consul api 接口添加服务注册,他会自动持久化)
[root@localhost ~]# vi /etc/consul.d/web3.json
{
"service": {
"name": "web3",
"tags": ["master"],
"address": "127.0.0.1",
"port": ,
"checks": [
{
"http": "http://localhost:10000/health",
"interval": "10s"
}
]
} # wget https://releases.hashicorp.com/consul/0.7.0/consul_0.7.0_web_ui.zip #启动客户端agent-
# consul agent -data-dir /tmp/consul -node=n4 -bind=192.168.217.161 -join=192.168.217.158 -dc=bj1 -config-dir=/etc/consul.d -ui-dir /tmp/ui -client=192.168.217.161

4) 测试

# 开一个端口10000的服务
[root@localhost ~]# vi web3.go
package main import (
"fmt"
"net/http"
) func handler(w http.ResponseWriter, r *http.Request) {
fmt.Println("hello Web3! This is n3")
fmt.Fprintf(w, "Hello Web3! This is n3")
} func healthHandler(w http.ResponseWriter, r *http.Request) {
fmt.Println("health check!")
} func main() {
http.HandleFunc("/", handler)
http.HandleFunc("/health", healthHandler)
http.ListenAndServe(":10000", nil)
}
# 运行服务
# go run web3.go
[root@consul- ~]# consul members
Node Address Status Type Build Protocol DC
n1 192.168.217.158: alive server 0.7. bj1
n2 192.168.217.159: alive server 0.7. bj1
n3 192.168.217.160: alive server 0.7. bj1
n4 192.168.217.161: alive client 0.7. bj1 # consul members -detailed
# curl localhost:/v1/catalog/nodes
# curl localhost:/v1/status/leader
# curl localhost:/v1/status/peers
# 服务发现
# curl -s http://192.168.217.161:8500/v1/catalog/service/web3|python -m json.tool
[
{
"Address": "192.168.217.161",
"CreateIndex": ,
"ModifyIndex": ,
"Node": "n4",
"ServiceAddress": "127.0.0.1",
"ServiceEnableTagOverride": false,
"ServiceID": "web3",
"ServiceName": "web3",
"ServicePort": ,
"ServiceTags": [
"master"
],
"TaggedAddresses": {
"lan": "192.168.217.161",
"wan": "192.168.217.161"
}
}
] [root@localhost ~]# dig @127.0.0.1 -p web3.service.consul SRV ; <<>> DiG 9.9.-RedHat-9.9.-.el7_2. <<>> @127.0.0.1 -p web3.service.consul SRV
; ( server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id:
;; flags: qr aa rd; QUERY: , ANSWER: , AUTHORITY: , ADDITIONAL:
;; WARNING: recursion requested but not available ;; QUESTION SECTION:
;web3.service.consul. IN SRV ;; ANSWER SECTION:
web3.service.consul. IN SRV n4.node.bj1.consul. ;; ADDITIONAL SECTION:
n4.node.bj1.consul. IN A 127.0.0.1 ;; Query time: msec
;; SERVER: 127.0.0.1#(127.0.0.1)
;; WHEN: Thu Oct :: EDT
;; MSG SIZE rcvd: # 浏览器访问
http://192.168.217.161:8500/

CentOS7 Install Consul的更多相关文章

  1. centos7上consul的集群安装

    centos7上consul的安装 ###一 下载 下载文件 wget https://releases.hashicorp.com/consul/0.6.4/consul_0.6.4_linux_a ...

  2. Centos7 install Openstack - (第四节)添加计算服务(Nova)

    Centos7 install Openstack - (第四节)添加计算服务(Nova) 我的blog地址:http://www.cnblogs.com/caoguo 该文根据openstack官方 ...

  3. Centos7 install Openstack - (第三节)添加镜像服务(Glance)

    Centos7 install Openstack - (第三节)添加镜像服务(Glance) 我的blog地址:http://www.cnblogs.com/caoguo 该文根据openstack ...

  4. (dev mode) install CONSUL on ubuntu

    WSL: V18.04.1 1. install $sudo apt-get update$sudo apt-get install consul wsl1017@DESKTOP-14G6K9S:~$ ...

  5. centos7 install vim8

    centos7 install vim8 Git and dependency Git: https://github.com/vim/vim # yum install -y perl-devel ...

  6. CentOS7 Install Shipyard

    # 采集木jj 原文:http://www.cnblogs.com/caoguo/p/5735189.html # CentOS7 Install Shipyard# yum install dock ...

  7. CentOS7 install vsftpd

    #mkdir -p /var/ftp/xcl/ #yum install -y vsftpd#useradd -g ftp -M -d /var/ftp/xcl -s /sbin/nologin xc ...

  8. centos7 install nginx+fastdfs

    说明:centos7单机部署 nginx fastdfs ## 创建一下目录作为存储数据图片的路径 可以自己定义 mkdir -pv /data/application/{storage,tracke ...

  9. docker centos7创建consul镜像以及用docker-compose启动镜像

    直接贴代码了: Dockfile: # Version 0.1 FROM kuba_centos7 MAINTAINER kuba si812cn@163.com # This is the rele ...

随机推荐

  1. Restrictions.or多个条件用法

    两个条件或查询: Restrictions.or(Restrictions.in("username",list1),Restrictions.idEq(1)); 三个或多个条件查 ...

  2. YTU 2952: A代码填充--谁挡住了我

    2952: A代码填充--谁挡住了我 时间限制: 1 Sec  内存限制: 128 MB 提交: 135  解决: 38 题目描述 n个人前后站成一列,对于队列中的任意一个人,如果排在他前面的人的身高 ...

  3. ACTION 关联表之间查询语句 SQL语句写法

    /** EquUseRecord * @author cll * @return * @右边菜单中的使用记录操作 */ public String QueryAllEquUserecordAllInf ...

  4. OpenMediaVault 系统安装问题

    /********************************************************************* * OpenMediaVault 系统安装问题 * 说明: ...

  5. UVA11722概率问题之线性规划

    链接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&am ...

  6. 一个tomcat部署多个应用实例总结

    项目组有好几个项目需要运行,之前项目少,一个tomcat对应一个项目还能应付,但现在项目多了,要是再一个tomcat对应一个项目的话,一方面看起来很业余,一方面也加大服务器的维护难度.所以现在需要对t ...

  7. hdu3709 (平衡数) 数位DP

    Balanced Number Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others) ...

  8. .NET获取汉字首字母

    /// <summary> /// 获取汉字首字母(可包含多个汉字) /// </summary> /// <param name="strText" ...

  9. asp.net Identity2 角色(Role)的使用(三)用户管理,用户控制器和视图

    修改用户控制器AccountController,增加角色管理器. public class AccountController : Controller { public AccountContro ...

  10. UVa 12712 && UVaLive 6653 Pattern Locker (排列组合)

    题意:给定 一个n * n 的宫格,就是图案解锁,然后问你在区间 [l, r] 内的所有的个数进行组合,有多少种. 析:本来以为是数位DP,后来仔细一想是排列组合,因为怎么组合都行,不用考虑实际要考虑 ...