设置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    #禁止开机自动启动(默认)
相关推荐
小厂永远得不到的男人14 分钟前
基于 Spring Validation 实现全局参数校验异常处理
java·后端·架构
roamingcode1 小时前
Claude Code NPM 包发布命令
前端·npm·node.js·claude·自定义指令·claude code
川石课堂软件测试2 小时前
技术干货|使用Prometheus+Grafana监控Tomcat实例详解
redis·功能测试·单元测试·tomcat·测试用例·grafana·prometheus
gc_22992 小时前
运行npm run命令报错“error:0308010C:digital envelope routines::unsupported”
npm·node.js
毅航4 小时前
从原理到实践,讲透 MyBatis 内部池化思想的核心逻辑
后端·面试·mybatis
展信佳_daydayup5 小时前
02 基础篇-OpenHarmony 的编译工具
后端·面试·编译器
Always_Passion5 小时前
二、开发一个简单的MCP Server
后端
用户721522078775 小时前
基于LD_PRELOAD的命令行参数安全混淆技术
后端
笃行3505 小时前
开源大模型实战:GPT-OSS本地部署与全面测评
后端
知其然亦知其所以然5 小时前
SpringAI:Mistral AI 聊天?一文带你跑通!
后端·spring·openai