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

Centos 系统服务脚本目录:

  1. /usr/lib/systemd/

有系统(system)和用户(user)之分,

如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即:

  1. /lib/systemd/system/

反之,用户登录后才能运行的程序,存在用户(user)里

服务以.service结尾。

这边以nginx开机运行为例

1.建立服务文件

[html] view plaincopyprint?

  1. vim /lib/systemd/system/nginx.service

[plain] view plaincopyprint?

  1. [Unit]
  2. Description=nginx
  3. After=network.target
  4. [Service]
  5. Type=forking
  6. ExecStart=/www/lanmps/init.d/nginx start
  7. ExecReload=/www/lanmps/init.d/nginx restart
  8. ExecStop=/www/lanmps/init.d/nginx  stop
  9. PrivateTmp=true
  10. [Install]
  11. WantedBy=multi-user.target

[Unit]:服务的说明

Description:描述服务
After:描述服务类别

[Service]服务运行参数的设置

Type=forking是后台运行的形式
ExecStart为服务的具体运行命令
ExecReload为重启命令
ExecStop为停止命令
PrivateTmp=True表示给服务分配独立的临时空间
注意:[Service]的启动、重启、停止命令全部要求使用绝对路径

[Install]服务安装的相关设置,可设置为多用户

2.保存目录

以754的权限保存在目录:

[html] view plaincopyprint?

  1. /lib/systemd/system

3.设置开机自启动

[html] view plaincopyprint?

  1. 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
时间: 2024-08-03 22:54:28

CentOS 7.x设置自定义开机启动,添加自定义系统服务的相关文章

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

Centos 系统服务脚本目录: [plain] view plain copy /usr/lib/systemd/ 有系统(system)和用户(user)之分, 如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: [plain] view plain copy lib/systemd/system/ 反之,用户登录后才能运行的程序,存在用户(user)里 服务以.service结尾. 这边以nginx开机运行为例 IT 1.建立服务文件 [plain] view p

CentOS7设置自定义开机启动,添加自定义系统服务

Centos 系统服务脚本目录: /usr/lib/systemd/ 有系统(system)和用户(user)之分,如需要开机没有登陆情况下就能运行的程序,存在系统服务(system)里,即: lib/systemd/system/ 反之,用户登录后才能运行的程序,存在用户(user)里,服务以.service结尾. 这边以nginx开机运行为例: 1.建立服务文件 vim /lib/systemd/system/nginx.service [Unit] Description=nginx Af

在Centos 中将zookeeper设置成开机启动

部署了Zookeeper之后,当需要重启机器时,开机后往往需要花一点时间对zookeeper集群进行启动,由于zookeeper没有主节点的概念,且一个节点的重启不会对集群造成什么影像,所以可以考虑把 zookeeper设置成开机启动,具体流程如下 准备工作 切换到/etc/rc.d/init.d/目录下 创建zookeeper文件:touch zookeeper 更新权限:chmod +x zookeeper 编辑 文件,在zookeeper里面输入如下内容 #!/bin/bash #chkc

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

1.服务权限 systemd有系统和用户区分:系统(/user/lib/systemd/system/).用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放在/etc/systemd/system/目录下面. 2.创建服务文件 [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.targe

systemd添加自定义系统服务设置自定义开机启动的方法

1.服务权限 systemd有系统和用户区分:系统(/user/lib/systemd/system/).用户(/etc/lib/systemd/user/).一般系统管理员手工创建的单元文件建议存放在/etc/systemd/system/目录下面. 2.创建服务文件 [Unit] Description=nginx - high performance web server Documentation=http://nginx.org/en/docs/ After=network.targe

CentOS 7 配置花生壳开机启动

在家安装服务器,外地可以随时登陆,感觉花生壳特别方便,具体路由器配置请参考http://service.oray.com/question/2486.html. 我使用的操作系统是 [[email protected] ~]# cat /etc/redhat-release CentOS Linux release 7.1.1503 (Core) 好了,进入正题 1 下载和安装花生壳公网包 参考http://hsk.oray.com/download/#type=linux, 1 下载软件包:

centos设置服务开机启动

Linux CentOS设置服务开机启动的方法 by 天涯 · 2013/07/26 CentOS设置服务开机启动的两种方法 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd.mysqld.postfix等,安装后系统默认不会自动启动的.就算 手动执行 /etc/init.d/mysqld start 启动了服务,只要服务器重启后,系统仍然不会自动启动服务. 在这个时候,我们就需要在安装后做个设置,让系统自动启动这些服务,

CentOS设置服务开机启动的方法

CentOS设置服务开机启动的两种方法 1.利用 chkconfig 来配置启动级别 在CentOS或者RedHat其他系统下,如果是后面安装的服务,如httpd.mysqld.postfix等,安装后系统默认不会自动启动的.就算手动执行 /etc/init.d/mysqld start 启动了服务,只要服务器重启后,系统仍然不会自动启动服务. 在这个时候,我们就需要在安装后做个设置,让系统自动启动这些服务,避免不必要的损失和麻烦. 其实命令很简单的,使用chkconfig即可. [天涯PHP博

CentOS 64-bit下安装JDK和Tomcat并设置Tomcat开机启动操作步骤

准备文件如下: 1.CentOS-6.4-x86_64-bin-DVD1.iso 2.jdk-7u67-linux-x64.rpm 3.apache-tomcat-7.0.55.tar.gz 安装步骤如下: 一.安装JDK [[email protected] /]# java -versionbash: java: command not found [[email protected] /]# rpm -ivh /soft/jdk-7u67-linux-x64.rpmPreparing...