linux中安装consul

https://blog.csdn.net/u014449653/article/details/61917159

 

 

部署consul: 
环境:linux-64bit 
点击进入下载cansul网页 
或者直接使用命令行:

wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_linux_amd64.zip 
unzip consul_0.7.5_linux_amd64.zip

接下来可以看见目录下多了一个文件 consul 
输入以下命令和结果表示基本安装成功

[hehe@pluto ~]$ ./consul 
usage: consul [--version] [--help] <command> [<args>]

Available commands are:
    agent          Runs a Consul agent
    configtest     Validate config file
    event          Fire a new event
    exec           Executes a command on Consul nodes
    force-leave    Forces a member of the cluster to enter the "left" state
    info           Provides debugging information for operators
    join           Tell Consul agent to join cluster
    keygen         Generates a new encryption key
    keyring        Manages gossip layer encryption keys
    kv             Interact with the key-value store
    leave          Gracefully leaves the Consul cluster and shuts down
    lock           Execute a command holding a lock
    maint          Controls node or service maintenance mode
    members        Lists the members of a Consul cluster
    monitor        Stream logs from a Consul agent
    operator       Provides cluster-level tools for Consul operators
    reload         Triggers the agent to reload configuration files
    rtt            Estimates network round trip time between nodes
    snapshot       Saves, restores and inspects snapshots of Consul server state
    version        Prints the Consul version
    watch          Watch for changes in Consul

[hehe@pluto ~]$ 
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
以ui形式开启:

./consul agent -server -ui -bootstrap-expect 1 -data-dir /tmp/consul 
输入control+c可以优雅的退出

[hehe@pluto ~]$ ./consul members
Node   Address             Status  Type    Build  Protocol  DC
pluto  192.168.122.1:8301  alive   server  0.7.5  2         dc1
[hehe@pluto ~]$ 

可以查看server的信息
1
2
3
4
5
6
[hehe@pluto ~]$ curl 127.0.0.1:8500/v1/catalog/nodes
[{"ID":"ec5f2994-0b0c-44b0-81d6-9787c8d2a664","Node":"pluto","Address":"192.168.122.1","TaggedAddresses":{"lan":"192.168.122.1","wan":"192.168.122.1"},"Meta":{},"CreateIndex":4,"ModifyIndex":5}][hehe@pluto ~]$ 

查看节点
1
2
3
4
以配置启动:

1
mkdir /home/hehe/etc/consul.d .d是携带信息的文件夹 
cd 到改目录下面 
vim mysql.json 
把下面的json内容写进去


对mysql的端口进行检测。注:mysql是tcp协议,支持脚本,http,tcp,ttl,python

vim mysql.json

{
    "services":[
        {
            "id":"mysql",
            "name":"mysql",
            "tags":["mysql"],
            "address":"127.0.0.1",
            "port":3306,
            "checks":[
                {
                    "Tcp":"127.0.0.1:3306",
                    "interval":"10s"
                }
            ]
        }
    ]
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
根据新的配置重启服务 
./consul agent -server -ui -bootstrap-expect 1 -data-dir /tmp/consul -config-dir etc/consul.d

[hehe@pluto ~]$ ./consul agent -server -ui -bootstrap-expect 1 -data-dir /tmp/consul -config-dir etc/consul.d 
==> WARNING: BootstrapExpect Mode is specified as 1; this is the same as Bootstrap mode. 
==> WARNING: Bootstrap mode enabled! Do not enable unless necessary 
==> Starting Consul agent… 
==> Starting Consul agent RPC… 
==> Consul agent running! 
Version: ‘v0.7.5’ 
Node ID: ‘ec5f2994-0b0c-44b0-81d6-9787c8d2a664’ 
Node name: ‘pluto’ 
Datacenter: ‘dc1’ 
Server: true (bootstrap: true) 
Client Addr: 127.0.0.1 (HTTP: 8500, HTTPS: -1, DNS: 8600, RPC: 8400) 
Cluster Addr: 192.168.122.1 (LAN: 8301, WAN: 8302) 
Gossip encrypt: false, RPC-TLS: false, TLS-Incoming: false 
Atlas:

==> Log data will now stream in as it occurs:

2017/03/13 15:29:40 [INFO] raft: Initial configuration (index=1): [{Suffrage:Voter ID:192.168.122.1:8300 Address:192.168.122.1:8300}]
2017/03/13 15:29:40 [INFO] raft: Node at 192.168.122.1:8300 [Follower] entering Follower state (Leader: "")
2017/03/13 15:29:40 [INFO] serf: EventMemberJoin: pluto 192.168.122.1
2017/03/13 15:29:40 [WARN] serf: Failed to re-join any previously known node
2017/03/13 15:29:40 [INFO] consul: Adding LAN server pluto (Addr: tcp/192.168.122.1:8300) (DC: dc1)
2017/03/13 15:29:40 [INFO] serf: EventMemberJoin: pluto.dc1 192.168.122.1
2017/03/13 15:29:40 [WARN] serf: Failed to re-join any previously known node
2017/03/13 15:29:40 [INFO] consul: Adding WAN server pluto.dc1 (Addr: tcp/192.168.122.1:8300) (DC: dc1)
2017/03/13 15:29:48 [ERR] agent: failed to sync remote state: No cluster leader
2017/03/13 15:29:49 [WARN] raft: Heartbeat timeout from "" reached, starting election
2017/03/13 15:29:49 [INFO] raft: Node at 192.168.122.1:8300 [Candidate] entering Candidate state in term 6
2017/03/13 15:29:49 [INFO] raft: Election won. Tally: 1
2017/03/13 15:29:49 [INFO] raft: Node at 192.168.122.1:8300 [Leader] entering Leader state
2017/03/13 15:29:49 [INFO] consul: cluster leadership acquired
2017/03/13 15:29:49 [INFO] consul: New leader elected: pluto
2017/03/13 15:29:49 [WARN] agent: socket connection failed '127.0.0.1:3306': dial tcp 127.0.0.1:3306: getsockopt: connection refused
2017/03/13 15:29:51 [INFO] agent: Synced service 'mysql'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值