问题描述
我在机器上安装了MariaDB-server。设置时遇到了一个问题,我是否必须一直启用它,因为我遵循的文档包含以下步骤,
sudo yum install mariadb mariadb-server
sudo systemctl start mariadb.service
sudo systemctl enable mariadb.service
最佳思路
systemctl start
和systemctl enable
做不同的事情。
enable
会将指定的单元挂在相关的位置,以便它将在启动时或在插入相关的硬件时自动启动,或根据单元文件中指定的内容在其他情况下自动启动。
start
立即启动本机。
disable
和stop
分别与此相反。
这意味着,当您首次安装MariaDB时,可能需要运行systemctl enable mariadb.service
来启用它,以便它在启动时启动。您可能还需要运行systemctl start mariadb.service
或仅重新启动才能启动MariaDB。要停止MariaDB,请运行systemctl stop mariadb.service
(它将在下次启动或手动启动时再次启动)。要禁用它,使其不再在启动时启动,请运行systemctl disable mariadb.service
。
次佳思路
从systemctl
联机帮助页:
enable NAME...
Enable one or more unit files or unit file instances, as specified
on the command line. This will create a number of symlinks as
encoded in the "[Install]" sections of the unit files. After the
symlinks have been created, the systemd configuration is reloaded
(in a way that is equivalent to daemon-reload) to ensure the
changes are taken into account immediately. Note that this does not
have the effect of also starting any of the units being enabled. If
this is desired, either --now should be used together with this
command, or an additional start command must be invoked for the
unit.
...
Enabling units should not be confused with starting (activating)
units, as done by the start command. Enabling and starting units is
orthogonal: units may be enabled without being started and started
without being enabled. Enabling simply hooks the unit into various
suggested places (for example, so that the unit is automatically
started on boot or when a particular kind of hardware is plugged
in). Starting actually spawns the daemon process (in case of
service units), or binds the socket (in case of socket units), and
so on.
本质上,enable
将服务标记为在引导时启动,而start
实际上实际上立即启动了服务。
第三种思路
从systemctl版本220开始,启用和禁用支持–now开关,以在启用/禁用的同时启动/停止服务。
例如systemctl --now enable foobar.service
使用systemctl --version
检查您的安装版本。