nacos官方集群部署说明
centos7安装并配置jdk
nacos2.x集群实现
centos7安装mysql8
使用nginx反代nacos报错 badrequest 400
nacos单机模式时使用的数据库是内嵌的derby数据库,但是集群时需要做数据同步,nacos官方使用MySQL作为数据同步中心
以 nacos-8848为例, nacos-8838, nacos-8858修改对应的端口号即可
server.port=8848
mv cluster.conf.example cluster.conf
- #2022-10-10T09:59:01.124
- 192.168.4.52:8838
- 192.168.4.52:8848
- 192.168.4.52:8858
- http {
- sendfile on;
- keepalive_timeout 65;
- upstream nginx_cluster {
- server 192.168.4.52:8838;
- server 192.168.4.52:8848;
- server 192.168.4.52:8858;
- }
-
- server {
- listen 8888;
- server_name vm52.com;
-
- location / {
- proxy_pass http://nginx_cluster;
- proxy_set_header Host $http_host;
- }
- }
- }
官方说明: Nacos2.0版本相比1.X新增了gRPC的通信方式,因此需要增加2个端口。新增端口是在配置的主端口(server.port)基础上,进行一定偏移量自动生成。
- stream {
- upstream nacos-server-grpc {
- server 192.168.4.52:9838;
- server 192.168.4.52:9848;
- server 192.168.4.52:9858;
- }
- server {
- listen 9888;
- proxy_pass nacos-server-grpc;
- }
- }
- # 端口规则
- server.port(默认8848)
- raft port: ${server.port} - 1000
- grpc port: ${server.port} + 1000
- grpc port for server: ${server.port} + 1001
可以看到grpc用于服务间同步的端口需要+1001,这就导致在虚拟机跑三台nacos时,三台nacos的端口是不能连续的,否则会出现端口冲突问题
- #!/bin/bash
- echo "starting nacos 8847"
- /usr/local/nacos/nacos-8838/bin/startup.sh
- echo "starting nacos 8848"
- /usr/local/nacos/nacos-8848/bin/startup.sh
- echo "starting nacos 8849"
- /usr/local/nacos/nacos-8858/bin/startup.sh
- !/bin/bash
- echo "starting nacos 8847"
- /usr/local/nacos/nacos-8838/bin/shutdown.sh
- echo "starting nacos 8848"
- /usr/local/nacos/nacos-8848/bin/shutdown.sh
- echo "starting nacos 8849"
- /usr/local/nacos/nacos-8858/bin/shutdown.sh
./startupall.sh
./nginx -c /usr/local/nginx/conf/nginx.conf