mac m1 docker 装 nacos2.x 启动报错,解决方案

nacos启动错误信息

错误:	
13:52:43.134 [main] ERROR org.springframework.boot.SpringApplication - Application run failed
com.alibaba.nacos.api.exception.runtime.NacosRuntimeException: ErrCode:500, ErrMsg:Function not implemented
	at com.alibaba.nacos.core.listener.StartingApplicationListener.loadPreProperties(StartingApplicationListener.java:161)
	at com.alibaba.nacos.core.listener.StartingApplicationListener.environmentPrepared(StartingApplicationListener.java:100)
	at com.alibaba.nacos.core.code.SpringApplicationRunListener.environmentPrepared(SpringApplicationRunListener.java:65)
	at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:53)
	at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:342)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:305)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215)
	at org.springframework.boot.SpringApplication.run(SpringApplication.java:1204)
	at com.alibaba.nacos.Nacos.main(Nacos.java:35)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.boot.loader.MainMethodRunner.run(MainMethodRunner.java:49)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:108)
	at org.springframework.boot.loader.Launcher.launch(Launcher.java:58)
	at org.springframework.boot.loader.PropertiesLauncher.main(PropertiesLauncher.java:467)
Caused by: com.alibaba.nacos.api.exception.NacosException: java.io.IOException: Function not implemented
	at com.alibaba.nacos.sys.file.WatchFileCenter$WatchDirJob.<init>(WatchFileCenter.java:189)
	at com.alibaba.nacos.sys.file.WatchFileCenter.registerWatcher(WatchFileCenter.java:97)
	at com.alibaba.nacos.core.listener.StartingApplicationListener.registerWatcher(StartingApplicationListener.java:167)
	at com.alibaba.nacos.core.listener.StartingApplicationListener.loadPreProperties(StartingApplicationListener.java:159)
	... 16 common frames omitted
Caused by: java.io.IOException: Function not implemented
	at sun.nio.fs.LinuxWatchService.<init>(LinuxWatchService.java:64)
	at sun.nio.fs.LinuxFileSystem.newWatchService(LinuxFileSystem.java:47)
	at com.alibaba.nacos.sys.file.WatchFileCenter$WatchDirJob.<init>(WatchFileCenter.java:184)
	... 19 common frames omitted

解决方案

/Users/alex/development/mydata 替换为你的 挂载主机的地址

1.搭建临时nacos容器,将初始的naocos配置文件,从临时容器中复制到主机中
# 下载nacos镜像
docker pull nacos/nacos-server:latest

# 搭建临时nacos容器
docker run -p 8848:8848 --name nacos -d nacos/nacos-server:latest

# 创建主机挂载目录
mkdir -p /Users/alex/development/mydata/nacos/conf
mkdir -p /Users/alex/development/mydata/nacos/logs

# 将初始的naocos配置文件,从临时容器中复制到主机中
docker cp nacostest:/home/nacos/logs/ /Users/alex/development/mydata//nacos/
docker cp nacostest:/home/nacos/conf/ /Users/alex/development/mydata//nacos/

# 删除nacos临时容器
docker stop nacos

2. mysql新建nacos的数据库,并执行脚本

下载地址:
https://github.com/alibaba/nacos/blob/master/config/src/main/resources/META-INF/nacos-db.sql

3. 修改nacos的配置文件application.properties
# 查看docker里mysql的ip
# 注意: 此ip为连接docker容器mysql的ip
docker inspect mysql

mysql ip

# 进入配置文件
vim /Users/alex/development/mydata/nacos/conf/application.properties 

修改配置文件,如下

# spring
server.servlet.contextPath=${SERVER_SERVLET_CONTEXTPATH:/nacos}
server.contextPath=/nacos
server.port=${NACOS_APPLICATION_PORT:8848}
spring.datasource.platform=mysql
nacos.cmdb.dumpTaskInterval=3600
nacos.cmdb.eventTaskInterval=10
nacos.cmdb.labelTaskInterval=300
nacos.cmdb.loadDataAtStart=false

# -------- begin -----------
db.num=1
db.url.0=jdbc:mysql://填写mysql的ip:3306/nacos_config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=30000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=Asia/Shanghai
db.url.1=jdbc:mysql://${MYSQL_SERVICE_HOST}:${MYSQL_SERVICE_PORT:3306}/${MYSQL_SERVICE_DB_NAME}?${MYSQL_SERVICE_DB_PARAM:characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useSSL=false}
db.user=填写mysql账号
db.password=填写mysql密码
# -------- end -----------

### The auth system to use, currently only 'nacos' is supported:
nacos.core.auth.system.type=${NACOS_AUTH_SYSTEM_TYPE:nacos}


### The token expiration in seconds:
nacos.core.auth.default.token.expire.seconds=${NACOS_AUTH_TOKEN_EXPIRE_SECONDS:18000}

### The default token:
nacos.core.auth.default.token.secret.key=${NACOS_AUTH_TOKEN:SecretKey012345678901234567890123456789012345678901234567890123456789}

### Turn on/off caching of auth information. By turning on this switch, the update of auth information would have a 15 seconds delay.
nacos.core.auth.caching.enabled=${NACOS_AUTH_CACHE_ENABLE:false}
nacos.core.auth.enable.userAgentAuthWhite=${NACOS_AUTH_USER_AGENT_AUTH_WHITE_ENABLE:false}
nacos.core.auth.server.identity.key=${NACOS_AUTH_IDENTITY_KEY:serverIdentity}
nacos.core.auth.server.identity.value=${NACOS_AUTH_IDENTITY_VALUE:security}
server.tomcat.accesslog.enabled=${TOMCAT_ACCESSLOG_ENABLED:false}
server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D
# default current work dir
server.tomcat.basedir=
## spring security config
### turn off security
nacos.security.ignore.urls=${NACOS_SECURITY_IGNORE_URLS:/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-fe/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/**}
# metrics for elastic search
management.metrics.export.elastic.enabled=false
management.metrics.export.influx.enabled=false

nacos.naming.distro.taskDispatchThreadCount=10
nacos.naming.distro.taskDispatchPeriod=200
nacos.naming.distro.batchSyncKeyCount=1000
nacos.naming.distro.initDataRatio=0.9
nacos.naming.distro.syncRetryDelay=5000
nacos.naming.data.warmup=true

位置

4. 执行挂载命令
docker run -d -e MODE=standalone -v /Users/alex/development/mydata/nacos/logs:/home/nacos/logs -v /Users/alex/development/mydata/nacos/conf:/home/nacos/conf -p 8848:8848 --name nacos --restart=always zill057/nacos-server-apple-silicon:2.0.3

非mac 拉正常拉取 nacos/nacos-server:latest 即可

参考:https://github.com/alibaba/nacos/issues/6340


附:
nacos配置中心无法添加yml
解决方案:
mysql中nacos库
config_info和his_config_info两表中 encrypted_data_key字段 设置可以为空
在这里插入图片描述

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐