1、
 
systemctl命令
说明
systemctl    start   [unit type]
启动服务
systemctl    stop   [unit type]
停止服务
systemctl    restart   [unit type]
重启服务
 
 
  • status:参数来查看服务运行情况
  • reload:重新加载服务,加载更新后的配置文件(并不是所有服务都支持这个参数,比如network.service)
 
2、设置开机启动/不启动服务
 
systemctl命令
说明
systemctl enable [unit type]
设置服务开机启动
systemctl disable [unit type]
设备服务禁止开机启动
 
 
3、查看系统上的所有服务
 
systemctl命令
说明
systemctl
列出所有的系统服务
systemctl list-units
列出所有启动unit
systemctl list-unit-files
列出所有启动文件
systemctl list-units –type=service –all
列出所有service类型的unit
systemctl list-units –type=service –all grep cpu
列出 cpu电源管理机制的服务
systemctl list-units –type=target –all
列出所有target
 
 
 
4、systemctl的特殊用法
 
systemctl命令
说明
systemctl is-active [unit type]
查看服务是否运行
systemctl is-enable [unit type]
查看服务是否设置为开机启动
systemctl mask [unit type]
注销指定服务
systemctl unmask [unit type]
取消注销指定服务
 
 
应用举例:
#查看网络服务是否启动
systemctl is-active network.service
#检查网络服务是否设置为开机启动
systemctl is-enable network.service
#停止cups服务
systemctl stop cups.service
#注销cups服务
systemctl mask cups.service
#查看cups服务状态
systemctl status cups.service
#取消注销cups服务
systemctl unmask cups.service
 
关闭sshd服务
在使用systemctl关闭网络服务时有一些特殊 需要同时关闭unit.servce和unit.socket
[root@localhost ~]# systemctl list-units --all |grep sshd
  sshd-keygen.service          loaded    inactive dead      OpenSSH Server Key Generation
  sshd.service                          loaded    active   running   OpenSSH server daemon
  sshd.socket                          loaded    inactive dead      OpenSSH Server Socket
 
可以看到系统同时开启了 sshd.service 和 sshd.socket , 如果只闭关了 sshd.service 那么 sshd.socket还在监听网络,在网络上有要求连接 sshd 时就会启动 sshd.service 。因此如果想完全关闭sshd服务的话,需要同时停用 sshd.service 和 sshd.socket 。
systemctl stop sshd.service
systemctl stop sshd.socket
systemctl disable sshd.service sshd.socket
 
 
5、init命令与systemctl命令对比
 
init命令
systemctl命令
说明
init 0
systemctl poweroff
系统关机
init 6
systemctl reboot
重新启动
 
 
与开关机相关的其他命令:
systemctl命令
说明
systemctl suspend
进入睡眠模式
systemctl hibernate
进入休眠模式
systemctl rescue
强制进入救援模式
systemctl emergency
强制进入紧急救援模式
 
 
 
 
6、设置系统运行级别
 
运行级别对应表:
 
init级别
systemctl target
0
shutdown.target
1
emergency.target
2
rescure.target
3
multi-user.target
4
5
graphical.target
6
 
此外还有一个getty.target用来设置tty的数量。
 
 
设置运行级别:
命令格式:
systemctl     [command]      [unit.target]
 
参数详解:
command:
  • get-default :取得当前的target
  • set-default :设置指定的target为默认的运行级别
  • isolate :切换到指定的运行级别
  • unit.target :为5.1表中列出的运行级别
 
 
 
systemctl命令
说明
systemctl get-default
获得当前的运行级别
systemctl set-default multi-user.target
设置默认的运行级别为mulit-user
systemctl isolate multi-user.target
在不重启的情况下,切换到运行级别mulit-user下
systemctl isolate graphical.target
在不重启的情况下,切换到图形界面下
 
 
 
7、使用systemctl分析各服务之间的依赖关系
命令格式
systemctl    list-dependencies    [unit]    [–reverse]
 
示例:
#获得当前运行级别的target
[root@www ~]# systemctl get-default
multi-user.target
 
#查看当前运行级别target(mult-user)启动了哪些服务
[root@www ~]# systemctl list-dependencies
 
#查看哪些target引用了当前运行级别的target
[root@www ~]# systemctl list-dependencies --reverse
 
 
8、开机关机
Table 4.2 systemctl Commands for Shutting Down, Suspending, or Rebooting a System
 
systemctl Command
Description
systemctl halt
Halt the system.
systemctl hibernate
Put the system into hibernation.
systemctl hybrid-sleep
Put the system into hibernation and suspend its operation.
systemctl poweroff
Halt and power off the system.
systemctl reboot
Reboot the system.
systemctl suspend
Suspend the system.

RHEL7使用systemctl管理服务的更多相关文章

  1. Linux_CentOS 中systemctl 管理服务、防火墙 firewalld 以及 SELinux 配置

    使用 systemctl 管理服务 systemctl 就是 service 和 chkconfig 这两个命令的整合,在 CentOS 7 就开始被使用了,systemctl是系统服务管理器命令,它 ...

  2. 二进制编译安装nginx并加入systemctl管理服务

    一.安装nginx所需环境 # yum install gcc-c++ pcre pcre-devel zlib zlib-devel openssl openssl-devel -y 二.安装ngi ...

  3. Linux学习-透过 systemctl 管理服务

    透过 systemctl 管理单一服务 (service unit) 的启动/开机启动与观察状态 一般来说,服务的启动有两个阶段,一 个是『开机的时候设定要不要启动这个服务』, 以及『你现在要不要启动 ...

  4. 使用 Centos 7 的 systemctl 管理服务

    CentOS 7的服务systemctl脚本存放在:/usr/lib/systemd/,有系统(system)和用户(user)之分,像需要开机不登陆就能运行的程序,存系统服务里即:/usr/lib/ ...

  5. 使用systemctl管理服务

    系统服务,开机不需要登录就能运行的程序(相当于开机自启)/usr/lib/systemd/system 用户服务,需要登录后才能运行的程序/usr/lib/systemd/user 目录下又存在两种类 ...

  6. CentOS7下普通账号通过systemctl管理服务需要输入root密码问题

    问题描述: 使用普通账号test通过systemctl启动系统服务提示需要输入root密码: 解决方案: 根据上面提示得知权限由polkit进行管理,对应的是org.freedesktop.syste ...

  7. CentOS7 使用systemctl来管理服务

    1.建立service文件 以tomcat为例 , 建立tomcat.service文件 #服务说明 [Unit] #服务描述 Description=Tomcat Service #前置需要启动的服 ...

  8. 手动编译安装Libvirt之后利用systemctl管理libvirtd服务

    因为要给特殊的虚拟机关联文件指定selinux标签,而默认的Libvirt没有这个功能,所以需要修改LIbvirt源代码,重新编译安装Libvirt,而手动编译安装的LIbvirt,没有办法使用sys ...

  9. 透过systemctl管理mysqld服务

    1. 背景 CentOS 7.x 之前的版本,系统启动时,第一支呼叫的程序是 init ,然后 init 去唤起所有的系统所需要的服务,无论是本地服务还是网络服务.所有的服务启动脚本都放置于 /etc ...

随机推荐

  1. jdbcTemplate的queryForList的使用方法

    jdbcTemplate的queryForList的使用方法如下,它不一样的地方是,它获得的结果,会再放到一个map里去: List rows = jdbcTemplate.queryForList( ...

  2. python - 函数any() 和 all() 的区别

    转自:https://www.cnblogs.com/nulige/p/6128816.html any()与all()函数的区别: any是任意,而all是全部. 版本:该函数适用于2.5以上版本, ...

  3. 使用 iview Table 表格组件修改操作的显示隐藏

    使用 iview Table 表格组件修改操作的显示隐藏,如下图 1.如何设置 table 操作按后台传入的状态值去渲染 不同的按钮? 解决方法 我们在vue2中,动态渲染html 使用的是 retu ...

  4. DataGridViewCheckBoxColumn的Value值和EditFormatedValue值不一致

    今天要做一个代码修改DataGridViewCheckBoxColumn的Value值然后再遍历获取DataGridview选中项,因为遍历的时候为了能获取跟界面一致的选项,所以判断是否选中使用的是E ...

  5. C语言Ⅰ博客作业03

    一. 这个作业属于那个课程 C语言程序设计II 这个作业要求在哪里 https://edu.cnblogs.com/campus/zswxy/CST2019-3/homework/8718 我在这个课 ...

  6. 学习Linux第一周记

    2019/11/25 服务器硬件详述1) CPU                         作用:运算/控制      关注信息 :路数 服务器中CPU的颗数   一般有  (单路    双路  ...

  7. BUUOJ reverse 刮开有奖

    刮开有奖 这是一个赌博程序,快去赚钱吧!!!!!!!!!!!!!!!!!!!!!!!!!!!(在编辑框中的输入值,即为flag,提交即可) 注意:得到的 flag 请包上 flag{} 提交 拖到id ...

  8. MyBatis Mapper XML 详解

    MyBatis Mapper XML 详解 MyBatis 真正的力量是在映射语句中.这里是奇迹发生的地方.对于所有的力量,SQL 映射的 XML 文件是相当的简单.当然如果你将它们和对等功能的 JD ...

  9. 使用lombok.Data编译时无法找到get/set方法

    我的IDEA版本是2019.2 在使用IDEA创建了一个SpringBoot项目,其中一个实体类使用了@Data注解,但是在Service中调用的时候找不到get/set方法. 检查步骤: 1.在St ...

  10. numpy使用数组进行数据处理

    numpy使用数组进行数据处理 meshgrid函数 理解: 二维坐标系中,X轴可以取三个值1,2,3, Y轴可以取三个值7,8, 请问可以获得多少个点的坐标? 显而易见是6个: (1,7)(2,7) ...