CentOS7设置自定义开机启动,添加自定义系统服务
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
CentOS7设置自定义开机启动,添加自定义系统服务的更多相关文章
- CentOS 7 设置自定义开机启动,添加自定义系统服务
详细文档,http://www.linuxidc.com/Linux/2015-04/115937.htm 摘自: http://www.centoscn.com/CentOS/config/2015 ...
- CentOS 7.x设置自定义开机启动,添加自定义系统服务
Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分, 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: /l ...
- (转)Mysql数据库之Binlog日志使用总结CentOS 7.x设置自定义开机启动,添加自定义系统服务
Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分, 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: li ...
- Centos7 设置Mongodb开机启动-自定义服务
(1).在/lib/systemd/system/目录下新建mongodb.service文件,内容如下 [Unit] Description=mongodb After=network.target ...
- centos7 设置 查看 开机 启动项
1.查看开机自启项centos7自启项已不用chkconfig改为:systemctl list-unit-files左边是服务名称,右边是状态,enabled是开机启动,disabled是开机不启动 ...
- linux centOS7 设置 redis 开机启动
1.为了让redis-server能在系统启动时自动运行,需要将redis服务作为守护进程(daemon)来运行,我们回/usr/local/cluster/7000/目录中找到一个redis.con ...
- systemd添加自定义系统服务设置自定义开机启动
1.服务权限 systemd有系统和用户区分:系统(/user/lib/systemd/system/).用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放 ...
- linux(centos7)设置tomcat开机启动
1.在/etc/rc.d/rc.local中加入: #java environment export JAVA_HOME=/usr/java/jdk1.8.0_161 export CLASSPATH ...
- linux开机自启动设置,自定义开机启动模版,nginx开机自启动服务
/etc/init.d 目录,我们把shell脚本放在这个目录下来作为启动脚本 都是用来放服务脚本的,当Linux启动时,会寻找这些目录中的服务脚本,并根据脚本的run level确定不同的启动级别. ...
随机推荐
- IIS7.5配置Asp.net项目出现HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理。
近日在将一个Asp.net项目部署到IIS7.5上时却出现了HTTP 错误 404.17 - Not Found 请求的内容似乎是脚本,因而将无法由静态文件处理程序来处理. 因为IIS里面使用的都是默 ...
- 简单账本-用完即走的微信小程序
作为一个记账强迫症患者,对当前手机中的记账App都不太满意.这类软件越来越臃肿,越来越慢,启动要半天.联网同步要半天,进入界面又有一堆新功能要介绍.好不容易开始记账,又得各种高大上的选择设定,一笔帐下 ...
- iptables与SELinux
iptables: 开始配置我们来配置一个filter表的防火墙.(1)查看本机关于IPTABLES的设置情况 [root@tp ~]# iptables -L Chain INPUT (policy ...
- JavaScript 之 日常积累
1. <a>标签"加入收藏",兼容IE,FireFox等 function bookmarksite() { if (window.sidebar) { // Mozi ...
- expdp impdp 错误: ORA-39064: 无法写入日志文件 ORA-29285: 文件写入错误(解决方案)
windows: 运行 -> regedit ->查找 键值 NLS_LANG 将字符集 SIMPLIFIED CHINESE_CHINA.ZHS16GBK 修改为AMERICAN_AME ...
- 〖Linux〗Ubuntu13.10,配置tftp服务器
前言,配置了好久没有发现老是出问题tftp: server error: (2) Access violation,一般侦测之后... 1. 安装软件包:apt-getsudo apt-get ins ...
- struts2接收参数的几种形式
1.使用属性 HTML: <form action="login" method="post" name="form1"> 用户 ...
- python学习笔记之基础数据和控制
注释: 单行注释 # 多行注释''' ''' 注意:当注释中有汉字时需要在python文件的第一行添加如下内容之一:#coding:gbk或#coding:utf-8或##-*- coding ...
- 开源大数据技术专场(下午):Databircks、Intel、阿里、梨视频的技术实践
摘要: 本论坛第一次聚集阿里Hadoop.Spark.Hbase.Jtorm各领域的技术专家,讲述Hadoop生态的过去现在未来及阿里在Hadoop大生态领域的实践与探索. 开源大数据技术专场下午场在 ...
- 訪问可能没有定义的data (通过static类型flash.net:FileReference引用)
今天使用Flex实现了图片预览及其上传的功能,在整个开发过程中遇到了"訪问可能没有定义的data (通过static类型flash.net:FileReference引用)"错误, ...