ACL访问控制
ACL訪問控制和squid日志分析工具
- ACL訪問控制和squid日志分析工具
- ACL訪問控制
- ACL列表的應用
- 反向代理網站加速
- ACL實驗環境
- squid日志分析工具實驗
- 在squid服務端配置
- squid反向代理實驗
- 配置第一臺http服務端頁面
- 配置第二臺http服務端頁面
- 在squid服務器上配置
- 在web服務器配置
ACL訪問控制和squid日志分析工具
ACL訪問控制
ACL訪問控制方式
- 根據源地址、目標URL、文件類型等定義列表
acl列表名稱列表類型列表內容… - 針對已定義的acl列表進行限制
http_access allow或deny列表名稱…
ACL規則優先級
- 一個用戶訪問代理服務器時,Squid會順序匹配Squid中定
義的所有規則列表,一旦匹配成功,立即停止匹配 - 所有規則都不匹配時,Squid會使用與最后一條相反的規則
ACL訪問控制
常用的ACL列表類型
- src →>源地址
- dst >自標地址
- port→>端口
- dstdomain>目標域
- time →>訪問時間
- maxconn →最大并發連接
- ourl_regex >目標URL地址
- Urlpath_regex→整個目標URL路徑
ACL列表的應用
最簡單的ACL控制
禁止任何客戶機使用此代理服務
[root@localhost~]# vi letclsquid.conf acKalsrc 0.0.0.0/0.0.0.0 http_access deny all反向代理網站加速
工作機制
- 緩存網頁對象,減少重復請求
- 將互聯網請求輪訓或按權重分配到內網Web服務器
- 代理用戶請求,避免用戶直接訪問Web服務器,提高安全
搭建反向代理實現加速
- 設置網絡參數
- 安裝部署squid服務器
- 配置squid支持透明代理
- 配詈防火墻
- 測試驗證
ACL實驗環境
3臺服務器
1臺squid代理服務器 : 192.168.136.40
1臺apache服務器:192.168.136.30
1臺web客戶機 192.168.136.50
下面的實驗基于squid傳統代理基礎上配置(ps:配置squid不在贅述,如有不會請回看上一篇博客)
在squid代理服務器上配置
[root@squid network-scripts]# vim /etc/squid.conf # should be allowed acl hostlocal src 192.168.136.50/32 #增控制的是win10的地址# Deny requests to certain unsafe ports http_access deny hostlocal #增加
開啟服務
[root@squid network-scripts]# service squid reload [root@squid network-scripts]# netstat -natp | grep 3128tcp 0 0 192.168.10.1:3128 0.0.0.0:* LISTEN 101064/(squid-1)訪問已經拒絕
開啟服務
[root@localhost ~]# vim /etc/squid.conf #http_access deny hostlocal 注釋掉squid日志分析工具實驗
記得把前面的acl控制web端口注釋掉
[root@squid network-scripts]# vim /etc/squid.conf #http_access deny hostlocal #acl hostlocal src 192.168.136.50/32在squid服務端配置
解壓縮
[root@localhost ~]# tar zxvf sarg-2.3.7.tar.gz -C /opt/安裝圖像化處理工具,gd庫
[root@squid sarg-2.3.7]# yum install gd gd-devel -y編譯配置
[root@localhost ~]# cd squid-3.4.6/ [root@localhost squid-3.4.6]# ./configure --prefix=/usr/local/sarg \ > --sysconfdir=/etc/sarg \ > --enable-extraprotection [root@localhost squid-3.4.6]# make && make install配置sarg服務
root@squid sarg-2.3.7]# cd /etc/sarg/ [root@squid sarg]# vim sarg.conf 7 access_log /usr/local/squid/var/logs/access.log //squid的訪問日志位置25 title "Squid User Access Reports" //網頁標題 120 output_dir /var/www/html/squid-reports //分析報告存放位置178 user_ip no //不使用IP代替用戶ID 184 topuser_sort_field connect reverse //升序排列190 user_sort_field connect reverse // 這條必讀要注釋掉(不要開啟)206 exclude_hosts /usr/local/sarg/noreport #這個文件待會需要創建,里面存放的是不生成報告的主機257 overwrite_report no289 mail_utility mailq.postfix //指定發郵件命令434 charset UTF-8 字符集518 weekdays 0-6 //指定top排序星期周期525 hours 0-23 //指定top排序時間周期633 www_document_root /var/www/html //網頁根目錄檢查一下
[root@localhost sarg]# grep -v "^#" sarg.conf創建一個文件名(不生成報告的主機)
touch /usr/local/sarg/noreport命令可以識別
ln -s /usr/local/sarg/bin/sarg /usr/local/bin/開啟服務(生成報告記錄)
[root@localhost sarg]# sarg SARG: 紀錄在文件: 382, reading: 100.00% SARG: 成功的生成報告在 /var/www/html/squid-reports/2020Sep07-2020Sep08可以看到生成的記錄在哪
2020Sep07-2020Sep07在這里
[root@localhost squid-reports]# ls /var/www/html/squid-reports/ 2020Sep07-2020Sep07 images index.html在aquid服務中安裝http展現服務
[root@localhost squid-reports]# yum -y install httpd開啟并查看
[root@localhost squid-reports]# systemctl restart httpd[root@localhost sarg]# netstat -ntap | grep httpd tcp6 0 0 :::80 :::* LISTEN 60702/httpd去win10客戶端查看
地址 192.168.136.40/squid-reports
點擊進去查了詳細
更換地址訪問
在squid日志服務器上配置
[root@squid squid-reports]# 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反向代理實驗
需要3臺服務器
1臺squit代理服務器 192.168.136.40
2http服務器 編譯首頁 web01 192.168.136.30
3http服務器 編譯首頁 web02 192.168.136.88
配置第一臺http服務端頁面
[root@localhost ~]# yum -y install httpd [root@localhost ~]# vim /var/www/html/index.html <h1>this is web 01 </h1> [root@localhost ~]# systemctl restart httpd.service配置第二臺http服務端頁面
[root@localhost ~]# yum -y install httpd [root@promote ~]# vim /var/www/html/index.html <h1> this is web 02</h1> [root@localhost ~]# systemctl restart httpd.service在squid服務器上配置
查看一下端口有沒有被占用,因為httpd會占用80端口,必須關閉
[root@localhost ~]# netstat -ntap | grep 80 [root@localhost ~]# systemctl stop httpd配置反向代理squid服務
[root@localhost ~]# vim /etc/squid.conf #http_port 3128 注釋監聽端口 并在下面配置 http_port 192.168.136.40:80 accel vhost vport cache_peer 192.168.136.30 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1 cache_peer 192.168.136.88 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web2 cache_peer_domain web1 web2 www.yun.com開啟服務
監聽端口為本地80端口
[root@localhost ~]# service squid stop [root@localhost ~]# netstat -ntap | grep squid [root@localhost ~]# service squid start 正在啟動 squid... [root@localhost ~]# netstat -ntap | grep squid tcp 0 0 192.168.136.40:80 0.0.0.0:* LISTEN 57844/squid-1)在web服務器配置
修改端口號為80
配置wen10的DNS
c/windows/system32/drivers/etc設置文件權限
文本打開
配置dns
ping查看是否在線
刷新一下
如果顯示不出來在配置正確的情況下,在兩臺http服務機上關閉防火墻或win10防火墻
總結
- 上一篇: 内存条新选择,3200MHz高速稳定,散
- 下一篇: 内存需求揭秘:8GB是否够用?还是需要1