设置nginx和tomcat开机自动启动

  1. nginx启动命令

    bash 复制代码
        /usr/local/nginx/sbin/nginx
        ./nginx                       # ./代表从当前目录找nginx
  2. nginx停止命令

    bash 复制代码
        /usr/local/nginx/sbin/nginx -s quit
        ./nginx -s quit
  3. tomcat启动命令 /usr/local/tomcat/bin/startup.sh ./startup.sh

  4. tomcat停止命令

    arduino 复制代码
    /usr/local/tomcat/bin/shutdown.sh
    ./shutdown.sh

    设置nginx和tomcat开机自动启动要告诉操作系统nginx启动命令在哪,tomcat启动命令在哪 systemctl nginx.service/nginx

    arduino 复制代码
    cd /lib/systemd/system   //存放由操作系统管理的启动程序
    vim nginx.service     //创建一个nginx服务文件

    写入以下内容

    ini 复制代码
    [Unit]
    Description=nginx
    After=network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/nginx/sbin/nginx
    ExecReload=/usr/local/nginx/sbin/nginx -s reload
    ExecStop=/usr/local/nginx/sbin/nginx -s quit
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    创建好这个服务文件后,启动nginx就可以在任何目录中使用

    systemctl 操作 nginx.service/nginx

    bash 复制代码
    systemctl stop nginx        #停止
    systemctl restart nginx    #重启
    systemctl status nginx     #状态
    systemctl enable nginx     #允许开机自动启动
    systemctl disable nginx    #禁止开机自动启动(默认)
  5. 设置可以在任何目录中使用 systemctl 操作 tomcat 来操作 tomcat 程序 创建tomcat.service服务文件/lib/systemd/system/tomcat.service

    arduino 复制代码
    cd /lib/systemd/system   //存放由操作系统管理的启动程序
    vim tomcat.service     //创建一个tomcat服务文件

    写入以下内容

    ini 复制代码
    [Unit]
    Description=Apache Tomcat 8
    After=syslog.target network.target
    
    [Service]
    Type=forking
    ExecStart=/usr/local/tomcat/bin/startup.sh
    ExecReload=/bin/kill -s HUP $MAINPID
    ExecStop=/usr/local/tomcat/bin/shutdown.sh
    PrivateTmp=true
    
    [Install]
    WantedBy=multi-user.target

    创建好这个服务文件后,启动tomcat就可以在任何目录中使用systemctl 操作 tomcat.service/tomcat

    bash 复制代码
    systemctl stop tomcat       #停止
    systemctl restart tomcat    #重启
    systemctl status tomcat     #状态
    systemctl enable tomcat     #允许开机自动启动
    systemctl disable tomcat    #禁止开机自动启动(默认)
相关推荐
Wellijohn29 分钟前
`s += x` 到底是 O(n) 还是 O(n²)?我把 CPython 的字符串拼接拆开测了一遍
后端·python·性能优化
努力的小雨12 小时前
手里捏着纸,谁来暂停视频?我把折纸老师塞进了 AI 眼镜
后端
狗头大军之江苏分军12 小时前
《潮水漫过十七岁》倒计时
前端·javascript·后端
Wellijohn12 小时前
dict、tuple、dataclass 还是 slots?我把 6 种数据载体的 8 项开销全测了一遍
后端·python·性能优化
HarmonSir13 小时前
OpenManus 的架构解析:另一个通用 Agent 的最小内核与扩展边界
后端·架构
hsfxuebao13 小时前
Sandbox(沙箱)到底是什么?
后端
一条Go13 小时前
proto 契约:校验注解、错误码与「文案即接口」
后端·github
狗头大军之江苏分军14 小时前
《潮水漫过十七岁》好久没写了
前端·javascript·后端
苍何14 小时前
用 OiiOii Motion + Opus 5.5 做动画视频,效果猛的离谱
后端