linux学习-centos7上的服务管理systemclt等

一、使用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-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


猜你喜欢

转载自blog.51cto.com/11555417/2146113