首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >"systemctl start“和"systemctl enable”之间有什么区别?

"systemctl start“和"systemctl enable”之间有什么区别?
EN

Ask Ubuntu用户
提问于 2016-02-14 11:21:44
回答 3查看 182.1K关注 0票数 164

我在我的机器上安装了MariaDB服务器。在设置过程中,我遇到了一个问题,即是否应该一直启用它,正如我遵循的文档所建议的那样:

代码语言:javascript
运行
复制
sudo yum install mariadb mariadb-server 
sudo systemctl start mariadb.service  
sudo systemctl enable mariadb.service
EN

回答 3

Ask Ubuntu用户

回答已采纳

发布于 2016-02-14 13:37:34

systemctl startsystemctl enable做的事情不一样。

enable会将指定的单元连接到相关的位置,以便在启动时自动启动,或者在插入相关硬件时自动启动,或者根据单元文件中指定的内容在其他情况下启动。

start马上启动这个单位。

disablestop分别与之相反。

这意味着当您第一次安装MariaDB时,您可能希望运行systemctl enable mariadb.service来启用它,以便它在引导时启动。您还可能希望运行systemctl start mariadb.service,或者只是重新启动,以便启动MariaDB。要停止MariaDB,请运行systemctl stop mariadb.service (它将在下一次引导或手动启动时再次启动)。若要禁用它,使其不再在引导时启动,请运行systemctl disable mariadb.service

更新:

正如第220版在2015年5月发布的答案中指出的那样,enabledisable都开始使用可选的--now开关,以便根据使用的命令启动或停止该单元。

若要禁用和停止具有相同命令的单元,请使用systemctl disable mariadb.service --now。同样,要同时启用和启动一个单元,请使用systemctl enable mariadb.service --now

来源:systemctl手册页

票数 244
EN

Ask Ubuntu用户

发布于 2016-02-14 11:26:13

来自这个systemctl命令页

代码语言:javascript
运行
复制
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实际上会立即启动服务。

票数 25
EN

Ask Ubuntu用户

发布于 2019-04-15 14:15:02

从systemctl版本220开始,启用和禁用支持a--现在切换到与启用/禁用并发的启动/停止服务。

例如systemctl --now enable foobar.service

使用systemctl --version检查已安装的版本。

票数 16
EN
页面原文内容由Ask Ubuntu提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://askubuntu.com/questions/733469

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档