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. ubuntu安装ssh服务记录

    执行命令: sudo apt-get install openssh-server 有时候会出现这个错误: unable to  fetch some archives ,maybe run apt- ...

  2. Lisp分配给保护的符号…

    在进行调试时,弹出"分配给保护的符号:pf,是否进入中断循环",但似乎不会影响结果. 明经版主解译说是:给受保护的符号重新赋值了,所以有此提示,此提示仅在打开了vlide 编辑器才 ...

  3. angular cli中的--flat参数

    添加--flat 参数,表示不创建单独的目录 例如 ng g c news/news-detail 会将文件创建在app/news/news-detail目录下 ng g c news/news-de ...

  4. 天气预报的Ajax效果

    最近在网站上看了很多显示实时天气预报的,挺实用而且用户体验也不错.对用户的帮助也比较大,用户可以通过你的网站了解到实时的天气信息.感觉比较有意思,于是自己钻研了一下其中的实现方法.于是决定把代码分享给 ...

  5. [置顶] Android之服务器编程

    这个教程主要是讲解服务器编程的,如果你的应用需要和服务器通信,那就必须了解服务器编程(当然,也许你不需要了解,因为你只开发客户端),Android应用和服务器的通信可以使用Http + JSON来通信 ...

  6. 给你一个能生成1到5随机数的函数,用它写一个函数生成1到7的随机数。 (即,使用函数rand5()来实现函数rand7())

    给你一个能生成1到5随机数的函数,用它写一个函数生成1到7的随机数. (即,使用函数rand5()来实现函数rand7()). 解答 rand5可以随机生成1,2,3,4,5:rand7可以随机生成1 ...

  7. 总结js(1)

    已经一个月没敲代码了,工作难找,挺烦. 先总结一下javascript吧. 1.js概述 2.语法结构 3.类型.值和变量 4.表达式和运算符 5.语句 6.对象 7.数组 8.函数 9.类和模块 1 ...

  8. html5开放资料

    http://www.cnblogs.com/tim-li/archive/2012/08/06/2580252.html KineticJS教程(12) 摘要: KineticJS教程(12) 作者 ...

  9. line-height测量及使用

    1.line-height定义 line-height表示行高,即两行文字基线间的距离. 以下是图示说明: 行高是2条红线之间的距离,即:1+2+3+4 在实际测量中,基线不好找,可测量顶线到顶线的距 ...

  10. 19、java内存分配 常量池详解

    在class文件中,“常量池”是最复杂也最值得关注的内容. Java是一种动态连接的语言,常量池的作用非常重要,常量池中除了包含代码中所定义的各种基本类型(如int.long等等)和对象型(如Stri ...