Showing posts with label Squid. Show all posts
Showing posts with label Squid. Show all posts

10/23/2025

Config squid 5.7

 

Config squid 5.7
คำอธิบาย Authorization ประกอบด้วย 3 ส่วน ใช้ วรรคในการแบ่ง
เช่น
acl web_bypass dstdomain "/etc/squid/web_bypass.txt"

ประกอบด้วย
acl เริ่มต้นด้วยคำสั่ง
web_bypass ตัวแปรที่จะนำไปใช้ในการ allow หรือ denied
"/etc/squid/web_bypass.txt" ค่าที่ต้องการ allow หรือ denied เก็บเป็นไฟล์ หรือใช้ค่า เลยก็ได้
ใช้ค่าเลยเช่น
acl sci_servers dstdomain .sci.com .scivalve.com .alfresco.com


คำสั่ง allow หรือ denied ประกอบด้วย 3 ส่วน ใช้วรรคเป็นตัวแบ่ง เช่น
http_access allow sci_macs

จะขึ้นต้นด้วย http_access เริ่มต้นคำสั่ง
allow จะ allow หรือ denied
sci_macs ตัวแปรที่เก็บค่าไว้ หรือ Fix ค่าไปเลยก็ได้

dstdomain คือ domain ต้องตรงกันกับค่าที่ต้องการ allow หรือ denied
url_regex -i คือ มีคำหรือข้อความนั้นใน ค่าที่ต้องการ allow หรือ denied
rep_mime_type -i mime-type คือชนิดที่ต้องการ เช่น application/x-bittorrent

ส่วนที่ 1 Authorization
  1. forwarded_for on
  2. request_header_access Allow allow all
  3. request_header_access Authorization allow all
  4. request_header_access WWW-Authenticate allow all
  5. request_header_access Proxy-Authorization allow all
  6. request_header_access Proxy-Authenticate allow all
  7. request_header_access Cache-Control allow all
  8. request_header_access Content-Encoding allow all
  9. request_header_access Content-Length allow all
  10. request_header_access Content-Type allow all
  11. request_header_access Date allow all
  12. request_header_access Expires allow all
  13. request_header_access Host allow all
  14. request_header_access If-Modified-Since allow all
  15. request_header_access Last-Modified allow all
  16. request_header_access Location allow all
  17. request_header_access Pragma allow all
  18. request_header_access Accept allow all
  19. request_header_access Accept-Charset allow all
  20. request_header_access Accept-Encoding allow all
  21. request_header_access Accept-Language allow all
  22. request_header_access Content-Language allow all
  23. request_header_access Mime-Version allow all
  24. request_header_access Retry-After allow all
  25. request_header_access Title allow all
  26. request_header_access Connection allow all
  27. request_header_access Proxy-Connection allow all
  28. request_header_access User-Agent allow all
  29. request_header_access Cookie allow all
  30. request_header_access All deny all
  31.  
  32. ################## Start SCI ################################
  33. #acl sci-mac arp 90:21:55:02:6c:e2
  34. acl sci_macs arp "/etc/squid/MAC.lst"
  35. http_access allow sci_macs
  36.  
  37. acl sci_servers dstdomain .sci.com .scivalve.com .alfresco.com
  38. always_direct allow sci_servers
  39. http_access allow sci_servers
  40.  
  41. #Google
  42. acl googles dstdomain .google.com
  43. #always_direct allow googles
  44. http_access allow googles
  45.  
  46. #hotmail
  47. acl HM_SERVER dstdomain .msn.com .hotmail.com .passport.com .live.com .outlook.live.com .outlook.office.net .scivalve.com
  48. http_access allow HM_SERVER
  49.  
  50. acl web_bypass dstdomain "/etc/squid/web_bypass.txt"
  51. http_access allow web_bypass
  52.  
  53. acl GoodSites dstdomain "/etc/squid/goodsites.txt"
  54. #acl GoodSites url_regex -i "/etc/squid/goodsites.txt"
  55. http_access allow GoodSites
  56.  
  57. acl webblocked url_regex -i '/etc/squid/webblocked.txt'
  58. #acl webblocked dstdomain '/etc/squid/webblocked.txt'
  59. http_access deny webblocked
  60. #deny_info denied.html webblocked
  61.  
  62. acl TorrentFiles rep_mime_type -i mime-type application/x-bittorrent
  63. http_reply_access deny TorrentFiles
  64. deny_info TCP_RESET TorrentFiles
  65.  
  66. auth_param basic program /usr/lib/squid/basic_ldap_auth -v 3 -b "cn=Users,dc=sci,dc=com" -D CN=ldap-user,CN=Users,DC=SCI,DC=COM -w PASSWORD -f "(&(sAMAccountName=%s)(objectClass=person)(memberof=CN=InetAllow,OU=SCI,DC=SCI,DC=COM))" -h dc04.sci.com
  67. acl ldap-auth proxy_auth REQUIRED
  68.  
  69. #external_acl_type InetGroup %LOGIN /usr/lib/squid3/ext_wbinfo_group_acl
  70.  
  71. #acl InetAccessFree external InetGroup FreeNet
  72. #http_access allow InetAccessFree
  73.  
  74. acl webblocked_tmp dstdomain '/etc/squid/webblocked_tmp.txt'
  75. acl day_am time 08:00-11:59
  76. acl day_pm time 13:00-17:39
  77. acl day_ot time 18:00-20:59
  78. acl day_after time 21:00-23:59
  79. acl day_before time 00:00-05:59
  80. http_access deny webblocked_tmp day_am
  81. http_access deny webblocked_tmp day_pm
  82. http_access deny webblocked_tmp day_ot
  83. http_access deny webblocked_tmp day_after
  84. http_access deny webblocked_tmp day_before
  85.  
  86. acl domain_blocked dstdomain '/etc/squid/webblocked_https.txt'
  87. http_reply_access deny domain_blocked day_am
  88. http_reply_access deny domain_blocked day_pm
  89. http_reply_access deny domain_blocked day_ot
  90. http_reply_access deny domain_blocked day_after
  91. http_reply_access deny domain_blocked day_before
  92. http_access deny CONNECT domain_blocked day_am
  93. http_access deny CONNECT domain_blocked day_pm
  94. http_access deny CONNECT domain_blocked day_ot
  95. http_access deny CONNECT domain_blocked day_after
  96. http_access deny CONNECT domain_blocked day_before
  97.  
  98. http_access allow ldap-auth
  99. #SCI End 
  100.  

ส่วนที่ 2 localnet และ ports
  1. #Start SCI
  2. acl localnet src 192.168.0.0/24 192.168.100.0/24 192.168.2.0/24
  3. acl SSL_ports port 995          #mail.scivalve.com new
  4. acl SSL_ports port 8443         #scivalve.com new
  5. acl SSL_ports port 443
  6. acl SSL_ports port 993
  7. acl SSL_ports port 2222         # SCI: for hosting
  8. acl SSL_ports port 6301         # gpsiam
  9.  
  10. acl Safe_ports port 80          # http
  11. acl Safe_ports port 110         # SCI: POP3
  12. acl Safe_ports port 587         # SCI: smtp
  13. acl Safe_ports port 25          # SCI: smtp
  14. #End SCI


ส่วนที่ 3 Log Server
  1. #SCI Start Sent Log Squid To Log Server
  2. #Sent To access.log file.
  3. access_log /var/log/squid/access.log squid
  4.  
  5. #Sent To Log Server.
  6. logformat squid %tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
  7. access_log tcp:192.168.2.108:514 squid
  8. #SCI End

6/23/2020

Squid Error : tcp logger buffer overflowed

Squid Error : tcp logger buffer overflowed
ทำให้ใช้งานไปสักพักมีข้อความถามรหัส proxy ขึ้นมาอีก

ใช้คำสั่ง
/etc/init.d/squid status
Jun 23 13:11:58 proxy squid[969]: Squid Parent: (squid-1) process 31962 started
Jun 23 13:13:04 proxy (squid-1)[31962]: tcp logger buffer overflowed
Jun 23 13:13:04 proxy squid[969]: Squid Parent: (squid-1) process 31962 exited with status 1
Jun 23 13:13:07 proxy squid[969]: Squid Parent: (squid-1) process 32384 started
Jun 23 13:14:11 proxy (squid-1)[32384]: tcp logger buffer overflowed
Jun 23 13:14:11 proxy squid[969]: Squid Parent: (squid-1) process 32384 exited with status 1
Jun 23 13:14:14 proxy squid[969]: Squid Parent: (squid-1) process 311 started
Jun 23 13:15:03 proxy (squid-1)[311]: tcp logger buffer overflowed
Jun 23 13:15:03 proxy squid[969]: Squid Parent: (squid-1) process 311 exited with status 1
Jun 23 13:15:06 proxy squid[969]: Squid Parent: (squid-1) process 763 started

เกิดจากตัว squid ส่ง log ไปเก็บที่เครื่อง log server ไม่ได้
ตรวจสอบที่เครื่อง log server มีการย้าย Folder เก็บข้อมูลใหม่
พบว่า driver lan เปลี่ยนชื่อไป จาก eth3 เป็น eth4 ทำให้ เครื่อง log ไม่ได้ ip แก้ไขใหม่ reboot ใช้งานได้

ทดลองแก้ squid ไม่ให้ส่งไป ที่เครื่อง 192.168.2.108 ก็จะไม่มี error Mark ไว้ เมื่อ server log ใช้งานได้ตามปกติก็แก้คืนเอา Mark ออก
#Sent To Log Server.
logformat squid %tl %6tr %>a %Ss/%03Hs %<st %rm %ru %un %Sh/%<A %mt
access_log tcp:192.168.2.108:514 squid

1/25/2017

Proxy : Ubuntu 16.04 Squid

Proxy : Ubuntu 16.04 Squid
- ติดต้้่ง 16.04 Server set apt.conf update upgrade ให้เรียบร้อย
  1. apt nano /etc/apt/apt.conf

Acquire::http { Proxy "http://192.168.2.16:9999"; };
  1. apt-get update
  1. apt-get upgrade


- Generate locale perl: warning
  1. locale-gen en_US en_US.UTF-8 th_TH th_TH.UTF-8


- ติดตั้ง โปรแกรม
  1. apt-get install squid3
  1. apt-get install apache2


- join domain
  1. apt-get install krb5-user samba winbind


- แก้ไฟล์ krb5.conf
  1. nano /etc/krb5.conf

แทนที่ทั้งหมด
  1. [logging]
  2. default = FILE:/var/log/krb5.log
  3. [libdefaults]
  4. ticket_lifetime = 24000
  5. clock_skew = 300
  6. default_realm = SCI.COM
  7. krb4_config = /etc/krb.conf
  8. krb4_realms = /etc/krb.realms
  9. kdc_timesync = 1
  10. ccache_type = 4
  11. forwardable = true
  12. proxiable = true
  13. default_tgs_enctypes = aes256-cts arcfour-hmac-md5 des3-hmac-sha1 des-cbc-crc des-cbc-md5
  14. default_tkt_enctypes = aes256-cts arcfour-hmac-md5 des3-hmac-sha1 des-cbc-crc des-cbc-md5
  15. v4_instance_resolve = false
  16. v4_name_convert = {
  17. host = {
  18. rcmd = host
  19. ftp = ftp
  20. }
  21. plain = {
  22. something = something-else
  23. }
  24. }
  25. fcc-mit-ticketflags = true
  26. [realms]
  27. SCI.COM = {
  28. kdc = dc01.sci.com
  29. admin_server = dc01.sci.com
  30. default_domain = SCI.COM
  31. }
  32. [domain_realm]
  33. .sci.com = SCI.COM
  34. sci.com = SCI.COM
  35. [login]
  36. krb4_convert = true
  37. krb4_get_tickets = false
  38.  


- แก้ไฟล์ smb.conf
  1. nano /etc/samba/smb.conf

แทนที่ทั้งหมด
  1. [global]
  2. security = ads
  3. realm = SCI.COM
  4. password server = dc01.sci.com
  5. workgroup = SCI
  6. idmap uid = 10000-20000
  7. idmap gid = 10000-20000
  8. winbind enum users = yes
  9. winbind enum groups = yes
  10. template homedir = /home/%U
  11. template shell = /bin/bash
  12. client use spnego = yes
  13. client ntlmv2 auth = yes
  14. encrypt passwords = yes
  15. winbind use default domain = yes
  16. restrict anonymous = 2
  17. map acl inherit = yes
  18. nt acl support = yes
  19. disable spoolss = yes
  20. wins server = 192.168.0.253
  21.  


- join domain ด้วยคำสั่ง
  1. net rpc join ads SCI.COM -S dc01.sci.com -U Administrator

หรือ
  1. net ads join SCI.COM -S dc01.sci.com -U Administrator


- restart service
  1. /etc/init.d/smbd restart 
  1. /etc/init.d/winbind restart


- test kerberos
  1. kinit Administrator@SCI.COM  #domain ใช้ตัวพิมพ์ใหญ่
  2.     klist

ควรจะได้ผลลัพธ์ ประมาณนี้
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: Administrator@SCI.COM

Valid starting Expires Service principal
02/24/11 13:31:44 02/24/11 20:11:44 krbtgt/SCI.COM@SCI.COM


- get group get user
  1. wbinfo -u
#แสดงรายการ user ใน domain
  1. wbinfo -g
#แสดงรายการ group ใน domain

- get password get group AD
  1. getent passwd
#จะเห็นรายชื่อบน AD
  1. getent group
#จะเห็น group บน AD

- แก้ squid.conf
  1. nano /etc/squid/squid.conf

copy config บางส่วนที่ใช้ block มา จากเครื่องเดิม

แก้ squid บางส่วน
  1. acl localnet src 192.168.0.0/24 192.168.100.0/24
  2. http_access allow localnet
  3. http_port 8080
  4.  


ส่วนของ Authentication แก้เป็นดังนี้ ส่วนที่ต่างจาก Version เก่า คือสีแดง
  1. auth_param basic program /usr/lib/squid3/basic_ldap_auth -R -b "dc=sci,dc=com" -D "cn=ldap-user,cn=Users,dc=sci,dc=com" -w "password" -f "sAMAccountName=%s" -h 192.168.0.254
  2.     auth_param basic children 5
  3.     auth_param basic realm Squid proxy-caching web server
  4.     auth_param basic credentialsttl 5 minutes


  1. external_acl_type InetGroup %LOGIN /usr/lib/squid3/ext_wbinfo_group_acl
  2. acl InetAccess external InetGroup InetAllow
  3. http_access allow InetAccess

  1. acl webblocked url_regex '/etc/squid/webblocked.txt'
  2. acl day_am time 08:00-12:00
  3. acl day_pm time 13:00-17:40
  4. http_access deny webblocked day_am
  5. http_access deny webblocked day_pm


- copy พวกไฟล์ webblocked.txt จากเครื่องเดิมมา

- restart service
  1. /etc/init.d/squid restart


- test Authen ว่าผ่านหรือไม่
  1. echo "suwit_j InetAllow" | /usr/lib/squid/ext_wbinfo_group_acl -d

ต้องได้ผลลัพท์แบบนี้
Debugging mode ON.
Got suwit_j InetAllow from squid
User: -suwit_j-
Group: -InetAllow-
SID: -S-1-5-21-2702268678-3437982827-1986072043-3107-
GID: -10019-
Sending OK to squid
OK


- Test Set proxy on browser.

นำ Cache จากเครื่องเดิมมาใช้งานต่อ
- snap เครื่องเดิม เพื่อเอา disk cache ไปใส่เครื่องใหม่
- download file vmdk
จะได้ไฟล์ 2 ไฟล์ .vmdk และ flat.vmdk
- upload ขึ้น folder ที่ต้องการ
- add disk ใส่ VMware
- ดู disk dev อะไร
  1. fdisk -l

- สร้าง folder สำหรับ mount disk cache
  1. mkdir /cache

- mount disk ใส่ /cache
  1. mount /dev/sdb1 /cache

- mount auto
  1. nano /etc/fstab
  1. /dev/sdb1 /cache reiserfs notail,noatime 1 2


- แก้ squid.conf
  1. nano /etc/squid/squid.conf

เพิ่ม
  1. cache_dir ufs /cache 10240 32 512
  2. cache_mem 64 MB
  3.  
  4. #cache_effective_user proxy
  5. #cache_effective_group proxy
  6.  
  7. maximum_object_size 64 MB
  8. maximum_object_size_in_memory 64 KB
  9.  
  10. memory_replacement_policy heap LFUDA
  11. cache_replacement_policy heap LFUDA


-restar service
  1. /etc/init.d/squid restart


- gen reports แล้วดู lightsquid ที่มี hit ว่ามีการใช้งานหรือไม่ถ้ามี แสดงว่าใช้งานจาก cache
  1. /usr/local/lightsquid/lightparser.pl