In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-26 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to use commands in systemd". In daily operation, I believe many people have doubts about how to use commands in systemd. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts about "how to use commands in systemd". Next, please follow the editor to study!
One: description
CentOS 7 replaces SysV with systemd. The purpose of Systemd is to replace the init system that has been in use since the Unix era, to be compatible with SysV and LSB startup scripts, and to boot the loading service more effectively during the process startup.
The features of systemd are:
1. Support for parallelization tasks
two。 Both socket and D-Bus bus activation services are adopted. Start the daemon on demand (daemon)
3. Monitoring processes using cgroups of Linux
4. Support for snapshots and system recovery
5. Maintain mount point and automatic mount point
6. The services are precisely controlled based on the dependency relationship.
Two: command
When using a systemctl control unit, you usually need to use the full name of the unit file, including the extension (for example, sshd.service). However, some units can be abbreviated in systemctl.
1. If there is no extension, systemctl defaults to the extension as .service. For example, netcfg and netcfg.service are equivalent.
two。 The mount point is automatically converted to the corresponding .mount unit. For example, / home is equivalent to home. Mount .
3. The device is automatically converted to the corresponding .device unit, so / dev/sda2 is equivalent to dev-sda2.device.
1.systemctl
This command can be used to view system status and manage systems and services. This command is equivalent to systemctl list-units
2.systemctl-failed
Output the unit that failed to run
3.systemctl start
Activation unit
4.systemctl stop
Stop unit
5.systemctl restart
Restart unit
6.systemctl reload
Reread the configuration
7.systemctl status
View running status
8.systemctl enable
Open the automatic activation unit
9.systemctl is-enabled
Check to see if it starts automatically
10.systemctl disable
Cancel the boot automatic activation unit
III: unit file preparation
The syntax of the systemd unit file is derived from the XDG desktop portal configuration file. desktop file, and the original source is the Microsoft Windows .ini file. Unit files can be loaded from two places
The priorities from low to high are:
1. / the unit installed by the usr/lib/systemd/system/: package
2. / etc/systemd/system/: system administrator installed unit
When writing custom service files, you can choose several different ways to start the service. The startup mode can be set through the Type= parameter in the [Service] section of the configuration file. ?
1.Type=simple (default): systemd believes that the service will start immediately. The service process will not fork. If the service is going to start other services, do not start using this type unless the service is socket-activated. ?
2.Type=forking:systemd believes that the service starts successfully when the service process fork and the parent process exits. For regular daemons (daemon), unless you are sure that this startup method does not meet the requirements, you can use this type of startup. Using this startup type, you should also specify PIDFile=, so that systemd can track the main process of the service. ?
3.Type=oneshot: this option applies to services that perform only one task and then exit immediately. You may need to set RemainAfterExit=yes at the same time so that systemd still thinks the service is active after the service process exits.
4.Type=notify: same as Type=simple, but the contract service sends a signal to syst emd when it is ready. The implementation of this notification is provided by libsystemd-daemon.so. ?
5.Type=dbus: if started in this way, systemd thinks the service is ready when the specified BusName appears on the DBus system bus. ?
6.Type=idle: systemd waits for all task (Jobs) processing to complete before starting to execute a unit of type idle. In addition, other behaviors are similar to Type=simple
Four: give an example
Click (here) to collapse or open
[Unit]
Description=Docker Application Container Engine
Documentation= http://docs.docker.com
After=network.target
Wants=docker-storage-setup.service
Requires=docker-cleanup.timer
[Service]
Type=notify
NotifyAccess=all
KillMode=process
EnvironmentFile=-/etc/sysconfig/docker
EnvironmentFile=-/etc/sysconfig/docker-storage
EnvironmentFile=-/etc/sysconfig/docker-network
Environment=GOTRACEBACK=crash
Environment=DOCKER_HTTP_HOST_COMPAT=1
Environment=PATH=/usr/libexec/docker:/usr/bin:/usr/sbin
ExecStart=/usr/bin/dockerd-current\
-- add-runtime docker-runc=/usr/libexec/docker/docker-runc-current\
-- default-runtime=docker-runc\
-- exec-opt native.cgroupdriver=systemd\
-- userland-proxy-path=/usr/libexec/docker/docker-proxy-current\
$OPTIONS\
$DOCKER_STORAGE_OPTIONS\
$DOCKER_NETWORK_OPTIONS\
$ADD_REGISTRY\
$BLOCK_REGISTRY\
$INSECURE_REGISTRY
ExecReload=/bin/kill-s HUP $MAINPID
LimitNOFILE=1048576
LimitNPROC=1048576
LimitCORE=infinity
TimeoutStartSec=0
Restart=on-abnormal
MountFlags=slave
[Install]
WantedBy=multi-user.target
At this point, the study on "how to use commands in systemd" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.