linux设置开机启动nginx、java
1、开机启动nginx
我是用yum安装的nginx,nginx启动程序在/usr/sbin/nginx
#修改/etc/rc.d/rc.local文件
#添加/usr/sbin/nginx
#添加后执行chmod +x /etc/rc.d/rc.local
#如果重启后没有自启成功,查看/var/log/boot.log日志中是否有错误
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
/usr/sbin/nginx
2、开机启动java程序
同样是用yum安装的jdk
1、在/etc/rc.d目录下添加runJar.sh启动文件
#!/bin/bash
#设置或显示环境变量
export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.an7.x86_64
export JRE_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.372.b07-1.an7.x86_64/jre
export CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib:$CLASSPATH
export PATH=$JAVA_HOME/bin:$PATH
#进入jar包目录
cd /home/superuser/nlzcpt/bin
nohup java -jar ruoyi-admin.jar --server.port=8012 &
2、执行chmod +x /etc/rc.d/runJar.sh
chmod +x /etc/rc.d/runJar.sh
3、在/etc/rc.d/rc.local中添加/etc/rc.d/runJar.sh
#!/bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.
touch /var/lock/subsys/local
/usr/sbin/nginx
/etc/rc.d/runJar.sh
标签:java,etc,linux,boot,nginx,rc,local
From: https://www.cnblogs.com/sumling/p/17465442.html