方法一:(rc.local)
1、因为在centos7中/etc/rc.d/rc.local
的权限被降低了,所以需要赋予其可执行权
chmod +x /etc/rc.d/rc.local
2、赋予脚本可执行权限
假设/usr/local/script/autostart.sh
是你的脚本路径,给予执行权限
chmod +x /usr/local/script/autostart.sh
3、打开/etc/rc.d/rc.local
文件,在末尾增加如下内容
/usr/local/script/autostart.sh
ps: 示例:autostart.sh
#!/bin/bash
echo "aaaaaaaaaaa"
sleep 2 #2秒
echo "bbbbbbbbbbb"
####################################################
export JAVA_HOME=/usr/local/jdk/jdk1.8.0_231
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin
nohup java -jar /usr/local/project/springcloud/zipkin-server-2.12.9-exec.jar >zipkin.log 2>&1 &
#nohup /usr/local/jdk/jdk1.8.0_231/bin/java -jar /usr/local/project/springcloud/zipkin-server-2.12.9-exec.jar >zipkin.log 2>&1 &