- 一、Squid服務器ACL訪問控制
- (一)ACL訪問控制原理:
- (二)acl串列的型別:
- (三)將串列名單存放在檔案中,定義檔案進行訪問控制
- 示范:
- 1.添加ACl規則
- 2.Client訪問Web測驗
- 二、Squid反向代理
- 實驗拓撲:
- 【Web1端】IP:192.168.30.30
- 1.制作一個測驗頁面
- 2.訪問Web測驗,頁面顯示正常
- 【Web2端】IP:192.168.30.40
- 1.制作一個測驗頁面
- 2.訪問Web測驗,頁面顯示正常
- 【Squid端】 IP:192.168.30.10
- 1.清空防火墻規則,并放通80埠
- 【客戶端訪問測驗】 IP :192.168.30.100
- 三、Squid——Sarg日志統計功能
- 1.安裝sarg日志程式
- 2.修改組態檔
- 3.優化路徑,并生成報告檔案
- 4.安裝Apache服務
- 5.客戶端訪問查看
- 6.制定周期性計劃任務
一、Squid服務器ACL訪問控制
(一)ACL訪問控制原理:
1.首先定義acl串列 :格式:acl 串列名稱 串列型別 串列內容 ……
2.基于acl串列指定規則 :格式:http_access allow|deny串列名稱
(二)acl串列的型別:
| 型別 | 示例 |
|---|---|
| src 源地址 | acl localhost src 192.168.175.136/32 ##定義源主機ip acl MYLAN src 192.168.175.0/24 ##定義網段 |
| dst 目標地址 | acl destionhost dst 192.168.175.130/32 ##定義具體目標主機ip |
| port 目標埠 | // |
| dstdomain 目標域名 | // |
| time 訪問時間 | acl work time MTWHFAC 08:30-17:30 注意:MTWHFAC 字母分別指周一到周日 |
| maxconn 最大并發量 | acl MC20 maxconn 20 ##定義MC20串列,指明最大連接數 |
| url_regex 目標URL | acl BURL ur1_regex -i ^rtsp:// ^emule:// ##可以通過正則定義域名 |
| url path_regex 整個目標URL 路徑 | acl PURL urlpath_regex -i .mp3$ .mp4$ .rmvb$ ##以.mp3,.mp4等結尾 |
(三)將串列名單存放在檔案中,定義檔案進行訪問控制
示例:
[root@localhost ~]# vi /etc/squid/ipblock.list ##創建ip名單,注意,要在
61.135.167.36
60.28.14.0/24
[root@localhost ~]# vi /etc/squid/dmblock.list
.qq.com
.msn.com
[root@squid ~]# vim /etc/squid.conf
acl lPBLOCK dst "/etc/squid/ipblock.list" ##定義目標ip的檔案
acl DMBLOCK dstdomain "/etc/squid/dmblock.list" ##定義目標域名的檔案
thttp_access deny IPBLOCK
http_access deny DMBLOCK
示范:
1.添加ACl規則
[root@squid ~]# vim /etc/squid.conf
acl MMM src 192.168.30.0/24 ##定義一條名為MMM的訪問控制串列
http_access deny MMM ##拒絕所有MMM串列中名單的http請求
http_access allow all ##放通所有(默認與最后一條ACL規則相反,可以不用設)
2.Client訪問Web測驗
(1)配置規則前

(2)配置ACL則后,請求失敗

二、Squid反向代理

實驗拓撲:

基于上次傳統模式上繼續試驗https://blog.csdn.net/CN_LiTianpeng/article/details/109387464
【Web1端】IP:192.168.30.30
1.制作一個測驗頁面
[root@localhost httpd]# cd /var/www/html/
[root@localhost html]# vi index.html
<title>HELLO</title>
<h1>this is test1 Web</h1>
[root@localhost html]# systemctl restart httpd
2.訪問Web測驗,頁面顯示正常

【Web2端】IP:192.168.30.40
1.制作一個測驗頁面
[root@localhost httpd]# cd /var/www/html/
[root@localhost html]# vi index.html
<title>GOOD</title>
<h1>this is test2 Web</h1>
[root@localhost html]# systemctl restart httpd
2.訪問Web測驗,頁面顯示正常

【Squid端】 IP:192.168.30.10
1.清空防火墻規則,并放通80埠
[root@squid ~]# iptables -F
[root@squid ~]# iptables -t nat -F
[root@squid ~]# systemctl start firewalld
[root@squid ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
2.修改組態檔,反向代理配置
[root@squid init.d]# vim /etc/squid.conf ##修改配置
#http_port 3128
http_port 192.168.10.10:80 accel vhost vport ##配置監聽地址80埠作為虛擬加速地址和埠,配置80埠后,客戶機瀏覽器就可以不用做代理服務器了,可以http直接訪問,
cache_peer 192.168.10.20 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web1 ##匹配192.168.10.20地址80埠,并且禁止查詢真實域內服務器,輪詢調度,最大連接數30,權重為1,該域內服務器命名為web1
cache_peer 192.168.10.40 parent 80 0 no-query originserver round-robin max_conn=30 weight=1 name=web2
cache_peer_domain web1 web2 www.yun.com 192.168.30.10 ##匹配域內主機web1,web2;可以使用域名www.yun.com或IP地址192.168.30.10訪問
//注意:若在cache_peer_domain配置的末尾不加域名或者ip,就無法使用域名或ip進行負載均衡反向代理,并且如果只有域名,那么只能訪問域名進行反向代理輪詢調度,訪問ip無效,反之同理,一般只需要配置域名即可
[root@squid init.d]# service squid stop
[root@squid init.d]# service squid start
正在啟動 squid....
[root@squid init.d]# netstat -lanpt |grep 80
tcp 0 0 192.168.30.10:80 0.0.0.0:* LISTEN 3935/(squid-1)
【客戶端訪問測驗】 IP :192.168.30.100


三、Squid——Sarg日志統計功能
1.安裝sarg日志程式
[root@squid ~]# ls ##查看sarg軟體包
sarg-2.3.7.tar.gz ……省略部分
[root@squid ~]# yum -y install gd gd-devel
[root@squid ~]# yum -y install gcc gcc-c++ make
[root@squid ~]# tar zxvf sarg-2.3.7.tar.gz -C /opt
[root@squid ~]# cd /opt/sarg-2.3.7/
[root@squid sarg-2.3.7]# ./configure \
--prefix=/usr/local/sarg \
--sysconfdir=/etc/sarg \
--enable-extraprotection ##額外安全防護
[root@squid sarg-2.3.7]# make -j3 && make install
2.修改組態檔
[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 ##指定訪問日志檔案
25行// title "Squid User Access Reports" ##網頁標題
120行// output_dir /var/www/html/squid-reports ##報告輸出目錄
178行// user_ip no ##使用用戶名顯示
184行// topuser_sort_field connect reverse ### 在 top 排序中,指定連接次數,訪問位元組數,采用降序排列,升序是normal
206行// exclude_hosts /usr/local/sarg/noreport ##不計入排序的站點串列檔案
257行// overwrite_report no ##同名日志是否覆寫
289行// mail_utility mailq.postfix ##發送郵箱報告的命令
434行// charset UTF-8 ##使用字符集
516行// weekdays 0-6 ##指定 top 排序時的星期周期,0 為周日
525行// hours 0-23 ## top排序的時間周期
633行// www_document_root /var/www/html ##網頁根目錄
[root@squid sarg]# egrep -vn '^#|^$' /etc/sarg/sarg.conf ##過濾檢查配置是否修改正確
7:access_log /usr/local/squid/var/logs/access.log
25:title "Squid User Access Reports"
120:output_dir /var/www/html/squid-reports
178:user_ip no
184:topuser_sort_field connect reverse
206:exclude_hosts /usr/local/sarg/noreport
257:overwrite_report no
289:mail_utility mailq.postfix
434:charset UTF-8
516:weekdays 0-6
525:hours 0-23
633:www_document_root /var/www/html
[root@squid sarg]# touch /usr/local/sarg/noreport
3.優化路徑,并生成報告檔案
[root@squid ~]# ln -s /usr/local/sarg/bin/sarg /usr/local/bin/
[root@squid ~]# sarg ##生成報告
SARG: Records in file: 2528, reading: 100.00%
SARG: Successful report generated on /var/www/html/squid-reports/2020Oct30-2020Nov01
[root@squid ~]# cd /var/www/html/squid-reports/
[root@squid squid-reports]# ls ##查看,里面有index.html首頁檔案
2020Oct30-2020Nov01 images index.html
[root@squid sarg-2.3.7]# cd /etc/sarg/
[root@squid sarg]# vim sarg.conf
190行// user_sort_field reverse ##對于用戶訪問記錄,連接次數按降序排列,注意,這個功能一定要在使用sarg命令生成報告檔案后開啟,否則會報錯
4.安裝Apache服務
[root@squid ~]# yum -y install httpd ##安裝一個Apache訪問
[root@squid ~]# systemctl start httpd ##啟動Apache
[root@squid ~]# cd /var/www/html/
[root@squid html]# ls
squid-reports
5.客戶端訪問查看


6.制定周期性計劃任務
[root@squid html]# 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)
##執行這條陳述句,制定每日計劃任務,sarg -l 生成訪問日志,-o輸出到/var/www/html/squid-reports/目錄下,-d指定時間間隔“當天時間減去前一天時間” 即一天間隔,
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/199226.html
標籤:python
上一篇:樹莓派4b深度學習心得
