網(wǎng)站如何安裝源碼網(wǎng)絡(luò)推廣策劃書
linux腳本
需求:
CPU 負(fù)載:使用?
uptime
?命令,我們可以清楚地了解系統(tǒng)的 CPU 負(fù)載情況。這個(gè)命令會(huì)顯示系統(tǒng)在過去 1 分鐘、5 分鐘和 15 分鐘的平均負(fù)載。高負(fù)載可能意味著系統(tǒng)正在處理大量的任務(wù),可能會(huì)導(dǎo)致性能下降或服務(wù)響應(yīng)延遲。內(nèi)存使用:通過?
free -m
?命令,我們可以以 MB 為單位查看系統(tǒng)的內(nèi)存使用情況,包括已使用內(nèi)存、空閑內(nèi)存、緩存和交換空間。這有助于我們判斷系統(tǒng)是否需要更多的內(nèi)存資源,或者是否存在內(nèi)存泄漏等問題。磁盤使用:
df -h
?命令為我們提供了磁盤空間使用情況的信息,讓我們清楚地知道各個(gè)文件系統(tǒng)的使用比例。當(dāng)磁盤空間接近飽和時(shí),會(huì)嚴(yán)重影響系統(tǒng)的正常運(yùn)行,甚至導(dǎo)致服務(wù)無法寫入數(shù)據(jù)。網(wǎng)絡(luò)狀態(tài):
ifconfig
?命令可以讓我們查看網(wǎng)絡(luò)接口的狀態(tài),包括 IP 地址、MAC 地址、接收和發(fā)送的數(shù)據(jù)包數(shù)量等,幫助我們確保網(wǎng)絡(luò)連接的正常。?服務(wù)狀態(tài)檢查:你可以添加檢查服務(wù)是否正在運(yùn)行的功能,比如檢查?
Apache
?服務(wù)器是否正在運(yùn)行,可以使用?systemctl status apache2
?或?service apache2 status
?命令,并將結(jié)果添加到報(bào)告中。
開發(fā)腳本內(nèi)容:
#!/bin/bash# 定義報(bào)告文件和錯(cuò)誤日志文件 REPORT_FILE="/root/linux_inspection_report.txt" HTML_REPORT="/root/linux_inspection_report.html" ERROR_LOG="/root/linux_inspection_error.log" DATE=`date "+%Y-%m-%d %H:%M:%S"`> $REPORT_FILE > $ERROR_LOGcat<<EOF > $HTML_REPORT <!DOCTYPE html> <html> <head> <title>Linux System Inspection Report</title> </head> <body> <h1>Linux System Inspection Report</h1> <p>Date:$DATE</p> EOF#uptime echo "<h2>System load</h2>" >> $HTML_REPORTif LOAD=`uptime 2>> $ERROR_LOG` thenecho "<p>$LOAD</p>" >> $HTML_REPORT elseecho "<p>Error occurred. Check $ERROR_LOG</p>" >> $HTML_REPORT fiecho "<h2>Disk Usage</h2>" >> $HTML_REPORT if DISK_USAGE=`df -h 2>> $ERROR_LOG` thenecho "<p>$DISK_USAGE</p>" >> $HTML_REPORT elseecho "<p>Error occurred. Check $ERROR_LOG</p>" >> $HTML_REPORT fiecho "<h2>Memory Usage</h2>" >> $HTML_REPORT if MEMORY_USAFE=`free -m 2>> $ERROR_LOG` thenecho "<p>$MEMORY_USAFE</p>" >> $HTML_REPORT elseecho "<p>Error occurred. Check $ERROR_LOG</p>" >> $HTML_REPORT fiecho "<h2>Network Status</h2>" >> $HTML_REPORT if NETWORK_STATUS=`ifconfig 2>> $ERROR_LOG` thenecho "<p>$NETWORK_STATUS</p>" >> $HTML_REPORT elseecho "<p>Error occrred. Check $ERROR_LOG</p>" >> $HTML_REPORT fiecho "<h2>Nginx Service Status</h2>" >> $HTML_REPORT if NGINX_STATUS=`systemctl status nginx 2>> $ERROR_LOG` thenecho "<p>$NGINX_STATUS</p>" >> $HTML_REPORT elseecho "<p>Error occurred. Check $ERROR_LOG</p>" >> $HTML_REPORT fi# echo "</body></html>
腳本文件需要設(shè)置可執(zhí)行權(quán)限
# chmod? +x? jiankong.sh?
執(zhí)行結(jié)果如下:
[root@hcss-ecs- ~]# ll
total 32
-rwxr-xr-x 1 root root 1725 Jan 27 14:12 jiankong.sh
-rw-r--r-- 1 root root 0 Jan 27 14:12 linux_inspection_error.log
-rw-r--r-- 1 root root 2960 Jan 27 14:12 linux_inspection_report.html
-rw-r--r-- 1 root root 0 Jan 27 14:12 linux_inspection_report.txt
-rw------- 1 root root 16817 Jan 27 14:12 sent
?執(zhí)行記錄的文件內(nèi)容如下:
[root@hcss-ecs-6f98 ~]# cat linux_inspection_report.html
<!DOCTYPE html>
<html>
<head>
<title>Linux System Inspection Report</title>
</head>
<body>
<h1>Linux System Inspection Report</h1>
<p>Date:2025-01-27 14:12:24</p>
<h2>System load</h2>
<p> 14:12:24 up 4:49, 3 users, load average: 0.00, 0.00, 0.00</p>
<h2>Disk Usage</h2>
<p>Filesystem Size Used Avail Use% Mounted on
devtmpfs 389M 0 389M 0% /dev
tmpfs 405M 0 405M 0% /dev/shm
tmpfs 405M 5.6M 399M 2% /run
tmpfs 405M 0 405M 0% /sys/fs/cgroup
/dev/vda1 40G 2.9G 35G 8% /
tmpfs 81M 0 81M 0% /run/user/0</p>
<h2>Memory Usage</h2>
<p> total used free shared buff/cache available
Mem: 808 187 391 7 229 490
Swap: 0 0 0</p>
<h2>Network Status</h2>
<p>eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500inet 192.168.5.15 netmask 255.255.240.0 broadcast 192.168.15.255inet6 fe80::f816:3eff:fe68:c5cf prefixlen 64 scopeid 0x20<link>ether fa:16:3e:68:c5:cf txqueuelen 1000 (Ethernet)RX packets 79035 bytes 68357573 (65.1 MiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 43600 bytes 7583848 (7.2 MiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536inet 127.0.0.1 netmask 255.0.0.0inet6 ::1 prefixlen 128 scopeid 0x10<host>loop txqueuelen 1000 (Local Loopback)RX packets 1454 bytes 113048 (110.3 KiB)RX errors 0 dropped 0 overruns 0 frame 0TX packets 1454 bytes 113048 (110.3 KiB)TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0</p>
<h2>Nginx Service Status</h2>
<p>● nginx.service - The nginx HTTP and reverse proxy serverLoaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)Active: active (running) since Mon 2025-01-27 09:42:01 CST; 4h 30min agoProcess: 13209 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)Process: 13206 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)Process: 13205 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)Main PID: 13210 (nginx)Tasks: 3 (limit: 4976)Memory: 5.9MCGroup: /system.slice/nginx.service├─13210 nginx: master process /usr/sbin/nginx├─13211 nginx: worker process└─13212 nginx: worker processJan 27 09:42:01 hcss-ecs-6f98 systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 27 09:42:01 hcss-ecs-6f98 nginx[13206]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 27 09:42:01 hcss-ecs-6f98 nginx[13206]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 27 09:42:01 hcss-ecs-6f98 systemd[1]: Started The nginx HTTP and reverse proxy server.</p>
</body></html>
發(fā)送到的郵箱郵件內(nèi)容如下: