栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

nacos集群 2.x版本使用grpc长连接

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

nacos集群 2.x版本使用grpc长连接

pom.xml

        
            com.alibaba.nacos
            nacos-client
            2.0.3
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-discovery
            
                
                    com.alibaba.nacos
                    nacos-client
                
            
        
        
            com.alibaba.cloud
            spring-cloud-starter-alibaba-nacos-config
            
                
                    com.alibaba.nacos
                    nacos-client
                
            
        
    
    
    
        
            
                com.alibaba.cloud
                spring-cloud-alibaba-dependencies
                2021.0.1.0
                pom
                import
            
            
                org.springframework.cloud
                spring-cloud-dependencies
                2021.0.2
                pom
                import
            
            
                org.springframework.boot
                spring-boot-dependencies
                2.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

测试

 

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/865476.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号