Nacos使用WinSW设置为Windows 系统服务,开机自启

发布时间 2023-10-19 16:23:49作者: 古月辣糖满一满

WinSW(Windows Service Wrapper 是一个开源的 Windows 服务包装器,它可以帮助你将应用程序打包成系统服务,并实现开机自启动的功能。

nacos 安装目录 C:\plugin\nacos

下载 WinSW-x64.exe 

https://github.com/winsw/winsw/releases/tag/v2.11.0

1.使用WinSW-x64.exe 拷贝到 拷贝到nacos下 bin目录

2.将WinSW-x64.exe重命名为nacos-service.exe

3.在nacos下 bin目录分别 建 winsw.xml   、 start.bat文件,编码格式为UTF-8,内容如下:

start.bat
 set current_dir=%~dp0
cd %current_dir%\..\..\jdk-11
set JAVA_HOME=C:\Program Files\Java\jdk1.8.0_311
cd %current_dir%
startup.cmd -m standalone
winsw.xml
<configuration>
  
  <!-- ID of the service. It should be unique accross the Windows system-->
  <id>nacos-2.0</id>
  <!-- Display name of the service -->
  <name>nacos-2.1.1</name>
  <!-- Service description -->
  <description>nacos-2.1.1</description>
  
  <!-- Path to the executable, which should be started -->
  <executable>start.bat</executable>
  <arguments></arguments>

</configuration>

 

安装和启动 Nacos 服务

CMD 切换到 C:\plugin\nacos\bin 目录下,执行以下命令完成服务的安装和启动

# 安装服务
nacos-service.exe install
# 启动服务
nacos-service.exe start

 

在 Windows 系统服务列表可以看到 Nacos 服务(已验证可以开机自启动)

 

 

其他命令

# 删除服务
nacos-service.exe uninstall
# 查看状态
nacos-service.exe status
# 重启服务
nacos-service.exe restart