
第一部分 網(wǎng)絡(luò)服務(wù)第一章 Linux的例行性工作單一一次的任務(wù)計(jì)劃單一一次的定時(shí)任務(wù)at程序包是否安裝[rootlocalhost ~]# rpm -q at at-3.1.23-11.el9.x86_64 [rootlocalhost ~]# rpm -qa | grep -w at at-spi2-core-2.40.3-1.el9.x86_64 at-spi2-atk-2.38.0-4.el9.x86_64 at-3.1.23-11.el9.x86_64軟件程序是否運(yùn)行[rootlocalhost ~]# ps -aux | grep -w atd root 1195 0.0 0.2 12472 4992 ? Ss 18:13 0:00 /usr/sbin/atd -f root 2442 0.0 0.1 221812 2688 pts/0 S 18:57 0:00 grep --colorauto -w atd [rootlocalhost ~]# systemctl status atd ● atd.service - Deferred execution scheduler Loaded: loaded (/usr/lib/systemd/system/atd.service; enabled; preset: enabled) Active: active (running) since Wed 2026-10-21 18:13:02 CST; 44min ago Docs: man:atd(8) Main PID: 1195 (atd) Tasks: 1 (limit: 10707) Memory: 896.0K CPU: 13ms CGroup: /system.slice/atd.service └─1195 /usr/sbin/atd -f [rootlocalhost ~]# systemctl is-active atd active [rootlocalhost ~]# yum install at -y #沒安裝通過該命令安裝單一一次的定時(shí)任務(wù)at命令-m當(dāng)任務(wù)完成后即使沒有標(biāo)準(zhǔn)輸出也會(huì)給用戶發(fā)送郵件 --了解-l列出系統(tǒng)上所有用戶的at任務(wù)等價(jià)于atq-d刪除或取消一個(gè)任務(wù)-v任務(wù)項(xiàng)以前顯示時(shí)間列出at任務(wù)-c可以列出任務(wù)之后的命令內(nèi)容-f從文件中讀取時(shí)間格式參數(shù)說明HH:MM在今天HH小時(shí)的MM分鐘執(zhí)行若時(shí)間點(diǎn)錯(cuò)過將在明天執(zhí)行HH:MM YYYY-MM-DD規(guī)定在某年某月的某一天的特殊時(shí)刻執(zhí)行該工作now 2 minutes從現(xiàn)在開始的minutes、hours、days、weeks執(zhí)行4pm12am 00:00命令用法示例[rootnode1 ~]# at 12:12 warning: commands will be executed using /bin/sh at touch file111 #執(zhí)行任務(wù) at EOT #ctrl-D job 1 at Thu Oct 22 12:12:00 2026 #查看 [rootnode1 ~]# at -l 1 Thu Oct 22 12:12:00 2026 a root [rootnode1 ~]# atq 1 Thu Oct 22 12:12:00 2026 a root #刪除 [rootnode1 ~]# at -d 1 #通過任務(wù)文件匹配任務(wù) [rootnode1 ~]# at -f at.txt 12:12 warning: commands will be executed using /bin/sh job 3 at Thu Oct 22 12:12:00 2026[rootlocalhost ~]# wall haha wall: /dev/seat0: 沒有那個(gè)文件或目錄 來自 rootlocalhost.localdomain (pts/0) (Wed Oct 21 19:22:52 2026) 的廣播 haha [rootlocalhost ~]# at now 2 minutes warning: commands will be executed using /bin/sh at wall 外面太吵了 at EOTEOT job 7 at Wed Oct 21 19:25:00 2026 [rootlocalhost ~]#配置文件程序運(yùn)行參數(shù)文件程序按照約定格式讀取從而決定怎么軟件如何運(yùn)行。/etc/at.allow白名單/etc/at.deny黑名單定義的任務(wù)文件存放位置/var/spool/at周期任務(wù)crontabcrontabs程序是否存在[rootnode1 at]# dnf list installed | grep crontabs crontabs.noarch 1.11-27.20190603git.el9_0 anacondacrond程序運(yùn)行狀態(tài)[rootnode1 at]# ps -aux | grep crond root 1142 0.0 0.2 223976 3676 ? Ss 18:48 0:00 /usr/sbin/crond -n root 3101 0.0 0.1 221812 2588 pts/0 S 19:58 0:00 grep --colorauto crond [rootnode1 at]# systemctl status crond ● crond.service - Command Scheduler Loaded: loaded (/usr/lib/systemd/system/crond.service; enabled; preset: enabled) Active: active (running) since Wed 2026-10-21 18:48:26 CST; 1h 10min ago Main PID: 1142 (crond) Tasks: 2 (limit: 10289) Memory: 1.5M (peak: 4.2M) CPU: 38ms CGroup: /system.slice/crond.service ├─1142 /usr/sbin/crond -n └─2748 /usr/sbin/anacron -s Oct 21 19:01:01 node1 run-parts[2738]: (/etc/cron.hourly) starting 0anacron Oct 21 19:01:01 node1 anacron[2748]: Anacron started on 2026-10-21 Oct 21 19:01:01 node1 anacron[2748]: Will run job cron.daily in 42 min. Oct 21 19:01:01 node1 anacron[2748]: Will run job cron.weekly in 62 min. Oct 21 19:01:01 node1 anacron[2748]: Will run job cron.monthly in 82 min. Oct 21 19:01:01 node1 anacron[2748]: Jobs will be executed sequentially Oct 21 19:01:01 node1 run-parts[2750]: (/etc/cron.hourly) finished 0anacron Oct 21 19:01:01 node1 CROND[2734]: (root) CMDEND (run-parts /etc/cron.hourly) Oct 21 19:43:01 node1 anacron[2748]: Job cron.daily started Oct 21 19:43:01 node1 anacron[2748]: Job cron.daily terminated [rootnode1 at]# systemctl is-active crond activecrontab周性任務(wù)管理命令用法參數(shù)解釋示例-llist 查看定時(shí)任務(wù)crontab -l-eedit 編輯定時(shí)任務(wù)建議手動(dòng)編輯crontab -e-i刪除定時(shí)任務(wù)提示用戶確認(rèn)刪除避免出錯(cuò)crontab -i-r刪除定時(shí)任務(wù)移除/var/spool/cron/username文件crontab -r-u user指定用戶執(zhí)行任務(wù)root 可以管理普通用戶計(jì)劃任務(wù)crontab -u redhat -l代表意義分鐘小時(shí)日期月份星期命令數(shù)字范圍0-590-231-311-120-70和7表示周日?qǐng)?zhí)行的動(dòng)作特使字符含義*任意時(shí)刻-表示時(shí)間范圍1-5逗號(hào)分割時(shí)段 月 1,3*/數(shù)字指定時(shí)間間隔的頻率如每3分鐘執(zhí)行一次crontab命令用法示例 ---用戶級(jí)別定義單用戶[rootnode1 at]# crontab -e no crontab for root - using an empty one crontab: installing new crontab [rootnode1 at]# crontab -l # 分 時(shí) 日 月 周 任務(wù) * * * * * touch /crontab1 [rootnode1 at]# ll /crontab1 -rw-r--r--. 1 root root 0 Oct 21 20:06 /crontab1 [rootnode1 at]# #清空周期性任務(wù) [rootnode1 at]# crontab -r [rootnode1 at]# crontab -l #周期性任務(wù)文件位置 [rootnode1 at]# ll /var/spool/cron/ total 4 -rw-------. 1 root root 25 Oct 21 20:09 root [rootnode1 at]# vim /var/spool/cron/root/etc/crontab 定義周期性任務(wù)系統(tǒng)級(jí)別可以是系統(tǒng)中任意用戶定義周期性任務(wù)課堂練習(xí)定時(shí)發(fā)送郵件企業(yè)應(yīng)用場(chǎng)景判斷當(dāng)前系統(tǒng)內(nèi)存是否不足如果內(nèi)存使用率超過80%需要給運(yùn)維管理員以郵箱方式發(fā)送警告提示通過linux通過郵箱客戶端s-nail 登錄郵箱賬戶能夠給其他郵箱用戶發(fā)送郵件1.安裝s-nail軟件[rootnode1 at]# mkdir /sr0 [rootnode1 at]# mount /dev/sr0 /sr0 mount: /sr0: WARNING: source write-protected, mounted read-only. 2.[rootnode1 ~]# cat /etc/yum.repos.d/base.repo [AppStream] nameAppStream baseurlfile:///sr0/AppStream gpgcheck0 [BaseOS] nameBaseOS baseurlfile:///sr0/BaseOS gpgcheck0 3.[rootnode1 ~]#dnf install s-nail -y2.在該軟件軟件登錄郵箱賬戶[rootnode1 ~]# tail -6 /etc/s-nail.rc ################################################## set fromlxx1xxxxxx163.com set smtpsmtp.163.com set smtp-auth-userlxx1xxxxx8163.com set smtp-auth-passwordVRxxxxx set smtp-authlogin3.發(fā)送郵件[rootnode1 ~]# echo 郵件內(nèi)容 | mail -s 郵件主題 lxx1065372838163.com周期性觸發(fā)定時(shí)發(fā)送郵件[rootnode1 ~]# crontab -e crontab: installing new crontab [rootnode1 ~]# crontab -l 26 * * * * echo 盡快處理問題 | mail -s 內(nèi)存嚴(yán)重不足 lxx1065372838163.com第二章 Chrony服務(wù)器1.服務(wù)網(wǎng)絡(luò)由一方按照約定方式給用戶或者主機(jī)程序提供對(duì)應(yīng)功能、數(shù)據(jù)、計(jì)算能力。服務(wù)響應(yīng)方式被動(dòng)方式OSI應(yīng)用層數(shù)據(jù)傳輸?shù)臉?biāo)準(zhǔn)協(xié)議 ntp ssh http/https nfs/ftp表示層數(shù)據(jù)格式轉(zhuǎn)換 編碼會(huì)話層通信會(huì)話傳輸層 端口TCP 可靠傳輸 效率低UDP 不可靠 高網(wǎng)絡(luò)層ip 源ip 目標(biāo)ip 發(fā)送 主機(jī)地址標(biāo)記數(shù)據(jù)鏈路層MAC物理接口ens160TCP/IP應(yīng)用層 應(yīng)用層協(xié)議 數(shù)據(jù) chrony(ntp) http/https dns ssh chrony(ntp) nfs傳輸層 端口TCP 可靠傳輸 效率低網(wǎng)絡(luò)層 ip sip dip物理接口 ens160配置文件守護(hù)進(jìn)程daemon不依賴終端窗口進(jìn)程在主機(jī)后臺(tái)運(yùn)行正常系統(tǒng)運(yùn)行中不手動(dòng)結(jié)束進(jìn)程是實(shí)時(shí)運(yùn)行的。Chrony時(shí)間服務(wù)時(shí)間管理命令hwclock-s 硬件時(shí)間到系統(tǒng)時(shí)間-w 系統(tǒng)時(shí)間到硬件時(shí)間date 月日時(shí)分年點(diǎn)秒-s 設(shè)置時(shí)間%F%Ttimedatectl set-timezone 時(shí)區(qū)軟件程序 chrony/ntpnetstat 查看報(bào)文監(jiān)聽結(jié)果-t TCP-u UDPss 查看報(bào)文監(jiān)聽結(jié)果軟件程序 chronyNTP network time protocal 網(wǎng)絡(luò)時(shí)間協(xié)議守護(hù)進(jìn)程daemon程序運(yùn)行后再主機(jī)后運(yùn)行且該程序進(jìn)程不依賴終端設(shè)備不會(huì)因終端退出結(jié)束進(jìn)程只有系統(tǒng)重啟進(jìn)程才會(huì)受影響NTP應(yīng)用層協(xié)議 網(wǎng)絡(luò)時(shí)間協(xié)議提供時(shí)間的查看的校驗(yàn)端口區(qū)分不同程序進(jìn)行數(shù)據(jù)交互 ntp協(xié)議的端口是123/udp配置文件介紹/etc/chrony.conf客戶端 pool 2.rhel.pool.ntp.org iburst # 池 時(shí)間服務(wù)器的主機(jī)名 初始化爆發(fā) pool 3.rhel.pool.ntp.org iburst #上層服務(wù)器存儲(chǔ)池 間服務(wù)器的主機(jī)名 服務(wù)端主機(jī) # local stratum 10 #標(biāo)記時(shí)間服務(wù)器主機(jī)的層級(jí) 1-16 # allow 192.168.0.0/16 #允許哪些客戶端主機(jī)可以發(fā)起請(qǐng)求連接實(shí)驗(yàn)一自定義時(shí)間服務(wù)能夠給客戶端主機(jī)進(jìn)行時(shí)間校時(shí)環(huán)境準(zhǔn)備 S/Cserver (linux) --- 192.168.211.131client (linux) --- 192.168.211.1321.server主機(jī)1.判斷chrony軟件程序是否安裝 2.判斷軟件是否啟動(dòng) 3.自定義軟件功能ntp時(shí)間服務(wù)器 vim /etc/chrony.conf #pool 2.rhel.pool.ntp.org iburst #當(dāng)前主機(jī)的時(shí)間就是標(biāo)準(zhǔn)時(shí)間不再通過上層服務(wù)器進(jìn)行校時(shí) allow 172.25.250.0/24 #哪些客戶端主機(jī)發(fā)起校時(shí)請(qǐng)求 local stratum 10 #1-16 指定自定義時(shí)間服務(wù)區(qū)的層級(jí) 4.加載新的配置 systemctl restart chronyd 5.關(guān)閉防火墻selinux systemctl stop firewalld #立即停止防火墻 systemctl disable firewalld #取消防火墻的開機(jī)自啟 systemctl status firewalld #查看防火墻服務(wù)狀態(tài) setenforce 0 #臨時(shí)把selinux設(shè)置為permissive寬容模式 getenforce #查看selinux狀態(tài) Permissive 關(guān)閉 | enforce 開啟 vim /etc/selinux/config SELINIUXPermissive #永久關(guān)閉2.client1.判斷chrony軟件程序是否安裝 2.判斷軟件是否啟動(dòng) 3.自定義軟件功能ntp時(shí)間客戶端 vim /etc/chrony.conf pool 192.168.211.131 iburst 4.辨別時(shí)間校時(shí)是否成功 date 月日時(shí)分年月點(diǎn)秒 5.發(fā)起時(shí)間同步請(qǐng)求 systemctl restart chronyd 6.判斷 [rootclient-146 ~]# date Fri Dec 12 10:10:38 AM CST 2025 [rootclient-146 ~]# date Fri Dec 12 10:10:39 AM CST 2025 [rootclient-146 ~]# date Sat Oct 24 11:46:23 AM CST 2026 [rootlocalhost ~]# chronyc sources -v # -v參數(shù)表示顯示內(nèi)容是否有解釋 .-- Source mode ^ server, peer, # local clock. / .- Source state * current best, combined, - not combined, | / x may be in error, ~ too variable, ? unusable. || .- xxxx [ yyyy ] /- zzzz || Reachability register (octal) -. | xxxx adjusted offset, || Log2(Polling interval) --. | | yyyy measured offset, || \ | | zzzz estimated error. || | | \ MS Name/IP address Stratum Poll Reach LastRx Last sample ^* 203.107.6.88 2 6 177 8 18ms[ 19ms] /- 48ms ^*:server 類型當(dāng)前最優(yōu)同步源 Stratum 3三層時(shí)間服務(wù)器 Poll 6每64秒同步一次 Reach 377最近8次全部連通 377八進(jìn)制表示8次連通八進(jìn)制377 二進(jìn)制 111111118位全1 LastRx 1212秒前剛收到回復(fù) offest -423us本機(jī)比NTP服務(wù)器慢423微秒實(shí)驗(yàn)二主機(jī)通過外網(wǎng)時(shí)間服務(wù)器進(jìn)行校時(shí)1.更改配置同步外網(wǎng)時(shí)間服務(wù)器 ntp.aliyun.com vim /etc/chrony.conf pool ntp.aliyun.com iburst 2.發(fā)起校時(shí)請(qǐng)求 systemctl restart chronyd 3.查看同步的服務(wù)器 [rootlocalhost ~]# chronyc sources -v # -v參數(shù)表示顯示內(nèi)容是否有解釋 [rootclient-146 ~]# chronyc sources MS Name/IP address Stratum Poll Reach ^* 203.107.6.88 3 6 17 35ms [rootclient-146 ~]# ping ntp.aliyun.com PING ntp.aliyun.com(203.107.6.88) 56(84) byte 64 bytes from 203.107.6.88 (203.107.6.88): icms問題分析1.客戶端主機(jī)和服務(wù)端主機(jī)網(wǎng)絡(luò)互通 ping 2.包能不能正常請(qǐng)求 pool SERVERNAME iburst 3.服務(wù)端是否可以成功響應(yīng) allow 主機(jī)/主機(jī)網(wǎng)段 4.服務(wù)程序不能成功啟動(dòng)錯(cuò)誤分析方式 [rootserver-142 ~]# journalctl -xeu chronyd.service # 早期啟動(dòng)的日志結(jié)果也會(huì)記錄 時(shí)間不能同步的另外兩個(gè)細(xì)節(jié) 兩臺(tái)主時(shí)區(qū)不一致 時(shí)間偏差過大第三章 SSH遠(yuǎn)程登陸服務(wù)1.概念2.telnet能夠通過當(dāng)前主機(jī)遠(yuǎn)程連接對(duì)端主機(jī)通過命令行接口進(jìn)行控制管理23 / tcp 數(shù)據(jù)明文傳輸搭建telnet遠(yuǎn)程連接服務(wù)支持終端主機(jī)設(shè)備能夠通過telnet進(jìn)行遠(yuǎn)程連接server linux --- telnet-server --- 192.168.211.131clientwindows --- xshell --- 192.168.211.1server端 1.部署telnet服務(wù) dnf install telnet-server -y 2.啟動(dòng)服務(wù)監(jiān)聽23/tcp端口等待客戶端主機(jī)的請(qǐng)求連接 systemctl start telnet.socket client xshell 發(fā)起telnet連接 [C:\~]$ telnet 192.168.211.131 Connecting to 192.168.211.131:23... Connection established. To escape to local shell, press CtrlAlt]. Kernel 5.14.0-570.12.1.el9_6.x86_64 on an x86_64 localhost login: root Password: Last login: Sat Oct 24 16:07:50 from ::ffff:192.168.211.1 [rootnodel -]# dnf install wireshark -y 通過主機(jī)圖形化終端啟動(dòng)wireshark程序 [rootnodel ~]# wireshark 16:10:23.189 Main Info Warning: Ignoring XDG_SESSION_TYPEWayland on Gnome. Use QT_OPALPLATFORMwayland to run on Wayland anyway.3.ssh secure shell能夠通過當(dāng)前主機(jī)遠(yuǎn)程連接對(duì)端主機(jī)通過命令行接口進(jìn)行控制管理22 / tcp 數(shù)據(jù)加密傳輸實(shí)驗(yàn)二部署ssh遠(yuǎn)程openssh-clients-8.7p1-45.el9.x86_64 客戶端程序名-----sshopenssh-server-8.7p1-45.el9.x86_64 服務(wù)程序名查看ssh程序網(wǎng)絡(luò)監(jiān)聽信息 [rootlocalhost ~]# ss -tunlp | grep ssh tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:((sshd,pid1154,fd3)) tcp LISTEN 0 128 [::]:22 [::]:* users:((sshd,pid1154,fd4)) [rootlocalhost ~]# netstat -tunlp | grep ssh tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1154/sshd: /usr/sbi tcp6 0 0 :::22 :::* LISTEN 1154/sshd: /usr/sbi 查看指定端口監(jiān)聽的程序 [rootlocalhost ~]# lsof -i:22 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME sshd 1154 root 3u IPv4 19184 0t0 TCP *:ssh (LISTEN) sshd 1154 root 4u IPv6 19186 0t0 TCP *:ssh (LISTEN)安全加固管理vim /etc/ssh/sshd_config Port 2222 AllowUsers 用戶名1 用戶名2 vim /etc/ssh/sshd_config.d/01-permitrootlogin.conf PermitRootLogin no 秘鑰驗(yàn)證配置文件初始化重裝軟件程序編輯配置文件時(shí)記得對(duì)配置文件進(jìn)行備份主配置/etc/ssh/sshd_conf/etc/ssh/ssh_conf --- 客戶端的配置文件子配置文件/etc/ssh/sshd_config.d/*.conf自配置文件名的數(shù)值越小級(jí)別越高優(yōu)先讀取SSH建立遠(yuǎn)程連接的原理1.tcp三次握手2.版本協(xié)商3.對(duì)稱算法的協(xié)商階段數(shù)據(jù)加密算法的協(xié)商4.身份驗(yàn)證身份偽裝數(shù)據(jù)泄露加密算法對(duì)稱加密算法加密 解密用的是同一把秘鑰 A秘鑰---123? --- 加密*............---B 秘鑰秘鑰不允許發(fā)送數(shù)據(jù)雙向傳輸數(shù)據(jù)傳輸?shù)男瘦^高非對(duì)稱加密算法加密解密用的是不同秘鑰 私鑰 --- 數(shù)據(jù)解密 公鑰 --- 數(shù)據(jù)加密私鑰留到制作端主機(jī)不允許公開發(fā)送公鑰公開發(fā)送所有用戶都能夠獲取數(shù)據(jù)僅支持單向傳輸身份驗(yàn)證A私鑰 B公鑰公鑰密鑰交換算法Diffie-HellmanDH密鑰交換算法 ----非對(duì)稱算法服務(wù)端驗(yàn)證客戶端身份通過秘鑰驗(yàn)證服務(wù)驗(yàn)證客戶端主機(jī)身份1.客戶端提前將自己的公鑰(如~/.ssh/id_rsa.pub)上傳到服務(wù)器的~/.ssh/authorized_keys 文件中;2.驗(yàn)證時(shí)服務(wù)器生成一個(gè)隨機(jī)字符串用服務(wù)端公鑰加密后發(fā)送給客戶端;3.客戶端用自己的私鑰解密得到隨機(jī)字符串再用會(huì)話密鑰加密后返回給服務(wù)器;4.服務(wù)器解密并對(duì)比原始隨機(jī)字符串一致則驗(yàn)證通過。宿舍遠(yuǎn)程實(shí)現(xiàn)秘鑰驗(yàn)證免密登錄預(yù)處理:2臺(tái)機(jī)子都恢復(fù)快照第一步:定位客戶端制作公私鑰對(duì)客戶端:192.168.48.128服務(wù)端:192.168.48.130[rootnodel ~]# ssh-keygen -t rsa #一路回車第二步:定位客戶端將公鑰上傳到服務(wù)器端[rootnodel ~]# ssh-copy-id root192.168.48.130 # 輸入服務(wù)端的賬戶及IP地址 The authenticity of host 192.168.48.130 (192.168.48.130) cant be established. ED25519 key fingerprint is SHA256:K7nvJFkfIhp9YytEGR44wLbTfpB0Y52oVou0UdG6nc. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? yes # 輸Ayes /usr/bin/ssh-copy-id: INFo: attempting to log in with the new key(s), to filter out any that are already installed /usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys root192.168.48.130s password: #輸入服務(wù)端root賬戶的的密碼 Number of key(s) added: 1 Now try logging into the machine, with: ssh root192.168.48.130 and check to make sure that only the key(s) you wanted were added. #注意:客戶端將公鑰上傳到服務(wù)器端后服務(wù)器端的/root/.ssh/authorized_keys文件會(huì)存儲(chǔ)客戶端的公鑰數(shù)據(jù)第三步:客戶端測(cè)試[rootnodel ~]# ssh root192.168.48.130 Activate the web console with: systemctl enable --now cockpit.socket Register this system with Red Hat Insights: insights-client --register Create an account or view all your systems at https://red.ht/insights-dashboard Last login: Wed Mar 22 11:31:31 2023 [rootserver ~]#實(shí)驗(yàn)三 通過window---xshell和服務(wù)器主機(jī)進(jìn)行秘鑰驗(yàn)證