CentOS7.5下开发systemctl管理的自定义Nginx启动服务程序
一、systemctl知识简介
从CentOS7 Linux开始,系统里的网络服务启动已经从传统的service改成了systemctl(一个systemd工具,主要负责控制systemd系统和服务管理器。),管理开机自启动的命令也从chkconfig改为了systemctl,由systemctl一个命令代替了CentOS7以前系统中的service和chkconfig两个命令。
系统服务的脚本也从传统的路径的/etc/init.d(/etc/rc.d/init.d/),改到了/usr/lib/systemd(除此之外还有/etc/systemd/system),需要自启动运行的程序,一般存在这个系统服务目录下,即:/usr/lib/systemd/system目录,每一个服务以“服务名.service”结尾,该文件的内容一般分为3部分:即[Unit]、[Service]和[Install]。
二、systemctl管理的sshd服务配置介绍
下面是系统中sshd服务配置及解释说明。
cat /usr/lib/systemd/system/sshd.service [Unit] #<==对该系统服务描述及说明模块。
Description=OpenSSH server daemon #<==描述性说明。
Documentation=man:sshd() man:sshd_config() #<==文档列表说明。
After=network.target sshd-keygen.service #<==服务依赖类别说明。
Wants=sshd-keygen.service #<==可选的依赖服务。 [Service] #<==系统服务的运行参数设置模块
Type=notify #<==服务类型,可选有forking、notify、simple等。
EnvironmentFile=/etc/sysconfig/sshd #<==环境变量等的配置文件。
ExecStart=/usr/sbin/sshd -D $OPTIONS #<==服务的启动程序。
ExecReload=/bin/kill -HUP $MAINPID #<==重启程序。
KillMode=process
Restart=on-failure
RestartSec=42s [Install] #<==服务安装的相关设置。
WantedBy=multi-user.target #<==这里为设置多用户级别。可为空格分隔的列表, 表示在使用 systemctl enable 启用此单元时, 将会在对应的目录设置对应文件的软连接。
更多说明,可参考systemd.unit、system.service文档,此不细述,都掌握了意义也不大,可以写出启动脚本即可。
三、根据上面的服务配置创建nginx启动脚本
vim /usr/lib/systemd/system/nginx.service [Unit]
Description=The nginx HTTP and reverse proxy server #描述说明;
After=network.target remote-fs.target nss-lookup.target #服务依赖类别说明; [Service]
Type=forking #服务类型,可选有forking、notify、simple等;
ExecStartPre=/application/nginx/sbin/nginx -t #启动前检查配置文件是否正确;
ExecStart=/application/nginx/sbin/nginx #启动nginx
ExecReload=/bin/kill -s HUP $MAINPID #重载reload
ExecStop=/bin/kill -s QUIT $MAINPID #停止服务
PrivateTmp=true #为服务分配独立的空间; [Install]
WantedBy=multi-user.target #多用户级别 说明第一次启动会提示以下报错:
[root@server nginx-1.8.]# systemctl restart nginx.service
Warning: nginx.service changed on disk. Run 'systemctl daemon-reload' to reload units.
Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details. 执行下面的命令重新载入 systemd,扫描新的或有变动的单元即可:
systemctl daemon-reload #重新载入 systemd,扫描新的或有变动的单元
启动nginx:
[root@lb01 ~]# systemctl daemon-reload
[root@lb01 ~]# systemctl stop nginx
[root@lb01 ~]# systemctl start nginx
[root@lb01 ~]# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disabled)
Active: active (running) since 五 -- :: CST; 7s ago
Process: ExecStart=/application/nginx/sbin/nginx (code=exited, status=/SUCCESS)
Process: ExecStartPre=/application/nginx/sbin/nginx -t (code=exited, status=/SUCCESS)
Main PID: (nginx)
CGroup: /system.slice/nginx.service
├─ nginx: master process /application/nginx/sbin/nginx
└─ nginx: worker process 9月 :: lb01 systemd[]: Starting The nginx HTTP and reverse proxy server...
9月 :: lb01 nginx[]: nginx: the configuration file /application/nginx-1.8./conf/nginx.conf syntax is ok
9月 :: lb01 nginx[]: nginx: configuration file /application/nginx-1.8./conf/nginx.conf test is successful
9月 :: lb01 systemd[]: Started The nginx HTTP and reverse proxy server.
[root@lb01 ~]# systemctl restart nginx
[root@lb01 ~]# systemctl reload nginx
[root@lb01 ~]# systemctl stop nginx
[root@lb01 ~]# systemctl restart nginx
[root@lb01 ~]# systemctl enable nginx
[root@lb01 ~]# systemctl list-unit-files|grep nginx
nginx.service enabled
CentOS7.5下开发systemctl管理的自定义Nginx启动服务程序的更多相关文章
- centos7.0下的 systemctl 用法
参考链接: http://man.linuxde.net/systemctl
- 手动编译安装Libvirt之后利用systemctl管理libvirtd服务
因为要给特殊的虚拟机关联文件指定selinux标签,而默认的Libvirt没有这个功能,所以需要修改LIbvirt源代码,重新编译安装Libvirt,而手动编译安装的LIbvirt,没有办法使用sys ...
- Centos7 环境下开机 自启动服务(service) 设置的改变 (命令systemctl 和 chkconfig用法区别比较)
参考文章: <Linux 设置程序开机自启动 (命令systemctl 和 chkconfig用法区别比较)> http://blog.csdn.net/kenhins/article/ ...
- [转帖]备忘:CentOS-7 使用systemctl 管理的服务,文件打开数上限1024要改
备忘:CentOS-7 使用systemctl 管理的服务,文件打开数上限1024要改 https://blog.csdn.net/toontong/article/details/50440272 ...
- Centos7下创建和管理用户
centos服务管理主要命令是systemctl,centos7的服务不再放在/etc/init.d/下;而放在/usr/lib/systemd/system下,centos7系统中systemctl ...
- 在VS下使用 GitFlow管理项目开发
在VS下使用 GitFlow管理项目开发 1.右键将你的解决方案添加到源代码管理,如果你的VS没有安装git,会提示安装,安装完成之后,在团队资源管理可以看到如下界面 (图一) 2.安装gitflow ...
- Centos7下的systemctl命令与service和chkconfig
博主使用的操作系统是最新的CentOS 7,所以可能和网上一些老的博文有一定出入,那是因为版本更新的原因. 这里写图片描述1 service service命令用于对系统服务进行管理,比如启动(sta ...
- CentOS7 安装tomcat为系统服务器 Systemctl管理Tomcat,并设置开机启动
本文转载:http://blog.chinaunix.net/uid-24648266-id-5729891.html CentOS7开始,从/etc/init.d脚本改为了systemctl管理服务 ...
- centos7把编译安装的服务通过systemctl管理
nginx编译安装的目录是/usr/local/nginx nginx配置文件是/usr/local/nginx/conf/nginx.conf systemctl管理的服务文件在/usr/lib/s ...
随机推荐
- js字符串与正则匹配
这里就说一下具体的使用方法,不做过多的解释. 字符串匹配正则的方法:str.方法(reg) 1.str.search() 参数是正则,将会从开始查找字符串中与正则匹配的字符,并返回该字符的第一次出现的 ...
- Flask (七) 部署
阿里云部署Flask项目 部署Flask项目和部署Django项目基本一致,我们也使用uwsgi+nginx 我们在部署Django项目基础上部署Flask项目 1, 将uwsgi.ini ...
- GYM 101889J(枚举、环上gcd)
答案只有n - 1种暴举即可,对于每种,gcd是一那踩雷稳了,否则看雷的分布有没有把模余占满. const int maxn = 1e5 + 5; int n, ans; char str[maxn] ...
- Dwarves, Hats and Extrasensory Abilities Codeforces - 1063C
https://codeforces.com/contest/1063/problem/C 首先可以想到一个简单做法:先钦定这个直线的斜率k=-1,然后设直线y=-x+b 设黑点放直线上方:如果已知( ...
- SSE练习:单精度浮点数组求和
SSE(Streaming SIMD Extensions)指令是一种SIMD 指令, Intrinsics函数则是对SSE指令的函数封装,利用C语言形式来调用SIMD指令集,大大提高了易读性和可维护 ...
- vue中的number
今天在vue文档中看到有number这样一个修饰符 觉得挺方便的就尝试了一下下面是代码 <body> <div id="box"> <input ty ...
- JVM垃圾回收机制二
对象的回收 垃圾的回收涉及的几个问题:何时回收,由谁回收,怎样回收.这几个问题我们一一来解决. 1.何时回收----对象的生死判定 对象达到什么条件才能判断这个对象已经无用了.常见的判断对象生死的方法 ...
- get和post请求及进程和线程及cookie和session的区别
get和post请求及进程和线程及cookie和session的区别 1.get和post请求的区别 get请求是指向服务器进行获取查询数据的请求,post请求指向服务器提交数据的请求. get请求如 ...
- 洛谷 First Step (ファーストステップ) 3月月赛T1
题目背景 知らないことばかりなにもかもが(どうしたらいいの?) 一切的一切 尽是充满了未知数(该如何是好) それでも期待で足が軽いよ(ジャンプだ!) 但我仍因满怀期待而步伐轻盈(起跳吧!) 温度差なん ...
- 51nod 1174 区间中最大的数(送盾题)
基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题 收藏 关注 给出一个有N个数的序列,编号0 - N - 1.进行Q次查询,查询编号i至j的所有数中,最大的数是多少. ...