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 查看服务的状态,返回的状态有以下几种:
- loaded ##系统服务已经初始化完成,加载过配置
- active(running) ##正有一个或多个程序正在系统中执行, vsftpd就是这种模式
- atcive(exited) ##仅执行一次就正常结束的服务, 目前并沒有任何程序在系統中执行
- atcive(waiting)##正在执行当中,不过还在等待其他的事件才能继续处理
- inactive #服务关闭
- enbaled ##服务开机启动
- disabled ##服务开机不自启
- static ##服务开机启动项不可被管理
- failed ##系统配置错误
4、systemctl 设置服务的自启动状态
4.1 systemctl list-unit-files 查看自启动列表
状态:enabled:启动; disabled:关闭;static:未配置;

4.2 systemctl enable 服务名 :设置服务开机启动),
对 3(无界面)和 5(GUI)运行级别都生效
4.3 systemctl disable 服务名 (关闭服务开机启动),
对 3(无界面)和 5 (GUI)运行级别都生效
4.4 systemctl is-enabled 服务名 :查询某个服务是否是自启动的
5、防火墙操作
1. systemctl status firewalld 查看防火墙状态;

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

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

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

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

6、关机重启
- sync 将内存中的数据写入到硬盘中(在关机或者开机前,多执行几次该命令,确保数据写入硬盘。);
- shutdown 一分钟后关机;
- shutdown - c 取消关机操作;
- shutdown now 立即关机;
- shutdown 3 在3分钟后关机(设置多长时间自动关机);
- shutdown 9:30 在9:30关机(自定义关机);
- reboot 重启,等同于shutdown -r now;
- halt 停机,关闭系统,但不断电;
- poweroff 关机,断电;

浙公网安备 33010602011771号