• Centos7 systemctl的使用


    CentOS7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,需要开机不登陆就能运行的程序,存在系统服务里,即:/usr/lib/systemd/system目录下.这样说吧 ,它融合之前service和chkconfig的功能于一体!!!

    说明

    CentOS7的每一个服务以.service结尾,一般会分为3部分:[Unit]、[Service]和[Install]

    • [Unit] 服务的说明
      • Description 描述服务
      • After 描述服务类别
    • [Service] 服务的关键,是服务的一些具体运行参数的设置
      • Type=forking是后台运行的形式
      • User=users是设置服务运行的用户
      • Group=users是设置服务运行的用户组
      • PIDFile为存放PID的文件路径
      • ExecStart为服务的具体运行命令
      • ExecReload为重启命令
      • ExecStop为停止命令
      • PrivateTmp=True表示给服务分配独立的临时空间

    注意:[Service]部分的启动、重启、停止命令全部要求使用绝对路径,使用相对路径则会报错!

    • [Install] 部分是服务安装的相关设置,可设置为多用户的

    栗子

    就拿tomcat为栗子吧

    首先

    vim /usr/lib/systemd/system/tomcat.service

    然后加入内容

    [Unit]
    Description=java tomcat project
    After=tomcat.service

    [Service]
    Type=forking
    大专栏  Centos7 systemctl的使用>User=users
    Group=users
    PIDFile=/usr/local/tomcat/tomcat.pid
    ExecStart=/usr/local/tomcat/bin/startup.sh
    ExecReload=
    ExecStop=/usr/local/tomcat/bin/shutdown.sh
    PrivateTmp=true

    [Install]
    WantedBy=multi-user.target

    添加可执行权限

    chmod 754 /usr/lib/systemd/system/tomcat.service

    然后就可以使用了

    systemctl start  tomcat.service

    常规的操作

    systemctl is-enabled xxx.service  //查询服务是否开机启动
    systemctl enable xxx.service //开机运行服务
    systemctl disable xxx.service //取消开机运行
    systemctl start xxx.service //启动服务
    systemctl stop xxx.service //停止服务
    systemctl restart xxx.service //重启服务
    systemctl reload xxx.service //重新加载服务配置文件
    systemctl status xxx.service //查询服务运行状态
    systemctl --failed //显示启动失败的服务
    systemctl list-unit-files|grep enabled //查看已启动的服务列表

    只能说俩字 niubi。

  • 相关阅读:
    codeforces#1343E. Weights Distributing(bfs)
    Windows编程调试技巧-控制台调试
    Windos编程中窗口的尺寸cxClient和cyClient初始化的问题
    windows下pip安装python模块时报错总结
    .md即markdown文件的基本常用编写语法(图文并茂)
    如何转载cnsd的博客
    codeforces#1332F. Independent Set(树上dp)
    codeforces#1333 E. Road to 1600(构造)
    codeforces#1329C
    codeforces#1293E. Xenon's Attack on the Gangs(树上dp)
  • 原文地址:https://www.cnblogs.com/lijianming180/p/12361092.html
Copyright © 2020-2023  润新知