目录
#9000 ~ 9002测试
server.port=9000
### nacos 内置有数据库 所以需要设置公用数据库MySQL 开启下面设置
spring.datasource.platform=mysql
### Count of DB:
db.num=1
### Connect URL of DB:
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC
db.user.0=root
db.password.0=123456
#要用真实ip 勿用localhost
192.168.111.1:9000
192.168.111.1:9001
192.168.111.1:9002
可以看到集群已经启动
org.springframework.cloud spring-cloud-starter-gateway
spring: application: name: springcloud-gateway #服务实例 cloud: gateway: routes:#list数组 添加要跳转的服务 - id: springcloud-good uri: lb://springcloud-good #loadbanlance 使用ribbon的负载均衡 predicates: - Path=/** #跳转的路径 nacos: discovery: server-addr: localhost:81#nginx 代理的端口 register-enabled: false #不注册到nacos上 只拉取服务
@SpringBootApplication public class SpringGatewayApplication { public static void main(String[] args) { SpringApplication.run(SpringGatewayApplication.class, args); } @Bean @LoadBalanced #开启负载均衡 public RestTemplate restTemplate(){ return new RestTemplate(); } }
#代理的ip
upstream nacos{
server 192.168.111.1:9000;
server 192.168.111.1:9001;
server 192.168.111.1:9002;}
server {
listen 81;
server_name localhost;location / {
proxy_pass http://nacos;
}
}