背景:公司测试windows服务器经常重启,每次服务器重启后都要重新启动nacos,配置个nacos开机自启
1.创建nacos.service文件
vim /lib/systemd/system/nacos.service
nacos.service内容如下:将/usr/local/soft/nacos修改为你自己nacos的安装目录
[Unit]
Description=nacos
After=network.target
[Service]
Type=forking
ExecStart=/usr/local/soft/nacos/bin/startup.sh -m standalone
ExecReload=/usr/local/soft/nacos/bin/shutdown.sh
ExecStop=/usr/local/soft/nacos/bin/shutdown.sh
PrivateTmp=true
[Install]
WantedBy=multi-user.target
2.编辑nacos/bin目录下的startup.sh, 修改JAVA_HOME的路径, 注释其他三行.
不修改startup.sh文件的JAVA_HOME的路径,启动报错:报错信息如下:ERROR: Please set the JAVA_HOME variable in your environment, We need java(x64)! jdk8 or later is better! !!
查看JAVA_HOME路径
[root@localhost bin]# cat /etc/profile | grep "export JAVA_HOME"
export JAVA_HOME=/opt/jdk1.8.0_202
3、设置开启自启动
systemctl daemon-reload --重新加载所有service服务
systemctl enable nacos.service --开启开机自启
systemctl start nacos.service --启动nacos服务
systemctl status nacos.service --查看nacos服务启动状态
systemctl is-enabled nacos.service --查看该service是否开机启用
标签:bin,systemd,管理器,service,nacos,systemctl,自启动,HOME,JAVA
From: https://www.cnblogs.com/muzlei/p/16894953.html