阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

RHEL7开机自启动shell脚本

164次阅读
没有评论

共计 1800 个字符,预计需要花费 5 分钟才能阅读完成。

1. RHEL7 下自己新建一个脚本,如 tomcat。

经过后面的几个步骤后, 这个脚本在开机的时候会执行, 在这个脚本里面可以写你开机的时候想执行的命令, 如启动 Tomcat,Oracle 等服务

2. 在脚本中输入启动服务的命令, 如 (开机启动 tomcat):

# vi /etc/init.d/tomcat
#!/bin/bash
#chkconfig:  2345 08 92
#description: Start

export Java_HOME=/usr/java/jdk1.6.0_45

echo “Starting Tomcat Service …”
/root/tomcat6.0/bin/startup.sh

注意:export JAVA_HOME=/usr/java/jdk1.6.0_45 这里要配置环境变量,在 /etc/profile 中的配置在系统服务中不生效

3. 执行如下命令, 将该脚本标记为可执行文件 (添加可执行的权限)

chmod +x /etc/init.d/tomcat

4. 执行如下命令将 /etc/rc.d/rc.local 文标记为可执行文件

在 CentOS7 中,/etc/rc.d/rc.local 文件的权限被降低了, 开机的时候执行在自己的脚本是不能起动一些服务的, 执行下面的命令可以文件标记为可执行的文件

chmod +x /etc/rc.d/rc.local

5. 打开 /etc/rc.d/rc.local 文件, 在最后面添加如下脚本

/etc/init.d/tomcat 

这样 tomcat 这个脚本在开机的时候就会被执行了, 以后再这里面写启动服务的命令就可以了

6. 自启动多个 tomcat

需要配置各个 tomcat 的环境变量,在 /etc/profile 中的配置在系统服务中不生效,修改各自己的 bin 目录 catalina.sh 文件

添加如下代码:

export JAVA_HOME=/usr/java/jdk1.8.0_144
export JRE_HOME=/usr/java/jdk1.8.0_144/jre

6.1 创建自启动多个 tomcat 的 shell 脚本

# vi /etc/init.d/tomcat.sh 或者自己定义 shell 脚本位置也行(/home/sh/tomcat.sh)
#!/bin/bash
#chkconfig:  2345 08 92
#description: Start

echo “Starting Tomcat Service …”
/root/tomcat6.0/bin/startup.sh
/root/tomcat7.0/bin/startup.sh
/root/tomcat8.0/bin/startup.sh

8.  /etc/rc.d/rc.local 文件, 在最后面添加如下脚本

/home/sh/tomcat.sh

9. 如果一台服务器上 tomcat 应用和数据库在一台服务器上,开机自启动是需要数据库先启动在启动 tomcat 应用,所以命令顺序:启动数据库命令放在前面,tomcat 启动命令放在最后

# cat /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

su – oracle -lc “/u01/app/oracle/product/11.2.0/dbhome_1/bin/lsnrctl start ORCL”
su – oracle -lc /u01/app/oracle/product/11.2.0/dbhome_1/bin/dbstart

/etc/init.d/starttomcat.sh

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-21发表,共计1800字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中