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. https://leetcode-cn.com/

    https://leetcode-cn.com/ 码,马不停蹄,码不停题 英文版:https://leetcode.com/

  2. [android错误] Installation error: INSTALL_FAILED_VERSION_DOWNGRA

    错误表现: [2014-06-27 18:19:51 - XXX] Installing XXXX.apk... [2014-06-27 18:20:00 - XXX] Installation er ...

  3. iOS中ActionSheet和Alert的区别

    首先,样子长得就不一样 看下图:

  4. MySQL 导出函数与存储过程

    C:\Users\yan>mysqldump -u用户 -p -n -t -d -R 数据库 > .sql Enter password: ******** C:\Users\yan> ...

  5. SQL 查询排名是第三位的人

    MYSQL可以使用如下的用法: SELECT id FROM partner_broker_account_record ORDER BY id LIMIT 2, 1 在limit为2的基础上加1, ...

  6. MVC下的DAO接口类和SERVICE接口类区别?

    简单理解: DAO数据库访问对象 实现连接数据库 修改.添加等细节 service服务层 面向功能 把一个整个服务 细化 调用DAO其实service其中都是一些方法 去调用DAO 甚至方法名都和DA ...

  7. photoshop 切片工具进行切图

    1.使用切片工具切图 2.存储为web所用格式 3.选择图片格式 4.只保存切片(选择所有用户切片)  5.查看:

  8. 彻底抛弃脚本录制,LR脚本之使用web_custom_request函数自定义http请求

    初学性能测试时候,第一步必学脚本录制,但一路下来各种录制失败.回放脚本失败的问题层出不穷,究其原因一是LR本身存在对测试环境的兼容性问题导致录制失败,更深层次的原因是录制者不清楚LR录制脚本的原理,或 ...

  9. Windows I/O完成端口

    内容: 1.基本概念     2.WINDOWS完成端口的特点     3.完成端口(Completion Ports )相关数据结构和创建     4.完成端口线程的工作原理     5.Windo ...

  10. Spring(十二)使用Spring的xml文件配置方式实现AOP

    配置文件与注解方式的有非常大不同,多了非常多配置项. beans2.xml <?xml version="1.0" encoding="UTF-8"? & ...