centos7中安装consul(单机+集群)

单机安装

出处 https://blog.csdn.net/qq_38270106/article/details/83239921

下载

wget https://releases.hashicorp.com/consul/0.7.5/consul_0.7.5_[linux](https://so.csdn.net/so/search?from=pc_blog_highlight&q=linux)_amd64.zip

解压

unzip consul_0.7.5_linux_amd64.zip

检查

./consul

出现

Usage: consul [--version] [--help] <command> [<args>]

Available commands are:
    acl            Interact with Consul's ACLs
    agent          Runs a Consul agent
    catalog        Interact with the catalog
    config         Interact with Consul's Centralized Configurations
    connect        Interact with Consul Connect
    debug          Records a debugging archive for operators
    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.
    intention      Interact with Connect service intentions
    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
    login          Login to Consul using an auth method
    logout         Destroy a Consul token created with login
    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
    services       Interact with services
    snapshot       Saves, restores and inspects snapshots of Consul server state
    tls            Builtin helpers for creating CAs and certificates
    validate       Validate config files/directories
    version        Prints the Consul version
    watch          Watch for changes in Consul

启动

# 启动 #写本机地址
./consul agent -dev -ui -node=consul-dev -client=192.168.128.149

#静寂启动 #写本机地址
 nohup ./consul agent -dev -ui  -client=192.168.1.106&
 

说明

-dev(该节点的启动不能用于生产环境,因为该模式下不会持久化任何状态),该启动模式仅仅是为了快速便捷的启动单节点consul
该节点处于server模式
该节点是leader
该节点是一个健康节点

访问

192.168.128.149:8500

关闭

# 查看pid
netstat -nlp |grep consul
# 杀死pid
kill -9 27166

集群安装

出处:https://blog.csdn.net/qq_25934401/article/details/82459486

修改hosts

192.168.1.120 node1.consul.com
192.168.1.119 node2.consul.com
192.168.1.118 node3.consul.com

启动

# 10.200.110.90启动consul
consul agent -server -bootstrap-expect=3 -data-dir=/tmp/consul -node=192.168.1.120 -bind=192.168.1.120 -client=0.0.0.0 -datacenter=shenzhen -ui

#10.200.110.91启动consul
consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul -node 192.168.1.119 -bind=192.168.1.119 -client=0.0.0.0 -datacenter shenzhen -ui

#10.200.110.93启动consul
consul agent -server -bootstrap-expect 3 -data-dir /tmp/consul -node 192.168.1.118 -bind=192.168.1.118 -client=0.0.0.0 -datacenter shenzhen -ui

参数说明

 server: 以server身份启动。默认是client
 bootstrap-expect:集群要求的最少server数量,当低于这个数量,集群即失效。
 data-dir:data存放的目录,更多信息请参阅consul数据同步机制
 node:节点id,集群中的每个node必须有一个唯一的名称。默认情况下,Consul使用机器的hostname
 bind:监听的ip地址。默认绑定0.0.0.0,可以不指定。表示Consul监听的地址,而且它必须能够被集群中的其他节点访问。Consul默认会监听第一个private IP,但最好还是提供一个。生产设备上的服务器通常有好几个网卡,所以指定一个不会出错
 client: 客户端的ip地址,0.0.0.0是指谁都可以访问(不加这个,下面的ui :8500无法访问)
 ui: 可以访问UI界面
-config-dir指定配置文件夹,Consul会加载其中的所有文件
-datacenter 指定数据中心名称,默认是dc1

加入集群

分别登录后两个服务器,加入到第一个的集群中

[root@localhost server]# ./consul join 192.168.1.120

Successfully joined cluster by contacting 1 nodes.
[root@localhost server]# 

测试

访问页面

http://192.168.1.120:8500/ui/shenzhen/nodes
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值