Nacos注册为windows服务时错误处理记录
自己安装nacos时,想把 nacos 注册成一个 winserver 为了保证nacos一直在后台运行,还可以通过注册的服务名自定义开机自启动等。
自己配置时出现的问题包括解决方式记录一下
问题
执行注册服务时报错:The configuration file cound not be loaded. Invalid character in the given encoding. Line 2, position 10.
工具下载
下载 WinSW-x64.exe
下载地址 https://github.com/winsw/winsw/releases
配置nacos-service.xml
下载好 exe 文件后,执行如下两个步骤
将WinSW-x64.exe文件重命名为 nacos-service.exe,放在 nacos 的 bin 目录下
创建配置文件 nacos-service.xml
nacos-service.xml 文件的内容如下:
<service>
<!-- 唯一服务ID -->
<id>nacos</id>
<!-- 显示服务的名称 -->
<name>Nacos Service</name>
<!-- 服务描述 -->
<description>Nacos服务</description>
<!-- 日志路径 -->
<logpath>你的nacos路径\nacos\bin\logs\</logpath>
<!-- 日志模式 -->
<logmode>roll</logmode>
<!-- 可执行文件的命令 -->
<executable>你的nacos路径\nacos\bin\startup.cmd</executable>
<!-- 停止可执行文件的命令 -->
<stopexecutable>你的nacos路径\nacos\bin\shutdown.cmd</stopexecutable>
</service>
问题与解决
在 “你的nacos路径\nacos\bin” 下,运行以下命令,将 nacos 注册成 Windows 服务
cmd 执行 nacos-service.exe install
问题来了,我的报错了
The configuration file cound not be loaded. Invalid character in the given encoding. Line 2, position 10.
解决办法
把nacos-service.xml中的中文删除就好了,或者该编码格式我简单粗暴直接删
启动与停止Nacos Service服务
按组合键 Win + X,选择 Windows PowerShell(管理员)
输入如下命令启动 nacos 服务:
net start nacos
输入如下命令启停止 nacos 服务:
net stop nacos
卸载Nacos Service服务
如果你需要卸载,进入到 nacos 的 bin 目录下,执行以下命令:
nacos-service.exe uninstall