Centos 系统服务脚本目录:

/usr/lib/systemd/

有系统(system)和用户(user)之分,

如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即:

/lib/systemd/system/

反之,用户登录后才能运行的程序,存在用户(user)里

服务以.service结尾。

这边以nginx开机运行为例

1.建立服务文件

vim /lib/systemd/system/nginx.service

  1. [Unit]
  2. Description=nginx
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/www/lanmps/init.d/nginx start
  7. ExecReload=/www/lanmps/init.d/nginx restart
  8. ExecStop=/www/lanmps/init.d/nginx  stop
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target

[Unit]:服务的说明

Description:描述服务
After:描述服务类别

[Service]服务运行参数的设置

Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径

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

2.保存目录

以754的权限保存在目录:/lib/systemd/system

3.设置开机自启动

systemctl enable nginx.service

4.其他命令

任务 旧指令 新指令
使某服务自动启动 chkconfig --level 3 httpd  on              systemctl enable httpd.service
使某服务不自动启动 chkconfig --level 3 httpd off systemctl disable httpd.service
检查服务状态 service httpd status systemctl status httpd.service (服务详细信息) 
systemctl is-active httpd.service (仅显示是否 Active)
显示所有已启动的服务 chkconfig --list systemctl list-units --type=service
启动某服务 service httpd start systemctl start httpd.service
停止某服务 service httpd stop systemctl stop httpd.service
重启某服务 service httpd restart systemctl restart httpd.service

启动nginx服务

systemctl start nginx.service

设置开机自启动

systemctl enable nginx.service

停止开机自启动

systemctl disable nginx.service

查看服务当前状态

systemctl status nginx.service

重新启动服务

systemctl restart nginx.service

查看所有已启动的服务

systemctl list-units --type=service

CentOS 7.x设置自定义开机启动,添加自定义系统服务的更多相关文章

  1. (转)Mysql数据库之Binlog日志使用总结CentOS 7.x设置自定义开机启动,添加自定义系统服务

    Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分, 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: li ...

  2. CentOS 7 设置自定义开机启动,添加自定义系统服务

    详细文档,http://www.linuxidc.com/Linux/2015-04/115937.htm 摘自: http://www.centoscn.com/CentOS/config/2015 ...

  3. CentOS7设置自定义开机启动,添加自定义系统服务

    Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分,如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: lib ...

  4. systemd添加自定义系统服务设置自定义开机启动

    1.服务权限 systemd有系统和用户区分:系统(/user/lib/systemd/system/).用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放 ...

  5. centos设置服务开机启动

    Linux CentOS设置服务开机启动的方法 by 天涯 · 2013/07/26 CentOS设置服务开机启动的两种方法 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHa ...

  6. CentOS设置服务开机启动的方法

    CentOS设置服务开机启动的两种方法 1.利用 chkconfig 来配置启动级别在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd.mysqld.postfix等,安装后 ...

  7. linux开机自启动设置,自定义开机启动模版,nginx开机自启动服务

    /etc/init.d 目录,我们把shell脚本放在这个目录下来作为启动脚本 都是用来放服务脚本的,当Linux启动时,会寻找这些目录中的服务脚本,并根据脚本的run level确定不同的启动级别. ...

  8. centos下设置nodejs开机启动

    node环境的安装便不再赘述了,网上有很多教程,也非常简单. 上一篇博客介绍了用nginx代理nodejs.这一篇是使用pm2实现nodejs的自动重启. 什么是pm2? 如官网介绍的,pm2是nod ...

  9. linux自定义开机启动服务和chkconfig使用方法

    linux自定义开机启动服务和chkconfig使用方法 1. 服务概述在linux操作系统下,经常需要创建一些服务,这些服务被做成shell脚本,这些服务需要在系统启动的时候自动启动,关闭的时候自动 ...

随机推荐

  1. C# 构建动态树

    public class Tree { public Guid Id { get; set; } public string Url { get; set; } public Guid? Parent ...

  2. 【spoj705】 Distinct Substrings

    [题目描述] 给定一个字符串,计算其不同的子串个数. [输入格式] 一行一个仅包含大写字母的字符串,长度<=50000 [输出格式] 一行一个正整数,即不同的子串个数. [样例输入] ABABA ...

  3. oracle 学习笔记(一)

    1. 数据库原理 1.1. 数据库简介 1.1.1. 文件存储 对数据的存储需求一直存在.保存数据的方式,经历了手工管理.文件管理等阶段,直至数据库管理阶段. 文件存储方式保存数据的弊端: 缺乏对数据 ...

  4. Linux下编译安装MariaDB

    MariaDB是MySQL的一个开源分支,主要是社区在维护,并且完全兼容MySQL,并且可以很方便的称为MySQL的替代,MariaDB的诞生正是出自MySQL创始人Michael Widenius之 ...

  5. [转]Android静态变量的生命周期

    原文地址:https://my.oschina.net/jerikc/blog/137207 Android是用Java开发,其静态变量的生命周期遵守Java的设计.我们知道静态变量是在类被load的 ...

  6. disconf搭建

    简介: Distributed Configuration Management Platform(分布式配置管理平台) 它是百度的一套完整的基于zookeeper的分布式配置统一解决方案,具有如下特 ...

  7. WinForm 遍历用户控件里CheckBox

    1.常用调用方法 public partial class UCRights : UserControl { private readonly int LOCATIONY; private DataT ...

  8. RakNet基本教程

    官方网址:http://www.jenkinssoftware.com/raknet/manual/tutorialsample3.html Tutorial code sample 3 Remote ...

  9. WPF中运行时使内容可以上下左右被鼠标拖动应该怎么做?

    <Window x:Class="testGridSplitter.MainWindow" xmlns="http://schemas.microsoft.com/ ...

  10. js 数组删去重复的加上没有的元素

    为了一个数组的删除操作竟然费了一个多小时,下面分享一下我的代码: 代码功能:判断数组里是否有我要看的元素,如果没有就添加到数组里,如果有就去掉. var selectArr=[]; function ...