综合实践
学习目标
这一节,我们从网络实践、文件实践、小结三个方面来学习。
网络实践
简介
所谓的网络实践,主要是借助于 awk 的数组功能,进行站点的信息统计操作。
准备网络环境
# 安装软件
yum install nginx -y
systemctl restart nginx.service
# 重置网站首页
echo 'hello nginx' > /usr/share/nginx/html/index.html
# 测试访问
curl localhost
# 输出:hello nginx
curl localhost/nihao -I -s | head -1
# 输出:HTTP/1.1 404 Not Found
# 模拟外网访问
curl http://10.0.0.12/ -s -I -H "X-Forwarded-For: 2.2.2.2" | head -1
# 输出:HTTP/1.1 200 OK
# 查看日志
tail -n1 /var/log/nginx/access.log
# 准备 IP 地址文件
cat ip.txt
# 内容示例:
# 112.64.233.130
# 114.101.40.170
# ... (省略部分)
# 准备站点访问测试脚本
cat curl_web_site.sh
#!/bin/bash
# 功能:模拟外网访问网站
while true do
cat ip.txt | while read ip
do
NUM=$(echo $ip | cut -d"." -f 4)
for i in $(seq $NUM)
do
curl http://10.0.0.12/ -s -I -H >> /dev/null
curl http://10.0.0.12// -s >> /dev/null
1

