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

An example of linux operation and maintenance managing services through systemctl

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

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

Learn about the example of linux operation and maintenance managing services through systemctl? This problem may be often seen in our daily study or work. I hope you can gain a lot from this question. The following is the reference content that the editor brings to you, let's take a look at it!

Since centOS7, a new command for managing services, systemctl, has been added, through which services on the system can be easily managed.

Enable and disable services via systemctl

The options for enabling and shutting down the service are listed below

Start enables the service.

Stop shuts down the service

Restart restart service

Status to view service status

Reload reloads the configuration file (does not shut down the service)

Enable starts the service at boot time

Disable shutdown Boot self-start

Let's learn through a case.

# View service health # systemctl status atd ● atd.service-Job spooling tools Loaded: loaded (/ usr/lib/systemd/system/atd.service; enabled; vendor preset: enabled) Active: active (running) since Sat 2020-11-07 16:20:59 CST 3 days ago Main PID: 3002 (atd) CGroup: / system.slice/atd.service └─ 3002 / usr/sbin/atd-fNov 07 16:20:59 iz8vb626ci0aehwsivxaydz systemd [1]: Started Job spooling tools.Nov 07 16:20:59 iz8vb626ci0aehwsivxaydz systemd [1]: Starting Job spooling tools...

Through the information shown above, we can get a lot of information. From the second line Loaded, an enabled appears to indicate that the service boots on itself. Learn from the running on the third line that the service is running.

Next, let's demonstrate shutting down and starting the service.

# systemctl stop atd# systemctl start atd

With regard to the health of the service, in addition to the common running, dead, etc., there are also some, which are listed below

Active (running) is running

Active (waiting): wait for execution (wait for other services to execute)

Active (exited): a service that ends normally after only one execution

Inactive (dead): the service is not started

In addition, there are several options for whether the service starts up or not:

Enable: boot up

Disable: boot does not start

Static: boot cannot be self-started, but it can be started by other self-starting services

Mask: it will not be started anyway, the service has been forced to log out

Observe the service on the system through systemctl

Through systemctl, you can see which services are currently running, all the services on the system (including those that are not started), and a certain type of service.

List-units lists all currently started services, which are used by default if the task option is not used. Add-a to show all, including unstarted services

-- type=TYPE lists a certain type of service

Let's take a look at the demonstration.

# list all running services in the system # systemctl UNIT LOAD ACTIVE SUB DESCRIPTION proc-sys-fs-binfmt_misc.automount loaded active running Arbitrary Executable File Formats File System Automoun sys-devices-pci0000:00-0000:00:03.0-virtio0-net-eth0.device loaded active plugged Virtio network device sys -devices-pci0000:00-0000:00:04.0-virtio1-virtio\ x2dports-vport1p1.device loaded active plugged / sys/devices/pci0000:00/0000:00:04. …… # list the service-type services that the system is running # systemctl-- type=service UNIT LOAD ACTIVE SUB DESCRIPTION aegis.service loaded active running LSB: aegis update. Aliyun.service loaded active running aliyun-assist atd.service loaded active running Job spooling tools auditd.service loaded active running Security Auditing Service# lists all services on the system, including # systemctl-a that is not running.

Manage different operating environments (target unit) through systemctl

There are many target unit in centos7, but here we only need to know a few commonly used target unit. Here is a list of commonly used target unit:

Graphical.target graphics mode

Multi-user.target text mode

Rescue.target general rescue mode

Emergency.target emergency rescue mode

Next, let's see how to view the default operating environment of the system, and how to modify the operating environment.

Systemctl [options] [unit.target] [options] get-default: view system default operating environment set-default: set system default operating environment # View default operating environment # systemctl get-defaultmulti-user.target# reset new default operating environment # systemctl set-default graphical.targetRemoved symlink / etc/systemd/system/default.target.Created symlink from / etc/systemd/system/default.target to / usr/lib/systemd / system/graphical.target.# systemctl get-defaultgraphical.target Thank you for your reading! After reading the above, do you have a general understanding of the example of linux operation and maintenance managing services through systemctl? I hope the content of the article will be helpful to all of you. If you want to know more about the relevant articles, you are welcome to follow the industry information channel.

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

Servers

Wechat

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

12
Report