下面几个脚本仅供参考,请根据本身须要作调整
start.shhtml
#!/bin/shrm -f tpid
APP_NAME=fm-eureka-client-1.0-SNAPSHOT
APP_JAR=$APP_NAME".jar"##nohup命令提交做业,那么在缺省状况下该做业的全部输出都被重定向到一个名为nohup.out的文件中,除非另外指定了输出文件。这里指定输出文件在为./fm-eureka-client-1.0-SNAPSHOT.lognohup java -jar $APP_JAR > $APP_NAME".log" 2>&1 &echo $! > $APP_NAME".tpid"echo $APP_NAME Start Success!12345678910111213
stop.shjava
#!/bin/shAPP_NAME=fm-eureka-client-1.0-SNAPSHOT
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then
echo 'Stopping' $APP_NAME '...'
kill -15 $tpidfisleep 5tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then
echo 'Kill' $APP_NAME 'Process!'
kill -9 $tpidelse
echo $APP_NAME 'Stoped Success!'fi12345678910111213141516
kill.shspring
#!/bin/shAPP_NAME=fm-eureka-client-1.0-SNAPSHOT
tpid=`ps -ef|grep $APP_NAME|grep -v grep|grep -v kill|awk '{print $2}'`if [ ${tpid} ]; then
echo 'Kill Process!'
kill -9 $tpidelse
echo $APP_NAME 'is not running!'fi12345678910
授予执行权限vim
chmod +x start.shchmod +x stop.shchmod +x kill.sh123
只要修改变量 $APP_NAME 就能够用这种方式运行jar项目app
使用Linux服务的方式运行
在项目pom.xml中配置插件dom
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins></build>
须要注意一下:<executable>true<executable>maven
1ide
2spring-boot
3oop
4
5
6
7
8
9
10
11
打包jar
正常使用 mvn clean package -Dmaven.test.skip=true 将工程打成jar包
部署
假设部署路径为 /var/apps/fm-eureka-client.jar ,使用命令作一个软链接到 /etc/init.d 目录,命令:
ln -s /var/apps/fm-eureka-client.jar /etc/init.d/fm-eureka-client
/etc/init.d/fm-eureka-client中的fm-eureka-client就是服务名。
另删除软链的命令是:
rm /etc/init.d/fm-eureka-client
授予jar文件可执行权限
命令:
chmod +x /var/apps/fm-eureka-client.jar
启动服务
接下来,就可使用 service fm-eureka-client start|stop|restart|status 来对应用进行启停了。
执行命令后将获得形如 Started|Stopped [PID] 的结果反馈。
默认PID文件路径:/var/run/{servicename}/{servicename}.pid
默认服务日志文件路径:/var/log/{servicename}.log(能够经过下面.conf 的方式修改LOG_FOLDER)
自定义.conf文件来变动默认配置
在jar包相同路径下建立一个.conf文件,名称应该与.jar的名称相同,如fm-eureka-client.conf(若是咱们打包的文jar文件为 fm-eureka-client-1.0-SNAPSHOT.jar 那么这里的conf文件也应该是 fm-eureka-client-1.0-SNAPSHOT.conf),其内容配置能够以下:
JAVA_HOME=/usr/local/jdkJAVA_OPTS=-Xmx1024MLOG_FOLDER=/data/logs/myapp
注:LOG_FOLDER 对应的文件夹目录要必须存在,若是目录不存在,服务并不会自从建立目录。
- - - - - - - - - - - 分 - - - - - - - 割 - - - - - - - 线 - - - - - - - - - - - - - -12
若是你是CentOS 7或红帽7以上,你还能够用下面的方法处理,为何要用这样的方法(请自行研究),这里直接提供结果
编辑服务文件 vim /usr/lib/systemd/system/fm-eureka-client.service
[Unit][Unit]Description=test[Service]WorkingDirectory=/servers/eureka_clientPrivateTmp=trueRestart=alwaysType=simpleExecStart=/usr/bin/java -jar /servers/eureka_client/fm-eureka-client-1.0-SNAPSHOT.jarExecStop=/usr/bin/kill -15 $MAINPID[Install]WantedBy=multi-user.target1234567891011121314
systemctl 管理,让配置生效。如果修改配置文件,须要reload:
sudo systemctl daemon-reloadsudo systemctl enable fm-eureka-client.service12
启动服务
systemctl start fm-eureka-client1
查看服务状态
systemctl status eureka-client.service1
显示以下:
eureka-client.service - test
Loaded: loaded (/usr/lib/systemd/system/eureka-client.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2017-10-25 21:32:24 CST; 16min ago
Main PID: 17080 (java)
Memory: 478.0M
CGroup: /system.slice/eureka-client.service
└─17080 /usr/bin/java -jar /servers/eureka_client/fm-eureka-client-1.0-SNAPSHOT.jar
Oct 25 21:47:03 localhost.localdomain java[17080]: gen usersig times:1Oct 25 21:47:05 localhost.localdomain java[17080]: load times:0Oct 25 21:47:05 localhost.localdomain java[17080]: gen usersig times:0Oct 25 21:47:07 localhost.localdomain java[17080]: load times:0Oct 25 21:47:07 localhost.localdomain java[17080]: gen usersig times:1Oct 25 21:47:28 localhost.localdomain java[17080]: 2017-10-25 21:47:28.647 INFO 17080 --- [trap-executor-0] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka...figurationOct 25 21:47:43 localhost.localdomain java[17080]: load times:0Oct 25 21:47:43 localhost.localdomain java[17080]: gen usersig times:0Oct 25 21:47:46 localhost.localdomain java[17080]: load times:0Oct 25 21:47:46 localhost.localdomain java[17080]: gen usersig times:0Warning: eureka-client.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Hint: Some lines were ellipsized, use -l to show in full.1234567891011121314151617181920
查看日志(实时):
journalctl _PID=17080 -f//或journalctl -u eureka-client.service -f123
使用Linux 7 之后服务新的启动方式,相关命令
//启动systemctl start myapp//中止systemctl stop myapp//重启systemctl restart myapp//查看日志journalctl -u myapp//关于更多 systemctl 命令的使用方法,度娘有不少。123456789
转载:http://blog.csdn.net/catoop/article/details/50588851
journalctl 资料:http://blog.csdn.net/qq_31863071/article/details/52047593
原地址:https://blog.csdn.net/u011861035/article/details/78646141
https://docs.spring.io/spring-boot/docs/current/reference/html/deployment-install.html#deployment-script-customization-conf-file