一、使用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
#列出所有可用系统套接口
systemctl list-unit-files --type=socket
#获取当前某个服务的CPU分配额(如httpd)
systemctl show -p CPUShares httpd.service
#检查某个服务的所有配置细节
systemctl show httpd
#获取某个服务的依赖性列表
systemctl list-dependencies httpd.service
二、systemd-anlyzer
该命令查看启动耗时
#查看启动耗时
systemd-anlyzer
#查看每个服务的启动耗时
systemd-anlyzer blame
#分析启动时的关键链
systemd-analyze critical-chain
#显示指定服务的启动链
systemd-analyze critical-chain httpd.service
三、hostnamectl
#显示当前主机信息
hostnamectl
#设置主机名
hostnamectl set-hostname centos7
四、localctl
查看和设置一些本地化信息
#查看本地化
localectl
#设置本地化参数
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