【Linux init】systemd 服务单元管理

系统服务管理systemd  Control the systemd system and service manager  #控制systemd系统和服务管理
先前的使用SysV初始化或Upstart的红帽企业版Linux版本中,使用位于/etc/rc.d/init.d/目录中的bash初始化脚本进行管理。
在RHEL 7/CentOS 7中,这些启动脚本被服务单元取代了。为了向后兼容,旧的service命令在CentOS 7中仍然可用,它会重定向所有命令到新的systemctl工具。
systemctl有很多控制参数,这里仅列出常用的部分,更多命令请看man systemctl
单元命令:
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 list-units --type=service # 列出type为service的所有服务的启动状况 # chkconfig –list
systemctl is-active mariadb # 查询mariadb服务状态 
systemctl list-units --state=failed # 查询state为failed的单元
systemctl list-units --state=loaded  --type=socket # 列出已加载的类型为socket的单元
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 --plain --no-pager # 分类列出系统单元,直接输出所有结果,不分页
systemctl get-default # 获得默认的系统target
systemctl try-restart mariadb # 尝试重启mariadb,如果mariadb没有启动,则不做任何操作
系统命令
systemctl is-system-running  # running 系统完全可控;degraded 系统可控,但存在单元失败;maintenance 营救模式启动;stopping 管理器停止
systemctl suspend  #系统挂起
systemctl hibernate  #系统睡眠
systemctl daemon-reload  #操作系统所有初始化脚本重载
自动启动的原理Systemctl控制着SysV所管理的程序脚本,由此实现了对SysV的兼容,脚本软连接重定向到chkconfig来管理,系统启动的init进程为Systemctl,
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的间接管理
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值