squid日誌分析與反向代理
阿新 • • 發佈:2018-08-02
src exc 列表 enable 發送 shadow ins 圖片 fix 一、squid日誌分析
Srag是一款Squid日誌分析工具,采用HTML格式,詳細列出每一位用戶訪問Internet的站點信息,時間占用信息,排名,連接次數和訪問量等。
Srag的部署過程如下。
(1)安裝圖像處理工具
yum install -y gd gd-devel
(2)創建sarg工作目錄
mkdir /usr/local/sarg
(3)手工編譯安裝sarg
./configure --prefix=/usr/local/sarg --sysconfdir=/etc/sarg --enable-extraprotection
make && make install
(4)編輯sarg.conf配置文件
vim /etc/sarg/sarg.conf #將下列註釋掉的條目打開 access_log /usr/local/squid/var/logs/access.log //指定訪問日誌文件 title "Squid User Access Reports" //網頁標題 output_dir /var/www/html/squid-reports //報告輸出目錄 user_ip no //使用用戶名顯示 exclude_hosts /usr/local/sarg/noreport //不計入排序的站點列表文件 topuser_sort_field connect reverse //top排序中有連接次數、訪問字節、降序排列 升序是normal user_sort_field reverse //用戶訪問記錄 連接次數、訪問字節按降序排序 overwrite_report no //同名日誌是否覆蓋 mail_utility mailq.postfix //發送郵件報告命令 charset UTF-8 //使用字符集 weekdays 0-6 //top排行的星期周期 hours 0-23 //top排行的時間周期 www_document_root /var/www/html //網頁根目錄
#添加不計入站點文件,添加的域名將不被顯示在排序中
touch /usr/local/sarg/noreport
創建軟鏈接,便於管理
ln -s /usr/local/sarg/bin/sarg /usr/local/bin/
開啟服務
[root@bogon sarg]# sarg
SARG: 紀錄在文件: 152, reading: 100.00%
SARG: 成功的生成報告在 /var/www/html/squid-reports/2018Aug01-2018Aug02
(5)安裝httpd服務
yum install httpd -y
創建周期性計劃任務執行每天生成報告
sarg -l /usr/local/squid/var/logs/access.log -o /var/www/html/squid-reports/ -z -d $(date -d "1 day ago" +%d/%m/%Y)-$(date +%d/%m/%Y)
(6)在win7測試機上測試
二、squid反向代理
角色 | ip地址 | 安裝服務 |
---|---|---|
squid代理服務器 | 192.168.174.209 | squid |
節點服務器1 | 192.168.174.208 | httpd |
節點服務器22 | 192.168.174.142 | httpd |
win7測試機 | 192.168.174.129 | null |
1.編輯squid.conf配置文件
http_port 192.168.174.209:80 accel vhost vport
cache_peer 192.168.175.208 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1
cache_peer 192.168.174.142 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web2
cache_peer_domain web1 web2 www.yun.com
2.兩臺httpd服務器安裝httpd服務
yum install -y httpd
開啟服務
systemctl start httpd.service
分別創建httpd首頁,便於區分
vim /var/www/html/index.html
3.在win7上測試
(1)修改host文件,添加代理服務器地址
(3)輸入www.yun.com進行測試
(4)關閉web2這臺服務器的httpd服務,進行測試,此時仍能訪問web2.
squid日誌分析與反向代理