Nginx和Tomcat的管理脚本

网友投稿 738 2023-03-09

本站部分文章、图片属于网络上可搜索到的公开信息,均用于学习和交流用途,不能代表睿象云的观点、立场或意见。我们接受网民的监督,如发现任何违法内容或侵犯了您的权益,请第一时间联系小编邮箱jiasou666@gmail.com 处理。

Nginx和Tomcat的管理脚本

一、传统模式下Nginx的启动、关闭

1、启动:/usr/local/nginx/sbin/nginx2、关闭:killall nginx3、重启:/usr/local/nginx/sbin/nginx -s reload

1、启动:/usr/local/nginx/sbin/nginx2、关闭:killall nginx3、重启:/usr/local/nginx/sbin/nginx -s reload

二、通过配置/etc/init.d/nginx来管理Nginx

#!/bin/bash  # nginx Startup script for the Nginx HTTP Server  nginxd=/usr/local/nginx/sbin/nginx  nginx_config=/usr/local/nginx/conf/nginx.conf  nginx_pid=/var/run/nginx.pid  RETVAL=0  prog="nginx"  # Source function library.  . /etc/rc.d/init.d/functions  # Source networking configuration.  . /etc/sysconfig/network  # Check that networking is up.  [ ${NETWORKING} = "no" ] && exit 0  [ -x $nginxd ] || exit 0  # Start nginx daemons functions.  start() {  if [ -e $nginx_pid ];then     echo "nginx already running...."     exit 1  fi     echo -n $"Starting $prog: "     daemon $nginxd -c ${nginx_config}     RETVAL=$?     echo     [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx     return $RETVAL  }  # Stop nginx daemons functions.  stop() {          echo -n $"Stopping $prog: "          killproc $nginxd          RETVAL=$?          echo          [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid  }  # reload nginx service functions.  reload() {      echo -n $"Reloading $prog: "      #kill -HUP `cat ${nginx_pid}`      killproc $nginxd -HUP      RETVAL=$?      echo  }  # See how we were called.  case "$1" in  start)          start          ;;  stop)          stop          ;;  reload)          reload          ;;  restart)          stop          start          ;;  status)          status $prog          RETVAL=$?          ;;  *)          echo $"Usage: $prog {start|stop|restart|reload|status|help}"          exit 1  esac  exit $RETVAL  保存并添加执行权限service nginx start    //启动Nginxservice nginx stop    //关闭Nginxservice nginx restart  //重启Nginxservice nginx status  //查看Nginx的状态添加至开机启动chkconfig --add nginxchkconfig nginx on

#!/bin/bash # nginx Startup script for the Nginx HTTP Server nginxd=/usr/local/nginx/sbin/nginx nginx_config=/usr/local/nginx/conf/nginx.conf nginx_pid=/var/run/nginx.pid RETVAL=0 prog="nginx" # Source function library. . /etc/rc.d/init.d/functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 [ -x $nginxd ] || exit 0 # Start nginx daemons functions. start() { if [ -e $nginx_pid ];then echo "nginx already running...." exit 1 fi echo -n $"Starting $prog: " daemon $nginxd -c ${nginx_config} RETVAL=$? echo [ $RETVAL = 0 ] && touch /var/lock/subsys/nginx return $RETVAL } # Stop nginx daemons functions. stop() { echo -n $"Stopping $prog: " killproc $nginxd RETVAL=$? echo [ $RETVAL = 0 ] && rm -f /var/lock/subsys/nginx /var/run/nginx.pid } # reload nginx service functions. reload() { echo -n $"Reloading $prog: " #kill -HUP `cat ${nginx_pid}` killproc $nginxd -HUP RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) reload ;; restart) stop start ;; status) status $prog RETVAL=$? ;; *) echo $"Usage: $prog {start|stop|restart|reload|status|help}" exit 1 esac exit $RETVAL 保存并添加执行权限service nginx start //启动Nginxservice nginx stop //关闭Nginxservice nginx restart //重启Nginxservice nginx status //查看Nginx的状态添加至开机启动chkconfig --add nginxchkconfig nginx on

三、传统Tomcat的开启、关闭

1、启动:/usr/local/apache-tomcat-9.0.7/bin/startup.sh2、关闭:/usr/local/apache-tomcat-9.0.7/bin/shutdown.sh

1、启动:/usr/local/apache-tomcat-9.0.7/bin/startup.sh2、关闭:/usr/local/apache-tomcat-9.0.7/bin/shutdown.sh

四、配置/etc/init.d/tomcat管理Tomcat

# tomcat startup script for the Tomcat server  . /etc/rc.d/init.d/functionsprog=tomcatJAVA_HOME=/usr/local/java/export JAVA_HOME  CATALANA_HOME=/usr/local/apache-tomcat-9.0.7/export CATALINA_HOME  case "$1" instart)    echo "Starting Tomcat..."      $CATALANA_HOME/bin/startup.sh    ;;stop)    echo "Stopping Tomcat..."      $CATALANA_HOME/bin/shutdown.sh    ;;restart)    echo "Stopping Tomcat..."      $CATALANA_HOME/bin/shutdown.sh    sleep 2    echo      echo "Starting Tomcat..."      $CATALANA_HOME/bin/startup.sh    ;;*)    echo "Usage: $prog {start|stop|restart}"      ;;esacexit 0service tomcat startservice tomcat stopservice tomcat restartchkconfig --add tomcatchkconfig tomcat on

# tomcat startup script for the Tomcat server . /etc/rc.d/init.d/functionsprog=tomcatJAVA_HOME=/usr/local/java/export JAVA_HOME CATALANA_HOME=/usr/local/apache-tomcat-9.0.7/export CATALINA_HOME case "$1" instart) echo "Starting Tomcat..." $CATALANA_HOME/bin/startup.sh ;;stop) echo "Stopping Tomcat..." $CATALANA_HOME/bin/shutdown.sh ;;restart) echo "Stopping Tomcat..." $CATALANA_HOME/bin/shutdown.sh sleep 2 echo echo "Starting Tomcat..." $CATALANA_HOME/bin/startup.sh ;;*) echo "Usage: $prog {start|stop|restart}" ;;esacexit 0service tomcat startservice tomcat stopservice tomcat restartchkconfig --add tomcatchkconfig tomcat on

上一篇:Nginx+Tomcat+Keepalived实现高可用web集群
下一篇:网络告警关联分析报告(网络告警关联分析报告范文)
相关文章

 发表评论

暂时没有评论,来抢沙发吧~