首页 > 其他分享 >consul部署

consul部署

时间:2024-05-12 11:42:13浏览次数:21  
标签:10.0 部署 consul 52 mcw12 mcw root

 

 

下载二进制包

下载地址:https://developer.hashicorp.com/consul/install

 https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_linux_amd64.zip

 

下载解压

wget 
 https://releases.hashicorp.com/consul/1.18.1/consul_1.18.1_linux_amd64.zip
[root@mcw12 mcw]# ls
consul_1.18.1_linux_amd64.zip
[root@mcw12 mcw]# unzip consul_1.18.1_linux_amd64.zip 
Archive:  consul_1.18.1_linux_amd64.zip
  inflating: consul                  
[root@mcw12 mcw]# ls
consul  consul_1.18.1_linux_amd64.zip
[root@mcw12 mcw]# 

复制到指定位置

[root@mcw12 mcw]# ls
consul  consul_1.18.1_linux_amd64.zip
[root@mcw12 mcw]# 
[root@mcw12 mcw]# ls /usr/local/bin/
[root@mcw12 mcw]# cp consul /usr/local/bin/
[root@mcw12 mcw]# ls /usr/local/bin/
consul
[root@mcw12 mcw]# 

服务部署

下面三个机器都是consul节点

 

创建启动文件

[root@mcw12 mcw]# cat /etc/systemd/system/consul.service
[Unit]
Description=consul
Wants=network.target
After=network.target

[Service]
LimitCORE=infinity
LimitNOFILE=65535
LimitNPROC=65535
Environment="GOMAXPROCS=2" "PATH=/usr/local/bin:/usr/bin:/bin"
ExecStart=/usr/local/bin/consul agent -config-dir=/etc/consul.d
ExecReload=/bin/kill -HUP $MAINPID
KillSignal=TERM
Restart=on-failure
RestartSec=1s
User=root
Group=root

[Install]
WantedBy=multi-user.target
[root@mcw12 mcw]#

创建配置文件并启动。下面的token随便写的

[root@mcw12 mcw]#  mkdir /etc/consul.d
[root@mcw12 mcw]# vim /etc/consul.d/config.json
[root@mcw12 mcw]# cat /etc/consul.d/config.json
{
  "acl": {
    "default_policy": "deny",
    "down_policy": "extend-cache",
    "enabled": true,
    "tokens": {
      "agent": "m1896af6-xiao3-3e89-6dcc-6eab0dd031c0mcw",
      "master": "m18pVDL3+4TxiaodNSqY4pqAx1G40WLVSDlfOQI4cKwmcw="
    }
  },
  "bind_addr": "10.0.0.22",
  "bootstrap_expect": 3,
  "client_addr": "10.0.0.22",
  "data_dir": "/var/consul",
  "datacenter": "mcwdatacenter",
  "enable_debug": false,
  "encrypt": "",
  "log_level": "info",
  "rejoin_after_leave": true,
  "retry_interval": "15s",
  "retry_join": [
    "10.0.0.22",
    "10.0.0.23",
    "10.0.0.24"
  ],
  "server": true,
  "start_join": [
    "10.0.0.22",
    "10.0.0.23",
    "10.0.0.24"
  ],
  "ui": true
}
[root@mcw12 mcw]# systemctl start consul
[root@mcw12 mcw]# systemctl status consul
● consul.service - consul
   Loaded: loaded (/etc/systemd/system/consul.service; disabled; vendor preset: disabled)
   Active: active (running) since Sun 2024-05-12 10:52:24 CST; 4s ago
 Main PID: 2411 (consul)
    Tasks: 8
   CGroup: /system.slice/consul.service
           └─2411 /usr/local/bin/consul agent -config-dir=/etc/consul.d

May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO]  agent: Starting server: address=10.0.0.22:8500 network=tcp protocol=http
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO]  agent: Starting server: address=scada::core_api network=scada protocol=http
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO]  agent: Started gRPC listeners: port_name=grpc_tls address=10.0.0.22:8503 network=tcp
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO]  agent: Retry join is supported for the following discovery methods: cluster=LAN discovery_methods...ton vsphere"
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO]  agent: Joining cluster...: cluster=LAN
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.382+0800 [INFO]  agent: (LAN) joining: lan_addresses=["10.0.0.22", "10.0.0.23", "10.0.0.24", "10.0.0.22", "10.0.0...."10.0.0.24"]
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.400+0800 [INFO]  agent: started state syncer
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.400+0800 [INFO]  agent: Consul agent running!
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.403+0800 [INFO]  agent: (LAN) joined: number_of_nodes=2
May 12 10:52:24 mcw12 consul[2411]: 2024-05-12T10:52:24.403+0800 [INFO]  agent: Join cluster completed. Synced with initial agents: cluster=LAN num_agents=2
Hint: Some lines were ellipsized, use -l to show in full.
[root@mcw12 mcw]# consul members
Error retrieving members: Get "http://127.0.0.1:8500/v1/agent/members?segment=_all": dial tcp 127.0.0.1:8500: connect: connection refused
[root@mcw12 mcw]# 

访问网页

10.0.0.22:8500,目前另外两个节点还没启动,复制一下consul命令和配置到其它节点,修改配置为当前机器的ip,然后启动一下,agent token 和mastertoken,三个节点一样就可以

 启动另外两个节点之前没有leader

[root@mcw12 mcw]# curl http://10.0.0.22:8500/v1/status/leader
""[root@mcw12 mcw]#

 

启动另外两个节点

[root@mcw13 ~]# cat /etc/consul.d/config.json
{
  "acl": {
    "default_policy": "deny",
    "down_policy": "extend-cache",
    "enabled": true,
    "tokens": {
      "agent": "m1896af6-xiao3-3e89-6dcc-6eab0dd031c0mcw",
      "master": "m18pVDL3+4TxiaodNSqY4pqAx1G40WLVSDlfOQI4cKwmcw="
    }
  },
  "bind_addr": "10.0.0.23",
  "bootstrap_expect": 3,
  "client_addr": "10.0.0.23",
  "data_dir": "/var/consul",
  "datacenter": "mcwdatacenter",
  "enable_debug": false,
  "encrypt": "",
  "log_level": "info",
  "rejoin_after_leave": true,
  "retry_interval": "15s",
  "retry_join": [
    "10.0.0.22",
    "10.0.0.23",
    "10.0.0.24"
  ],
  "server": true,
  "start_join": [
    "10.0.0.22",
    "10.0.0.23",
    "10.0.0.24"
  ],
  "ui": true
}
[root@mcw13 ~]# systemctl restart consul
[root@mcw14 ~]# cat /etc/consul.d/config.json
{
  "acl": {
    "default_policy": "deny",
    "down_policy": "extend-cache",
    "enabled": true,
    "tokens": {
      "agent": "m1896af6-xiao3-3e89-6dcc-6eab0dd031c0mcw",
      "master": "m18pVDL3+4TxiaodNSqY4pqAx1G40WLVSDlfOQI4cKwmcw="
    }
  },
  "bind_addr": "10.0.0.24",
  "bootstrap_expect": 3,
  "client_addr": "10.0.0.24",
  "data_dir": "/var/consul",
  "datacenter": "mcwdatacenter",
  "enable_debug": false,
  "encrypt": "",
  "log_level": "info",
  "rejoin_after_leave": true,
  "retry_interval": "15s",
  "retry_join": [
    "10.0.0.22",
    "10.0.0.23",
    "10.0.0.24"
  ],
  "server": true,
  "start_join": [
    "10.0.0.22",
    "10.0.0.23",
    "10.0.0.24"
  ],
  "ui": true
}
[root@mcw14 ~]# systemctl restart consul
[root@mcw14 ~]# 

再次curl访问,可以找到leader节点了

[root@mcw13 ~]# curl http://10.0.0.23:8500/v1/status/leader
"10.0.0.22:8300"[root@mcw13 ~]#

consul页面使用

再次访问页面,提示要登录

 登录一下

 试试这个

 用上面的登录成功了,点进去查看

是所有的节点,再点进去一个节点看看

 

 

 

 

 再看这里,点进去leader查看下

 

 

 

 

 现在还没有键值对

 

 看下token

 

 

点击进入

 

 点击这里,复制出我这里登录用的token

 

 只读

 

 

 

 

 

 

 常用命令

 查看集群leader

任一节点,用当前节点ip看

[root@mcw13 ~]# curl http://10.0.0.23:8500/v1/status/leader
"10.0.0.22:8300"[root@mcw13 ~]# 
[root@mcw13 ~]# 

 

标签:10.0,部署,consul,52,mcw12,mcw,root
From: https://www.cnblogs.com/machangwei-8/p/18187627

相关文章

  • Microsoft Deployment Toolkit(MDT)是微软提供的一套免费的部署工具,旨在简化和自动化 Wi
    MicrosoftDeploymentToolkit(MDT)是微软提供的一套免费的部署工具,旨在简化和自动化Windows操作系统及其他Microsoft产品的部署过程。MDT可以帮助IT管理员在企业环境中轻松地部署Windows操作系统,以及必要的应用程序和设置。MDT提供了一系列工具和功能,包括:部署环......
  • Kubernetes Dashboard部署安装recommended.yaml
    ```yml#Copyright2017TheKubernetesAuthors.##LicensedundertheApacheLicense,Version2.0(the"License");#youmaynotusethisfileexceptincompliancewiththeLicense.#YoumayobtainacopyoftheLicenseat##http://www.apache.......
  • centos7下redis集群部署
    1、环境准备安装redis所需依赖环境#在线:yum-yinstallepel-releasegcc #离线:#下载yuminstall--downloadonly--downloaddir=/home/filesepel-releasegcc#将依赖包放到离线服务器,进入目录cd/home/files#执行安装rpm-Uvh./*.rpm--node......
  • 1-部署LVS-NAT
    1.部署LVS-NAT部署LVS-NAT集群主机名IP地址clienteth0:192.168.4.10/24proxyeth1:192.168.2.5/24eth0:192.168.4.5/24web1eth0:192.168.2.100/24web2eth0:192.168.2.200/24客户端访问LVS调度器的外网IP(VIP),调度器根据算法选择后端的一台真实服务......
  • 2-部署LVS-DR
    2.部署LVS-DR主机IPclienteth0:192.168.4.10/24proxyeth0:0:192.168.4.15/24eth0:192.168.4.5/24web1lo:0:192.168.4.15/32eth0:192.168.4.100/24web2lo:0:192.168.4.15/32eth0:192.168.4.200/24DR原理通过为请求报文重新封装一个......
  • KubeKey 部署 K8s v1.28.8 实战
    在某些生产环境下,我们仅需要一个原生的K8s集群,无需部署KubeSphere这样的图形化管理控制台。在我们已有的技术栈里,已经习惯了利用KubeKey部署KubeSphere和K8s集群。今天,我将为大家实战演示如何在openEuler22.03LTSSP3上,利用KubeKey部署一套纯粹的K8s集群。实......
  • 以docker-compose方式部署halo
    1.安装****dockercurl-fsSLhttps://get.docker.com|bash-sdocker--mirrorAliyun安装完成后,使用以下命令启动dockersystemctlstartdocker接下来,使用以下命令将docker设置为开机自启;并重启服务使得更改生效systemctlenabledockersystemctlreboot可以通......
  • 使用 Docker 部署 VS Code in The Browser
    1)介绍GitHub:https://github.com/coder/code-server在日常学习工作中,Vscode已成为我们首选的代码编辑器。然而,其局限性在于当我们从家到公司移动时,难以保持连续的编码体验。针对这一痛点,虽然市面上已有如VisualStudioCodespaces、Cloudstudio和CloudIDE等在线编辑器(Web......
  • 使用Consul服务注册和发现
    2.1服务注册2.1.1引入依赖<dependency><groupId>org.springframework.cloud</groupId><artifactId>spring-cloud-starter-consul-discovery</artifactId></dependency>2.1.2编写配置文件server:port:80spring:application:......
  • Consul安装
    1.1Win安装选择我们想要下载的版本点击下载,如果芯片是AMD选择右边下载。解压下载的文件进入解压之后的文件查看是否成功安装consulagent-dev-dev表示开发模式运行,另外还有-server表示服务模式运行前端查看:1.2CentOS安装1.查看系统芯片架构:arch2.安装解压......