linux中添加tomcat,mysql,apache自动启动

4 篇文章 0 订阅

        本来就是个很简单的事情,不过linux接触得少,所以在这里记录一下,也可能方便到需要得人.

原因,由于公司的几个项目是部署到别人管理的服务器上,而且用的好像是虚拟平台(虚拟机), 出现过几次平台重启导致应用down掉的情况, 被客户投诉才发现这个问题, 所以使用添加开机启动项目来解决这个现象.

       在 /etc/rc.local 文件中可以添加需要开机后执行的命令行.

环境 red had 5.10 64位, mysql5.1 apache2

vi /etc/rc.local


 #!/bin/sh

#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local
/usr/local/apache2/bin/apachectl start
sh /usr/tomcatGdxr/bin/startup.sh


但是在另外一台服务器上测试出问题了, tomcat启动失败. 提示什么网络不可达.


感觉是tomcat读取变量的问题,于是在tomcat/bin 目录下, 创建了一个 auto-startup.sh 文件,

touch auto-startup.sh

chmod +x auto-startup.sh

vi auto-startup.sh

export JAVA_HOME=/usr/java/jdk1.7.0_21
export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.  
export PATH=$JAVA_HOME/bin:$PATH  
export CATALINA_HOME=/usr/local/tomcat/
/usr/local/tomcat/bin/catalina.sh start


然后再把这个auto-startup.sh放到rc.local中,

但还是偶尔会出现项目启动时数据库连接失败的情况.

为了保险起见,于是在mysql start之后 sleep 30秒, 重启reboot了几次也成功了.


vi /etc/rc.local


 #!/bin/sh

#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

touch /var/lock/subsys/local

/etc/init.d/mysqld start

sleep 30s

/usr/tomcatGdxr/bin/auto-startup.sh

sleep 30s
/usr/local/apache2/bin/apachectl start




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

it夜猫who

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值