CentOS 7.x设置自定义开机启动,添加自定义系统服务
Centos 系统服务脚本目录:
/usr/lib/systemd/
有系统(system)和用户(user)之分,
如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即:
/lib/systemd/system/
反之,用户登录后才能运行的程序,存在用户(user)里
服务以.service结尾。
这边以nginx开机运行为例
1.建立服务文件
vim /lib/systemd/system/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
[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设置自定义开机启动,添加自定义系统服务的更多相关文章
- (转)Mysql数据库之Binlog日志使用总结CentOS 7.x设置自定义开机启动,添加自定义系统服务
Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分, 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: li ...
- CentOS 7 设置自定义开机启动,添加自定义系统服务
详细文档,http://www.linuxidc.com/Linux/2015-04/115937.htm 摘自: http://www.centoscn.com/CentOS/config/2015 ...
- CentOS7设置自定义开机启动,添加自定义系统服务
Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分,如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: lib ...
- systemd添加自定义系统服务设置自定义开机启动
1.服务权限 systemd有系统和用户区分:系统(/user/lib/systemd/system/).用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放 ...
- centos设置服务开机启动
Linux CentOS设置服务开机启动的方法 by 天涯 · 2013/07/26 CentOS设置服务开机启动的两种方法 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHa ...
- CentOS设置服务开机启动的方法
CentOS设置服务开机启动的两种方法 1.利用 chkconfig 来配置启动级别在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd.mysqld.postfix等,安装后 ...
- linux开机自启动设置,自定义开机启动模版,nginx开机自启动服务
/etc/init.d 目录,我们把shell脚本放在这个目录下来作为启动脚本 都是用来放服务脚本的,当Linux启动时,会寻找这些目录中的服务脚本,并根据脚本的run level确定不同的启动级别. ...
- centos下设置nodejs开机启动
node环境的安装便不再赘述了,网上有很多教程,也非常简单. 上一篇博客介绍了用nginx代理nodejs.这一篇是使用pm2实现nodejs的自动重启. 什么是pm2? 如官网介绍的,pm2是nod ...
- linux自定义开机启动服务和chkconfig使用方法
linux自定义开机启动服务和chkconfig使用方法 1. 服务概述在linux操作系统下,经常需要创建一些服务,这些服务被做成shell脚本,这些服务需要在系统启动的时候自动启动,关闭的时候自动 ...
随机推荐
- MiniProfiler
1.安装MiniProfiler包 PM> Install-Package MiniProfiler 2.在Views下的web.config中引入命名空间: <pages pageBas ...
- ubuntu下C++连接mysql数据库
参考了该博客的做法:http://zhmy.michael.blog.163.com/blog/static/861578792012101244715692/ 1.安装mysql: sudo apt ...
- php下载远程文件方法~
直接上代码: getFile("http://easyread.ph.126.net/N8gDl6ayo5wLgKbgT21NZQ==/7917056565549478184.jpg&quo ...
- CRUD操作
1.增加 insert into 表名 values(列的值,列的值) insert into 表名(列名,列名)valuse(值,值) 2.删除 delete from 表明 delete from ...
- PHP window下安装Spl_Types模块
1. Window下,Spl_Types的模块的下载地址:http://pecl.php.net/package/SPL_Types/0.4.0/windows 2. php的可执行文件已经加到系统的 ...
- U盘写保护,不能被格式化
有时故障不在U盘本身,而在那台机器上.这时对U盘进行格式化.转换格式等操作都不会起作用. 解决步骤: 1.开始-->运行-->regedit-->确定,进入注册表. 2.查看HKEY ...
- APM程序分析-Control_rtl.cpp
bool Copter::rtl_init(bool ignore_checks) { if (position_ok() || ignore_checks) { rtl_build_path(!fa ...
- StringBuffer与StringBuilder的简单理解
联系:两者都适用于字符串的操作,都可以随便对字符串的内容进行变更操作,都继承至AbstractStringBuilder. 区别:StringBuffer是线程安全的,方法都加了synchronize ...
- MFC 静态文本的自绘 空心字的实现
想在对话框里,显示几个字是很简单的,只要用静态文本的输出就可以了.然而有时候我们需要显示特效的字,我们希望显示的文字就像Word里的艺术字一样,看起来美观.这时我们可以重写CStatic类.用Draw ...
- 安装SQL Developer,连接Oracle 12c,创建新用户
1.访问Oracle官网:https://www.oracle.com/index.html,下载SQL Developer 2.安装... 3.打开Sql Developer,右键"创建新 ...