准备工作
需要部署一个consul ,创建一个token用于docker-compose和prometheus 同步数据
#启动命令
docker run -d --restart=always --net=host -v /data/prom/consulmanager/consul:/consul --name consul-prometheus consul:1.12.2 agent -config-dir=/consul/config
#创建consul.hcl配置文件
mkdir -p /data/prom/consulmanager/consul/config
cat >/data/prom/consulmanager/consul/config/consul.hcl <<EOF
advertise_addr = "10.x.x.x" #host内网地址
data_dir = "/consul"
client_addr = "0.0.0.0"
ui_config = {
enabled = true
}
server = true
bootstrap = true
acl = {
enabled = true
default_policy = "deny"
enable_token_persistence = true
}
EOF
#执行bootstrap获取token并配置下面配置文件中
docker run -it consul-prometheus consul acl bootstrap
启动程序docker-compose文件
cat > docker-compose.yml << EOF
version: "3.2"
services:
flask-consul:
image: registry.cn-shenzhen.aliyuncs.com/starsl/flask-consul:latest
container_name: flask-consul
hostname: flask-consul
restart: always
volumes:
- /usr/share/zoneinfo/PRC:/etc/localtime
environment:
consul_token: xxx #上面consul的token
consul_url: http://10.X.X.X:8500/v1
admin_passwd: asdsadxx #自己定义控制台密码
nginx-consul:
image: registry.cn-shenzhen.aliyuncs.com/starsl/nginx-consul:latest
container_name: nginx-consul
hostname: nginx-consul
restart: always
ports:
- "1026:1026"
volumes:
- /usr/share/zoneinfo/PRC:/etc/localtime
EOF
docker-compose up -d
网友评论