mirror of
https://github.com/LCTT/TranslateProject.git
synced 2025-01-13 22:30:37 +08:00
Translated:20140819 Linux Systemd--Start or Stop or Restart Services in RHEL or CentOS 7.md
This commit is contained in:
parent
f604527178
commit
424b20aea4
@ -1,69 +0,0 @@
|
||||
Translating by GOLinux ...
|
||||
Linux Systemd - Start/Stop/Restart Services in RHEL / CentOS 7
|
||||
================================================================================
|
||||
One of the major changes in RHEL / CentOS 7.0 is the swtich to **systemd**, a system and service manager, that replaces SysV and Upstart used in previous releases of Red Hat Enterprise Linux. systemd is compatible with SysV and Linux Standard Base init scripts.
|
||||
|
||||
**Systemd** is a system and service manager for Linux operating systems. It is designed to be backwards compatible with SysV init scripts, and provides a number of features such as parallel startup of system services at boot time, on-demand activation of daemons, support for system state snapshots, or dependency-based service control logic.
|
||||
|
||||
Previous versions of Red Hat Enterprise Linux, which were distributed with SysV init or Upstart, used init scripts written in bash located in the /etc/rc.d/init.d/ directory. In RHEL 7 / CentOS 7, these init scripts have been replaced with service units. Service units end with the .service file extension and serve a similar purpose as init scripts. To view, start, stop, restart, enable, or disable system services you will use the systemctl instead of the old service command.
|
||||
|
||||
> Note: for backwards compatibility the old service command is still available in CentOS 7 and it will redirect any command to the new systemctl utility.
|
||||
|
||||
### Start/Stop/Restart Services with systemctl ###
|
||||
|
||||
To start a service with systemctl you will need to use the command like this:
|
||||
|
||||
# systemctl start httpd.service
|
||||
|
||||
This will start the httpd service, in our case Apache HTTP Server.
|
||||
|
||||
To stop it use this command as root:
|
||||
|
||||
# systemctl stop httpd.service
|
||||
|
||||
To restart you can use either the restart options, it will restart the service if it’s running or start it if it’s not running. You can also use the try-restart option that will restart the service only if it’s already running. Also you have the reload option that will reload the configuration files.
|
||||
|
||||
# systemctl restart httpd.service
|
||||
# systemctl try-restart httpd.service
|
||||
# systemctl reload httpd.service
|
||||
|
||||
The commands in our example look like this:
|
||||
|
||||
![systemctl start-stop-restart](http://linoxide.com/wp-content/uploads/2014/08/systemctl-start-stop-restart.gif)
|
||||
|
||||
### Checking the status of a service ###
|
||||
|
||||
To check the status of a service you can use the status option like this:
|
||||
|
||||
# systemctl status httpd.service
|
||||
|
||||
And the output should look like this:
|
||||
|
||||
![systemctl status](http://linoxide.com/wp-content/uploads/2014/08/systemctl-status.gif)
|
||||
|
||||
Informing you of various aspects of the running service.
|
||||
|
||||
### Enable / Disable services to run at boot time ###
|
||||
|
||||
You can also use the enable / disable options to make a service run at boot time, using the command like this:
|
||||
|
||||
# systemctl enable httpd.service
|
||||
# systemctl disable httpd.service
|
||||
|
||||
The output looks like this:
|
||||
|
||||
![systemctl-enable](http://linoxide.com/wp-content/uploads/2014/08/systemctl-enable.gif)
|
||||
|
||||
Although the adoption of systemd has been very controversial in the last few years, slowly most of the major Linux distributions have either adopted or are planning to have it in the next point release, so it’s a useful tool to get used to.
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/start-stop-services-systemd/
|
||||
|
||||
作者:[Adrian Dinu][a]
|
||||
译者:[译者ID](https://github.com/译者ID)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/adriand/
|
@ -0,0 +1,69 @@
|
||||
Linux Systemd —— 在RHEL/CentOS 7中启动/停止/重启服务
|
||||
================================================================================
|
||||
|
||||
RHEL/CentOS 7.0中一个最主要的改变,就是切换到了**systemd**。它用于替代红帽企业版Linux的前任版本中的SysV和Upstart,对系统和服务进行管理。systemd兼容SysV和Linux标准组的启动脚本。
|
||||
|
||||
**Systemd**是一个Linux操作系统下的系统和服务管理器。它被设计成向后兼容SysV启动脚本,并提供了大量的特性,如开机时平行启动系统服务,按需启动守护进程,支持系统状态快照,或者基于依赖的服务控制逻辑。
|
||||
|
||||
先前的使用SysV初始化或Upstart的红帽企业版Linux版本中,使用位于/etc/rc.d/init.d/目录中的bash初始化脚本进行管理。而在RHEL 7/CentOS 7中,这些启动脚本被服务单元取代了。服务单元以.service扩展结束,提供了与初始化脚本同样的用途。要查看、启动、停止、重启、启用或者禁用系统服务,你要使用systemctl来代替旧的service命令。
|
||||
|
||||
> 注:为了向后兼容,旧的service命令在CentOS 7中仍然可用,它会重定向所有命令到新的systemctl工具。
|
||||
>
|
||||
### 使用systemctl来启动/停止/重启服务 ###
|
||||
|
||||
要启动一个服务,你需要使用像这样的命令:
|
||||
|
||||
# systemctl start httpd.service
|
||||
|
||||
这会启动httpd服务,就我们而言,Apache HTTP服务器。
|
||||
|
||||
要停掉它,可以以root身份使用该命令:
|
||||
|
||||
# systemctl stop httpd.service
|
||||
|
||||
要重启,你可以使用restart选项,如果服务在运行中,它将重启服务;或者使用start,如果服务不在运行。你也可以使用try-start选项,它只会在服务已经在运行中的时候重启服务。同时,reload选项你也可以有,它会重新加载配置文件。
|
||||
|
||||
# systemctl restart httpd.service
|
||||
# systemctl try-restart httpd.service
|
||||
# systemctl reload httpd.service
|
||||
|
||||
我们例子中的命令看起来会像下面这样:
|
||||
|
||||
![systemctl start-stop-restart](http://linoxide.com/wp-content/uploads/2014/08/systemctl-start-stop-restart.gif)
|
||||
|
||||
### 检查服务状态 ###
|
||||
|
||||
要检查服务状态,你可以使用status选项,看这里:
|
||||
|
||||
# systemctl status httpd.service
|
||||
|
||||
输出结果就像这样:
|
||||
|
||||
![systemctl status](http://linoxide.com/wp-content/uploads/2014/08/systemctl-status.gif)
|
||||
|
||||
它会告诉你运行中的服务的方方面面。
|
||||
|
||||
### 使用启用/禁用服务来控制开机启动 ###
|
||||
|
||||
你也可以使用enable/disable选项来控制一个服务是否开机启动,命令如下:
|
||||
|
||||
# systemctl enable httpd.service
|
||||
# systemctl disable httpd.service
|
||||
|
||||
输出结果看这里:
|
||||
|
||||
![systemctl-enable](http://linoxide.com/wp-content/uploads/2014/08/systemctl-enable.gif)
|
||||
|
||||
虽然在过去的几年中,对systemd的采用饱受争议,然而大多数主流发行版都已经逐渐采用或打算在下一个发行版中采用它。所以,它是一个有用的工具,我们需要好好熟悉它。
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
via: http://linoxide.com/linux-command/start-stop-services-systemd/
|
||||
|
||||
作者:[Adrian Dinu][a]
|
||||
译者:[GOLinux](https://github.com/GOLinux)
|
||||
校对:[校对者ID](https://github.com/校对者ID)
|
||||
|
||||
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创翻译,[Linux中国](http://linux.cn/) 荣誉推出
|
||||
|
||||
[a]:http://linoxide.com/author/adriand/
|
Loading…
Reference in New Issue
Block a user