Linux 系统服务操作 - systemctl

​ Linux 服务管理两种方式service和systemctl,systemd是Linux系统最新的初始化系统(init),作用是提高系统的启动速度,尽可能启动较少的进程,尽可能更多进程并发启动。systemd对应的进程管理命令是systemctl。
​ CentOS 7.x开始,CentOS开始使用systemd服务来代替daemon,原来管理系统启动和管理系统服务的相关命令全部由systemctl命令来代替。

1、基本语法

systemctl  start | stop |restart | status  服务名 //启动  | 停止 | 重启 |  状态

2、查看systemd 服务

systemctl list-unit-files

3、systemctl状态说明

​ 使用systemctl 查看服务的状态,返回的状态有以下几种:

  1. loaded ##系统服务已经初始化完成,加载过配置
  2. active(running) ##正有一个或多个程序正在系统中执行, vsftpd就是这种模式
  3. atcive(exited) ##仅执行一次就正常结束的服务, 目前并沒有任何程序在系統中执行
  4. atcive(waiting)##正在执行当中,不过还在等待其他的事件才能继续处理
  5. inactive #服务关闭
  6. enbaled ##服务开机启动
  7. disabled ##服务开机不自启
  8. static ##服务开机启动项不可被管理
  9. failed ##系统配置错误

4、systemctl 设置服务的自启动状态

​ 4.1 systemctl list-unit-files 查看自启动列表

​ 状态:enabled:启动; disabled:关闭;static:未配置;
image
​ 4.2 systemctl enable 服务名 :设置服务开机启动),

​ 对 3(无界面)和 5(GUI)运行级别都生效

​ 4.3 systemctl disable 服务名 (关闭服务开机启动),

​ 对 3(无界面)和 5 (GUI)运行级别都生效

​ 4.4 systemctl is-enabled 服务名 :查询某个服务是否是自启动的

5、防火墙操作

1. ​	systemctl status firewalld  查看防火墙状态;

image

2.    systemctl stop firewalld.service 关闭防火墙;

image

3. systemctl disable firewalld.service 关闭防火墙且关闭自启动;

image

4. systemctl enable firewalld.service  开启防火墙自启动;

image

5. systemctl start firewalld.service  启动防火墙;

image

6、关机重启

  1. ​ sync 将内存中的数据写入到硬盘中(在关机或者开机前,多执行几次该命令,确保数据写入硬盘。);
  2. shutdown 一分钟后关机;
  3. shutdown - c 取消关机操作;
  4. shutdown now 立即关机;
  5. shutdown 3 在3分钟后关机(设置多长时间自动关机);
  6. shutdown 9:30 在9:30关机(自定义关机);
  7. reboot 重启,等同于shutdown -r now;
  8. halt 停机,关闭系统,但不断电;
  9. poweroff 关机,断电;
posted @   DAZKT12  阅读(441)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 记一次.NET内存居高不下排查解决与启示
· DeepSeek 开源周回顾「GitHub 热点速览」
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了
点击右上角即可分享
微信分享提示