Docker创建Consul并添加权限控制

一、部署Consul

1、拉取镜像:

bash 复制代码
docker pull consul:<consul-version>

2、运行

bash 复制代码
docker run --name consul1 -p 8300:8300/tcp -p 8301:8301/tcp -p 8301:8301/udp -p 8302:8302/tcp -p 8302:8302/udp -p 8500:8500 -p 8600:8600/tcp -p 8600:8600/udp -v /home/docker/consul/config:/consul/config -itd consul:<consul-version> agent -dev -client 0.0.0.0

3、创建配置文件

创建文件夹

bash 复制代码
mkdir /home/docker/consul/config -p

创建文件

bash 复制代码
cd /home/docker/consul/config

创建config.json

bash 复制代码
vim config.json

填写如下内容:

python 复制代码
{
  "datacenter": "dc1",
  "acl": {
    "enabled": true,
    "default_policy": "deny",
    "enable_token_persistence": true,
    "tokens": {
      "master": "master-token",
      "agent": "agent-token"
    }
  },
  "server": true,
  "bootstrap_expect": 1,
  "ui": true
}

4、创建ACL Token

http://<ip>:<port>进入图形界面

进入ACL页面

创建一个Token,并进入Token详细,点击Use按钮应用这个Token

5、Spring Consul中设置Token

进入对应工程的yml配置文件,在Consul配置中添加如下配置:

Groovy 复制代码
spring:
  cloud:
    consul:
      host: ${CONSUL_SERVER_HOST:192.168.193.199}
      port: ${CONSUL_SERVER_PORT:8500}
      acl-token: 00000000-0000-0000-0000-000000000000(你的Token)

二、设置Spring Consul

1、添加Actuator依赖

XML 复制代码
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

2、添加Actuator配置

Groovy 复制代码
spring:
  cloud:
    consul:
      host: ${CONSUL_SERVER_HOST:192.168.193.199}
      port: ${CONSUL_SERVER_PORT:8500}
      acl-token: 00000000-0000-0000-0000-000000000000(你的Token)
      discovery:
        service-name: ${spring.application.name}
        health-check-url: http://${CONSUL_HEALTH_HOST:127.0.0.1}:${UI_CONFIGURATION_SERVICE_PORT:8060}/actuator/health
相关推荐
Patrick_Wilson3 天前
从「改个端口」到 502:Next.js on k8s 的容器端口、Service 映射与 env 覆盖
docker·kubernetes·next.js
Suroy3 天前
DockerView-Go:用 Go 写一个终端 Docker 监控工具,顺便做了个 Web 仪表盘
docker
云恒要逆袭3 天前
运行你的第一个Docker容器
后端·docker·容器
宋均浩4 天前
# Docker 镜像瘦身实战:从 1.2G 到 80MB 的五个优化步骤
ci/cd·docker
程序员老赵5 天前
10 分钟部署 OpenCode:Docker 一键安装,浏览器打开就能用 AI 写代码(附完整命令与排错)
docker·容器·ai编程
WangMingHua1115 天前
LM Studio Docker 部署——本地大模型一键启动
docker
曲幽6 天前
别再用网页翻译看源码了!你的私人翻译神器LibreTranslate,部署避坑指南来了
python·docker·web·pot·translate·libretranslate·arogstranslate
武子康8 天前
调查研究-183 Apple container:Mac 上用轻量 VM 跑 Linux 容器,Swift 会改写本地容器体验吗?
docker·容器·apple
Alsn8611 天前
等待学习-学习目录:Docker 容器安全攻防
学习·安全·docker
2601_9618752411 天前
决战申论100题2026|最新|范文
linux·容器·centos·debian·ssh·fabric·vagrant