pom.xml
com.alibaba.nacos nacos-client2.0.3 com.alibaba.cloud spring-cloud-starter-alibaba-nacos-discoverycom.alibaba.nacos nacos-clientcom.alibaba.cloud spring-cloud-starter-alibaba-nacos-configcom.alibaba.nacos nacos-clientcom.alibaba.cloud spring-cloud-alibaba-dependencies2021.0.1.0 pom import org.springframework.cloud spring-cloud-dependencies2021.0.2 pom import org.springframework.boot spring-boot-dependencies2.6.7 pom import
nacos中需要配置两处
1. cluster.conf 中全部都需要写公网ip地址 【注:如果是云服务器全部填写公网ip、如果是本地填写 ifconfig 或 ipconfig获取到eth0的IP地址】
1.xx.100.xxx:8848 101.xx.123.xxx:8848 59.38.xxx.xxx:8848
2. application.properties
### Specify local server's IP: 配置该选项绑定公网ip地址 nacos.inetutils.ip-address=59.xx.137.xxx
VIP服务器这里使用的是Nginx + haproxy
其中nginx 作为http代理8848,haproxy作为grpc代理9848
注意nginx端口如果需要自定义端口,haproxy也需要更改代理端口 在nginx端口的基础上+1000,推荐nginx和nacos使用一样的8848端口
1. nginx.conf
upstream nacos{
server 1.14.xxx.234:8848;
server 101.x5.xxx.xxx:8848;
server 59.xx.xxx.1x0:8848;
}
server {
listen 8848;
server_name localhost;
#charset koi8-r;
#access_log logs/host.access.log main;
location / {
proxy_pass http://nacos;
root /nacos/;
}
2.haproxy.cfg
global
log 127.0.0.1 local0
nbproc 1
maxconnrate 300
maxcomprate 300
maxsessrate 500
chroot /usr/local/haproxy
pidfile /usr/local/haproxy.pid
maxconn 30000
user haproxy
group haproxy
daemon
stats socket /usr/local/haproxy/stats
defaults
mode tcp # 注意grpc需要通过tcp进行转发
log global
option dontlognull
option redispatch
option http-use-htx
option logasap
option tcplog # 注意grpc需要通过tcp进行转发
retries 3
timeout queue 1m
timeout connect 5m
timeout client 5m
timeout server 5m
timeout http-keep-alive 100s
timeout check 10s
maxconn 100000
listen admin_stats
stats enable
bind 0.0.0.0:9999
mode http
log global
maxconn 10
stats uri /admin
stats realm welcome Haproxy
stats auth admin:admin
stats admin if TRUE
option httplog
stats refresh 30s
stats hide-version
frontend nacos_cluster
bind :9848 # +1000
mode tcp # 注意grpc需要通过tcp进行转发
log global
option tcplog
option dontlognull
option nolinger
timeout client 30s
maxconn 8000
default_backend nacos_cluster_nodes
backend nacos_cluster_nodes
mode tcp # 注意grpc需要通过tcp进行转发
server nacos-a 1.14.100.234:9848 check
server nacos-b 101.35.123.144:9848 check
server nacos-c 59.38.137.150:9848 check
bootstrap.yaml配置文件
server:
port: 88
spring:
application:
name: gateway
cloud:
nacos:
discovery:
server-addr: 42.1x4.xx.x:8848
username: nacos
password: ZXC891225
测试



