Become a sponsor

操作系统
Windows 10 或以上版本。Nacos 2.x 版本,支持 JDK 17。确保已安装 JDK 17,并配置好环境变量。
打开命令提示符,运行 java -version,确认输出为 JDK 17。
C:\Users>java -version
java version "17.0.9" 2023-10-17 LTS
Java(TM) SE Runtime Environment (build 17.0.9+11-LTS-201)
Java HotSpot(TM) 64-Bit Server VM (build 17.0.9+11-LTS-201, mixed mode, sharing)温馨提示
如果未安装 JDK 17,请前往 《基础环境搭建>>#安装-JDK17》 查阅详细的安装步骤和流程。
推荐使用 Nacos 2.x 版本,支持 JDK 17。



Nacos 集群模式需要使用 MySQL 作为外部数据库。
访问 Nacos 的 GitHub Release 页面:Nacos Releases 下载安装包。

下载最新版本的 Nacos 压缩包(如 nacos-server-2.5.1.zip)。

将下载的压缩包解压到一个目录,例如:E:\nacos-server-2.5.1。

Nacos 单机模式默认使用嵌入式数据库(Derby),无需额外配置。如果需要使用 MySQL 作为数据库,可以按照以下步骤配置:
application.properties打开 Nacos 解压目录下的 conf 文件夹,找到 application.properties 文件。

编辑 application.properties,修改以下内容以启用 MySQL 数据库:
# 启用 MySQL 数据源
spring.datasource.platform=mysql
# 数据库数量(单机模式为 1)
db.num=1
# MySQL 连接配置
db.url.0=jdbc:mysql://127.0.0.1:3306/nacos?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true
db.user.0=root
db.password.0=root
# 开启登录认证
nacos.core.auth.enabled=true
### Since 1.4.1, worked when nacos.core.auth.enabled=true and nacos.core.auth.enable.userAgentAuthWhite=false.
### The two properties is the white list for auth and used by identity the request from other server.
nacos.core.auth.server.identity.key=serverIdentity
nacos.core.auth.server.identity.value=security
# 设置默认令牌
nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789温馨提示
db.url.0 中的 127.0.0.1:3306 替换为你的 MySQL 地址和端口。db.user.0 和 db.password.0 替换为你的 MySQL 用户名和密码。在 MySQL 中创建一个数据库,例如 nacos。
执行 Nacos 安装包 E:\nacos-server-2.5.1\conf\nacos-mysql.sql 路径下提供的 mysql-schema.sql 脚本初始化数据库;

执行成功后,nacos 数据库表结构如下:
nacos
|- config_info
|- config_info_gray
|- config_tags_relation
|- group_capacity
|- his_config_info
|- permissions
|- roles
|- tenant_capacity
|- tenant_info
|- users打开命令提示符 (CMD),进入 Nacos 的 bin 目录:
cd E:\nacos-server-2.5.1\bin
运行以下命令启动 Nacos:
./startup.cmd -m standalone
单机模式
-m standalone 表示以单机模式启动。
如果启动成功,你会看到类似以下的日志:
PS E:\nacos-server-2.5.1\bin> ./startup.cmd -m standalone
"nacos is starting with standalone"
,--.
,--.'|
,--,: : | Nacos 2.5.1
,`--.'`| ' : ,---. Running in stand alone mode, All function modules
| : : | | ' ,'\ .--.--. Port: 8848
: | \ | : ,--.--. ,---. / / | / / ' Pid: 12820
| : ' '; | / \ / \. ; ,. :| : /`./ Console: http://192.168.124.60:8848/nacos/index.html
' ' ;. ;.--. .-. | / / '' | |: :| : ;_
| | | \ | \__\/: . .. ' / ' | .; : \ \ `. https://nacos.io
' : | ; .' ," .--.; |' ; :__| : | `----. \
| | '`--' / / ,. |' | '.'|\ \ / / /`--' /
' : | ; : .' \ : : `----' '--'. /
; |.' | , .-./\ \ / `--'---'
'---' `--`---' `----'
2025-03-18 13:13:32,171 INFO Tomcat initialized with port(s): 8848 (http)
2025-03-18 13:13:32,792 INFO Root WebApplicationContext: initialization completed in 3578 ms
2025-03-18 13:13:37,450 INFO Will secure any request with [org.springframework.security.web.session.DisableEncodeUrlFilter@fe87ddd, org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter@4eea94a4, org.springframework.security.web.context.SecurityContextPersistenceFilter@4fb04a72, org.springframework.security.web.header.HeaderWriterFilter@2abbd0d9, org.springframework.security.web.csrf.CsrfFilter@46046c06, org.springframework.security.web.authentication.logout.LogoutFilter@17dad32f, org.springframework.security.web.savedrequest.RequestCacheAwareFilter@343e225a, org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter@1a07bf6, org.springframework.security.web.authentication.AnonymousAuthenticationFilter@7c281eb8, org.springframework.security.web.session.SessionManagementFilter@6025d790, org.springframework.security.web.access.ExceptionTranslationFilter@32ec9c90]
2025-03-18 13:13:37,910 INFO Adding welcome page: class path resource [static/index.html]
2025-03-18 13:13:38,521 INFO Exposing 1 endpoint(s) beneath base path '/actuator'
2025-03-18 13:13:38,547 WARN You are asking Spring Security to ignore Ant [pattern='/**']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2025-03-18 13:13:38,548 INFO Will not secure Ant [pattern='/**']
2025-03-18 13:13:38,549 WARN You are asking Spring Security to ignore Mvc [pattern='/prometheus']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2025-03-18 13:13:38,550 INFO Will not secure Mvc [pattern='/prometheus']
2025-03-18 13:13:38,550 WARN You are asking Spring Security to ignore Mvc [pattern='/prometheus/namespaceId/{namespaceId}']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2025-03-18 13:13:38,550 INFO Will not secure Mvc [pattern='/prometheus/namespaceId/{namespaceId}']
2025-03-18 13:13:38,550 WARN You are asking Spring Security to ignore Mvc [pattern='/prometheus/namespaceId/{namespaceId}/service/{service}']. This is not recommended -- please use permitAll via HttpSecurity#authorizeHttpRequests instead.
2025-03-18 13:13:38,550 INFO Will not secure Mvc [pattern='/prometheus/namespaceId/{namespaceId}/service/{service}']
2025-03-18 13:13:38,641 INFO Tomcat started on port(s): 8848 (http) with context path '/nacos'
2025-03-18 13:13:38,657 INFO No TaskScheduler/ScheduledExecutorService bean found for scheduled processing
2025-03-18 13:13:38,706 INFO Nacos started successfully in stand alone mode. use external storage访问 Nacos 控制台
打开浏览器,访问 Nacos 控制台:
http://localhost:8848/nacos
默认用户名和密码均为 nacos。

如果需要停止 Nacos,可以在 bin 目录下运行以下命令:
./shutdown.cmd
JDK 17 兼容性问题如果启动时遇到 JDK 17 的兼容性问题,可以尝试以下解决方案:
确保使用的是 Nacos 2.x 版本,Nacos 2.x 已经支持 JDK 17。
如果仍然有问题,可以尝试在 startup.cmd 中显式指定 JDK 17 的路径:
set JAVA_HOME=C:\path\to\jdk-17如果端口 8848 被占用,可以修改 Nacos 的端口:
conf/application.properties,修改以下配置:server.port=8849Nacos 服务。如果 MySQL 连接失败,检查以下内容:
MySQL 服务是否已启动。
MySQL 的用户名和密码是否正确。
MySQL 是否允许远程连接(如果 Nacos 和 MySQL 不在同一台机器)。通过以上步骤,你可以在 Windows 环境下基于 JDK 17 成功部署 Nacos 单机版本。如果需要进一步扩展为集群模式,可以参考 《Nacos官方文档》进行配置。
