consul安装过程与一些指令

1.下载consul_0.7.5_linux_amd64.zip

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

2.解压consul_0.7.5_linux_amd64.zip

unzip consul_0.7.5_linux_amd64.zip
解决办法-bash: unzip: 未找到命令如果解压出现该错误
yum -y install unzip

3.检查

./consul 看到如下界面说明安装成功

4.启动

我的linux Ip地址192.168.128.149
./consul agent -dev -ui -node=consul-dev -client=192.168.128.149

5.访问

192.168.128.149:8500
如果访问不了,临时关闭防火墙
systemctl stop firewalld

6.使用postMan注册服务(Post请求)

http://192.168.128.149:8500/v1/catalog/register
参数
{
“Datacenter”: “dc1”,
“Node”: “tomcat”,
“Address”: “192.168.1.100”,
“Service”: {
“Id”: “192.168.1.100:8080”,
“Service”: “itmayiedu”,
“tags”: [
“dev”
],
“Port”: 8080
}
}
参数
{
“Datacenter”: “dc1”,
“Node”: “tomcat”,
“Address”: “192.168.1.100”,
“Service”: {
“Id”: “192.168.1.100:8081”,
“Service”: “itmayeidu”,
“tags”: [
“dev”
],
“Port”: 8081
}
}
Datacenter指定数据中心,Address指定注册服务的IP,Service.Id指定服务唯一标识,Service.Service指定服务分组,Service.tags指定服务标签(如测试环境、发布环境等),Service.Port指定服务端口

7.存储key/value

使用postmen 发送put请求
http://192.168.128.149:8500/v1/kv/upstreams/itmayiedu/192.168.1.100:8080
http://192.168.128.149:8500/v1/kv/upstreams/itmayiedu/192.168.1.100:8081

Consul的安装与启动

cd /usr/local/bin/
wget https://releases.hashicorp.com/consul/1.0.0/consul_1.0.0_linux_amd64.zip?_ga=2.86515800.1546778999.1510551854-179199314.1510551854
unzip consul_1.0.0_linux_amd64.zip
得到consul 文件,这样就完成了安装。
启动consul./consul agent -dev # -dev表示开发模式运行,另外还有-server表示服务模式运行
-dev(该节点的启动不能用于生产环境,因为该模式下不会持久化任何状态),该启动模式仅仅是为了快速便捷的启动单节点consul
该节点处于server模式
该节点是leader
该节点是一个健康节点

输入http://127.0.0.1:8500/ui/ 访问Consul,可查看到默认的ui界面:
尝试访问http://192.168.11.143/ui/ ,会发现无法访问。说明Consul还不能被远程访问.
Consul常用命令
Consul常用命令

Consul常用命令详解
输入consul agent --help ,可以看到consul agent 的选项,如下:

  -advertise=addr          Sets the advertise address to use
  -advertise-wan=addr      Sets address to advertise on wan instead of advertise addr
  -atlas=org/name          Sets the Atlas infrastructure name, enables SCADA.
  -atlas-join              Enables auto-joining the Atlas cluster
  -atlas-token=token       Provides the Atlas API token
  -atlas-endpoint=1.2.3.4  The address of the endpoint for Atlas integration.
  -bootstrap               Sets server to bootstrap mode
  -bind=0.0.0.0            Sets the bind address for cluster communication
  -http-port=8500          Sets the HTTP API port to listen on
  -bootstrap-expect=0      Sets server to expect bootstrap mode.
  -client=127.0.0.1        Sets the address to bind for client access.
                           This includes RPC, DNS, HTTP and HTTPS (if configured)
  -config-file=foo         Path to a JSON file to read configuration from.
                           This can be specified multiple times.
  -config-dir=foo          Path to a directory to read configuration files
                           from. This will read every file ending in ".json"
                           as configuration in this directory in alphabetical
                           order. This can be specified multiple times.
  -data-dir=path           Path to a data directory to store agent state
  -dev                     Starts the agent in development mode.
  -recursor=1.2.3.4        Address of an upstream DNS server.
                           Can be specified multiple times.
  -dc=east-aws             Datacenter of the agent (deprecated: use 'datacenter' instead).
  -datacenter=east-aws     Datacenter of the agent.
  -encrypt=key             Provides the gossip encryption key
  -join=1.2.3.4            Address of an agent to join at start time.
                           Can be specified multiple times.
  -join-wan=1.2.3.4        Address of an agent to join -wan at start time.
                           Can be specified multiple times.
  -retry-join=1.2.3.4      Address of an agent to join at start time with
                           retries enabled. Can be specified multiple times.
  -retry-interval=30s      Time to wait between join attempts.
  -retry-max=0             Maximum number of join attempts. Defaults to 0, which
                           will retry indefinitely.
  -retry-join-wan=1.2.3.4  Address of an agent to join -wan at start time with
                           retries enabled. Can be specified multiple times.
  -retry-interval-wan=30s  Time to wait between join -wan attempts.
  -retry-max-wan=0         Maximum number of join -wan attempts. Defaults to 0, which
                           will retry indefinitely.
  -log-level=info          Log level of the agent.
  -node=hostname           Name of this node. Must be unique in the cluster
  -protocol=N              Sets the protocol version. Defaults to latest.
  -rejoin                  Ignores a previous leave and attempts to rejoin the cluster.
  -server                  Switches agent to server mode.
  -syslog                  Enables logging to syslog
  -ui                      Enables the built-in static web UI server
  -ui-dir=path             Path to directory containing the Web UI resources
  -pid-file=path           Path to file to store agent PID

consul agent 命令的常用选项,如下:

-data-dir作用:指定agent储存状态的数据目录这是所有agent都必须的对于server尤其重要,因为他们必须持久化集群的状态
-config-dir作用:指定service的配置文件和检查定义所在的位置通常会指定为"某一个路径/consul.d"(通常情况下,.d表示一系列配置文件存放的目录)
-config-file作用:指定一个要装载的配置文件该选项可以配置多次,进而配置多个配置文件(后边的会合并前边的,相同的值覆盖)
-dev作用:创建一个开发环境下的server节点该参数配置下,不会有任何持久化操作,即不会有任何数据写入到磁盘这种模式不能用于生产环境(因为第二条)
-bootstrap-expect作用:该命令通知consul server我们现在准备加入的server节点个数,该参数是为了延迟日志复制的启动直到我们指定数量的server节点成功的加入后启动。
-node作用:指定节点在集群中的名称该名称在集群中必须是唯一的(默认采用机器的host)推荐:直接采用机器的IP
-bind作用:指明节点的IP地址有时候不指定绑定IP,会报Failed to get advertise address: Multiple private IPs found. Please configure one. 的异常
-server作用:指定节点为server每个数据中心(DC)的server数推荐至少为1,至多为5所有的server都采用raft一致性算法来确保事务的一致性和线性化,事务修改了集群的状态,且集群的状态保存在每一台server上保证可用性server也是与其他DC交互的门面(gateway)
-client作用:指定节点为client,指定客户端接口的绑定地址,包括:HTTP、DNS、RPC默认是127.0.0.1,只允许回环接口访问若不指定为-server,其实就是-client
-join作用:将节点加入到集群
-datacenter作用:指定机器加入到哪一个数据中心
尝试一下:
consul agent -dev -client 10.128.223.231
发现果然可以使用http://10.128.223.231:8500/ui 访问了。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值