• 装tomcat和nginx心得


    开机启动tomcat

    1:在/etc/rc.d/init.d目录下生成一个文件tomcat8080

    2:在文件里添加如下内

    #!/bin/bash
    #2345 linux运行级别
    #10开机启动优先级,数值越大越排在前面,最大值100
    #90关机优先级
    #chkconfig:  2345 10 90
    #description: tomcat8080 start....
    start()
    {
        echo 'tomcat8080 start.....'
    #    tomcat 启动shell位置
        sh "/usr/tomcat/bin/startup.sh"
        return     1
    }
    
    stop()
    {
        echo 'tomcat8080 stop.....'
        sh "/usr/tomcat/bin/shutdown.sh"
        return 1
    
    }
    
    restart()
    {
        stop
        start
        return 1
    
    }
    
    case "$1" in
        start)
              start
            exit 1
              ;;
        stop)
            stop
             exit 1
            ;;
        restart)
            restart
            exit 1
            ;;
        *)
            echo "no option"
            exit 1
            ;;
    esac

    修改文件权限

    chmod 755 tomcat8080

    添加到开机启动的服务中

    chkconfig --add tomcat8080

    至于为什么要这样写启动文件

    service 命令会扫描/etc/init.d

    比如 service tomcat8080 start 这个时候运行的是我们自己写的shell,start是参数,tomcat8080文件那样写是为了兼容service命令

    nginx开机启动脚本如下

    #!/bin/bash
    #chkconfig: 2345 10 90
    #description: "nginx80 start...."
    #nginx who use 80 port
    #install direction is /usr/local/nginx
    #start shell is in /usr/local/nginx/sbin
    
    start()
    {
        nginx -c /usr/local/nginx/conf/nginx.conf
        return 1
    }
    
    stop()
    {
        nginx -s stop
        return 1
    }
    quit()
    {
        nginx -s quit
    }
    restart()
    {
        nginx -s reload
        return 1
    }
    status()
    {
    # no status     
    #     ps -ef | grep nginx
        return 1
    }
    
    
    case $1 in
        start)
            start
            exit 1
            ;;
        stop)
            stop
            exit 1
            ;;
        quit)
            quit
            exit 1
            ;;
        status)
            status
            exit 1
            ;;
        restart)
            restart
            exit 1
            ;;
        *)
            echo 'nginix service no options ' $1
    esac

        Linux下的7个运行级别:

    0系统停机状态,系统默认运行级别不能设置为0,否则不能正常启动,机器关闭。

    1单用户工作状态,root权限,用于系统维护,禁止远程登陆,就像Windows下的安全模式登录。

    2多用户状态,没有NFS支持。

    3完整的多用户模式,有NFS,登陆后进入控制台命令行模式。

    4系统未使用,保留一般不用,在一些特殊情况下可以用它来做一些事情。例如在笔记本电脑的电池用尽时,可以切换到这个模式来做一些设置。

    5X11控制台,登陆后进入图形GUI模式,X Window系统。

    6系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动。运行init 6机器就会重启。

  • 相关阅读:
    AE 线编辑
    ArcEngine判断要素(feature)是否为multipart feature及分解(炸开)代码
    AE二次开发技巧之撤销、重做
    ArcEngine数据编辑--选择要素
    java语言体系的技术简介之JSP、Servlet、JDBC、JavaBean(Application)
    MVC开发模式详解
    数据库设计中常见表结构的设计技巧
    Eclipse 保存文件时自动格式化代码
    优化你的java代码性能
    Hibernate 与mybatis的区别
  • 原文地址:https://www.cnblogs.com/shuiyonglewodezzzzz/p/5679135.html
Copyright © 2020-2023  润新知