centos 开机启动服务
一、启动脚本 /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 开机启动服务的更多相关文章
- centos 开机启动服务 systemctl
systemctl 实现开机自启服务 转载起一个好听的名字 最后发布于2018-06-26 13:49:06 阅读数 13473 收藏 展开 systemctl是RHEL 7 的服务管理工具中主要的 ...
- (转) CentOS 7添加开机启动服务/脚本
CentOS 7添加开机启动服务/脚本 原文:http://blog.csdn.net/wang123459/article/details/79063703 一.添加开机自启服务 在CentOS 7 ...
- centos 7 开机启动服务项优化
1. 使用 systemctl list-unit-files 可以查看启动项 systemctl list-unit-files | grep enable 过滤查看启动项如下 abrt-ccpp. ...
- Hortonworks HDP Sandbox定制(配置)开机启动服务(组件)
定制Hortonworks HDP开机启动服务能够这样做:本文原文出处: http://blog.csdn.net/bluishglc/article/details/42109253 严禁不论什么形 ...
- Centos7.x:开机启动服务的配置和管理
一.开机启动服务的配置 1.创建服务配置(权限754) vim /usr/lib/systemd/system/nginx.service 文件内容解释 [Unit]:服务的说明Description ...
- linux chkconfig添加开机启动服务
--add:增加所指定的系统服务,让chkconfig指令得以管理它,并同时在系统启动的叙述文件内增加相关数据: --del:删除所指定的系统服务,不再由chkconfig指令管理,并同时在系统启动的 ...
- linux自定义开机启动服务和chkconfig使用方法
linux自定义开机启动服务和chkconfig使用方法 1. 服务概述在linux操作系统下,经常需要创建一些服务,这些服务被做成shell脚本,这些服务需要在系统启动的时候自动启动,关闭的时候自动 ...
- (转)linux自定义开机启动服务和chkconfig使用方法
原文:https://www.cnblogs.com/jimeper/archive/2013/03/12/2955687.html linux自定义开机启动服务和chkconfig使用方法 1. 服 ...
- Linux创建Jenkins启动脚本以及开机启动服务
1.jenkins.sh #!/bin/bash ###主要目的用于开机启动服务,不然 启动jenkins.war包没有java -jar的权限 JAVA_HOME=/usr/lib/jdk1.8.0 ...
随机推荐
- 18.有一个网页地址, 比如PHP开发资源网主页: http://www.phpres.com/index.html,如何得到它的内容?
方法1(对于PHP5及更高版本): $readcontents = fopen("http://www.phpres.com/index.html", "rb" ...
- android aidl
参考: http://blog.csdn.net/u014614038/article/details/48399935 本文提供了一个关于AIDL使用的简单易懂的例子,分为客户端和服务端两部分,分别 ...
- html5 webDatabase 存储中sql语句执行可嵌套使用
html5 webDatabase 存储中sql语句执行可嵌套使用,代码如下: *); data.transaction(function(tx){ tx.executeSql("creat ...
- 二十四、JDK1.5新特性---泛型
由于本人认知有限,泛型在使用上没有太大压力,但是尚未具备详细介绍泛型的能力,因此本文只是粗略的描述泛型的相关知识,在以后的学习过程中会对这篇文章进行修改,希望这篇文章不会给读者带来迷惑,特此声明 什么 ...
- linux 使用 rz 和 sz 命令
linux系统 root权限 lrzsz安装包 ①. 安装 编译安装 root 账号登陆后,依次执行以下命令: tar zxvf lrzsz-.tar.gz cd lrzsz- ./configure ...
- 使用js倒计时还有几天及计时过了几天
公司主营业务是体育赛事为主的:尤其是足球赛事.现正值2016法国欧洲杯:之前忙于做欧洲杯专题没时间总结.现分享一个工作中需求带来的经历. 需求是:从现在开始倒计时欧洲杯还有多久开赛:当开赛之后开始计算 ...
- [课程设计]任务进度条&开发日志目录
任务进度条&开发日志目录 周期 时间 任务 Sprint One 11.14 ● Scrum团队分工及明确任务1.0 Sprint One 11.15 ● Scr ...
- sql常用单行函数
学到数据库了,小记一下的喽~~~>>>>常用的单行函数 select * from employees 查询所有 select first_name,lower(first_n ...
- python 学习随笔
要求: 用户输入一个数,比如输入387. 需要把387打乱,然后将这三个数组合成最大数输出. 如果最大值和用户输入的等大,输出-1. 方法一: #!/user/bin/env python # _*_ ...
- Auty 2017——WebMonitor接口检测平台
[本文出自天外归云的博客园] 2016Auty诞生 Auty接口测试框架系列 2017一个新的开始 今天早上决定要做一个接口检测平台,现在是2017.1.5日凌晨2:12.我在网易北京研发中心,准备睡 ...