linux tomcat7,nginx开机自启

linux tomcat7开机自启?/centos7 tomcat开机自启?
linux nginx开机自启?/centos7 nginx开机自启?
类似很多上面的这种开机自启问题都可以通过下面的方法解决,这两天查询了很多资料,试了很多方法。终于解决了。
比如想要开机自启动tomcat7,最简单的方法就是修改/etc/rc.d/rc.local文件。在最后添加
    export JAVA_HOME=/usr/cqzdkj/jdk/jdk1.7.0_79  
    export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.  
    export PATH=$PATH:$JAVA_HOME/bin  
    export CATALINA_HOME=/usr/cqzdkj/tomcat/apache-tomcat-7.0.42      
    /usr/cqzdkj/tomcat/apache-tomcat-7.0.42/bin/startup.sh  

通过上面的就可以实现开机的时候tomcat自启动。当然还有一个重要的事情要做。就是给rc.local文件一个可执行的权限:
    <span style="color:#ff0000;">chmod +x /etc/rc.d/rc.local</span>  
必须执行上一步,因为centos7开始,rc.local权限被降低了。当然前面的那个jdk的路径和tomcat的路径信息得按照你实际的来哦。
同理,如果想要启动nginx,就直接在rc.local文件里面添加:
    /usr/local/nginx/sbin/nginx  
反正就是你的nginx的路径。注意,这个是nginx安装后的路径,不是解压的路径。要你手动能够启动才能够执行开机自启动的哦。
下面贴下我整个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.    
    export JAVA_HOME=/usr/cqzdkj/jdk/jdk1.7.0_79  
    export CLASSPATH=$CLASSPATH:$JAVA_HOME/lib/tools.jar:$JAVA_HOME/lib/dt.jar:.  
    export PATH=$PATH:$JAVA_HOME/bin  
    export CATALINA_HOME=/usr/cqzdkj/tomcat/apache-tomcat-7.0.42  
      
      
    /usr/cqzdkj/tomcat/apache-tomcat-7.0.42/bin/startup.sh  
    /usr/local/nginx/sbin/nginx  
    touch /var/lock/subsys/local  
  我觉得上面有一行特别重要:
  提示我们必须chmod +x /etc/rc.d/rc.local下才能正常开机自启!!!
二、添加开机自启脚本
在centos7中增加脚本有两种常用的方法,以脚本autostart.sh为例:
#!/bin/bash
#description:开机自启脚本
/usr/local/tomcat/bin/startup.sh  #启动tomcat
方法一
赋予脚本可执行权限(/opt/script/autostart.sh是你的脚本路径)
chmod  +x /opt/script/autostart.sh
打开/etc/rc.d/rc/local文件,在末尾增加如下内容
/opt/script/autostart.sh
在centos7中,/etc/rc.d/rc.local的权限被降低了,所以需要执行如下命令赋予其可执行权限
chmod +x /etc/rc.d/rc.local
方法二
将脚本移动到/etc/rc.d/init.d目录下
mv /opt/script/autostart.sh /etc/rc.d/init.d
增加脚本的可执行权限
chmod+x  /etc/rc.d/init.d/autostart.sh
添加脚本到开机自动启动项目中
cd  /etc/rc.d/init.d
chkconfig --add autostart.sh
chkconfig autostart.sh on
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值