Nacos现在在微服务领域用的比较广了,最近使用时发现一些问题记录下,我是nacos服务器用的是最新版,客户端为了兼容Springboot版本用的是0.1.2,现在最新客户端是0.2.2,具体请看版本说明对照表
版本说明:
- Nacos Server采用1.4.1版本, kubernetes部署
- Spring cloud采用Edgware.RELEASE版本
- Springboot采用1.5.9.RELEASE版本
<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,具体有两种办法解决:
- 使用单机模式
将MODE属性有cluster改成standalone
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: nacos
spec:
selector:
matchLabels:
app: nacos
serviceName: nacos
replicas: 3
template:
....
spec:
containers:
....
- name: MODE
value: "standalone"
....
- 单独引入依赖包
单独引入discovery和config包
<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"
...
网友评论