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设置自定义开机启动,添加自定义系统服务的更多相关文章

  1. CentOS 7 设置自定义开机启动,添加自定义系统服务

    详细文档,http://www.linuxidc.com/Linux/2015-04/115937.htm 摘自: http://www.centoscn.com/CentOS/config/2015 ...

  2. CentOS 7.x设置自定义开机启动,添加自定义系统服务

    Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分, 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: /l ...

  3. (转)Mysql数据库之Binlog日志使用总结CentOS 7.x设置自定义开机启动,添加自定义系统服务

    Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分, 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: li ...

  4. Centos7 设置Mongodb开机启动-自定义服务

    (1).在/lib/systemd/system/目录下新建mongodb.service文件,内容如下 [Unit] Description=mongodb After=network.target ...

  5. centos7 设置 查看 开机 启动项

    1.查看开机自启项centos7自启项已不用chkconfig改为:systemctl list-unit-files左边是服务名称,右边是状态,enabled是开机启动,disabled是开机不启动 ...

  6. linux centOS7 设置 redis 开机启动

    1.为了让redis-server能在系统启动时自动运行,需要将redis服务作为守护进程(daemon)来运行,我们回/usr/local/cluster/7000/目录中找到一个redis.con ...

  7. systemd添加自定义系统服务设置自定义开机启动

    1.服务权限 systemd有系统和用户区分:系统(/user/lib/systemd/system/).用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放 ...

  8. linux(centos7)设置tomcat开机启动

    1.在/etc/rc.d/rc.local中加入: #java environment export JAVA_HOME=/usr/java/jdk1.8.0_161 export CLASSPATH ...

  9. linux开机自启动设置,自定义开机启动模版,nginx开机自启动服务

    /etc/init.d 目录,我们把shell脚本放在这个目录下来作为启动脚本 都是用来放服务脚本的,当Linux启动时,会寻找这些目录中的服务脚本,并根据脚本的run level确定不同的启动级别. ...

随机推荐

  1. [Bash] Create Aliases in .bash_profile for Common Bash Commands

    .bash_profile is a file that bash invokes (or more technically sources) before the start of a new ba ...

  2. UVALive 2949 Elevator Stopping Plan(二分 + 贪心)

    ZSoft Corp. is a software company in GaoKe Hall. And the workers in the hall are very hard-working. ...

  3. Speculative Execution in Hadoop

    来自:http://blog.csdn.net/macyang/article/details/7880671 所谓的推测执行,就是当所有task都开始运行之后,Job Tracker会统计所有任务的 ...

  4. TP5报错variable type error: array

      variable type error: array 当你在tp5框架中写方法时返回一个数组时,tp5会报错:variable type error: array 这是因为tp5不支持返回数组. ...

  5. MySQL 忘记密码:skip-grant-tables

    1.首先确认服务器出于安全的状态,也就是没有人能够任意地连接MySQL数据库. 因为在重新设置MySQL的root密码的期间,MySQL数据库完全出于没有密码保护的 状态下,其他的用户也可以任意地登录 ...

  6. 关于python打包成exe的一点经验之谈

    我经常用python写些脚本什么的,有时候脚本写完以后,每次运行都得在IDE打开在运行,很麻烦,所以经常将python编译成exe.SO...有了一点经验,在这和大家分享一下.      python ...

  7. eclipse svn插件

      eclipse svn插件 CreateTime--2018年4月22日23:09:42 Author:Marydon 下载地址:eclipse svn插件 将svn插件目录直接拷贝到eclips ...

  8. ORACLE检查死锁

    一.数据库死锁的现象程序在执行的过程中,点击确定或保存按钮,程序没有响应,也没有出现报错.二.死锁的原理当对于数据库某个表的某一列做更新或删除等操作,执行完毕后该条语句不提交,另一条对于这一列数据做更 ...

  9. 19、Java访问修饰符

    修饰符 本类 同一个包中的类 子类 其它类 public 可以访问 可以访问 可以访问 可以访问 protected 可以访问 可以访问 可以访问 不能访问 默认 可以访问 可以访问 不能访问 不能访 ...

  10. linux利器expect的使用

    1.什么是expect在做系统管理时,我们很多时候需要输入密码,例如:连接 ssh,连接ftp,那么如何能做到不输入密码,我们需要有一个工具,能代替我们实现与终端的交互,它能够代替我们实现与终端的交互 ...