nats集群部署
说明: 集群采用三台机器部署,每台机器的目录、安装包、配置名都一样,但配置里面每个节点的ip和路由不一样,自己注意对应更改,如果在一台机器配置部署,就需要更改每个节点的端口,避免端口冲突
1.下载
NATS Server当前的最新版本为v2.8.4版,有三种二进制发布包,详见:https://github.com/nats-io/nats-server/releases
- nats-server-v2.8.4-darwin-amd64.tar.gz for Mac的版本
- nats-server-v2.8.4-linux-amd64.tar.gz for Linux x64的版本
- nats-server-v2.8.4-linux-arm.tar.gz for Linux ARM的版本
2.解压
mkdir /biz-code/nats/ -p
cd /biz-code/nats/
wget https://github.com/nats-io/nats-server/releases/download/v2.8.4/nats-server-v2.8.4-linux-amd64.tar.gz
tar xf nats-server-v2.8.4-linux-amd64.tar.gz
cd nats-server-v2.8.4-linux-amd64/
3.添加配置
vim gnastd.conf
节点一:
port: 4333
http: 6333
net: 0.0.0.0
cluster {
host: 172.16.0.15
port: 8333
# authorization {
# user: root
# password: 123456
# timeout: 1
# }
routes = [
nats-route://172.16.0.18:8333
nats-route://172.16.0.24:8333
]
}
debug: true
trace: true
log_file: "/biz-code/nats/gnatsd-4222.log"
# max_connections
max_connections: 100
# Duration the server can block on a socket write to a client. Exceeding the
# deadline will designate a client as a slow consumer.
# 测试下是否有问题
write_deadline: "2s"
节点二:
port: 4333
http: 6333
net: 0.0.0.0
cluster {
host: 172.16.0.18
port: 8333
# authorization {
# user: root
# password: 123456
# timeout: 1
# }
routes = [
nats-route://172.16.0.15:8333
nats-route://172.16.0.24:8333
]
}
debug: true
trace: true
log_file: "/biz-code/nats/gnatsd-4222.log"
# max_connections
max_connections: 100
# Duration the server can block on a socket write to a client. Exceeding the
# deadline will designate a client as a slow consumer.
# 测试下是否有问题
write_deadline: "2s"
节点三:
port: 4333
http: 6333
net: 0.0.0.0
cluster {
host: 172.16.0.24
port: 8333
# authorization {
# user: root
# password: 123456
# timeout: 1
# }
routes = [
nats-route://172.16.0.18:8333
nats-route://172.16.0.15:8333
]
}
debug: true
trace: true
log_file: "/biz-code/nats/gnatsd-4222.log"
# max_connections
max_connections: 100
# Duration the server can block on a socket write to a client. Exceeding the
# deadline will designate a client as a slow consumer.
# 测试下是否有问题
write_deadline: "2s"
有个问题: 我这里配置文件里面写了集群通信认证的账号密码,但是在调试的过程中一直报错认证失败,然后我就把它注释了,在启动的时候通过参数指定的账号密码
4.启动
./nats-server --config gnastd.conf --user root --pass 123456
5.查看日志
cd /biz-code/nats
tail -f gnatsd-4222.log
日志中如果没有出现ERR,那估计就是启动成功了,另外调试完了可以将配置中的debug: true
选项注释