zoukankan      html  css  js  c++  java
  • 服务器添加 Systemd 自定义服务

    添加 Systemd 自定义服务

    一、以nginx为例

    使用yum命令安装的nginx

    Systemd服务文件以.service结尾,比如现在要建立nginx为开机启动,如果用yum install命令安装的,yum命令会自动创建nginx.service文件,直接用命令:

    systemcel enable nginx.service		//开机自启
    

    使用源码编译安装的

    1、手动创建nginx.service服务文件。并将其放入 /lib/systemd/system 文件夹中。

    nginx.service内容如下:

    [Unit]
    Description=nginx
    After=network.target
     
    [Service]
    Type=forking
    ExecStart=/data/nginx/sbin/nginx
    ExecReload=/data/nginx/sbin/nginx -s reload
    ExecStop=/data/nginx/sbin/nginx -s quit
    PrivateTmp=true
     
    [Install]
    WantedBy=multi-user.target
    
    

    PS: 注意上面的ExecStart/ExecReload/ExecStop 必须 以自己的为主
    所对应的key说明

    Description:描述服务
    After:描述服务类别
    [Service]服务运行参数的设置
    Type=forking是后台运行的形式
    ExecStart为服务的具体运行命令
    ExecReload为重启命令
    ExecStop为停止命令
    PrivateTmp=True表示给服务分配独立的临时空间
    注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
    [Install]运行级别下服务安装的相关设置,可设置为多用户,即系统运行级别为3
    
    保存退出。
    
    

    2、设置开机启动

    systemctl enable nginx.service
    

    其他服务命令

    systemctl start nginx.service (启动nginx服务)
    systemctl stop nginx.service (停止nginx服务)
    systemctl enable nginx.service (设置开机自启动)
    systemctl disable nginx.service (停止开机自启动)
    systemctl status nginx.service (查看服务当前状态)
    systemctl restart nginx.service (重新启动服务)
    systemctl list-units --type=service (查看所有已启动的服务)
    
    
  • 相关阅读:
    win10 uwp 读取保存WriteableBitmap 、BitmapImage
    win10 uwp 读取保存WriteableBitmap 、BitmapImage
    win10 uwp 按下等待按钮
    win10 uwp 按下等待按钮
    win10 uwp 右击选择 GridViewItem
    win10 uwp 右击选择 GridViewItem
    PHP array_column() 函数
    PHP array_chunk() 函数
    PHP array_change_key_case() 函数
    PHP array() 函数
  • 原文地址:https://www.cnblogs.com/buzheng/p/13552523.html
Copyright © 2011-2022 走看看