Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

Linux 常見面試題 1:命令、網路、腳本與資料庫

檔案與效能排查

查詢 file1 中空行行號:

cat file1 | grep -n ^$

查詢以 abc 結尾的行:

grep abc$ file1

常見效能監控工具包含 iostat、mpstat、top。

網路故障時可先用 ping、traceroute、dig、nslookup 排查,再檢查 IP、閘道與 DNS 設定。

端口轉發

將本機 80 端口轉發到 8080,可使用 iptables DNAT:

iptables -A PREROUTING -d 192.168.2.1 -p tcp -m tcp --dport 80 -j DNAT --to-destination 192.168.2.1:8080

Shell 腳本

在 11 月每天 6 點到 12 點每隔兩小時執行腳本:

0 6-12/2 * 11 * /usr/bin/httpd.sh

把 /usr/local/test 中大於 100K 的檔案移到 /tmp:

for file in /usr/local/test/*; do
    if [ -f "$file" ]; then
        size=$(stat -c %s "$file")
        if [ "$size" -gt 102400 ]; then
            mv "$file" /tmp
        fi
    fi
done

MySQL 與監控

MySQL 備份可用:

mysqldump -uroot -p test > test.sql
mysql -uroot -p test < test.sql

查看 8080 端口佔用:

lsof -i:8080

常見監控工具包含 Nagios、Cacti、Zabbix。

DNS 與分析

常用 DNS 軟體為 bind,常見記錄包含 A、MX、CNAME。若為 abc.com 設定郵件伺服器,可增加 MX 與 A 記錄。bind 智能解析通常透過 view 依來源 IP 回傳不同結果。

Copyright © Linux教程網 All Rights Reserved