Linux systemctl命令是系统和服务管理器的主要命令之一,它可以启动、停止、重启、重新加载和查询系统服务状态等操作。
语法格式:
systemctl 参数 [动作] [服务名]
常用参数:
| -a | 显示所有单位 |
| -f | 覆盖任何冲突的符号链接 |
| -H | 设置要连接的主机名 |
| -M | 设置要连接的容器名 |
| -n | 设置要显示的日志行数 |
| -o | 设置要显示的日志格式 |
| -q | 静默执行模式 |
| -r | 显示本地容器的单位 |
| -s | 设置要发送的进程信号 |
| -t | 设置单元类型 |
| –help | 显示帮助信息 |
| –version | 显示版本信息 |
常用动作:
| start | 启动服务 |
| stop | 停止服务 |
| restart | 重启服务 |
| enable | 设置服务开机自启 |
| disable | 取消服务开机自启 |
| status | 查看服务状态 |
| list | 显示所有已启动服务 |
举例:
1、查看特定服务的状态
systemctl status httpd
![Linux常用命令之systemctl用法详解 图片[1]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-10.webp)
2、启动特定服务
systemctl start httpd
![Linux常用命令之systemctl用法详解 图片[2]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-9.webp)
3、停止特定服务
systemctl stop httpd
![Linux常用命令之systemctl用法详解 图片[3]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-8.webp)
4、重新加载服务
必须在服务启动的情况下,重新加载服务,不然报错,它并不支持所有的服务,比如 network
systemctl reload httpd
![Linux常用命令之systemctl用法详解 图片[4]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-7.webp)
5、将特定服务设置成开机启动
systemctl enable httpd
![Linux常用命令之systemctl用法详解 图片[5]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-6.webp)
6、取消开机启动
systemctl disable httpd
![Linux常用命令之systemctl用法详解 图片[6]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-5.webp)
7、查看服务是否设置成开机启动
看输出结果,就知道是否是开机启动,enabled 代表开机启动,disabled 代表开机不启动
systemctl is-enabled httpd
![Linux常用命令之systemctl用法详解 图片[7]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-4.webp)
8、注销指定服务
注销服务后,服务就没法启用了,这对于禁用高危服务相当有用
systemctl mask httpd
![Linux常用命令之systemctl用法详解 图片[8]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-3.webp)
9、取消注销指定服务
重新启用注销的服务
systemctl unmask httpd
![Linux常用命令之systemctl用法详解 图片[9]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-2.webp)
10、列出所有可用单元
systemctl list-unit-files
![Linux常用命令之systemctl用法详解 图片[10]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image-1.webp)
11、列出所有已启动的服务列表信息
systemctl list-units --type=service
![Linux常用命令之systemctl用法详解 图片[11]-Linux常用命令之systemctl用法详解-不念博客](https://www.bunian.cn/wp-content/uploads/2023/11/image.webp)
© 版权声明
本站文章由不念博客原创,未经允许严禁转载!
THE END









