建立服务文件
以nginx 为例

vim /lib/systemd/system/nginx.service  

在nginx.service 中插入一下内容

[Unit]
Description=nginx
After=network.target [Service]
Type=forking
ExecStart= 服务启动命令
ExecReload= 服务重启命令
ExecStop=服务停止命令
PrivateTmp=true [Install]
WantedBy=multi-user.target

[Unit]:服务的说明
Description:描述服务
After:描述服务类别
[Service]服务运行参数的设置
Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径
以754的权限保存在目录:/lib/systemd/system

设置开机自启动:

systemctl enable nginx.service 

相关命令

功能                                       cnetos7以前                                          cnetos7
显示所有已启动的服务            chkconfig --list                 systemctl list-units --type=service

启动某服务       service nginx start systemctl             start nginx.service 或 systemctl start nginx

停止某服务       service nginx stop systemctl             stop nginx.service 或 systemctl stop nginx

重启某服务       service nginx restart                    systemctl restart nginx.service 或 systemctl restart nginx

使某服务自动启动     chkconfig --level 3 nginx  on       systemctl enable nginx.service 或 systemctl enable nginx

使某服务不自动启动     chkconfig --level 3 nginx off    systemctl disable nginx.service 或 systemctl disable nginx

检查服务状态       service nginx status                 systemctl is-active nginx.service (仅显示是否 Active) systemctl status nginx.service (服务详细信息)

转载请注明出处:http://www.cnblogs.com/phpshen/p/6027407.html

centos 服务开机启动设置的更多相关文章

  1. CentOS程序 开机启动设置与chkconfig命令学习

    CentOS设置程序开机启动的方法: 1.启动命令添加到/etc/rc.d/rc.local 文件中, 如: vim /etc/rc.d/rc.local #!/bin/sh # # This scr ...

  2. centos设置服务开机启动

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

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

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

  4. centos 6 与 centos 7 服务开机启动、关闭设置的方法

    简单说明下 centos 6 与 centos 7 服务开机启动.关闭设置的方法: centos 6 :使用chkconfig命令即可. 我们以apache服务为例: #chkconfig --add ...

  5. (转)CentOS 7 sytemctl 自定义服务开机启动

    CentOS 7 sytemctl 自定义服务开机启动 原文:http://blog.csdn.net/ithomer/article/details/51766319 CentOS 7继承了RHEL ...

  6. 【CentOS】centos7上查看服务开机启动列表

    centos7上查看服务开机启动列表 命令: systemctl list-unit-files; 点击回车,可以向下翻页查询

  7. (转)CentOS下开机启动查看管理命令:chkconfig用法

    CentOS下开机启动查看管理命令:chkconfig用法   CentOS下开机启动查看管理的命令是:chkconfig   1. 开机启动列表查看: chkconfig --list     说明 ...

  8. centos 7 开机启动配置

    centos 7 开机启动 1 开机启动配置文件位于/usr/lib/systemd/system/ 2 nginx的配置[Unit]Description=nginx - high performa ...

  9. Redis加入Centos Linux开机启动

    Redis加入Centos Linux开机启动 网上有很多redis在linux下自动启动的例子,实现的方式很多,很多都是参考一个老外流传出来启动的例子,其实直接使用是不行,而且有很多地方有一些语法错 ...

随机推荐

  1. 对struct和class使用大括号初始化的测试

    #include <iostream> using namespace std; struct struct1{ /* struct1(){ cout<<"this ...

  2. CVTRES : fatal error CVT1100 , fatal error LNK1123:

    CVTRES : fatal error CVT1100: duplicate resource. type:DIALOG, name:901, language:0x0804LINK : fatal ...

  3. //sql过滤关键字

    //sql过滤关键字 public static bool CheckKeyWord(string sWord) { //过滤关键字 string StrKeyWord = @"select ...

  4. SVN 分支管理

    平时在工作中使用 SVN 只是限于 commit,update 这样的操作,至多再 reslove 解决一下冲突,没有用过分支管理.开发过程中一般都是一个功能开发完成之后整体进行提交,而最近在项目中有 ...

  5. loadrunner获取返回值为乱码

    找了很多方法,utf-8也设置了,还是不行,只有有转码方法了 web_reg_save_param("res2", "LB=\"msg\":\&quo ...

  6. Thinking in Java——笔记(8)

    Polymorphism The polymorphic method call allows one type to express its distinction from another, si ...

  7. P1079 Vigenère 密码

    #include <bits/stdc++.h> using namespace std; const int maxn = 1005; int main() { freopen(&quo ...

  8. Linux下安装vsftpd

    一.安装vsftpd及相关依赖包 #vsftpd安装程序 yum install vsftpd #vsftpd虚拟登陆账户必要依赖包 yum install pam* db4* 安装完之后,vsftp ...

  9. 【后台测试】Linux下小试jmeter

    ◆版权声明:本文出自胖喵~的博客,转载必须注明出处.  转载请注明出处:http://www.cnblogs.com/by-dream/p/5784288.html 前言 上一篇主要讲了在Window ...

  10. home page

    How To Set Your Home Page Step 1 – Navigate to Settings > Reading tab. Step 2 – Select A Static P ...