Nacos集群部署报400问题

2021-01-27  本文已影响0人  程序员王旺

Nacos现在在微服务领域用的比较广了,最近使用时发现一些问题记录下,我是nacos服务器用的是最新版,客户端为了兼容Springboot版本用的是0.1.2,现在最新客户端是0.2.2,具体请看版本说明对照表

版本说明:

  <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-alibaba-dependencies</artifactId>
                <version>0.1.2.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
      
        </dependencies>

    </dependencyManagement>

问题

问题1:工程启动时报错

Error creating bean with name 'nacosAutoServiceRegistration

版本冲突,重新引入版本覆盖

 <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-commons</artifactId>
        <version>1.3.5.RELEASE</version>
 </dependency>

问题2:工程启动时报错

failed to req API:/nacos/v1/ns/instance after all servers([nacos:8848]) tried: failed to req API:http://nacos:8848/nacos/v1/ns/instance. code:400 msg: <html><body><h1>Whitelabel Error Page</h1><p>This application has no explicit mapping for /error, so you are seeing this as a fallback.</p><div id='created'>Wed Jan 27 14:29:32 CST 2021</div><div>There was an unexpected error (type=Bad Request, status=400).</div><div>receive invalid redirect request from peer 100.97.40.95</div></body></html>

这个问题比较怪异,应该是一个bug,具体有两种办法解决:

apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: nacos
spec:
  selector:
    matchLabels:
      app: nacos
  serviceName: nacos
  replicas: 3
  template:
  ....
    spec:
      containers:
     ....
            - name: MODE
              value: "standalone"
       ....

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Edgware.RELEASE</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
 
            <!-- 解决启动报 Error creating bean with name 'nacosAutoServiceRegistration -->
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-commons</artifactId>
                <version>1.3.5.RELEASE</version>
            </dependency>


            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
                <version>0.1.2.RELEASE</version>
            </dependency>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
                <version>0.1.2.RELEASE</version>
            </dependency>
        </dependencies>

另外k8s中服务列表配成这样:

....
            - name: NACOS_SERVERS
              value: "nacos-0.nacos.default.svc.cluster.local:8848 nacos-1.nacos.default.svc.cluster.local:8848"
...
上一篇下一篇

猜你喜欢

热点阅读