diff --git "a/08 351円231円210円346円273円242円/20251028 346円234円215円345円212円241円347円256円241円347円220円206円347円273円203円344円271円240円351円242円230円.md" "b/08 351円231円210円346円273円242円/20251028 346円234円215円345円212円241円347円256円241円347円220円206円347円273円203円344円271円240円351円242円230円.md" new file mode 100644 index 0000000000000000000000000000000000000000..adc31d06511d57386da0f3a37508f2deb8b252a1 --- /dev/null +++ "b/08 351円231円210円346円273円242円/20251028 346円234円215円345円212円241円347円256円241円347円220円206円347円273円203円344円271円240円351円242円230円.md" @@ -0,0 +1,189 @@ +# Linux服务管理与日志管理 - 练习作业 + +## 一、选择题 + +### 1. 以下哪个命令可以查看nginx服务的状态?D +A) `systemctl status nginx` +B) `service nginx status` +C) `ps aux | grep nginx` +D) `A和B都可以` + +### 2. 设置服务开机自启动的正确命令是:B +A) `systemctl start nginx` +B) `systemctl enable nginx` +C) `systemctl auto nginx` +D) `systemctl boot nginx` + +### 3. 查看nginx服务日志的正确命令是:B +A) `journalctl -n nginx` +B) `journalctl -u nginx` +C) `journalctl -s nginx` +D) `journalctl -l nginx` + +### 4. 以下哪个日志级别最严重?D +A) `warning` +B) `err` +C) `alert` +D) `emerg` + +### 5. 实时查看nginx服务日志应该使用:C +A) `journalctl -u nginx -x` +B) `journalctl -u nginx -e` +C) `journalctl -u nginx -f` +D) `journalctl -u nginx -l` + +### 6. 重启nginx服务的正确命令是:C +A) `systemctl reload nginx` +B) `systemctl reset nginx` +C) `systemctl restart nginx` +D) `systemctl refresh nginx` + +### 7. 只查看错误级别的nginx日志应该使用:C +A) `journalctl -u nginx -p info` +B) `journalctl -u nginx -p warning` +C) `journalctl -u nginx -p err` +D) `journalctl -u nginx -p debug` + +### 8. 测试nginx配置文件语法的命令是:C +A) `nginx check` +B) `nginx verify` +C) `nginx -t` +D) `nginx test` + +### 9. 查看服务是否启用开机启动的命令是:B +A) `systemctl is-running nginx` +B) `systemctl is-enabled nginx` +C) `systemctl is-active nginx` +D) `systemctl is-failed nginx` + +### 10. 查看最近20条系统日志的命令是:B +A) `journalctl -n 10` +B) `journalctl -n 20` +C) `journalctl -l 20` +D) `journalctl -t 20` + +--- + +## 二、填空题 + +1. 启动nginx服务的命令是:______systemctl start nginx__________ +2. 停止nginx服务的命令是:______systemctl stop nginx__________ +3. 查看服务详细日志并跳转到末尾的命令是:`journalctl -u nginx ___-e___` +4. 查看服务从今天早上9点开始的日志:`journalctl --since "____2025年10月28日 09:00:00"` +5. 程序、进程、服务三者中,在后台长期运行的是:_________进程_______ +6. 服务配置文件通常存放在 _/etc/systemd/system__________ 目录 +7. 使用 `journalctl -p err` 会显示 ___错误___ 级别及以上的所有日志 +8. 服务管理系统中,`d` 的含义是:_________守护进程_______ + +--- + +## 三、操作实践题 + +### 实践1:基础服务管理 +```bash +# 任务:安装并管理nginx服务 +1. 安装nginx:sudo apt install nginx +2. 启动nginx服务 +3. 设置nginx开机自启动 +4. 查看服务状态 +5. 在浏览器中访问 http://localhost 验证是否正常工作 +``` + +```bash +root@hwx:~# apt install nginx +root@hwx:~# systemctl start nginx +root@hwx:~# systemctl enable nginx +root@hwx:~# systemctl status nginx +●くろまる nginx.service - A high performance web server and a reverse proxy server + Loaded: loaded (/lib/systemd/system/nginx.service; enabled; preset: en> + Active: active (running) since Sun 2025年11月02日 16:32:07 CST; 1min 38s a> + Docs: man:nginx(8) + Main PID: 2905 (nginx) + Tasks: 3 (limit: 9432) + Memory: 2.5M + CPU: 22ms + CGroup: /system.slice/nginx.service + ├─2905 "nginx: master process /usr/sbin/nginx -g daemon on; ma> + ├─2907 "nginx: worker process" + └─2908 "nginx: worker process" + +11月 02 16:32:07 hwx systemd[1]: Starting nginx.service - A high performanc> +11月 02 16:32:07 hwx systemd[1]: Started nginx.service - A high performance> + +``` + + + +### 实践2:日志分析 + +```bash +# 任务:分析nginx服务日志 +1. 查看nginx服务的所有日志 +2. 实时监控nginx日志(新开一个终端窗口) +3. 在浏览器中刷新 http://localhost +4. 观察实时日志中出现了什么新内容 +5. 只查看错误级别的nginx日志 +``` + +```bash +root@hwx:~# cat /var/log/nginx/error.log +2025年11月02日 16:32:07 [notice] 2905#2905: using inherited sockets from "5;6;" +root@hwx:~# tail -f /var/log/nginx/access.log /var/log/nginx/error.log +root@hwx:~# tail -f /var/log/nginx/error.log +``` + + + +### 实践3:时间范围查询 + +```bash +# 任务:按时间查询日志 +1. 查看最近1小时的系统日志 +2. 查看今天的所有nginx日志 +3. 查看从今天早上9点到12点的系统错误日志 +4. 记录你使用的命令和看到的日志条数 +``` + +```bash +root@hwx:~# journalctl --since "1 hour ago" -q +root@hwx:~# journalctl -u nginx --since today +root@hwx:~# journalctl --since "today 09:00" --until "today 12:00" -p err -q +``` + + + +### 实践4:故障模拟与修复 + +```bash +# 任务:故意制造和修复故障 +1. 备份nginx配置文件:sudo cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup +2. 编辑配置文件,故意删除一个分号制造错误 +3. 尝试重载nginx配置,观察错误信息 +4. 根据错误信息修复配置文件 +5. 重新测试并验证修复成功 +``` + +```bash +root@hwx:~# cp /etc/nginx/nginx.conf /etc/nginx/nginx.conf.backup +root@hwx:~# vim /etc/nginx/nginx.conf +root@hwx:~# nginx -t +root@hwx:~# vim /etc/nginx/nginx.conf +root@hwx:~# nginx -t +nginx: the configuration file /etc/nginx/nginx.conf syntax is ok +nginx: configuration file /etc/nginx/nginx.conf test is successful +``` + + + +### 实践5:运维实站【难点】 + +```bash +# 任务:在运行nginx的状态中,安装apache服务,提示,其软件包名为apache2 +# 安装后可能会有一些故障。想办法解决, +# 最终实现nginx 和 apache 都能运行 +``` + +```bash + +``` +