1. 目标:以windows服务形式,运行consul
2. IP分配
节点用途 | 节点主机IP | HTTP | HTTPS | DNS | GRPC | server | LAN | WAN |
Consul-Server1 | 本机IP | 8501 | 8511 | 8601 | 8401 | 8310 | 8311 | 8312 |
Consul-Server2 | 本机IP | 8502 | 8512 | 8602 | 8402 | 8320 | 8321 | 8322 |
Consul-Server3 | 本机IP | 8503 | 8513 | 8603 | 8403 | 8330 | 8331 | 8332 |
Consul-Agent | 本机IP | 8500 | 8510 | 8600 | 8400 | 8300 | 8301 | 8302 |
3. 准备Consul 1.8.1
4. 将下载的Consul文件放到C:\Windows\System32 主要为了创建 windows服务时用,试过是放在了指定位置,然后在Path添加,但没启作用
5. 创建4个节点的文件夹如下图
6. 首先创建Server-01, 单击右键以管理员身份运行run_install.bat,如下图
7. run_install 的内容如下:
cd /d %~dp0 //转到当前目录
set serviceName="YLSoft Consul Server-01" //服务名称
set serviceFilePath=consul agent -config-file=C:\Publish\Consul\Server-01\config\server.json //运行, -config-file需要绝对位置
set serviceDescription="裕林-发现服务-01节点" //服务描述
sc create %serviceName% BinPath= "%serviceFilePath%" //注意Binpath后面要有空格
sc config %serviceName% start=auto
sc description %serviceName% %serviceDescription%
sc start %serviceName%
pause
执行的时候,要把里面 // 及后面的注视去掉
8. Server.json的内容
{
"node_name": "server1", //节点名
"bootstrap_expect": 3, //三个节点
"datacenter": "ylsoft", //数据中心名
"bind_addr": "192.168.0.121", //本地IP
"client_addr":"0.0.0.0", //允许同一局域网其它电脑访问
"data_dir": "C:\\Publish\\Consul\\Server-01\\data", //数据文件位置,绝对路径
"ui":false, //
"server": true,
"log_level": "INFO",
"log_file": "C:\\Publish\\Consul\\Server-01\\log\\consul.log", //数据文件位置,绝对路径
"log_rotate_duration": "24h",
"enable_syslog": false,
"enable_debug": true,
"disable_host_node_id": true,
"ports": {
"http": 8501,
"https": 8511,
"dns": 8601,
"grpc": 8401,
"serf_lan": 8311,
"serf_wan": 8312,
"server": 8310
},
"retry_join": ["192.168.0.121:8311","192.168.0.121:8321","192.168.0.121:8331"]
}
Consul-Server2, Consul-Server3 服务点按上面表格改就可以了
9. 创建代理节点, 运行脚本
cd /d %~dp0
set serviceName="YLSoft Consul Agent"
set serviceFilePath=consul agent -config-dir=C:\Publish\Consul\Client\config\client.json
set serviceDescription="裕林-发现服务-代理"
sc create %serviceName% BinPath="%serviceFilePath%"
sc config %serviceName% start=auto
sc description %serviceName% %serviceDescription%
sc start %serviceName%
pause
client.json的内容
{
"node_name": "client1",
"data_dir": "C:\\Publish\\Consul\\Client\\data",
"server": false, //代理端为false
"bind_addr": "192.168.0.121", //本地IP
"advertise_addr":"121.37.136.160", //公网可以访问的IP
"advertise_addr_wan":"121.37.136.160", //公网可以访问的IP
"client_addr": "0.0.0.0",
"bootstrap": false,
"datacenter": "ylsoft",
"log_level": "INFO",
"log_file": "C:\\Publish\\Consul\\Client\\log\\consul.log",
"log_rotate_duration": "24h",
"enable_syslog": false,
"disable_host_node_id": true,
"rejoin_after_leave": true,
"ui": true,
"ports": {
"http": 8500,
"https": 8510,
"dns": 8600,
"grpc": 8400,
"serf_lan": 8301,
"serf_wan": 8302,
"server": 8300
},
"start_join": ["192.168.0.121:8311", "192.168.0.121:8321","192.168.0.121:8331"]
}
10. 成功可以访问客户端的http://外网ip:8500
11. 创建服务出错的话,可以在相应的log文件夹下查看日志
12,https://download.csdn.net/download/wang_peng/18503996 这是相应的文件资源