ubuntu22.04开机自启动Eureka服务

ubuntu22.04开机自启动Eureka服务

1、创建启动脚本eurekaService.sh

#我们把启动脚本放在/usr/software目录下
cd /usr/software
vim eurekaService.sh

eurekaService.sh内容为

#!/bin/sh
# this is a eurekaService shell to startup at the mechian power on.

echo "eurekaServer-0.0.1-SNAPSHOT.jar service start loading..." 
nohup java -jar /usr/software/eurekaServer-0.0.1-SNAPSHOT.jar > /usr/software/log.txt 2>&1 &
echo "eurekaService loads successful"

2、赋予可执行权限

chmod 777 eurekaService.sh

3、新建要启动的Eureka服务文件

#新建要启动的服务文件
vim /etc/systemd/system/eureka.service

eureka.service内容为

[Unit]
Description=this is eurekaService 
After=network.target
[Service]
Type=forking
ExecStart=/usr/software/eurekaService.sh  #指定上面创建的脚步文件路径
[Install]
WantedBy=multi-user.target  #多用户

4、启动Eureka服务

#让系统获取到你刚自定义的service文件并设置开机启动
systemctl daemon-reload
systemctl start eureka.service

systemctl enable eureka.service

#查看日志
systemctl status eureka.service

你可能感兴趣的:(Linux,eureka,云原生)