- 自己新建一个脚本,如centnet-service.sh
经过后面的几个步骤后,这个脚本在开机的时候会执行,在这个脚本里面可以写你开机的时候想执行的命令,如启动tomcat,oracle等服务 - 在脚本中输入启动服务的命令,如(开机启动tomcat):
#!/bin/bash
export JDK_HOME=/home/java/jdk1.8.0_91
export JAVA_HOME=/home/java/jdk1.8.0_91
/home/tomcat/apache-tomcat-8.0.36/bin/startup.sh - 执行如下命令,将该脚本标记为可执行文件(添加可执行的权限)
chmod +x /home/centnet/centnet-service.sh - 执行如下命令将/etc/rc.d/rc.local文标记为可执行文件
在centos7中,/etc/rc.d/rc.local文件的权限被降低了,开机的时候执行在自己的脚本是不能起动一些服务的,执行下面的命令可以文件标记为可执行的文件
chmod +x /etc/rc.d/rc.local - 打开/etc/rc.d/rc.local文件,在最后面添加如下脚本
/home/centnet/centnet-service.sh
这样,centnet-service.sh这个脚本在开机的时候就会被执行了,以后再这里面写启动服务的命令就可以了
/etc/rc.d/rc.local
#!/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
service mysqld start
/root/handle/service/restart.sh
/root/src/restart.sh