一、启动脚本 /etc/rc.local 启动

最简单的一种方式,在启动脚本 /etc/rc.local (其实 /etc/rc.local 是/etc/rc.d/rc.local 的软链接文件,实际的脚本文件为 /etc/rc.d/rc.local)中添加要启动的程序。当然需要注意将 /etc/rc.d/rc.local 和 /etc/rc.local 添加启动权限。 
    这种方式虽然简单,但是并不能保证程序在其依赖的系统服务之后启动,所以有可能会启动不成功。

二、编写启动服务.service

centos支持为自定义的服务编写service文件。centos系统服务脚本目录:/usr/lib/systemd。有系统(system)和用户(user) 之分,如需要开机没有登录的情况下就能运行的程序,存在系统服务里/lib/systemd/system/;反之,需要用户登录之后才能运行的程序,存在用户里/lib/systemd/user/,服务以 .service 结尾。

以ngix 开机运行为例: 
1. 建立服务文件 
nginx.service

[Unit]
Description=nginx
After=network.target [Service]
Type=forking
ExecStart=/www/lanmps/init.d/nginx start
ExecReload=/www/lanmps/init.d/nginx restart
ExecStop=/www/lanmps/init.d/nginx stop
PrivateTmp=true [Install]
WantedBy=multi-user.target

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

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

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

2.保存目录 
以754的权限保存在目录 /lib/systemd/system 中。

3. 设置开机自启动 
systemctl enable nginx.service

其他相关命令

任务 旧指令 新指令
使某项服务自启动 chkconfig --level 3 httpd on systemctl enable httpd.service
使某项服务不自启动 chkconfig --level 3 httpd off systemctl disable httpd.service
检查服务状态 serivce httpd status systemctl status httpd.service
显示已经启动的服务 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 开机启动服务的更多相关文章

  1. centos 开机启动服务 systemctl

    systemctl 实现开机自启服务 转载起一个好听的名字 最后发布于2018-06-26 13:49:06 阅读数 13473  收藏 展开 systemctl是RHEL 7 的服务管理工具中主要的 ...

  2. (转) CentOS 7添加开机启动服务/脚本

    CentOS 7添加开机启动服务/脚本 原文:http://blog.csdn.net/wang123459/article/details/79063703 一.添加开机自启服务 在CentOS 7 ...

  3. centos 7 开机启动服务项优化

    1. 使用 systemctl list-unit-files 可以查看启动项 systemctl list-unit-files | grep enable 过滤查看启动项如下 abrt-ccpp. ...

  4. Hortonworks HDP Sandbox定制(配置)开机启动服务(组件)

    定制Hortonworks HDP开机启动服务能够这样做:本文原文出处: http://blog.csdn.net/bluishglc/article/details/42109253 严禁不论什么形 ...

  5. Centos7.x:开机启动服务的配置和管理

    一.开机启动服务的配置 1.创建服务配置(权限754) vim /usr/lib/systemd/system/nginx.service 文件内容解释 [Unit]:服务的说明Description ...

  6. linux chkconfig添加开机启动服务

    --add:增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据: --del:删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的 ...

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

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

  8. (转)linux自定义开机启动服务和chkconfig使用方法

    原文:https://www.cnblogs.com/jimeper/archive/2013/03/12/2955687.html linux自定义开机启动服务和chkconfig使用方法 1. 服 ...

  9. Linux创建Jenkins启动脚本以及开机启动服务

    1.jenkins.sh #!/bin/bash ###主要目的用于开机启动服务,不然 启动jenkins.war包没有java -jar的权限 JAVA_HOME=/usr/lib/jdk1.8.0 ...

随机推荐

  1. Poj 1276 Cash Machine 多重背包

    Cash Machine Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26172   Accepted: 9238 Des ...

  2. html5,单击文字自动获得焦点

    <p><label for=""></label>这样单击后自动获得焦点</p>

  3. PARENT VIEW INVALIDATE

    如果启动display list,parentview 调用invalidate,子view是不会是去调用onDraw的,因为直接调用displaylist了,如果parentview认为子view应 ...

  4. c# winform 调用js

    1. 在winform中加入一个 WebBrowser 控件: 2. webBrowser控件加载html文件,html文件中包含了js代码, 代码如下(必须在 InitializeComponent ...

  5. apache2.4配置Django1.7运行环境

    系统环境Centos 6.5 这篇文章不适用6以下的系统,因为会碰到这个错误 [Mon Sep 22 18:13:02 2014] [error] [client 10.209.75.90] Trun ...

  6. 学习Linux系列--布署常用服务

    本系列文章记录了个人学习过程的点点滴滴. 回到目录 10.mediawiki 知名开源维基框架,我用来构建自己的知识库. 在mediawiki中新建一个http.conf文件 sudo vim /op ...

  7. [课程设计]Scrum 3.5 多鱼点餐系统开发进度(修复Bug&美化页面)

    Scrum 3.5 多鱼点餐系统开发进度(修复Bug&美化页面) 1.团队名称:重案组 2.团队目标:长期经营,积累客户充分准备,伺机而行 3.团队口号:矢志不渝,追求完美 4.团队选题:餐厅 ...

  8. 课堂 表单验证 JavaScript js

    页面加载完才开始执行代码要加上 window.onload = function{ } 获取元素节点 var uesrname = document.getElementById("user ...

  9. 函数动态参数实现format

    变量赋值一种是字符串格式化,一种是通过format的方式 1.字符串格式化 s="i am %s,age %d"%('Jasper',23)print(s) 打印输出:i am J ...

  10. git 设置不需要输入密码

    https方式每次都要输入密码,按照如下设置即可输入一次就不用再手输入密码的困扰而且又享受https带来的极速 设置记住密码(默认15分钟): git config --global credenti ...