CentOS7 Install Consul

Centos7 Install Consul

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

1) 环境

192.168.217.158 consul-1
192.168.217.159 consul-2
192.168.217.160 consul-3
192.168.217.161 agent-1

2) 安装

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

# unzip consul_0.7.0_linux_amd64.zip
# mv consul /usr/local/bin/

3)配置

# consul-1配置
# consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul -node=n1 -bind=192.168.217.158 -dc=bj1

# consul-2配置
# consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul -node=n2 -bind=192.168.217.159 -dc=bj1

# consul-3配置
# consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul -node=n3 -bind=192.168.217.160 -dc=bj1

# 将consul-2 consul-3加入集群
[[email protected]-1 ~]# consul join 192.168.217.159 192.168.217.160
Successfully joined cluster by contacting 2 nodes.

# 配置服务注册文件(也可以从consul api 接口添加服务注册,他会自动持久化)
[[email protected] ~]# vi /etc/consul.d/web3.json
{
"service": {
"name": "web3",
"tags": ["master"],
"address": "127.0.0.1",
"port": 10000,
"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-1
# 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的服务
[[email protected] ~]# 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
[[email protected]1 ~]# consul members
Node Address Status Type Build Protocol DC
n1 192.168.217.158:8301 alive server 0.7.0 2 bj1
n2 192.168.217.159:8301 alive server 0.7.0 2 bj1
n3 192.168.217.160:8301 alive server 0.7.0 2 bj1
n4 192.168.217.161:8301 alive client 0.7.0 2 bj1

# consul members -detailed
# curl localhost:8500/v1/catalog/nodes
# curl localhost:8500/v1/status/leader
# curl localhost:8500/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": 2853,
        "ModifyIndex": 3821,
        "Node": "n4",
        "ServiceAddress": "127.0.0.1",
        "ServiceEnableTagOverride": false,
        "ServiceID": "web3",
        "ServiceName": "web3",
        "ServicePort": 10000,
        "ServiceTags": [
            "master"
        ],
        "TaggedAddresses": {
            "lan": "192.168.217.161",
            "wan": "192.168.217.161"
        }
    }
]

[[email protected] ~]# dig @127.0.0.1 -p 8600 web3.service.consul SRV

; <<>> DiG 9.9.4-RedHat-9.9.4-29.el7_2.4 <<>> @127.0.0.1 -p 8600 web3.service.consul SRV
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 57200
;; flags: qr aa rd; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; WARNING: recursion requested but not available

;; QUESTION SECTION:
;web3.service.consul.        IN    SRV

;; ANSWER SECTION:
web3.service.consul.    0    IN    SRV    1 1 10000 n4.node.bj1.consul.

;; ADDITIONAL SECTION:
n4.node.bj1.consul.    0    IN    A    127.0.0.1

;; Query time: 1 msec
;; SERVER: 127.0.0.1#8600(127.0.0.1)
;; WHEN: Thu Oct 13 15:35:46 EDT 2016
;; MSG SIZE  rcvd: 85

# 浏览器访问
http://192.168.217.161:8500/

时间: 2024-11-06 07:12:57

CentOS7 Install Consul的相关文章

CentOS7 Install Shipyard

# 采集木jj 原文:http://www.cnblogs.com/caoguo/p/5735189.html # CentOS7 Install Shipyard# yum install docker# systemctl restart docker# docker login -u user-p password -e sample.aliyun.com registry.aliyuncs.com # 上面docker加速一大段实际就下面这一句# vi /etc/sysconfig/do

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

Centos7 install Openstack - (第四节)添加计算服务(Nova) 我的blog地址:http://www.cnblogs.com/caoguo 该文根据openstack官方文档配置 官方文档地址: http://docs.openstack.org/juno/install-guide/install/yum/content/# 0x01. Install and configure controller node (在控制节点安装配置一下内容) 一) 配置基本环境

centos7 install httpd

[1]Install Httpd for Centos7-media # yum --enablerepo=centos7-media -y install httpd Installed:   httpd.x86_64 0:2.4.6-18.el7.centos [2]start httpd,开机启动 # systemctl start httpd.service # systemctl enable httpd.service ln -s '/usr/lib/systemd/system/h

centos7 install lnmp

centos7 install lnmp yum install epel-releaseyum install php php-fpm nginx mariadb-devel mariadb-server mariadb test php 模块 vim /etc/nginx/nginx.confnotice:在location 下面添加这一行就可以 location ~* \.php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_param SCRIPT_FI

(dev mode) install CONSUL on ubuntu

WSL: V18.04.1 1. install $sudo apt-get install consul wsl1017@DESKTOP-14G6K9S:~$ consul version Consul 0.6.4.dev Consul Protocol: 3 (Understands back to: 1) 2. run $consul agent -dev -bind 192.168.1.114 wsl1017@DESKTOP-14G6K9S:~$ consul agent -dev -b

centos7 install vim8

centos7 install vim8 Git and dependency Git: https://github.com/vim/vim # yum install -y perl-devel configure CFLAGS="-I/usr/lib64/perl5/CORE/" ./configure --with-features=huge --enable-multibyte --enable-rubyinterp=yes --enable-pythoninterp=yes

centos7 install 安装mysql

CentOS 7的yum源中貌似没有正常安装mysql时的mysql-sever文件,需要去官网上下载 # wget http://dev.mysql.com/get/mysql-community-release-el7-5.noarch.rpm # rpm -ivh mysql-community-release-el7-5.noarch.rpm # yum install mysql-community-server   成功安装之后重启mysql服务 # service mysqld r

CentOS7安装Consul集群

1.准备4台服务器 linux1 192.168.56.101 linux2 192.168.56.102 linux3 192.168.56.103 linux4 192.168.56.104 2.下载并解压Consul文件,拷贝到/usr/local/bin目录下 [[email protected] ~]# wget https://releases.hashicorp.com/consul/0.8.1/consul_0.8.1_linux_amd64.zip?_ga=2.37003621

centos7 install nginx+fastdfs

说明:centos7单机部署 nginx fastdfs ## 创建一下目录作为存储数据图片的路径 可以自己定义 mkdir -pv /data/application/{storage,tracker,client} cd /data/application/ yum install lrzsz wget git gcc gcc-c++ zlib-devel cmake make git clone [email protected]:happyfish100/libfastcommon.gi