• linux问题-CentOS7和以往版本的变化


    1、systemd的服务管理程序:
    systemctl是主要的工具,它融合之前service和chkconfig的功能于一体。可以使用它永久性或只在当前会话中启用/禁用服务。
    systemctl可以列出正在运行的服务状态,如下:

    UNIT                        LOAD   ACTIVE SUB       DESCRIPTION
    proc-sys...t_misc.automount loaded active waiting   Arbitrary Executable File Fo
    sys-devi...block-sr0.device loaded active plugged   VMware_Virtual_IDE_CDROM_Dri
    sys-devi...block-sr1.device loaded active plugged   VMware_Virtual_IDE_CDROM_Dri
    sys-devi...-sda-sda1.device loaded active plugged   VMware_Virtual_S
    sys-devi...-sda-sda2.device loaded active plugged   VMware_Virtual_S
    sys-devi...-sda-sda3.device loaded active plugged   VMware_Virtual_S
    sys-devi...block-sda.device loaded active plugged   VMware_Virtual_S
    sys-devi...o16777736.device loaded active plugged   PRO/1000 MT Single Port Adap
    sys-devi...und-card0.device loaded active plugged   AudioPCI 64V/128 / Creative 
    sys-devi...block-fd0.device loaded active plugged   /sys/devices/platform/floppy
    sys-devi...tty-ttyS1.device loaded active plugged   /sys/devices/platform/serial
    sys-devi...tty-ttyS2.device loaded active plugged   /sys/devices/platform/serial
    sys-devi...tty-ttyS3.device loaded active plugged   /sys/devices/platform/serial
    sys-devi...tty-ttyS0.device loaded active plugged   /sys/devices/pnp0/00:08/tty/
    sys-module-configfs.device  loaded active plugged   /sys/module/configfs
    sys-module-fuse.device      loaded active plugged   /sys/module/fuse
    sys-subs...o16777736.device loaded active plugged   PRO/1000 MT Single Port Adap
    -.mount                     loaded active mounted   /
    boot.mount                  loaded active mounted   /boot
    dev-hugepages.mount         loaded active mounted   Huge Pages File System
    dev-mqueue.mount            loaded active mounted   POSIX Message Queue File Sys
    run-user-1000-gvfs.mount    loaded active mounted   /run/user/1000/gvfs
    ......
    LOAD   = Reflects whether the unit definition was properly loaded.
    ACTIVE = The high-level unit activation state, i.e. generalization of SUB.
    SUB    = The low-level unit activation state, values depend on unit type.
    
    133 loaded units listed. Pass --all to see loaded but inactive units, too.
    To show all installed unit files use 'systemctl list-unit-files'.

    systemd-cgls以树形列出正在运行的进程,它可以递归显示控制组内容。如下:

    [root@localhost conf.d]# systemd-cgls
    ├─1 /usr/lib/systemd/systemd --system --deserialize 23
    ├─user.slice
    │ └─user-1000.slice
    │   └─session-1.scope
    │     ├─12192 gdm-session-worker [pam/gdm-password]
    │     ├─12203 /usr/bin/gnome-keyring-daemon --daemonize --login
    │     ├─12205 gnome-session --session gnome-classic
    │     ├─12213 dbus-launch --sh-syntax --exit-with-session
    │     ├─12214 /bin/dbus-daemon --fork --print-pid 4 --print-address 6 --session
    │     ├─12279 /usr/libexec/gvfsd
    │     ├─12320 /usr/libexec//gvfsd-fuse /run/user/1000/gvfs -f -o big_writes
    │     ├─12357 /usr/bin/ssh-agent /bin/sh -c exec -l /bin/bash -c "env GNOME_SHEL
    │     ├─12373 /usr/libexec/at-spi-bus-launcher
    │     ├─12377 /bin/dbus-daemon --config-file=/etc/at-spi2/accessibility.conf --n
    │     ├─12381 /usr/libexec/at-spi2-registryd --use-gnome-session
    │     ├─12393 /usr/libexec/gnome-settings-daemon
    │     ├─12400 /usr/bin/pulseaudio --start
    │     ├─12458 /usr/libexec/gvfs-udisks2-volume-monitor
    │     ├─12471 /usr/libexec/gvfs-mtp-volume-monitor
    │     ├─12476 /usr/libexec/gvfs-afc-volume-monitor
    │     ├─12482 /usr/libexec/gvfs-goa-volume-monitor
    │     ├─12485 /usr/libexec/goa-daemon
    │     ├─12492 /usr/libexec/goa-identity-service
    ...
      ├─chronyd.service
      │ └─813 /usr/sbin/chronyd -u chrony
      ├─libstoragemgmt.service
      │ └─795 /usr/bin/lsmd -d
      ├─dbus.service
      │ ├─  833 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --
      │ └─84571 /usr/libexec/packagekitd
      └─firewalld.service
        └─793 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

    2、如何启动/关闭、启用/禁用服务?
    启动一个服务:systemctl start postfix.service
    关闭一个服务:systemctl stop postfix.service
    重启一个服务:systemctl restart postfix.service
    显示一个服务的状态:systemctl status postfix.service
    在开机时启用一个服务:systemctl enable postfix.service
    在开机时禁用一个服务:systemctl disable postfix.service
    查看服务是否开机启动:systemctl is-enabled postfix.service;echo $?
    查看已启动的服务列表:systemctl list-unit-files|grep enabled

    说明:启用服务就是在当前“runlevel”的配置文件目录/etc/systemd/system/multi-user.target.wants/里,建立/usr/lib/systemd/system里面对应服务配置文件的软链接;禁用服务就是删除此软链接。如下:

      │ ├─  833 /bin/dbus-daemon --system --address=systemd: --nofork --nopidfile --
      │ └─84571 /usr/libexec/packagekitd
      └─firewalld.service
        └─793 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid
    [root@localhost conf.d]# systemctl disable postfix.service
    rm '/etc/systemd/system/multi-user.target.wants/postfix.service'

    查看了/usr/lib/systemd/system 里的文件,语法跟旧版/etc/init.d/里的系统服务脚本完全不同了。

    二、修改系统运行级别:

    1、systemd使用比sysvinit的运行级更为自由的target替代。第3运行级用multi-user.target替代。第5运行级用graphical.target替代。runlevel3.target和runlevel5.target分别是指向 multi-user.target和graphical.target的符号链接。
    可以使用下面的命令切换到“运行级别3 ”:
    systemctl isolate multi-user.target或systemctl isolate runlevel3.target
    可以使用下面的命令切换到“运行级别5 ”:
    systemctl isolate graphical.target或systemctl isolate runlevel5.target

    2、如何改变默认运行级别?
    systemd使用链接来指向默认的运行级别。在创建新的链接前,可以通过下面命令删除存在的链接: rm /etc/systemd/system/default.target
    默认启动运行级别3 :
    ln -sf /lib/systemd/system/multi-user.target /etc/systemd/system/default.target
    默认启动运行级别5 :
    ln -sf /lib/systemd/system/graphical.target/etc/systemd/system/default.target
    systemd不使用/etc/inittab文件。

    3、如何查看当前运行级别?
    旧的runlevel命令在systemd下仍然可以使用。可以继续使用它,尽管systemd使用 ‘target’ 概念(多个的 ‘target’ 可以同时激活)替换了之前系统的runlevel。
    等价的systemd命令是systemctl list-units –type=target

    三、其他配置工具:

    1、setup和ntsysv工具还是保留了,但是功能已大大减弱,以前ntsysv工具可以控制所有系统服务的自启动,现在只能控制少部分服务。
    2、/etc/resolv.conf这个DNS配置文件没变。
    3、/etc/sysconfig/network-scripts/ifcfg-ens192网卡配置文件名字和一些选项有所变化。
    4、引导方式改用grub2引导,grub2有如下特点:1、模块化设计;2、支持多体系硬件架构;3、支持国际化多语言;4、独立内存管理;5、支持脚本语言。

    附:systemd简介
    systemd是Linux下的一种init软件,由Lennart Poettering带头开发,并在LGPL 2.1及其后续版本许可证下开源发布。其开发目标是提供更优秀的框架以表示系统服务间的依赖关系,并依此实现系统初始化时服务的并行启动,同时达到降低Shell的系统开销的效果,最终代替现在常用的System V与BSD风格init程序。
    与多数发行版使用的System V风格init相比,systemd采用了以下新技术:
    采用Socket激活式与总线激活式服务,以提高相互依赖的各服务的并行运行性能;
    用cgroups代替PID来追踪进程,以此即使是两次fork之后生成的守护进程也不会脱离systemd的控制。
    从设计构思上说,由于systemd使用了cgroup与fanotify等组件以实现其特性,所以只适用于Linux

    更详细的systemd介绍请参考:http://en.wikipedia.org/wiki/Systemd

    2015年10月16日21:29:10

  • 相关阅读:
    BZOJ5321 JXOI2017加法(二分答案+贪心+堆+树状数组)
    BZOJ5089 最大连续子段和(分块)
    Codeforces 893F(主席树+dfs序)
    BZOJ5092 分割序列(贪心)
    Codeforces Round #525 Div. 2 自闭记
    364. Nested List Weight Sum II
    362. Design Hit Counter
    369. Plus One Linked List
    370. Range Addition
    366. Find Leaves of Binary Tree
  • 原文地址:https://www.cnblogs.com/xccnblogs/p/4886435.html
Copyright © 2020-2023  润新知