Linux学习笔记(3)linux服务管理与启停

时间:2023-03-09 23:31:31
Linux学习笔记(3)linux服务管理与启停

一、LINUX 系统服务管理

1、RHEL/OEL 6.X及之前

  service命令用于对系统服务进行管理,比如启动(start)、停止(stop)、重启(restart)、查看状态(status)等。

  chkconfig用于查看、设置服务器的运行级别。ntsysv用于直观方便的设置各个服务是否自动启动。

  service命令本身是一个shell脚本,它在/etc/init.d/目录查找指定的服务器脚本,然后调用该服务脚本来完成任务。

2、RHEL/OEL 7.X之后

  systemctl是新的服务管理器命令,该命令是用来替代service和chkconfig的;

  systemctl是一个systemd工具,主要负责控制systemd系统的服务管理器。

  启用服务就是在当前的 "runlevel" 的配置文件目录 /etc/systemd/system/multi-user.target.wants/ 里,建立 /usr/lib/systemd/system 里面对应服务配置文件的软链接。禁用服务就是删除此软链接。

3.指令对照表

旧指令指的是redhat 6.X之前,新指令指定是红帽7.X之后

任务 旧指令(redhat 6.x及之前) 新指令(redhat 7.X及之后)
使某服务自动启动 chkconfig --level 3 httpd on systemctl enable httpd service
使某服务不自动启动 chkconfig --level 3 httpd off systemctl disable httpd service
检查服务状态 service httpd status

systemctl status httpd.service(详细信息)

systemctl is-active test.service(仅显示是否活跃)

加入自定义服务 chkconfig --add test systemctl load test.service
删除服务 chkconfig --del test 停掉应用,删除对应配置文件
显示所有已启动的服务 chkconfig --list systemctl list-units --type = service
启动某服务 service httpd start systemctl start httpd.service
停止某服务 service httpd stop systemctl stop httpd.service

重启某服务      service httpd restart      systemctl restart httpd.service