建立服务文件
以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. 修改cms 管理栏目路径

    Foosun.SQLServerDAL.Pagination throw new Exception("没有找到SQL");

  2. IOS第13天(1,私人通讯录,登陆功能,界面的跳转传值,自定义cell,编辑界面)

    ******HMLoginViewController 登陆的界面 #import "HMLoginViewController.h" #import "MBProgre ...

  3. PG, Pool之间的一些数量关系

    先说一下我的环境: Ceph cluster中包含6台OSD节点 (osd.0 - 5), 一共有10个Pool (0 - 9), 这些Pool共享了144个PG (这个数字是所有Pool的PG_SI ...

  4. JavaScript 入门教程一 开篇介绍

    一.JavaScript 刚开始是为了解决一些由服务器端进行的验证而开发的前端语言.在宽带还不普及的90年代,当用户辛苦输入很多信息并提交给服务器后,等了漫长的时间,等到的不是提交成功的提示而是某些必 ...

  5. A trip through the Graphics Pipeline 2011_06_(Triangle) rasterization and setup

    Welcome back. This time we’re actually gonna see triangles being rasterized – finally! But before we ...

  6. LightOj 1289 - LCM from 1 to n(LCM + 素数)

    题目链接:http://lightoj.com/volume_showproblem.php?problem=1289 题意:求LCM(1, 2, 3, ... , n)%(1<<32), ...

  7. ios开发xcode中设置代码块

    在开发中有很多重复的代码,很多开发者把常用的代码做成代码块提高开发效率. 在xcode里选中代码块的时候总是很不容易,点击选中的代码(文字),不要移动和松开鼠标左键,当竖线变成像拉长了的x(我也不知道 ...

  8. TCP/IP协议 三次握手与四次挥手

    一.TCP报文格式 TCP/IP协议的详细信息参看<TCP/IP协议详解>三卷本.下面是TCP报文格式图: 图1 TCP报文格式 上图中有几个字段需要重点介绍下:        (1)序号 ...

  9. 显示HTML文本

    + (NSAttributedString*)getAttributedStringFromHtmlString:(NSString*)htmlString{ return [[NSAttribute ...

  10. 【Android测试】【第十二节】Uiautomator——API详解

    ◆版权声明:本文出自carter_dream的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/4921701.html 简单的例子 以一个 ...