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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM