systemclt—centos7上的服务管理

一、使用systemctl管理服务

    在centos7中,可以使用systemctl显示,启动,停止和重启指定服务,操作更简单。

1.1基本用法

下面以firewalld服务为例,说明systemctl的用法

#启动服务
systemctl start firewalld
#停止服务
systemctl stop firewalld
#重启服务
systemctl restart firewalld
#仅当服务正在运行时才重启
systemctl try-restart firewalld
#重新加载服务
systemctl reload firewalld
#查看服务是否正在运行
systemctl is-active firewalld
#查开机启动状态
systemctl list-unit-files |grep fire 
#开机自启
systemctl enable firewalld.service
#禁止开机自启
systemctl disable firewalld.service
#显示当前已经运行的所有服务
systemctl [list-units] --type service
systemctl [list-units] -t service
#显示所有服务
systemctl [list-units] --type --all
systemctl [list-units] -at service
#显示已加载但是处于failed状态的服务
systemctl [list-units] --type service -failed
systemctl [list-units] -t service --failed

 

1.2扩展用法

#列出所有系统挂载点
systemctl list-unit-files --type=mount

image.png

#列出所有可用系统套接口
systemctl list-unit-files --type=socket

image.png

#获取当前某个服务的CPU分配额(如httpd)
systemctl show -p CPUShares httpd.service

image.png

#检查某个服务的所有配置细节
systemctl show httpd

image.png

#获取某个服务的依赖性列表
systemctl list-dependencies httpd.service

image.png

 

二、systemd-anlyzer

该命令查看启动耗时

#查看启动耗时
systemd-anlyzer

image.png

#查看每个服务的启动耗时
systemd-anlyzer blame

image.png

#分析启动时的关键链
systemd-analyze critical-chain

image.png

#显示指定服务的启动链
systemd-analyze critical-chain httpd.service

image.png


三、hostnamectl

#显示当前主机信息
hostnamectl

image.png

#设置主机名
hostnamectl set-hostname centos7

 

四、localctl

查看和设置一些本地化信息

#查看本地化
localectl

image.png

#设置本地化参数
localectl set-locale LANG=en_GB.UTF-8
localectl set-keymap en_GB

 

五、timedatectl

查看和设置当前时区

#查看当前时区设置
timedatectl
#显示所有可用的时区
timedatectl list-timezones                                                                                   
设置当前时区
timedatectl set-timezone America/New_York
timedatectl set-time YYYY-MM-DD
timedatectl set-time HH:MM:SS

六、loginctl

查看当前用户登录信息

#列出当前session
loginctl list-sessions
#列出当前登录用户$ 
loginctl list-users
#列出显示指定用户的信息
loginctl show-user ruanyf

 

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

zyh444

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值