Squid代理服務器——ACL訪問控制,sarg日誌,反向代理

一,ACL訪問控制

1,在squid服務器上修改配置文件

[root@squid ~]# vim /etc/squid.conf  ##修改配置文件
# should be allowed
acl hostlocal src 192.168.10.10/32  ##控制hostlocal10.10的主機
# Deny requests to certain unsafe ports
http_access deny hostlocal  ##拒絕訪問
[root@squid ~]# service squid reload   ##重啓squid服務
常用的ACL列表類型:
src→源地址
dst→目標地址
port→目標地址
dstdomain→目標域
time →訪問時間
maxconn→最大併發連接
url_regex→目標URL地址
Urlpath_regex→整個目標URL路徑

二,sarg日誌

1,在squid服務器上安裝sarg

[root@squid ~]# mount.cifs //192.168.100.100/LNMP-C7 /mnt/  ##掛載
Password for root@//192.168.100.3/LNMP-C7:  
[root@squid ~]# cd /mnt/
[root@squid mnt]# tar zxvf sarg-2.3.7.tar.gz -C /opt/   ##解壓
[root@squid mnt]# cd /opt/sarg-2.3.7/
[root@squid sarg-2.3.7]# yum install gd gd-devel -y  ##安裝gd庫
[root@squid sarg-2.3.7]# ./configure --prefix=/usr/local/sarg \  ##安裝路徑
> --sysconfdir=/etc/sarg \   ##配置文件
> --enable-extraprotection  ##開啓安全防護
[root@squid sarg-2.3.7]# make && make install  ##編譯安裝

2,修改sarg配置文件

[root@squid sarg-2.3.7]# vim /etc/sarg/sarg.conf  ##修改sarg配置文件
##將下面的模塊修改開啓
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
overwrite_report no  ##同名日誌是否覆蓋
mail_utility mailq.postfix  ##發送郵件報告命令
charset UTF-8  ##使用字符集
weekdays 0-6  ##top排行的時間週期
hours 0-23  ##top排行的時間週期
www_document_root /var/www/html  ##網頁根目錄
[root@squid ~]# sarg   ##生成報告
SARG: 紀錄在文件: 91, reading: 100.00%
SARG: 成功的生成報告在 /var/www/html/squid-reports/2019Dec11-2019Dec12
[root@squid sarg-2.3.7]# cd /var/www/html/squid-reports/  ##切換到html目錄下
[root@squid squid-reports]# ls
2019Dec11-2019Dec12   images  index.html
[root@squid squid-reports]# yum install httpd -y  ##安裝httpd服務
[root@squid squid-reports]# systemctl start httpd.service  ##開啓服務
[root@squid squid-reports]# systemctl stop firewalld.service   ##關閉防火牆
[root@squid squid-reports]# setenforce 0

3,用測試機訪問網頁查看訪問記錄

Squid代理服務器——ACL訪問控制,sarg日誌,反向代理

週期性計劃任務執行每天生成報告crontab

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)

三,squid反向代理

1,在web1服務器上編輯一個網頁內容

[root@web ~]# cd /var/www/html/
[root@web html]# vim index.html  ##編輯網頁內容
this is web01

2,在web2服務器上編輯一個網頁內容

[root@web2 ~]# systemctl stop firewalld.service   ##關閉防火牆
[root@web2 ~]# setenforce 0
[root@web2 ~]# yum install httpd -y   ##安裝httpd服務
[root@web2 ~]# cd /var/www/html/   ##創建網頁內容
[root@web2 html]# vim index.html
this is web02
[root@web2 html]# systemctl start httpd.service 

3,在squid服務上配置反向代理

[root@localhost squid]# vim /etc/squid.conf
# Squid normally listens to port 3128
http_port 192.168.13.184:80 accel vhost vport ##監控本機80端口
cache_peer 192.168.13.151 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1
##節點服務器1最大訪問30,權重1,別名web1
cache_peer 192.168.13.185 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1
cache_peer_domain web1 web2 www.yun.com  ##訪問yun.com匹配web1,web2節點
[root@localhost squid]# service squid restart  ##重啓squid服務

4,在測試機的admin用戶下配置解析域名地址,並設置代理

Squid代理服務器——ACL訪問控制,sarg日誌,反向代理
Squid代理服務器——ACL訪問控制,sarg日誌,反向代理

Squid代理服務器——ACL訪問控制,sarg日誌,反向代理

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章