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. sql 统计 url字符串处理

    SELECT SUBSTRING_INDEX(url,'/',1) AS wed_domain,COUNT(1),SUM(no_open_times),SUM(no_ad_times),SUM(ok_ ...

  2. GET 与 POST 的理解

    1 HTTP请求      超文本传输协议(HTTP)的设计目的是保证客户机与服务器之间的通信.      HTTP 的工作方式是客户机与服务器之间的请求-应答协议.      比如,客户端(浏览器) ...

  3. import-module in $profile

    $PROFILE C:\Users\clu\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 Import-Module 'C:\Users\ ...

  4. CentOS 7下修改rabbitmq打开文件数量方法

    以下为使用systemd的修改方法:   1.系统层修改: 通过修改sysctl配置,提高系统的打开文件数量 vim /etc/sysctl.conf,添加: fs.file-max = 65535 ...

  5. eclipse自动创建项目出错Cannot change version of project facet Dynamic Web Module to 2.3.

    Cannot change version of project facet Dynamic Web Module to 2.3. step1:修改properties step2:修改web.xml ...

  6. BZOJ_5343_[Ctsc2018]混合果汁_二分答案+主席树

    BZOJ_5343_[Ctsc2018]混合果汁_二分答案+主席树 题意:给出每个果汁的价格p,美味度d,最多能放的体积l.定义果汁混合后的美味度为果汁的美味度的最小值. m次询问,要求花费不大于g, ...

  7. AutoIT: 如何通过坐标相对位置来对无法识别的Menu以及GridView进行定位点击操作

    一般情况下,GridView中的数据来自数据库,我们通过Windows Info,是无法获取GridView中的信息的.而软件定制的Menu,很多时候无法通过系统提供的WinMenuSelectIte ...

  8. HashMap最大容量为什么是2的32次方

    123456观察jdk中HashMap的源码,我们知道极限值为2的31次方. void resize(int newCapacity) { Entry[] oldTable = table; int ...

  9. Java-Runoob-高级教程-实例-字符串:14. Java 实例 - 连接字符串

    ylbtech-Java-Runoob-高级教程-实例-字符串:14. Java 实例 - 连接字符串 1.返回顶部 1. Java 实例 - 连接字符串  Java 实例 以下实例演示了通过 &qu ...

  10. Application 效能分析有妙招 — 使用 perf 走天下(转载)

    转载:http://tech.mozilla.com.tw/posts/1803/application-%E6%95%88%E8%83%BD%E5%88%86%E6%9E%90-%E4%BD%BF% ...