Nacos 2.0+版本 docker部署启动出现9848端口错误

1.Docker Hub文档

通过访问Docker Hub官方文档,我们发现docker启动nacos的命令依旧为以下内容

1
docker run --name nacos-quick -e MODE=standalone -p 8849:8848 -d nacos/nacos-server:2.0.2

测试以后我们发现,通过这个命令虽然启动成功,但是我们的程序会报错com.alibaba.nacos.shaded.io.grpc.StatusRuntimeException: UNAVAILABLE: io exception以及Connection refused: no further information

2. 报错原因

  • 当nacos客户端升级为2.x版本后,新增了gRPC的通信方式,新增了两个端口。这两个端口在nacos原先的端口上(默认8848),进行一定偏移量自动生成。
端口 与主端口的偏移量 描述
9848 1000 客户端gRPC请求服务端端口,用于客户端向服务端发起连接和请求
9849 1001 服务端gRPC请求服务端端口,用于服务间同步等

3. 更新后的docker启动命令

1
docker run --name nacos-quick -e MODE=standalone -p 8848:8848 -p 9848:9848 -p 9849:9849 -d nacos/nacos-server:2.0.2

再次启动,发现错误消失

官方文档更新不及时,请大家及时避坑

附: 常用属性配置

| name | description | option | | ————————————— | ———————————————————— | ———————————————————— | | MODE | cluster/standalone | cluster/standalone default cluster | | NACOS_SERVERS | nacos cluster address | eg. ip1:port1 ip2:port2 ip3:port3 | | PREFER_HOST_MODE | Whether hostname are supported | hostname/ip default ip | | NACOS_APPLICATION_PORT | nacos server port | default 8848 | | NACOS_SERVER_IP | custom nacos server ip when network was mutil-network | | | SPRING_DATASOURCE_PLATFORM | standalone support mysql | mysql / empty default empty | | MYSQL_SERVICE_HOST | mysql host | | | MYSQL_SERVICE_PORT | mysql database port | default : 3306 | | MYSQL_SERVICE_DB_NAME | mysql database name | | | MYSQL_SERVICE_USER | username of database | | | MYSQL_SERVICE_PASSWORD | password of database | | | MYSQL_DATABASE_NUM | It indicates the number of database | default :1 | | MYSQL_SERVICE_DB_PARAM | Database url parameter | default : characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false | | JVM_XMS | -Xms | default :1g | | JVM_XMX | -Xmx | default :1g | | JVM_XMN | -Xmn | default :512m | | JVM_MS | -XX:MetaspaceSize | default :128m | | JVM_MMS | -XX:MaxMetaspaceSize | default :320m | | NACOS_DEBUG | enable remote debug | y/n default :n | | TOMCAT_ACCESSLOG_ENABLED | server.tomcat.accesslog.enabled | default :false | | NACOS_AUTH_SYSTEM_TYPE | The auth system to use, currently only ‘nacos’ is supported | default :nacos | | NACOS_AUTH_ENABLE | If turn on auth system | default :false | | NACOS_AUTH_TOKEN_EXPIRE_SECONDS | The token expiration in seconds | default :18000 | | NACOS_AUTH_TOKEN | The default token | default :SecretKey012345678901234567890123456789012345678901234567890123456789 | | NACOS_AUTH_CACHE_ENABLE | Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay. | default : false | | MEMBER_LIST | Set the cluster list with a configuration file or command-line argument | eg:192.168.16.101:8847?raft_port=8807,192.168.16.101?raft_port=8808,192.168.16.101:8849?raft_port=8809 | | EMBEDDED_STORAGE | Use embedded storage in cluster mode without mysql | embedded default : none | | NACOS_AUTH_CACHE_ENABLE | nacos.core.auth.caching.enabled | default : false | | NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE | nacos.core.auth.enable.userAgentAuthWhite | default : false | | NACOS_AUTH_IDENTITY_KEY | nacos.core.auth.server.identity.key | default : serverIdentity | | NACOS_AUTH_IDENTITY_VALUE | nacos.core.auth.server.identity.value | default : security | | NACOS_SECURITY_IGNORE_URLS | nacos.security.ignore.urls | default : /,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/** |