Taking mariadb as an example to introduce how to use the systemctl command set to set the service to start automatically

Taking mariadb as an example to introduce how to use the systemctl command set to set the service to start automatically

1. Introduction to systemd

systemd is system daemon, an init software under linux, developed by Lennart Poettering, and released as open source under LGPL 2.1 and its subsequent version licenses. The development goal is to provide a better framework to express the dependencies between system services relationship, and realize the parallel startup of services during system initialization, and at the same time achieve the effect of reducing the system overhead of the Shell, and finally replace the commonly used System V and BSD style init programs.

Systemd is used in Linux to manage background services. By configuring the service file, you can achieve the purpose of automatically starting a certain service at startup. Through command sets such as systemctl, you can control whether a service starts automatically, or you can manually start or stop it. This article briefly explains how to implement self-starting and introduces some basic commands.

Two, systemctl command set commonly used commands

  1. View service status
systemctl status xxx.service
  1. Enable service autostart
systemctl enable xxx.service  # 重启后生效
  1. Cancel the service from starting
systemctl disable xxx.service  # 重启后生效
  1. Start the service manually
systemctl start xxx.service
  1. Manually stop the service
systemctl stop xxx.service

3. Take mariadb self-starting as an example

Here we take the Mariadb server as an example. After installing mariadb on the redhat7 system, we hope to configure it to start automatically at boot.

Here I did not switch to execute under the root user, but use my own user to operate.

Check the service status of mariadb, you can see that it is disabled.

[hubing@192 ~]$ systemctl status mariadb.service

After enabling the self-starting of mariadb, check its status again, and you can see that it has become enabled

[hubing@192 ~]$ systemctl enabled mariadb.service

20221224203854

It needs to be restarted to take effect. Let’s restart it, and then check its status again. We can find that after the restart, the Mariadb service has completed self-starting and is in the running state.

20221224204347

4. More instructions

For how to use systemctl to manage systemd Services and Units, you can read this tutorial:
How To Use Systemctl to Manage Systemd Services and Units

Red Hat's official documentation introduces systemd:
Chapter 10. Managing Services with systemd

Guess you like

Origin blog.csdn.net/hubing_hust/article/details/128431693