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。
更新:
如gerardw的回答中所述,从2015年5月发布的版本220开始,enable和disable都开始接受可选的--now开关,以便根据使用的命令启动或停止单元。
要使用同一命令同时禁用和停止一个单元,请使用systemctl disable mariadb.service --now。同样地,要同时启用和启动一个单元,请使用systemctl enable mariadb.service --now。
来源:systemctl手册页。
systemctl disable。 - vurp0--user选项。 - Samuel来自 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 --now enable foobar.service
使用systemctl --version检查您安装的版本。
enable子命令的--now开关来同时启用和启动服务,例如:systemctl enable sshd --now。同样,disable命令也可用于停止服务。 - user359096