`

Centos7下的systemctl命令与service和chkconfig

 
阅读更多

博主使用的操作系统是最新的CentOS 7,所以可能和网上一些老的博文有一定出入,那是因为版本更新的原因。

这里写图片描述

1 service

service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、重新加载配置(reload)、查看状态(status)等。

下面我们来看看在Centos 7上service命令的使用情况。

这里写图片描述

这里写图片描述

这里写图片描述

相信看到这里,大家已经发现问题了。那就是service命令的使用情况已经和以前的老版本不一样了。(作为一个初学Linux的人,我也是通过看网上的资料,发现把网友贴出的命令执行时,发现的问题。)同样的情况对于 chkconfig 命令也是一样。



2 chkconfig

老版本的使用说明:

chkconfig

提供了一个维护/etc/rc[0~6] d 文件夹的命令行工具,它减轻了系统直接管理这些文件夹中的符号连接的负担。chkconfig主要包括5个原始功能:为系统管理增加新的服务、为系统管理移除服务、列出单签服务的启动信息、改变服务的启动信息和检查特殊服务的启动状态。当单独运行chkconfig命令而不加任何参数时,他将显示服务的使用信息。

必要参数
–add 开启指定的服务程序
–del 关闭指定的服务程序
–list 列出chkconfig所知道的所有服务

选择参数
–level<代号> 设置服务程序的等级代号,它是一串0~7的数字,如“-level35”代表指定运行等级3和5
–help 显示帮助信息
–version 显示版本信息


我们在Centos7中试一试嘛。

这里写图片描述

所以问题已经很明显了,service和chkconfig命令的功能好像都被阉割了,而且好像已经被systemctl命令取代了。是这样吗?我们来看一看systemctl命令的介绍。



3 systemctl

文档中是这么介绍它的:
systemctl may be used to introspect and control the state of the “systemd” system and service manager.

再结合上面两个命令的执行结果,我们已经可以大致猜出systemctl的作用了,那就是:主要负责控制systemd系统和服务管理器。


什么是systemd系统?

CentOS 7 使用systemd替换了SysV。Systemd目的是要取代Unix时代以来一直在使用的init系统,兼容SysV和LSB的启动脚本,而且够在进程启动过程中更有效地引导加载服务。
systemd的特性有:

  • 支持并行化任务;
  • 同时采用socket式与D-Bus总线式激活服务;
  • 按需启动守护进程(daemon);
  • 利用 Linux 的 cgroups 监视进程;
  • 支持快照和系统恢复;
  • 维护挂载点和自动挂载点;
  • 各服务间基于依赖关系进行精密控制。

我们再来看看维基百科对它的介绍:
systemd is an init system used by some Linux distributions to bootstrap the user space and manage all processes subsequently, instead of the UNIX System V or Berkeley Software Distribution (BSD) init systems. The name systemd adheres to the Unix convention of naming daemons by appending the letter d.[6] It is published as free and open-source software under the terms of the GNU Lesser General Public License (LGPL) version 2.1 or later.[5] One of systemd’s main goals is to unify basic Linux configurations and service behaviors across all distributions.[7]

As of 2015, many Linux distributions have adopted systemd as their default init system.[8] The increasing adoption of systemd has been controversial, with critics arguing the software has violated the Unix philosophy by becoming increasingly complex, and that distributions have been forced to adopt it due to the dependency of various other software upon it, including, most notably, the GNOME 3 desktop environment.

总结一下关键信息:

  1. systemd是一个取代了SysV和LSB的初始化系统;
  2. 现在的大多数Linux发行版本都进行了这个更新;
  3. systemd不仅仅只是个初始化系统,它还包括了还包括了管理系统各种的方面的 daemon;
  4. systemd是大势所趋又存在争议。

所以,我们可以把systemctl理解为systemd的一个工具。也可以认为systemctl命令将service和chkconfig命令结合在了一起。总之,需要的时候会用就行。下面我们来看一些常见用法。

查看systemctl的相关信息

[root@master ~]# systemctl --version
systemd 219
+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN
[root@master ~]# whereis systemctl
systemctl: /usr/bin/systemctl /usr/share/man/man1/systemctl.1.gz
[root@master ~]# 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

列出所有可用单元

# systemctl list-unit-files
  • 1

这里写图片描述


列出所有运行中单元

# systemctl list-units
  • 1

这里写图片描述


列出所有失败的单元

[root@master ~]# systemctl --failed
0 loaded units listed. Pass --all to see loaded but inactive units, too.
To show all installed unit files use 'systemctl list-unit-files'.
[root@master ~]# 
  • 1
  • 2
  • 3
  • 4

检查某个单元是否启用

[root@master ~]# systemctl is-enabled mysqld.service
disabled
[root@master ~]# 
  • 1
  • 2
  • 3

查看某个服务(单元)的状态

这里写图片描述

[root@master ~]# systemctl status firewalld.service
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
  • 1
  • 2
  • 3
  • 4

*启动、重启、停止、重载服务

# systemctl start httpd.service
# systemctl restart httpd.service
# systemctl stop httpd.service
# systemctl reload httpd.service
# systemctl status httpd.service
  • 1
  • 2
  • 3
  • 4
  • 5

*激活/禁止自动启动

# systemctl enable httpd.service
# systemctl disable httpd.service
  • 1
  • 2

*杀死服务

# systemctl kill httpd
  • 1


以上就是我目前需要用的和想要和大家分享的功能,下面的只是补充,也没有详细的示例,所以有兴趣的朋友可以再简单看一看说明文档就好了。

附录

使用Systemctl控制并管理挂载点:

systemctl list-unit-files --type=mount

# systemctl start tmp.mount
# systemctl stop tmp.mount
# systemctl restart tmp.mount
# systemctl reload tmp.mount
# systemctl status tmp.mount

# systemctl is-active tmp.mount
# systemctl enable tmp.mount
# systemctl disable tmp.mount

# systemctl mask tmp.mount
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

使用Systemctl控制并管理套接口

# systemctl list-unit-files --type=socket

# systemctl start cups.socket
# systemctl restart cups.socket
# systemctl stop cups.socket
# systemctl reload cups.socket
# systemctl status cups.socket

# systemctl is-active cups.socket
# systemctl enable cups.socket
# systemctl disable cups.socket

# systemctl mask cups.socket
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13

使用Systemctl管理服务的CPU利用率

# systemctl show -p CPUShares httpd.service

# systemctl set-property httpd.service CPUShares=2000
# systemctl show -p CPUShares httpd.service

# systemctl show httpd
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

其他

# systemd-analyze critical-chain httpd.service

# systemctl list-dependencies httpd.service

# systemd-cgls
# systemd-cgtop

# systemctl emergency

# systemctl reboot
# systemctl halt
# systemctl suspend
# systemctl hibernate
# systemctl hybrid-sleep
分享到:
评论

相关推荐

    Centos6与Centos7的服务注册及部署

    4. 常用命令包括启动服务(systemctl start tomcat.service)、停止服务(systemctl stop tomcat.service)、重启服务(systemctl restart tomcat.service)、设置服务为开机自启动(systemctl enable tomcat....

    Centos7防火墙命令

    ### CentOS 7 防火墙管理:Firewalld与Iptables详解 #### Firewalld 基础操作 **Firewalld** 是 CentOS 7 默认安装的防火墙服务,它提供了动态管理防火墙的功能,可以即时更新规则而无需重启服务。 ##### 查看 ...

    CentOS7系统服务管理1

    systemctl是systemd系统和服务管理器的一部分,它取代了传统的service和chkconfig命令,提供更高效和集中的服务控制。虽然旧的命令在CentOS7中仍可用,但systemctl具有更多的功能和控制选项。值得注意的是,...

    CentOS7打开关闭防火墙与端口

    CentOS7 打开关闭防火墙与端口 1、firewalld的基本使用 2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。

    CentOS7服务开机启动

    ### CentOS7服务开机...通过上述步骤,我们可以有效地在CentOS7中为特定服务实现开机自动启动,即使这些服务不支持直接通过`systemctl`命令来配置。这不仅有助于提高系统的可用性和稳定性,还能简化日常的运维工作。

    centos7新变化

    首先,systemd的服务管理程序systemctl成为管理服务的核心工具,它集成了service和chkconfig的功能。通过systemctl,用户可以方便地启动、停止、重启服务,以及查看服务状态。例如,要启动postfix服务,可以使用`...

    Centos 6和Centos 7下服务启动方法及添加到开机启动项的方法

    在linux系统中,安装完一个软件或应用后,有时候需要手动启动该应用,也需要收到将该应用添加到开机启动项中,让其可以能够在linux一开机...chkconfig SERVICE on|off CentOS 7 : systemctl enable|disable SERVICE 以

    VMware安装CentOS7手册

    主要体现在使用`systemctl`替代了`service`和`chkconfig`命令。 - **启动服务**:`systemctl start|stop|restart &lt;服务名&gt;`。 - **设置自启动**:`systemctl enable|disable &lt;服务名&gt;`。 - **防火墙配置**:CentOS...

    CentOS7 linux下yum安装redis以及使用

    ### CentOS7 下通过 YUM 安装与使用 Redis Redis 是一种开源的键值存储系统,因其高性能和灵活性被广泛应用于缓存、消息队列等多种场景。本文将详细介绍如何在 CentOS7 系统上通过 YUM 包管理器安装 Redis,并进行...

    systemctl命令 管理系统服务

    Centos7之后从init完全换成了systemd的启动方式,systemd 启动服务的机制主要是通过 systemctl 的这个系统服务管理指令来处理。systemctl在用法上也囊括 service / chkconfig / setup / init 的大部分功能。 语法...

    CentOS7下安装搭建Redis-4.0.6

    在本文中,我们将深入探讨如何在CentOS 7操作系统上安装和配置Redis 4.0.6版本。Redis是一款开源的、高性能的键值存储系统,常用于数据库、缓存和消息中间件的角色。让我们逐步了解这个过程。 首先,我们需要确保...

    centos6or7做bond

    完成所有配置后,重启网络服务以应用更改,例如在CentOS 6中使用`service network restart`,在CentOS 7中使用`systemctl restart network.service`。然后,通过`ip a`或`ifconfig`命令检查新配置的bond接口是否正常...

    CentOS_7安装.docx

    在本文中,我们将深入探讨如何在CentOS 7环境下进行安装和配置,主要涉及Linux操作系统的基础设置、网络配置、安全优化以及系统维护等方面。 首先,安装CentOS 7时,通常有多种安装选项,包括安装或升级现有系统、...

    centOS7环境下安装openjdk和tomcat文档

    ### CentOS7环境下安装OpenJDK和Tomcat详细指南 #### 一、安装OpenJDK **1.1 查看CentOS自带JDK是否已安装** 首先,我们需要确认系统中是否已经安装了Java运行环境(JRE)或Java开发工具包(JDK)。这一步非常...

    h5手游[星辰变]手工架设服务端+数据库+架设流程

    1、系统版本:centos7 2、安装宝塔 使用xshell登录服务器,安装宝塔命令: 3、关闭防火墙 centos6系统 service iptables stop chkconfig iptables off centos7系统 systemctl stop firewalld.service ...

    centos7磁盘阵列及开机软件自启动_centos7磁盘阵列_开机软件自启动_

    在Linux系统中,CentOS 7是一个广泛使用的服务器操作系统,其稳定性和安全性备受赞誉。本文将深入探讨如何在CentOS 7中配置磁盘阵列(RAID)以及设置开机软件自启动,这对于提高系统性能和确保服务的连续性至关重要...

    chkconfig-1.3.30c.tar.gz

    首先,使用tar命令解压文件得到chkconfig-1.3.30c目录,然后在该目录下执行`./configure`来配置编译环境,生成Makefile文件;接着运行`make`进行编译,生成可执行文件;最后,执行`make install`将编译好的程序安装...

    centos7 openssh升级

    ### CentOS 7 OpenSSH 升级指南 #### 一、背景与目的 随着技术的发展以及安全威胁的变化,定期更新和升级系统组件对于保障系统的稳定性和安全性至关重要。OpenSSH 是一个非常重要的工具,它为用户提供了一个安全的...

    RabbitMQ在CentOS 7.docx

    ### RabbitMQ 在 CentOS 7 的安装与配置 #### 一、引言 RabbitMQ 是一个开源的消息代理软件,基于 AMQP(高级消息队列协议)标准,支持多种消息传递模式,广泛应用于分布式系统中作为消息中间件。本文将详细介绍...

    linux之centos7防火墙基本使用详解

    2.systemctl是CentOS7的服务管理工具中主要的工具,它融合之前service和chkconfig的功能于一体。 启动防火墙: systemctl start firewalld.service 关闭防火墙: systemctl stop firewalld.service 重启防火墙: ...

Global site tag (gtag.js) - Google Analytics