博主使用的操作系统是最新的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.

总结一下关键信息:

systemd是一个取代了SysV和LSB的初始化系统;
    现在的大多数Linux发行版本都进行了这个更新;
    systemd不仅仅只是个初始化系统,它还包括了还包括了管理系统各种的方面的 daemon;
    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
---------------------
作者:凉秋cds
来源:CSDN
原文:https://blog.csdn.net/cds86333774/article/details/51165361
版权声明:本文为博主原创文章,转载请附上博文链接!

Centos7下的systemctl命令与service和chkconfig的更多相关文章

  1. centos7也支持service命令启动服务吗,对于centos7 中的systemctl和旧的service命令的区别和联系

    一.centos7也支持service命令启动服务吗 CentOS 7.0中一个最主要的改变,就是切换到了systemd.它用于替代红帽企业版Linux前任版本中的SysV和Upstart,对系统和服 ...

  2. Docker下构建centos7容器无法使用systemctl命令的解决办法

    最近在使用docker 构建centos7 容器时,发现无法使用systemctl 命令.后来万能的百度解决了问题,随记之以备后用. 解决办法: docker run --privileged -it ...

  3. CentOS7+Nginx设置Systemctl restart nginx.service服务

    centos 7上是用Systemd进行系统初始化的,Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvinit 固有的缺点,提高系统的启动速度.关于 ...

  4. Linux下使用systemctl命令

    systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一起. 任务 旧指令 新指令 使某服务自动启动 chkconfig --level 3 ...

  5. centos7下使用wget命令安装mysql

    1.首先安装wget命令: yum -y install  wget 2.下载mysql wget http://repo.mysql.com/mysql-community-release-el7- ...

  6. Centos7下常用配置命令

    1.禁用ipv6 Step 1: add this rule in /etc/sysctl.conf : net.ipv6.conf.all.disable_ipv6=1 Step 2: add th ...

  7. CentOS7下Firewall常用命令

    安装它,只需 yum install firewalld 如果需要图形界面的话,则再安装 yum install firewall-config 一.介绍 防火墙守护 firewalld 服务引入了一 ...

  8. centos7下安装iostat命令

    [root@node01 yum.repos.d]# yum intall -y sysstat Loaded plugins: fastestmirror No such command: inta ...

  9. centos7中systemctl命令使用方法和心得体会

    使用linux的同学对service和chkconfig两个命令都不陌生,其重要性不言而喻,那么怎么会突然冒出个systemctl命令呢?其实,为了简化操作,systemctl命令将service和c ...

随机推荐

  1. 【liunx】Linux下的压缩和解压缩命令——jar

    原文链接:http://blog.chinaunix.net/uid-692788-id-2681136.html JAR包是Java中所特有一种压缩文档,其实大家就可以把它理解为.zip包.当然也是 ...

  2. ORM 创建manytomay的三种方法 反向查询 和一些 双下方法版学员管理系统3

    老师信息管理   三种创建多对对外键的方式常用第二种和第三种 思考 三种方式创建多对多外键方式及其优缺点. 外键的查询和使用 1外键的创建: 在数据库表中的表现形式 如何连表查询和使用 表里边:  s ...

  3. 02Linux环境配置

    Linux环境配置 修改ip地址 1,图形化界面 2,setup 命令虚拟界面 3,修改配置文件(以网络方式为NAT示例) vi /etc/sysconfig/network-scripts/ifcf ...

  4. Quart.net配置oracle的坑

    引用的Oracle.DataAccess.dll是64位, 生成选项需要去除默认勾选的 “首选32位”,不然会导致未能加载程序集

  5. python 属性的访问权限,_,__,__XXX__

    1. 非私有变量,可以随意调用和修改 在class内部,有属性和方法,如下面的class Student 有name和score class Student(object): def __init__ ...

  6. 三种方法获取Class对象的区别

    有关反射的内容见 java反射 得到某个类的Class对象有三种方法: 使用“类名.class”取得 Class.forName(String className) 通过该类实例对象的getClass ...

  7. jersey2+freemarker+spring3的集成

    由于即将开始的新项目,是一个对外网开放访问权限的web应用.所以,公司技术管理层不允许使用struts以及spring mvc这一套.所以,我们开始转战曾经用作REST API的框架jersey及其周 ...

  8. 使用Tesseract-OCR 进行文字识别

    关于中文的识别,效果比较好而且开源的应该就是Tesseract-OCR了,所以自己亲身试用一下,分享到博客让有同样兴趣的人少走弯路. 文中所用到的身份证图片资源是百度找的,如有侵权可联系我删除. 一. ...

  9. 找进程的窗口Handle

    Process[] ProcessList = Process.GetProcessesByName("mspaint");//画图板 IntPtr test = ProcessL ...

  10. TabControl TabPage添加关闭按钮

    自定义控件代码如下: using System.Drawing; using System.Windows.Forms; namespace Demo.UC { public class KKTab ...