一、问题背景:
在同一台服务器(centos7)搭建nacos服务集群。部署了3个nacos服务,使用不同的端口8848,8858,8868。
使用nginx代理端口8847映射到nacos端口,如下
- upstream nacoscluster {
- server 127.0.0.1:8848;
- server 127.0.0.1:8858;
- server 127.0.0.1:8868;
- }
- server {
- listen 8847;
- server_name localhost;
- location /nacos/ {
- proxy_pass http://nacoscluster/nacos/;
- }
- }
访问ip:8847/nacos/可以正常显示nacos服务
二、问题
运行springcloud demo项目,控制台抛出无法连接ip:9847的问题。
三、解决方法
查询网上知道nacos2.0+增加了grpc通讯,如果使用nginx代理的话,需要使用nginx的tcp代理,而nginx默认未编译进去。
重新安装nginx
- yum install -y nginx
- #添加stream模块
- yum install -y nginx-mod-stream
在nginx.conf文件和http同级别增加代码
- stream {
- upstream nocos-tcp{
- server 127.0.0.1:9848 weight=1;
- server 127.0.0.1:9858 weight=1;
- server 127.0.0.1:9868 weight=1;
- }
- server {
- listen 9847;
- proxy_pass nocos-tcp;
- }
- }
重启nginx后,springcloud成功启动,并不在抛出错误