Windows下将jar包、redis、nginx设置为服务
一、将jar包设置为服务
1、将通过IDEA打包得到的demo.jar准备好。
2、下载WinSW,点我下载,将winsw-2.9.0-bin.exe文件直接重命名为demo.exe(必须和你生成的jar包名保持一致,我这里就都是demo)。
WinSW是一个可用于包装和管理作为Windows服务的自定义进程的工具,可以对windows中的服务程序进行管理(注册、卸载、启动、停止、重启等操作),其本质上就是一个可执行的二进制文件,运行于windows系统下。
3、新建XML文件demo.xml(必须和你生成的jar包名保持一致,我这里就都是demo),文件内容为:
<?xml version="1.0" encoding="UTF-8"?>
<service>
<id>test</id>
<name>xxx系统</name>
<description>xxx系统服务程序</description>
<executable>java</executable>
<arguments>-jar "demo.jar"</arguments>
<startmode>Automatic</startmode>
<logpath>%BASE%\log-server</logpath>
<logmode>reset</logmode>
</service>
注意:这里的<id>test</id>里面的test是服务名称,你可以自定义,xxx系统是显示名称,xxx系统服务程序是描述。同时<arguments>-jar "demo.jar"</arguments>需要同步修改。
4、新建批处理文件install.bat,文件内容为:
@echo on
:color 2f
mode con: cols=80 lines=25
:@echo 请按任意键开始安装后台服务...
:pause
cd /d %~dp0
demo.exe install
net start test
:pause
exit
注意:这里的net start test里面的test是demo.xml里面的service的id,也就是服务名称(需要保持一致),同时demo.exe install需要同步修改。
5、新建批处理文件uninstall.bat,文件内容为:
@echo on
color 2f
mode con: cols=80 lines=25
:@echo 请按任意键开始卸载后台服务...
:pause
cd /d %~dp0
net stop test
demo.exe uninstall
pause
注意:这里的net stop test里面的test是demo.xml里面的service的id,也就是服务名称(需要保持一致),同时demo.exe install需要同步修改。
6、点击install.bat启动会自动安装服务并启动,uninstall.bat可以卸载。
二、将redis设置为服务
1、下载Redis,此处不讲。

2、进入Redis安装目录,执行如下命令:
redis-server.exe --service-install redis.windows.conf --service-name redis --port 6379
3、进入服务,找到redis,设置为自动并启动服务。

三、将nginx设置为服务

1、同上,将winsw-2.9.0-bin.exe文件直接复制过来再次重命名为nginx-service.exe。
2、nginx-service.xml
<?xml version="1.0" encoding="UTF-8"?>
<service>
<id>nginx</id>
<name>nginx</name>
<description>Nginx Service</description>
<logpath>%BASE%\service-logs</logpath>
<log mode="roll-by-size">
<sizeThreshold>10240</sizeThreshold>
<keepFiles>8</keepFiles>
</log>
<executable>%BASE%\nginx.exe</executable>
<startarguments>-p %BASE%</startarguments>
<stopexecutable>%BASE%\nginx.exe</stopexecutable>
<stoparguments>-p %BASE% -s stop</stoparguments>
</service>
3、install.bat
@echo on
:color 2f
mode con: cols=80 lines=25
:@echo 请按任意键开始安装后台服务...
:pause
cd /d %~dp0
nginx-service.exe install
net start nginx
:pause
exit
4、uninstall.bat
@echo on
color 2f
mode con: cols=80 lines=25
:@echo 请按任意键开始卸载后台服务...
:pause
cd /d %~dp0
net stop nginx
nginx-service.exe uninstall
pause
更多推荐


所有评论(0)