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. uboot中关于LCD的代码分析【转】

    本文转载自:http://blog.csdn.net/oqqHuTu12345678/article/details/72236117 以下内容源于朱有鹏<物联网大讲坛>课程的学习,如有侵 ...

  2. YTU 2562: 黄金螺旋

    2562: 黄金螺旋 时间限制: 1 Sec  内存限制: 128 MB 提交: 832  解决: 427 题目描述 黄金螺旋是根据斐波那契数列画出来的螺旋曲线,自然界中存在许多斐波那契螺旋线的图案, ...

  3. 【POJ 1947】 Rebuilding Roads

    [题目链接] 点击打开链接 [算法] f[i][j]表示以i为根的子树中,最少删多少条边可以组成j个节点的子树 树上背包,即可 [代码] #include <algorithm> #inc ...

  4. 【转】Commonjs规范及Node模块实现

    前言: Node在实现中并非完全按照CommonJS规范实现,而是对模块规范进行了一定的取舍,同时也增加了少许自身需要的特性.本文将详细介绍NodeJS的模块实现 引入 nodejs是区别于javas ...

  5. Java-Runoob-高级教程-实例-字符串:11. Java 实例 - 字符串性能比较测试

    ylbtech-Java-Runoob-高级教程-实例-字符串:11. Java 实例 - 字符串性能比较测试 1.返回顶部 1. Java 实例 - 字符串性能比较测试  Java 实例 以下实例演 ...

  6. jQuery easyui datagrid pagenation 的分页数据格式

    {"total":28,"rows":[    {"productid":"FI-SW-01","unitco ...

  7. php 和 js之间使用json通信

    有时候我们需要用后台从数据库中得到的数据在js中进行处理,但是当从php中获取到数据的时候,使用的是键值对形式的多维关联数组.而我们知道,js只支持索引数组,不支持关联数组,这个时候从后台传递过来的数 ...

  8. javascript复制内容到剪切板/网页上的复制按钮的实现

    javascript复制内容到剪切板/网页上的复制按钮的实现:DEMO如下 <!doctype html> <html> <head> <meta chars ...

  9. bzoj 4276: [ONTAK2015]Bajtman i Okrągły Robin【线段树+最大费用最大流】

    --因为T点忘记还要+n所以选小了所以WA了一次 注意!题目中所给的时间是一边闭一边开的区间,所以读进来之后先l++(或者r--也行) 线段树优化建图,很神.(我记得还有个主席树优化建树的?)首先考虑 ...

  10. mysql创建数据库在硬盘位置 for Mac

    使用HomeBrew安装为/usr/local/var/mysql 使用官方下载的dmg镜像安装为/usr/local/mysql