Brc's blog
首页
前端
后端
运维
  • 工作笔记
  • 分类
  • 标签
  • 归档
关于

Brc

努力中
首页
前端
后端
运维
  • 工作笔记
  • 分类
  • 标签
  • 归档
关于
  • Linux基础

    • Bash shell
    • 文件属性
    • 编辑工具vim
    • 用户管理
    • 用户组管理
    • 普通用户提权
    • 基础权限
    • 特殊权限
    • 文件特殊属性
    • IO重定向
    • 文件查找
    • 文件压缩
    • 软件包管理

    • 磁盘管理

    • 进程管理
    • 计划任务
    • systemd
      • systemd的由来
      • 什么是systemd
      • systemd的优势
      • systemd配置文件
      • systemd相关命令
      • systemd管理运行级别
        • 什么是运行级别
        • 调整系统启动的运行级别
    • Supervisor
    • 网络管理

    • Chrony时间同步
    • NFS网络文件系统
  • Linux进阶

  • 其他

  • 运维
  • Linux基础
Brc
2021-08-03
目录

systemd

# systemd的由来

  • Linux一直以来都是采用init进程作为祖宗进程,但是init有两个缺点:
    • 启动时间长。init进程是串行启动,只有前一个进程启动完,才会启动下一个进程;
    • 启动脚本复杂。初始化完成后系统会加载很多脚本,脚本都会处理各自的情况,这会让脚本多而复杂;
  • Centos5是启动速度最慢的,串行启动过程,无论进程相互之间有无依赖关系;
  • Centos6相对启动速度有所改进,有依赖的进程之间依次启动而其他与之没有依赖关系的则并行同步启动;
  • Centos7所有进程无论有无依赖关系则都是并行启动(当然很多时候进程没有真正启动而是只有一个信号或者说是标记而已,在真正利用的时候才会真正启动);

image-20210803114950576

# 什么是systemd

  • systemd即为system daemon守护进程,systemd主要解决上文的问题而诞生;
  • systemd的目标是,为系统的启动和管理提供一套完整的解决方案;

# systemd的优势

  • 最新系统都采用systemd管理(RedHat7,CentOS7,Ubuntu15等);
  • Centos7支持开机并行启动服务,显著提高开机启动效率;
  • Centos7关机只关闭正在运行的服务,而Centos6全部都关闭一次;
  • Centos7服务的启动与停止不再使用脚本进行管理,也就是/etc/init.d下不再有脚本;
  • Centos7使用systemd解决原有模式缺陷,比如原有service不会关闭程序产生的子进程;

# systemd配置文件

  • /usr/lib/systemd/system/:类似Centos6系统的启动脚本/etc/init.d/
  • /etc/systemd/system/:类似Centos6系统的/etc/rc.d/rcN.d/
  • /etc/systemd/system/multi-user.target.wants/

# systemd相关命令

  • systemctl管理服务的启动、重启、停止、重载、查看状态等常用命令;

    systemctl命令 作用
    systemctl start crond.service 启动服务
    systemctl stop crond.service 停止服务
    systemctl restart crond.service 重启服务
    systemctl reload crond.service 重新加载配置
    systemctl status crond.servre 查看服务运行状态
    systemctl is-active sshd.service 查看服务是否在运行中
    systemctl mask crond.servre 禁止服务运行
    systemctl unmask crond.servre 取消禁止服务运行
  • 当我们使用systemctl启动一个守护进程后,可以通过sysytemctl status查看此守护进程的状态;

    状态 描述
    loaded 服务单元的配置文件已经被处理
    active(running) 服务持续运行
    active(exited) 服务成功完成一次的配置
    active(waiting) 服务已经运行但在等待某个事件
    inactive 服务没有在运行
    enabled 服务设定为开机运行
    disabled 服务设定为开机不运行
    static 服务开机不启动,但可以被其他服务调用启动
  • systemctl设置服务开机启动、不启动、查看各级别下服务启动状态等常用命令;

    systemctl命令(7系统) 作用
    systemctl enable crond.service 开机自动启动
    systemctl disable crond.service 开机不自动启动
    systemctl list-unit-files 查看各个级别下服务的启动与禁用
    systemctl is-enabled crond.service 查看特定服务是否为开机自启动
    systemctl daemon-reload 创建新服务文件需要重载变更
  • CentOS7系统, 管理员可以使用systemctl命令来管理服务器启动与停止;

    #关机相关命令
    [root@web ~]# systemctl poweroff      #立即关机,常用
    #重启相关命令
    [root@web ~]# systemctl reboot        #重启命令,常用
    
    1
    2
    3
    4
  • systemctl的journalctl日志;

    [root@web ~]# journalctl -n 20    	#查看最后20行
    [root@web ~]# journalctl -f       	#动态查看日志
    [root@web ~]# journalctl -p err   	#查看日志的级别
    [root@web ~]# journalctl -u crond 	#查看某个服务的单元的日志
    
    1
    2
    3
    4

# systemd管理运行级别

# 什么是运行级别

  • 运行级别就是操作系统当前正在运行的功能级别;

    System V init运行级别 systemd目标名称 作用
    0 runlevel0.target, poweroff.target 关机
    1 runlevel1.target, rescue.target 单用户模式
    2 runlevel2.target, multi-user.target
    3 runlevel3.target, multi-user.target 多用户的文本界面
    4 runlevel4.target, multi-user.target
    5 runlevel5.target, graphical.target 多用户的图形界面
    6 runlevel6.target, reboot.target 重启

# 调整系统启动的运行级别

  • systemd使用targets而不是runlevels;

  • 默认情况下,有两个主要目标:

    • multi-user.target:类似于运行级别3;
    • graphical.target:类似于运行级别5;
  • 查看系统默认运行级别;

    [root@web ~]# systemctl get-default
    
    1
  • 要设置默认目标,请运行;

    [root@web ~]# systemctl set-default TARGET.target
    
    1
#Linux
Last Updated: 2021/11/25, 10:57:04
计划任务
Supervisor

← 计划任务 Supervisor→

最近更新
01
谷歌云创建GKE集群
07-26
02
ElastiCacheForRedis启用密码
07-26
03
upload-to-gcs
06-29
更多文章>
Theme by Vdoing | Copyright © 2021-2024 Brc | MIT License | 浙ICP备19031881号-4
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式