1.docker pull consul:1.6.3
2.创建本地映射目录
cd /
mkdir mydata
cd mydata
mkdir consul
3.创建第一个镜像
docker run -d -p 8500:8500 --name consul1 --mount type=bind,src=/mydata/consul,dst=/consul/data -e CONSUL_BIND_INTERFACE='eth0' consul:1.6.3 agent -server -ui -bind=0.0.0.0 -client=0.0.0.0 -bootstrap-expect 2
4.查看第一个镜像IP
docker inspect --format '{{ .NetworkSettings.IPAddress }}' consul1
5.创建第二个镜像
docker run --name consul2 -d -p 8501:8500 consul agent -server -ui -bind=0.0.0.0 -client=0.0.0.0 -join 172.17.0.2
6.配置nginx
- cd /etc/nginx/conf.d
- vim consul_8500.conf
- 写入如下配置
server {
listen 80;//唯一入口
server_name consul.xxxxx.cn;//自身域名
location / {
proxy_pass http://0.0.0.0:8500;
proxy_redirect off;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
}
- /usr/sbin/nginx //启动nginx
consul(注册中心)地址
4.注册中心增加数据库链接配置
{
"host":"rm-bp1ddwvjwz2sjv09yfo.mysql.rds.aliyuncs.com",
"user":"micro",
"pwd":"Wang@wanG",
"database":"micro",
"prot":3306,
}