0Pricing
Linux Command Line Mastery · 课时

服务管理:`systemctl`(systemd)

使用 `systemctl` 命令控制和管理系统服务及守护进程。

服务管理:`systemctl`(systemd) 是 CoddyKit 上的免费 Linux Command Line Mastery 课时。 这是第 2 节课,共 4 节。 你可以在下方免费阅读本课时的完整内容 — 然后在浏览器中使用内置代码编辑器和全天候 AI 导师进行实践。 这是 Linux Command Line Mastery 学习路径的一部分,你的进度在网页和 CoddyKit 应用中同步。 Linux Command Line Mastery 课程共包含 4 节课。

本课时的部分内容尚未翻译,以英文显示。

What are System Services?

On Linux, many programs run silently in the background to perform essential tasks. These are called services or daemons.

Think of them as silent helpers: a web server, a database, or even your Wi-Fi manager. They often start automatically when your system boots.

Meet systemd

systemd is the initialization system used by most modern Linux distributions (like Ubuntu, Fedora, CentOS).

It's responsible for managing services and processes from boot-up to shut-down, ensuring everything starts and stops in the correct order.

Your Tool: systemctl

To interact with systemd and manage these services, we use the powerful systemctl command.

It's your primary interface for checking status, starting, stopping, enabling, and disabling services on your system.

Check Service Status

The first step is often checking if a service is running. Use systemctl status <service_name>.

Let's check the status of the SSH daemon (sshd), which allows secure remote access to your machine.

systemctl status sshd

Starting a Service

If a service isn't running or you've stopped it, you can start it with systemctl start <service_name>.

This command attempts to begin the service immediately. You'll often need root privileges (using sudo) for most system services.

sudo systemctl start sshd

Stopping a Service

To halt a running service, use systemctl stop <service_name>.

This is useful if you need to perform maintenance or reconfigure a service. Be cautious, as stopping critical services can affect system functionality.

sudo systemctl stop sshd

Restart vs. Reload

Restarting (systemctl restart <service>) fully stops and then starts a service. This is often needed after major configuration changes.

Reloading (systemctl reload <service>) tells a service to re-read its configuration without a full restart, minimizing downtime. Not all services support reload.

sudo systemctl restart sshd

Managing Autostart

Services can be set to start automatically at boot. This is called enabling the service.

  • sudo systemctl enable <service>: Configures a service to start on boot.
  • sudo systemctl disable <service>: Prevents a service from starting on boot.

These commands only modify boot behavior; they don't start/stop the service immediately.

sudo systemctl enable sshd

Listing All Services

To see a list of all loaded services and their current status (active, inactive, enabled, disabled), use systemctl list-units --type=service --all.

This command provides a comprehensive overview of what's configured on your system.

systemctl list-units --type=service --all

Quick Check: Service Control

Which command would you use to prevent the apache2 web server service from starting automatically when your Linux system boots up?

Recap: Service Management

You've learned how to manage system services using the powerful systemctl command!

  • Use status to check a service's state.
  • start, stop, restart to control running services.
  • enable and disable to manage boot-time behavior.
  • list-units --type=service --all to view all services.

Mastering systemctl is crucial for effective Linux system administration.

常见问题解答

「服务管理:`systemctl`(systemd)」课时是免费的吗?

是的 — 「服务管理:`systemctl`(systemd)」的完整文本可在网页上免费阅读。要进行交互式练习(内置代码编辑器和全天候 AI 导师)并解锁 Linux Command Line Mastery 课程的其余内容,请升级到 CoddyKit PRO。 Linux Command Line Mastery 课程共包含 4 节课。

「服务管理:`systemctl`(systemd)」这节课中我会学到什么?

使用 `systemctl` 命令控制和管理系统服务及守护进程。 你通过在浏览器中直接运行的动手代码来练习 Linux Command Line Mastery,全天候 AI 导师会在你学习这节课的过程中回答你的问题。

学习 Linux Command Line Mastery 需要有经验吗?

无需任何先前经验。CoddyKit 上的 Linux Command Line Mastery 课程适合初学者到高级学习者,你可以从这里开始或从头开始,按照自己的节奏学习。 这是第 2 节课,共 4 节。

「服务管理:`systemctl`(systemd)」课时需要多长时间?

大多数 CoddyKit 课程大约需要 5–10 分钟。每节课都很精短且互动,所以你能稳步进步,并在网页和应用中从离开的地方继续。

我能在这节 Linux Command Line Mastery 课中编写并运行代码吗?

能。每节 Linux Command Line Mastery 课都包含内置代码编辑器,你可以在浏览器中直接编写并运行真实代码,并获得即时 AI 反馈 — 无需本地设置。

此课程中的所有课时

  1. 任务调度:`cron` 和 `at`
  2. 服务管理:`systemctl`(systemd)
  3. 使用 Shell 函数自动化任务
  4. 使用 journald 与 logrotate 集中记录日志并轮换
← 返回 Linux Command Line Mastery