当前位置: 首页 > news >正文

linux 命令- systemctl

systemctl 参数说明

1、使用语法

用法:systemctl [OPTIONS…] {COMMAND} …

2 、参数说明

参数参数说明
start立刻启动后面接的unit
stop立刻关闭后面接的unit
restart立刻关闭后启动后面接的unit,亦即执行stop再start的意思
reload不关闭后面接的unit的情况下,重载配置文件,让设定生效
enable设定下次开机时,后面接的unit会被启动
disable设定下次开机时,后面接的unit 不会被启动
status目前后面接的这个unit 的状态,会列出是否正在执行、是否开机启动等信息。
is-active目前有没有正在运行中
is-enable开机时有没有预设要启用这个unit
kill不要被kill这个名字吓着了,它其实是向运行unit的进程发送信号
show列出unit的配置。
mask注销unit,注销后你就无法启动这个unit了
unmask取消对unit的注销
list-units依据unit列出目前有启动的unit。若加上–all才会列出没启动的。(等价于无参数)
list-unit-files列出所有以安装unit以及他们的开机启动状态(enabled、disabled、static、mask)。
–type=TYPE 就是unit type,主要有service,socket,target等
get-default取得目前的 target
set-default设定后面接的 target 成为默认的操作模式
isolate切换到后面接的模式

systemctl 描述

任务旧指令新指令
使某服务自动启动chkconfig --level 3httpd on systemctl enable httpd.service
使某服务不自动启动chkconfig --level 3 httpd offsystemctl disable httpd.service
检查服务状态service httpd status systemctl status httpd.service (服务详细信息)systemctl is-enabled httpd.service (仅显示是否 Active)
显示所有已启动的服务chkconfig --listsystemctl list-units --type=service
启动某服务service httpd startsystemctl start httpd.service
停止某服务service httpd stopsystemctl stop httpd.service
重启某服务service httpd restartsystemctl restart httpd.service
某服务重新加载配置文件service httpd reloadsystemctl reload httpd.service

在这里插入图片描述

systemctl 示例

列出所有可用单元

systemctl list-unit-files |moresystemctl list-units --type=target

在这里插入图片描述

列出所有已加载单元

 systemctl list-units |more

在这里插入图片描述

查看可用systemctl管理的所有服务

 systemctl list-units --type=service

在这里插入图片描述
在这里插入图片描述

systemctl可用管理单元分很多种,日常工作中我们仅仅用于管理服务,unit的常见类型:

Service unit: 文件扩展名.service, 用于定义系统服务;
Target unit: 文件扩展名.target, 用于模拟实现"运行级别";
Device unit: 文件扩展名.device, 用于定义内核识别的设备;
Mount unit: 文件扩展名.mount, 用于定义文件系统的挂载点;
Socket unit: 文件扩展名.socket, 用于标识进程间通信用到的socket文件;
Snapshot unit: 文件扩展名.snapshot, 用于管理系统快照;
Swap unit: 文件扩展名.swap, 用于标识swap设备;
Automount unit: 文件扩展名.automount, 用于定义文件系统自动点设备;
Path unit: 文件扩展名.path, 用于定义文件系统中的一文件或目录;

注销服务

服务被注销后该服务就无法通过systemctl进行启停管理。

[root@s153 system]# systemctl mask firewalld
Created symlink from /etc/systemd/system/firewalld.service to /dev/null.
[root@s153 system]# systemctl start firewalld
Failed to start firewalld.service: Unit is masked.

取消注销服务

[root@s153 system]# systemctl unmask firewalld
Removed symlink /etc/systemd/system/firewalld.service.
[root@s153 system]# systemctl start firewalld

设置服务开机自启动

[root@s153 system]# systemctl enable xinetd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/xinetd.service to /usr/lib/systemd/system/xinetd.service.

取消服务开机自启动

[root@s153 system]# systemctl disable xinetd.service
Removed symlink /etc/systemd/system/multi-user.target.wants/xinetd.service.

查看机器信息

[root@s153 system]# systemctl list-machines
NAME STATE FAILED JOBS
s153 (host) running 0 01 machines listed.

查看系统环境变量

[root@s153 system]# systemctl show-environment
LANG=zh_CN.UTF-8
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin

重新加载unit文件

如果手动修改了unit文件,可以使用此命令重新加载。

[root@s153 system]# systemctl daemon-reload

创建一个系统快照

[root@s153 system]# systemctl snapshot wuhs
wuhs.snapshot

删除指定快照

[root@s153 system]# systemctl delete wuhs

查看服务是否开机自启动

[root@s153 system]# systemctl is-enabled xinetd.service
enabled

杀死服务

[root@s153 system]# systemctl kill xinetd
[root@s153 system]# systemctl is-failed xinetd
inactive

进入救援模式

[root@s153 system]# systemctl rescueBroadcast message from root@s153 on pts/1 (三 2022-07-20 13:08:30 CST):The system is going down to rescue mode NOW!
#救援模式下切换到默认模式
[root@s153 ~]# systemctl default

关闭系统

[root@s153 ~]# systemctl poweroff

重启机器

[root@s153 ~]# systemctl reboot

系统睡眠

suspend暂停模式,类似window环境的睡眠模式,会将系统的状态数据保存到内存中,然后关闭掉大部分的系统硬件,当然,并没有实际关机。当用户按下唤醒机器的按钮,系统数据会重内存中回复,然后重新驱动被大部分关闭的硬件,就开始正常运作!唤醒的速度较快。

[root@s153 ~]# systemctl suspend

查看系统启动模式

[root@s153 boot]# systemctl get-default
multi-user.target

设置系统为图形界面启动

[root@s153 system]# systemctl set-default graphical.target
Removed symlink /etc/systemd/system/default.target.
Created symlink from /etc/systemd/system/default.target to /usr/lib/systemd/system/graphical.target.
http://www.lryc.cn/news/129158.html

相关文章:

  • 自动驾驶,一次道阻且长的远征|数据猿直播干货分享
  • 大数据培训前景怎么样?企业需求量大吗
  • redis — 基于Spring Boot实现redis延迟队列
  • 【日常积累】Linux之init系统学习
  • Python功能制作之3D方块
  • 【0基础入门Python笔记】二、python 之逻辑运算和制流程语句
  • python中的svm:介绍和基本使用方法
  • typedef
  • 校园跑腿市场行情分析
  • 微服务相关面试题
  • 前端-ES6
  • 169. 多数元素(摩尔投票法) 题解
  • python中的cnn:介绍和基本使用方法
  • Dockerfile概念、镜像原理、制作及案例讲解
  • 07-微信小程序-注册页面-模块化
  • 考研算法第46天: 字符串转换整数 【字符串,模拟】
  • Cesium for unity 1.5.0使用注意事项
  • 初阶C语言-结构体
  • Android Studio实现解析HTML获取图片URL,将URL存到list,进行瀑布流展示
  • java学习004
  • Linux网络编程:网络基础
  • 3D沉浸式旅游网站开发案例复盘【Three.js】
  • IO的几个模型
  • 中路对线发现正在攻防演练中投毒的红队大佬
  • 【LINUX相关】生成随机数(srand、/dev/random 和 /dev/urandom )
  • spark使用心得
  • 什么是边车
  • vue项目打包成exe文件
  • 基于MFCC特征提取和GMM训练的语音信号识别matlab仿真
  • client-go实战之十二:选主(leader-election)