systemd 工具命令使用

	systemd 新特性:
		系統引導時實現服務並行啓動。
		按需激活進程
		系統狀態快照
		基於依賴關係定義服務控制邏輯
		
	核心概念:unit (單元)
		配置文件進行標識和配置,文件中主要包含系統服務,監聽socket,保存系統快照及其餘init 相關信息
		文件保存至:
			/usr/lib/systemd/system
			/run/systemd/system 
			/etc/systemd/system 
	
		unit 類型:
			service unit :文件擴展名爲.service ,用於定義系統服務
			Target unit:文件擴展名爲.target ,用於模擬實現運行級別
			device unit :.device 用於定義內核識別的設備
			mount unit:.mount 定義文件系統掛載點
			socket unit : .socket ,用於標識進程間通訊的socket文件
			snapshot unit :管理系統快照
			swap unit :用於標識swap 設備
			automount unit : .automount 文件系統的自動掛載點
			path unit :.path  用於定義文件系統中的文件或目錄
			
	關鍵特性:
		基於socket 的激活機制,socket 與服務程序分離
		基於bus 的激活機制;
		基於device 的激活機制
		 基於path 的激活機制
		 系統快照
		 向後兼容sysv   init 腳本。
			
	不兼容:
		systemctl 命令固定不變,
		非由systemd 啓動的服務,systemctl 沒法與之通訊
	管理系統服務:
		CENTIOS 7:service unit
		注意 能兼容早起的服務腳本
		
		命令:systemctl COMMAND  name.service
		
	
	systemctl start name.service
	systemctl stop name.service	
	systemctl status name.service	
	systemctl restart name.service	
	
條件式重啓: systemctl try-restart name.service

查看服務當前狀態: systemctl is-active name.service
	
--------------------------------------------------------------
當前位置:首頁 » 系統管理 » systemctl systemctl命令進程和做業管理 systemctl命令是系統服務管理器指令,它實際上將 service 和 chkconfig 這兩個命令組合到一塊兒。 任務	舊指令	新指令 
使某服務自動啓動	chkconfig --level 3 httpd on	systemctl enable httpd.service 
使某服務不自動啓動	chkconfig --level 3 httpd off	systemctl disable httpd.service 
檢查服務狀態	service httpd status	             systemctl status httpd.service 
(服務詳細信息)                                    systemctl is-active httpd.service (僅顯示是否 Active) 
顯示全部已啓動的服務	chkconfig --list	          systemctl list-units --type=service 
啓動某服務	service httpd start	                     systemctl start httpd.service 
中止某服務	service httpd stop	                     systemctl stop httpd.service 
重啓某服務	service httpd restart	                 systemctl restart httpd.service
顯示全部服務:chkconfig --list	                     systemctl list-units --type=service --all
查看全部服務開機啓動狀態  systemctl list-unit-files --type=service


	target units:
			unit 配置文件 .target 
			運行級別:
			0  ==== runlevel0.target poweroff 關機
			1  ==== runlevel1.target rescue.target  救援模式
			2 ===== runlevel2.target multi-user.target 
			3 ===== runlevel3.target multi-user.target 
			4 ====	runlevel4.target multi-user.target
	#2 3 4 級別相同
			5  ==== runlevel5.target  GUI 級別  graphical.target 
			6  ==== runlevel6.target   reboot.target 
	
	級別切換:
		init N ==== systemctl isolate name.target 
		
		systemctl isolate graphical.target  #切換爲圖形界面
	
			systemctl list-units --type target  #查看裝載級別
--------------------------------------------------------------
basic.target          loaded active active Basic System
cryptsetup.target     loaded active active Encrypted Volumes
getty.target          loaded active active Login Prompts
graphical.target      loaded active active Graphical Interface
local-fs-pre.target   loaded active active Local File Systems (Pre)
local-fs.target       loaded active active Local File Systems
multi-user.target     loaded active active Multi-User System
network-online.target loaded active active Network is Online
network-pre.target    loaded active active Network (Pre)
network.target        loaded active active Network
paths.target          loaded active active Paths
remote-fs.target      loaded active active Remote File Systems
slices.target         loaded active active Slices
sockets.target        loaded active active Sockets
swap.target           loaded active active Swap
sysinit.target        loaded active active System Initialization
timers.target         loaded active active Timers
-------------------------------------------------------
	
	獲取默認運行級別:
	/etc/inittab 	systemctl get-default
	修改默認級別
	/etc/inittab    systemctl set-default graphical.target

	或者修改配置文件
	/etc/systemd/system/default.target 
	 /usr/lib/systemd/system/multi-user.target.

	將user lib 文件軟鏈接至 etc 下
	
	
	切換至救援模式:
	systemctl emergemcy 
	
	其餘經常使用命令
		systemctl halt 關機
		systemctl poweroff  關機
		systemctl reboot  重啓
		systemctl  suspend  掛起
		systemctl hiberate   快照
		systemctl hybrid-sleep 快照而且掛起
		
--------------------------------------------------------
System Commands:
  is-system-running               Check whether system is fully running
  default                         Enter system default mode
  rescue                          Enter system rescue mode
  emergency                       Enter system emergency mode
  halt                            Shut down and halt the system
  poweroff                        Shut down and power-off the system
  reboot [ARG]                    Shut down and reboot the system
  kexec                           Shut down and reboot the system with kexec
  exit                            Request user instance exit
  switch-root ROOT [INIT]         Change to a different root file system
  suspend                         Suspend the system
  hibernate                       Hibernate the system
  hybrid-sleep                    Hibernate and suspend the system
-------------------------------------------------------------------		
	
	
	systemctl list-dependencies httpd.service   #查看依賴關係
	
	systemctl reload-or-restart 			 #重載或重啓服務
	
	禁止設定爲開機自啓: 			systemctl mask name.service
		
	取消設定        				systemctl	umask name.service
相關文章
相關標籤/搜索