Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Linux system tool Systemd

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Xiaobian to share with you how to use Linux system tools Systemd, I hope you have something to gain after reading this article, let's discuss it together!

systemd is a collection of Linux system infrastructure components that provides a system and service manager that runs as PID 1 and is responsible for starting other programs. Features include: support for parallelization of tasks; socket and D-Bus activation of services; on-demand daemons; monitoring processes using Linux cgroups; support for snapshots and system recovery; maintenance of mount points and automatic mount points; precise control of services based on dependencies.

systemd Features:

1. The latest systems are managed by systemd (Red Hat 7, CentOS 7, Ubuntu15…)

2.CentOS7 supports parallel boot service, significantly improving boot efficiency

CentOS 7 shutdown only shuts down running services, while CentOS6, all shut down once.

4. CentOS7 service start and stop is no longer managed by scripts, that is, there are no scripts under/etc/init.d.

CentOS7 uses systemd to fix defects in the original mode, such as the original service does not close the child process generated by the program.

systemd syntax: systemctl [command] [unit](configured application name) command Optional· start: Start the specified unit systemctl start nginx· stop: Closes the specified unit systemctl stop nginx· restart: Restart the specified unit systemctl restart nginx· reload: overload specified unit systemctl reload nginx· enable: automatically start the specified unit when the system is booted, provided that there is relevant configuration in the configuration file systemctl enable nginx· disable: do not automatically run the specified unit when booting systemctl disable nginx· status: View the current running status of the specified unit systemctl status nginxsystemd configuration file description: Each Unit needs to have a configuration file to inform systemd how to manage the service. The configuration file is stored in/usr/lib/systemd/system/. After startup, a soft link file will be established in the/etc/systemd/system directory. The default suffix name of the configuration file of each Unit is.service. In the/usr/lib/systemd/system/directory, it is divided into two directories: system and user. Generally, programs that can run without logging in are stored in the system service, that is, the/usr/lib/systemd/system configuration file is divided into multiple parts using square brackets, and case-sensitive systemd related files:

Practical source code compilation installation nginx implementation systemd management control

Install nginx build environment

yum -y install gcc gcc-c++ openssl-devel pcre-devel gd-devel iproute net-tools telnet wget curlwget http://nginx.org/download/nginx-1.15.5.tar.gztar 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_modulemake -j 4 && make install

Common way to start nginx

/usr/local/nginx/sbin/nginx #Start/usr/local/nginx/sbin/nginx -s reload #Restart/usr/local/nginx/sbin/nginx -s quit #Close nginx

systemd management control startup mode

vim /usr/lib/systemd/system/nginx.service[Unit]Description=nginxAfter=network.target[Service]Type=forkingExecStart=/usr/local/nginx/sbin/nginxExecReload=/usr/local/nginx/sbin/nginx -s reloadExecStop=/usr/local/nginx/sbin/nginx -s quitPrivateTmp=true[Install]WantedBy=multi-user.target

Details of parameters

systemctl restart nginxsystemctl enable nginxsystemctl stop nginx

As shown in the figure, systemd management control nginx service is implemented.

After reading this article, I believe you have a certain understanding of "how to use Linux system tools Systemd". If you want to know more about relevant knowledge, welcome to pay attention to the industry information channel. Thank you for reading!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report