From 9eece21e7599fbdbc142c34c5f336245bdc06533 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=88=E6=99=93=E7=90=B3?= <2115152499@qq.com> Date: Mon, 24 Jun 2024 22:28:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=9C=E4=B8=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...15\345\212\241\347\256\241\347\220\206.md" | 58 +++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 "14 \346\262\210\346\231\223\347\220\263/20240624 \346\234\215\345\212\241\347\256\241\347\220\206.md" diff --git "a/14 \346\262\210\346\231\223\347\220\263/20240624 \346\234\215\345\212\241\347\256\241\347\220\206.md" "b/14 \346\262\210\346\231\223\347\220\263/20240624 \346\234\215\345\212\241\347\256\241\347\220\206.md" new file mode 100644 index 0000000..f1f95eb --- /dev/null +++ "b/14 \346\262\210\346\231\223\347\220\263/20240624 \346\234\215\345\212\241\347\256\241\347\220\206.md" @@ -0,0 +1,58 @@ +1.init是Linux系统操作中不可缺少的程序之一。init进程,它是一个由内核启动的用户级进程,然后由它来启动后面的任务,包括多用户环境,网络等。 + +2.service命令其实是去/etc/init.d目录下,去执行相关程序,init.d目录包含许多系统各种服务的启动和停止脚本。当Linux启动时,会寻找这些目录中的服务脚本,并根据脚本的run level确定不同的启动级别。 + +3.systemctl是一个systemd工具,主要负责控制systemd系统和服务管理器。 +在systemd管理体系中,被管理的deamon(守护进程)称作unit(单元),对于单元的管理是通过命令systemctl来进行控制的。unit表示不同类型的systemd对象,通过配置文件进行标识和配置;文件主要包含了系统服务、监听socket、保存的系统快照以及其它与init相关的信息。 + + +一.service nginx start : + +1.如果 你是system v,其实是用/etc/init.d/nginx start实现 + +2.如果 你是systemd ,其实是用systemctl start nginx 来实现 + +二.早期的linux可以/etc/init.d/服务名 操作命令 或者 service 服务名 操作命令 + +​ 现代的linux可以systemctl 操作命令 服务名 + +三.操作命令包含: +指令 功能 +systemctl list-unit-files 获取所用可用单元 +systemctl list-units 获取所有运行中的单元 +systemctl status service 获取service的状态 +systemctl start/stop/estart/reload service 改变service 的状态 启动、重启、停止、重载服务 +systemctl enable/disable service 是否开机自启 +systemctl kill service 强制结束服务 +systemctl daemon-reload 刷新systemd的配置文件 + +四.查看所有运行的服务: +1.service --status-all [简约版,直观] +2.systemctl list-unit-files [ 详细版,要自行筛选] + +练习: + +给自己的服务安装apache服务 + +```bash +systemctl stop nginx //停止nginx +systemctl status nginx //查看nginx运行状态 +apt install apache2 //安装apache +systemctl start apache2 //开启apache +systemctl status apache2 +``` + +或者 + +```bash +默认情况下,nginx监听80端口,apache监听80端口。 + +要改变nginx监听的端口,编辑nginx的配置文件/etc/nginx/sites-available/default,将listen 80;改为listen 8080;。 + +要改变apache监听的端口,编辑apache的配置文件/etc/httpd/conf/httpd.conf或/etc/apache2/ports.conf,找到Listen 80,并将80改为其它端口号,比如Listen 8081。 + +重启nginx和apache以应用更改: +sudo systemctl restart nginx +sudo systemctl restart apache2 +``` + -- Gitee