systemd是目前Linux系统上主要的系统守护进程管理工具,由于init一方面对于进程的管理是串行化的,容易出现阻塞情况,另一方面init也仅仅是执行启动脚本,并不能对服务本身进行更多的管理。 |
systemd是目前Linux系统上主要的系统守护进程管理工具,由于init一方面对于进程的管理是串行化的,容易出现阻塞情况,另一方面init也仅仅是执行启动脚本,并不能对服务本身进行更多的管理。所以从CentOS 7开始也由systemd取代了init作为默认的系统进程管理工具。
systemd所管理的所有系统资源都称作Unit,通过systemd命令集可以方便的对这些Unit进行管理。比如systemctl、hostnamectl、timedatectl、localctl等命令,这些命令虽然改写了init时代用户的命令使用习惯(不再使用chkconfig、service等命令),但确实也提供了很大的便捷性。
2. systemd特点:1.最新系统都采用systemd管理(RedHat7,CentOS7,Ubuntu15...)
2.CentOS7 支持开机并行启动服务,显著提高开机启动效率
3.CentOS7关机只关闭正在运行的服务,而CentOS6,全部都关闭一次。
4.CentOS7服务的启动与停止不再使用脚本进行管理,也就是/etc/init.d下不在有脚本。
5.CentOS7使用systemd解决原有模式缺陷,比如原有service不会关闭程序产生的子进程。
3. systemd语法:systemctl [command] [unit](配置的应用名称) command可选项 · start:启动指定的unit systemctl start Nginx · stop:关闭指定的unit systemctl stop Nginx · restart:重启指定unit systemctl restart Nginx · reload:重载指定unit systemctl reload Nginx · enable:系统开机时自动启动指定unit,前提是配置文件中有相关配置 systemctl enable Nginx · disable:开机时不自动运行指定unit systemctl disable Nginx · status:查看指定unit当前运行状态 systemctl status Nginx4. systemd配置文件说明:
- 每一个Unit都需要有一个配置文件用于告知systemd对于服务的管理方式
- 配置文件存放于/usr/lib/systemd/system/,设置开机启动后会在/etc/systemd/system目录建立软链接文件
- 每个Unit的配置文件配置默认后缀名为.service
- 在/usr/lib/systemd/system/目录中分为system和user两个目录,一般将开机不登陆就能运行的程序存在系统服务里,也就是/usr/lib/systemd/system
- 配置文件使用方括号分成了多个部分,并且区分大小写
安装Nginx编译环境
yum -y install gcc gcc-c++ openssl-devel pcre-devel gd-devel iproute net-tools telnet wget curl wget http://Nginx.org/download/Nginx-1.15.5.tar.gz tar zxf Nginx-1.15.5.tar.gz && cd Nginx-1.15.5 ./configure --prefix=/usr/local/Nginx \ --with-http_ssl_module \ --with-http_stub_status_module make -j 4 && make install
通用方式启动Nginx
/usr/local/Nginx/sbin/Nginx #启动 /usr/local/Nginx/sbin/Nginx -s reload #重启 /usr/local/Nginx/sbin/Nginx -s quit #关闭Nginx
systemd 管理控制启动模式
vim /usr/lib/systemd/system/Nginx.service [Unit] Description=Nginx After=network.target [Service] Type=forking ExecStart=/usr/local/Nginx/sbin/Nginx ExecReload=/usr/local/Nginx/sbin/Nginx -s reload ExecStop=/usr/local/Nginx/sbin/Nginx -s quit PrivateTmp=true [Install] WantedBy=multi-user.target
参数详解
systemctl restart Nginx systemctl enable Nginx systemctl stop Nginx
本文地址:https://www.linuxprobe.com/systemd-contor-jc.html
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。