环境:
3台机器采用同样的目录名字和文件名称
服务器
192.168.10.30
192.168.10.31
192.168.10.32
nats版本2.9.15
配置文件
# 192.168.10.30配置文件
port: 4242 # 供client连接的监听端口
net: 0.0.0.0 # 监听的网络地址
http_port: 8222 # HTTP监控端口
# client连接的认证信息
authorization {
user: nats
password: wg1q2w3e
timeout: 1
}
# 集群定义
cluster {
host: '192.168.10.30' # 本机IP
port: 4244 # 路由连接的入站(inbound)端口
# 路由连接的认证信息
authorization {
user: "nats"
password: "wg1q2w3e"
timeout: 0.5
}
# Routes are actively solicited and connected to from this server.
# Other servers can connect to us if they supply the correct credentials
# in their routes definitions from above.
routes = [
nats-route://nats:wg1q2w3e@192.168.10.31:4244 # 修改对应IP和对应端口、账号、密码
nats-route://nats:wg1q2w3e@192.168.10.32:4244
]
}
# 日志选项
debug: false # 正式环境可以关闭
trace: true
logtime: false
log_file: "/tmp/gnatsd.log"
# PID进程文件
pid_file: "/tmp/gnatsd.pid"
# 一些系统属性
# client最大连接数
max_connections: 100
# 最大协议控制行
max_control_line: 512
# 最大的有效负载
max_payload: 65536
# 其余2台机器修改下面2个地方,端口如果修改了routes也需要修改为对应端口
host: '192.168.10.30'
port: 4244
和
routes = [
nats-route://nats:wg1q2w3e@192.168.10.31:4244
nats-route://nats:wg1q2w3e@192.168.10.32:4244
]
启动命令
./nats-server -c gnatsd.yml