经常用到的高频命令小结

- 所有服务unit放在这里
ll /usr/lib/systemd/system- 默认启动级别
[root@n1 ~]# ll /etc/systemd/system/default.target
lrwxrwxrwx 1 root root 41 Mar  4 09:02 /etc/systemd/system/default.target -> /usr/lib/systemd/system/multi-user.target- 开机启动的服务
ll /etc/systemd/system/multi-user.target.wants/- 哪些服务开机会启动
[root@n1 ~]# systemctl list-unit-files --type service |grep enable
autovt@.service                               enabled
crond.service                                 enabled
docker.service                                enabled
getty@.service                                enabled
ntpdate.service                               enabled
rsyslog.service                               enabled
sshd.service                                  enabled
sysstat.service                               enabled - 目前哪些服务处于active状态
[root@n1 ~]# systemctl list-units --type service |grep active
crond.service                      loaded active running Command Scheduler
dbus.service                       loaded active running D-Bus System Message Bus
docker.service                     loaded active running Docker Application Container Engine
getty@tty1.service                 loaded active running Getty on tty1- 查看某个服务是否开机自启
systemctl is-enabled httpd.service 或
systemctl status httpd.service

systemd 有很多unit,其中service.unit是管理系统服务的.

unit的类型

/usr/lib/systemd/system

查看管理系统服务的相关的, 即 .service后缀的

[root@n1 system]# ls /usr/lib/systemd/system/*.service|more
/usr/lib/systemd/system/arp-ethers.service
/usr/lib/systemd/system/auditd.service
/usr/lib/systemd/system/autovt@.service
/usr/lib/systemd/system/blk-availability.service
/usr/lib/systemd/system/brandbot.service
...特点:不需要可执行权限,其内容也不能执行仅是systemd的调用的配置文件
unit类型 作用
Service unit 管理系统服务,我们暂且只关心这个
Target unit 多个Unit构成的一个组
Device Unit 硬件设备
Mount Unit 文件系统的挂载点
Automount Unit 自动挂载点
Path Unit 文件或路径
Scope Unit 不是由 Systemd 启动的外部进程
Slice Unit 进程组
Snapshot Unit Systemd 快照,可以切回某个快照
Socket Unit 进程间通信的 socket
Swap Unit swap 文件
Timer Unit 定时器

centos6 chkconfig VS 使用systemd的service unit治理centos7服务

任务 旧指令 新指令
哪些服务正在跑? chkconfig --list\grep 3:on systemctl list-units --type=service
哪些服务开机会自启动? chkconfig --list systemctl list-unit-files --type=service
使httpd开机自启动 chkconfig --level 3 httpd on systemctl enable httpd.service
使httd开机不自启动 chkconfig --level 3 httpd off systemctl disable httpd.service
查看httpd现在是否启动着 service httpd status systemctl status httpd.service (服务详细信息)
启动某服务 /etc/init.d/httpd start systemctl start httpd.service
停止某服务 /etc/init.d/httpd stop systemctl stop httpd.service
重启某服务 /etc/init.d/httpd restart systemctl restart httpd.service
所有已装载的级别(而非当前级别) runlevel systemctl list-units --type target
查看默认级别是啥 cat /etc/inittab systemctl get-default
设置默认级别 init 3 systemctl set-default multi-user.target
查看服务状态 /etc/init.d/http status systemctl is-enabled httpd.service/systemctl status httpd.service
默认启动第一个进程 init systemd
ls /usr/lib/systemd/system/*.service|more 下以service开头的文件,都是和系统服务有关的, 其下还有别的后缀的服务.是别的unit的配置文件.

serivice unit配置

target unit: 的含义是服务组,表示一组服务。

将很多服务放在一坨, 开启启动时候加载这个文件.

启动级别

/usr/lib/systemd/system
/etc/systemd/systemrunlevel0.target -> poweroff.target
runlevel2.target -> multi-user.target
runlevel3.target -> multi-user.target
runlevel4.target -> multi-user.target
runlevel5.target -> graphical.target
runlevel6.target -> reboot.target

注意: centos7里,运行级别234没区别.

查看在运行的服务

我们看ACTIVE就ok了,SUB这一列可以不用理会

[root@n1 system]# systemctl list-units --type=service
UNIT                               LOAD   ACTIVE SUB     DESCRIPTION
crond.service                      loaded active running Command Scheduler
dbus.service                       loaded active running D-Bus System Message Bus
docker.service                     loaded active running Docker Application Container Engine
getty@tty1.service                 loaded active running Getty on tty1
httpd.service                      loaded active running The Apache HTTP Server

查看开机是否会启动

[root@n1 system]# systemctl list-unit-files --type=service
UNIT FILE                                     STATE
arp-ethers.service                            disabled
auditd.service                                disabled
autovt@.service                               enabled #开机会启动
blk-availability.service                      disabled#开机不会启动
brandbot.service                              static  #这类不用管
conntrackd.service                            disabled

systemd管理服务入门

设置开机自动启动细节

[root@n1 ~]# yum install psmisc -y
[root@n1 ~]# pstree
systemd─┬─agetty├─crond├─dbus-daemon├─dockerd─┬─docker-containe─┬─docker-containe─┬─mysqld───20*[{mysqld}]│         │                 │                 └─8*[{docker-containe}]│         │                 └─9*[{docker-containe}]│         ├─docker-proxy───3*[{docker-proxy}]│         └─11*[{dockerd}]├─httpd───8*[httpd]├─lvmetad├─polkitd───5*[{polkitd}]├─rsyslogd───2*[{rsyslogd}]├─sshd───sshd───bash───pstree├─systemd-journal├─systemd-logind└─systemd-udevd
[root@n1 system]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.

相当于执行

ln -s /usr/lib/systemd/system/httpd.service /etc/systemd/system/multi-user.target.wants/httpd.service

disable相当于删除

[root@n1 system]# systemctl disable httpd
Removed symlink /etc/systemd/system/multi-user.target.wants/httpd.service.
[root@n1 system]# ll /etc/systemd/system/multi-user.target.wants
total 0
lrwxrwxrwx. 1 root root 37 Dec 27 04:44 crond.service -> /usr/lib/systemd/system/crond.service
lrwxrwxrwx  1 root root 38 Dec 26 21:05 docker.service -> /usr/lib/systemd/system/docker.service
lrwxrwxrwx  1 root root 37 Mar  4 03:39 httpd.service -> /usr/lib/systemd/system/httpd.service
lrwxrwxrwx. 1 root root 39 Dec 26 21:00 ntpdate.service -> /usr/lib/systemd/system/ntpdate.service
lrwxrwxrwx. 1 root root 40 Dec 27 04:44 remote-fs.target -> /usr/lib/systemd/system/remote-fs.target
lrwxrwxrwx. 1 root root 39 Dec 27 04:44 rsyslog.service -> /usr/lib/systemd/system/rsyslog.service
lrwxrwxrwx. 1 root root 36 Dec 27 04:44 sshd.service -> /usr/lib/systemd/system/sshd.service
lrwxrwxrwx. 1 root root 39 Dec 27 05:00 sysstat.service -> /usr/lib/systemd/system/sysstat.service

设置启动级别的命令

- 设置默认启动级别
[root@n1 ~]# 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.- 查看默认的启动级别
[root@n1 ~]# systemctl get-default
graphical.target- 手动修改启动级别(先将原来的rm了)
[root@n1 ~]# ln -sv /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target
ln: failed to create symbolic link ‘/etc/systemd/system/default.target’: File exists
[root@n1 ~]# rm -rf /etc/systemd/system/default.target
[root@n1 ~]# ln -sv /usr/lib/systemd/system/multi-user.target /etc/systemd/system/default.target
‘/etc/systemd/system/default.target’ -> ‘/usr/lib/systemd/system/multi-user.target’
[root@n1 ~]# systemctl get-default
multi-user.target- 查看服务状态
[root@n1 ~]# systemctl is-enabled httpd.service
disabled

转载于:https://www.cnblogs.com/iiiiher/p/8503665.html

[svc]centos7的服务治理-systemd相关推荐

  1. 使用 Flomesh 强化 Spring Cloud 服务治理

    作者 | Addo Zhang 来源 | 云原生指北 写在最前 这篇是关于如何使用 Flomesh[1] 服务网格来强化 Spring Cloud 的服务治理能力,降低 Spring Cloud 微服 ...

  2. 架构专家梁勇:哈啰在分布式消息治理和微服务治理中的实践

    背景介绍 哈啰已进化为包括两轮出行(哈啰单车.哈啰助力车.哈啰电动车.小哈换电).四轮出行(哈啰顺风车.全网叫车.哈啰打车)等的综合化移动出行平台,并向酒店.到店团购等众多本地生活化生态探索. 随着公 ...

  3. 酷家乐如何使用 Istio 解决新服务治理系统(Serverless)接入已有成熟自研 Java 服务治理体系...

    本文来自酷家乐先进技术工程团队,作者罗宁,酷家乐资深开发工程师. 公司背景 酷家乐 [1] 公司以分布式并行计算和多媒体数据挖掘为技术核心,推出的家居云设计平台,致力于云渲染.云设计.BIM.VR.A ...

  4. 微服务治理 - 初探Istio

    服务网格概念源于 Buoyant 公司的CEO Willain Morgan 的文章 "What's a service mesh ? And do i need one?" 一. ...

  5. Spring Cloud(二)Consul 服务治理实现

    Spring Cloud Consul 项目是针对Consul的服务治理实现.Consul是一个分布式高可用的系统,具有分布式.高可用.高扩展性. Consul 简介 Consul 是 HashiCo ...

  6. 当我们在说微服务治理的时候究竟在说什么

    点击上方"方志朋",选择"设为星标" 回复"666"获取新整理的面试文章 来源:https://urlify.cn/EZviUr 自从微服务 ...

  7. 聊聊服务治理中的路由设计

    前言 路由(Route)的设计广泛存在于众多领域,以 RPC 框架 Dubbo 为例,就有标签路由.脚本路由.权重路由.同机房路由等实现. 在框架设计层面,路由层往往位于负载均衡层之前,在进行选址时, ...

  8. 服务治理治什么,10张图告诉你答案

    凌晨四点被公司的监控告警叫醒了,告警的原因是生产环境跑批任务发生故障.即刻起床处理故障,但还是花了不少时间才解决. 这次故障是一次数据校验的跑批任务,校验前面跑批任务的数据是否正确.幸运的是,之前的核 ...

  9. 全面解析微服务系统监控分层,啃透服务治理核心!

    来源:掘金 juejin.cn/post/6844903846192349191#heading-6 -     前言     - "监控"是微服务治理的一个重要环节,监控系统的完 ...

最新文章

  1. Nginx使用http auth basic认证保护后台admin
  2. ajax核心代码提交,ajax表单在Asp.net核心提交后的RedirectToAction
  3. python主要运用于-Python八大主要应用领域,你都知道吗?
  4. Windows上 万能的串口调试助手
  5. Python2/3 list set性能测试
  6. 百度地图手机和电脑不一致_如何解决电脑显色和印刷色不一致的问题
  7. sap中泰国有预扣税设置吗_泰国餐厅密度细分:带有K-means聚类的python
  8. 终于有人把正态分布和二八法则讲明白了
  9. Linux常用最基础命令总结
  10. 云+社区「开源之道」主题直播,这些技术大佬都说了哪些干货?
  11. delphi 的 pos 函数 对中文支持不好。
  12. 配置SQL Server 2008 R2 Reporting Services
  13. php foreach创建文件,php – mkdir()在foreach函数中跳过第一个文件
  14. 斩获双奖 | 悬镜安全亮相IDC 2022 CSO全球网络安全峰会
  15. 三星 s4(i9502) android4.4rom 官方,三星i9502官方rom固件系统刷机包_三星i9502原版线刷包下载...
  16. 什么是即时通讯(IM)?
  17. LaTeX 嵌入MATLAB 绘图的字体
  18. 徐亚波博士出席暨南大学企管ME论坛,讲述数说“超级飞轮”的故事
  19. LintCode(M) 乱序字符串
  20. c 语言 模板函数参数,深入解析C++中的函数模板和函数的默认参数

热门文章

  1. Python入门--else语句
  2. python第三方插件pip是什么_Python怎么安装第三方模块?
  3. python里split以制表符分隔_在python中拆分以制表符分隔的大文件
  4. str_replace()函数
  5. UnityGI3:光照探针
  6. bzoj 1636 bzoj 1699: [Usaco2007 Jan]Balanced Lineup排队(RMQ)
  7. Ubuntu中需要安装的
  8. python后台架构Django教程——项目配置setting
  9. 使用help()输入keywords查看python中定义的关键字
  10. node获取windows pc 机器的标示