linux设置开机启动nginx、java

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
posted @   sumling  阅读(231)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
历史上的今天:
2021-06-08 static 、Throwable、自定义异常记录
点击右上角即可分享
微信分享提示