其他
双十一还在盖楼?少年你应该掌握Docker 部署 Consul了
▶ 部署 Consul
执行命令
1docker run -d --name consul -p 8500:8500 consul
端口说明
https://www.consul.io/docs/install/ports.html
挂载说明
/consul/data
:持久化数据存储/consul/config
:配置文件
Consul 配置
https://www.consul.io/docs/agent/options.html
▶ Deploy Single Consul With ACL In Production
1、生成 UUID,用于 Master Token
1# Mac OS
2$ uuidgen
329F747C5-F4F3-426B-805D-0ABF3109D7CB
2、创建配置文件 consul/config/basic_basic_config.json,示例:
1{
2 "datacenter": "anoyi",
3 "data_dir": "/consul/data",
4 "log_level": "INFO",
5 "node_name": "config-server",
6 "server": true,
7 "ui": true,
8 "bootstrap_expect": 1,
9 "addresses": {
10 "https": "0.0.0.0"
11 },
12 "ports": {
13 "http": 8500
14 },
15 "primary_datacenter": "anoyi",
16 "acl": {
17 "enabled": true,
18 "default_policy": "deny",
19 "enable_token_persistence": true,
20 "tokens": {
21 "master": "29F747C5-F4F3-426B-805D-0ABF3109D7CB",
22 "default": "29F747C5-F4F3-426B-805D-0ABF3109D7CB"
23 }
24 }
25}
3、运行 Consul
1docker run -it --rm --name consul -v `pwd`/config:/consul/config -p 8500:8500 consul agent
4、创建 Policy
1docker exec -it consul \
2consul acl policy create -name default-policy \
3-rules "node \"config-server\" { policy = \"write\" }" \
4-token 29F747C5-F4F3-426B-805D-0ABF3109D7CB
output example:
1ID: 1e94edab-c8f1-e805-a7ed-7cfd90b72e11
2Name: default-policy
3Description:
4Datacenters:
5Rules:
6node "config-server" { policy = "write" }
5、创建 Agent Access Token
1docker exec -it consul \
2consul acl token create -description "config-server agent token" \
3-policy-name default-policy \
4-token 29F747C5-F4F3-426B-805D-0ABF3109D7CB
output example:
1AccessorID: 194a55d1-e992-7416-9548-3a81a36335aa
2SecretID: 49fe7889-8611-bd52-01b8-d34c8aff6b25
3Description: config-server agent token
4Local: false
5Create Time: 2019-05-10 06:33:08.6721898 +0000 UTC
6Policies:
7 1e94edab-c8f1-e805-a7ed-7cfd90b72e11 - default-policy
此处 SecretID
即为 Agent Token
6、为 Agent 添加 Token
1docker exec -it consul \
2consul acl set-agent-token \
3-token 29F747C5-F4F3-426B-805D-0ABF3109D7CB \
4agent 49fe7889-8611-bd52-01b8-d34c8aff6b25
▶ 部署 Consul 集群
待补充。。。
▶ 相关地址
官方镜像:
https://hub.docker.com/_/consul
Consul 官网:
https://www.consul.io/
Github 地址:
https://github.com/hashicorp/consul
安全配置:
https://learn.hashicorp.com/consul/security-networking/production-acls
问题来了,你们项目中目前在使用下面哪一种服务注册中心组件呢?
● 天天玩微信,Spring Boot 开发私有即时通信系统了解一下
● Spring Boot 定制 parent 快速构建应用
● Spring Boot 日志处理你还在用Logback?
如有收获,请帮忙转发,您的鼓励是作者最大的动力,谢谢!