首页 > 系统相关 >[置顶]【Linux init】systemd 服务单元管理

[置顶]【Linux init】systemd 服务单元管理

时间:2022-12-09 12:04:42浏览次数:52  
标签:httpd systemd service -- sshd init systemctl 置顶


控制systemd系统和服务管理,并行启动服务时充分发挥了多核处理器的性能,缩短了系统启动所需时间。
先前的使用SysV初始化或Upstart的红帽企业版Linux版本中,使用位于/etc/rc.d/init.d/目录中的bash初始化脚本进行管理。
在RHEL 7/CentOS 7中,这些启动脚本被服务单元取代了。为了向后兼容,旧的service命令在CentOS 7中仍然可用,它会重定向所有命令到新的systemctl工具。
systemctl有很多控制参数,这里仅列出常用的部分,更多命令请看man systemctl

查看systemd进程号


[root@localhost ~]# pidof systemd
1


  单元命令


systemctl start httpd.service # 启动httpd # service httpd start
systemctl stop httpd.service # 停止httpd # service httpd stop
systemctl status httpd # 查看httpd状态 # service httpd status
systemctl restart httpd.service # 重启httpd # service httpd restart
systemctl try-restart httpd.service # 尝试重启httpd #
systemctl reload httpd.service # 重新加载httpd配置文件 #

systemctl enable sshd.service # 设置sshd开机启动 # chkconfig –level 3 sshd on
systemctl disable sshd.service # 设置sshd开机不启动 # chkconfig –level 3 sshd off
systemctl enable sshd.service --now -f # 设置自启的同时,立即启动sshd服务, 强制创建并覆盖冲突链接
systemctl disable sshd.service --now # 设置禁用的同时,立即停止sshd服务
systemctl enable mariadb --no-block --no-reload # 异步操作,不等待结果,不重载配置文件
systemctl disable mariadb --global # 对全局所有在线用户生效

systemctl list-units --type=service # 列出type为service的所有服务的启动状况 # chkconfig –list
systemctl list-units --state=failed # 查询state为failed的单元
systemctl list-units --state=loaded --type=socket # 列出已加载的类型为socket的单元
systemctl list-units --plain --no-pager # 分类列出系统单元,直接输出所有结果,不分页

systemctl is-active mariadb.service # 查询mariadb服务状态
systemctl is-enabled mariadb.service # 查询mariadb是否开机自启
  系统命令
systemctl is-system-running # running 系统完全可控;degraded 系统可控,但存在单元失败;maintenance 营救模式启动;stopping 管理器停止
systemctl suspend #系统挂起
systemctl hibernate #系统睡眠
systemctl daemon-reload #操作系统所有初始化脚本重载
systemctl get-default # 获得默认的系统target
systemctl set-default multi-user.target #设置默认的运行目标
systemctl isolate graphical.target #切换到图形界面



 

自动启动的原理:systemd控制着sysv所管理的程序脚本,由此实现了对sysv的兼容,脚本软连接重定向到chkconfig来管理,系统启动的init进程为systemd,
systemd所管理的程序脚本在/usr/lib/systemd/,而 /etc/systemd/下的都是软连接。操作系统init进程只有systemd这一个。
Created symlink from /etc/systemd/system/multi-user.target.wants/sshd.service to /usr/lib/systemd/system/sshd.service.


[dream361@za ~]$ sudo  systemctl enable network 
network.service is not a native service, redirecting to /sbin/chkconfig.
Executing /sbin/chkconfig network on


 

network 实际是被chkconfig直接管理,systemctl通过chkconfig实现了对network的间接管理

标签:httpd,systemd,service,--,sshd,init,systemctl,置顶
From: https://blog.51cto.com/u_15907520/5924547

相关文章