• 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
    

      

  • 相关阅读:
    IDEA中好用的插件
    Win10安装Docker
    win10系统关闭此电脑的文件夹
    postgreSQL主键自增长
    【设计模式】工厂模式
    vue2.0实现倒计时的插件(时间戳 刷新 跳转 都不影响),转载
    springCloud中的组件学习
    使用springBoot+jsp+redis解决单一用户问题
    使用HtmlUnit动态获取网页数据
    java爬取网站中所有网页的源代码和链接
  • 原文地址:https://www.cnblogs.com/zy09/p/11126514.html
Copyright © 2020-2023  润新知