#cd /usr/ports/www/squid30
#make config

โดยทำการเลือก SQUID_DELAY_POOLS, SQUID_SNMP,SQUID_SSL,
SQUID_DNS_HELPER,SQUID_VIA_DB,SQUID_WCCP,SQUID_WCCPV2,
SQUID_IDENT,SQUID_ARP_ACL,SQUID_IPFW,SQUID_PF,SQUID_IPFILTER,
SQUID_AUFS,SQUID_KQUEUE,SQUID_LARGEFILE
หลังจากนั้นก็ #make install clean
รอสักพัก จนกระทั่งติดตั้งเสร็จ

หลังจากนี้ ให้เข้าไปแก้ไฟล์ ที่อยู่ที่ /usr/local/etc/squid/squid.conf ให้ได้ตามนี้

#define by Aekarat Joolawan
acl mac arp "/usr/local/etc/squid/macaddress.txt"
acl ipnet src "/usr/local/etc/squid/ipnet.txt"
acl hostname srcdomain SERMSUK.SANDENINTERCOOL.COM PHUSIT.SANDENINTERCOOL.COM
acl EEI_ports port 8081
acl https port 4331
acl msn port 1863
acl mms port 7070
acl rudp port 154
acl shoutcase port 8000
acl proxy port 8080
acl white_url url_regex -i "/usr/local/etc/squid/white_url.txt"
acl black_url url_regex -i "/usr/local/etc/squid/black_url.txt"

acl all src 0.0.0.0/0.0.0.0

#Recommended minimum configuration:
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl to_localhost dst 127.0.0.0/8
acl SSL_ports port 443 563
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 70 # gopher
acl Safe_ports port 210 # wais
acl Safe_ports port 1025-65535 # unregistered ports
acl Safe_ports port 280 # http-mgmt
acl Safe_ports port 488 # gss-http
acl Safe_ports port 591 # filemaker
acl Safe_ports port 777 # multiling http
acl CONNECT method CONNECT
acl QUERY urlpath_regex cgi-bin \?

# Squid normally listens to port 3128
http_port 8080

#Need for transparent proxy
httpd_accel_host virtual
httpd_accel_port 80
httpd_accel_with_proxy on
httpd_accel_uses_host_header on
#We recommend you to use the following two lines.
acl apache rep_header Server ^Apache
acl list url_regex -i \.mp3$ \.wma$

#Allow policy by Aekarat
http_access allow EEI_ports
http_access allow https
http_access allow msn
http_access allow mms
http_access allow rudp
http_access allow list
http_access allow proxy
http_access allow white_url
#http_access deny black_url
http_access allow mac
http_access allow ipnet
http_access allow hostname
http_access deny CONNECT !SSL_ports
http_access deny !Safe_ports
http_access deny all

icp_access allow localhost
icp_access allow mac
icp_access allow ipnet
icp_access allow hostname
icp_access deny all

# Avoid caching cgi scripts
acl QUERY urlpath_regex cgi-gin
cache deny QUERY

acl magic_word1 url_regex -i 192.168
acl magic_word2 url_regex -i ftp .exe .mp3 .vqf .tar.gz .gz .rpm .zip .rar .avi .mpeg .mpe .qt .ram .rm .iso .raw .wav .mov .wma

delay_pools 2
delay_class 1 2
delay_parameters 1 256000/256000 5000/256000
delay_access 1 allow magic_words2
delay_access 1 allow mac
delay_access 1 allow ipnet
delay_access 1 allow hostname

delay_class 2 2
delay_parameters 2 -1/-1 -1/-1
delay_access 2 allow magic_words1

# Cancel download if file is bigger than 2MB
reply_body_max_size 2048 KB

acl snmppublic snmp_community public
snmp_access allow snmppublic localhost
snmp_access deny all
cache_mem 600 MB

memory_replacement_policy heap GDSF

cache_replacement_policy heap GDSF

cache_dir diskd /usr/local/squid/cache 15360 16 256 Q1=72 Q2=64
cache_dir ufs /usr/local/squid/cache 15360 16 256
access_log /usr/local/squid/logs/access.log squid

cache_access_log /usr/local/squid/logs/access.log
cache_log /usr/local/squid/logs/cache.log
cache_store_log /usr/local/squid/logs/store.log

ต่อไป เป็นการสร้าง cache

# chown –R nobody:nogroup /usr/local/squid/cache
# chmod –R 777 /usr/local/squid/cache
# cd /usr/local/squid/logs
# touch access.log cache.log store.log
# chmod 777 *
# cd /usr/local/sbin
# ./squid –z


ต่อ ไปทำการสั่ง squid ทำงาน โดยพิมพ์คำสั่ง /usr/local/sbin/RunCache & จะพบข้อความ Running: squid –sY >> /usr/local/squid.out 2>&1 แล้วกด Ctr+C เพื่อออก แล้วเพิ่มคำสั่ง /usr/local/sbin/RunCache & ลงในไฟล์ /etc/rc.local เพื่อให้ squid ทำงานโดยอัตโนมัติ

แสดง การใส่คำสั่ง เพื่อให้รันอัตโนมัติ ทุกครั้งที่ เปิดเครื่อง
ทำการแก้ไขไฟล์ /etc/rc.conf โดยใส่ ค่าพวกนี้ไป ท้ายไฟล์

#add these lines to enable ipfilter
ipfilter_enable="YES"
ipnat_enable="YES"
ipmon_enable="YES"
ipfs_enable="YES"
ทำการแก้ไขไฟล์ /etc/ipnat.rules โดยใส่ ค่าพวกนี้ไป ท้ายไฟล์
#add this line
#I assume rl0 is your internal nic
#Redirect everything else to squid on port 8080
rdr rl0 0/0 port 80 -> 127.0.0.1 port 8080 tcp

หลังจากนั้น ให้ทำการ complie kernel ใหม่ โดยใส่ค่าเหล่านี้เข้าไป

options SYSVMSG
options MSGMNB=8192 #max # of bytes in queue
options MSGMNI=40 # number of message queue identifiers
options MSGSEG=512 #number of message segments per queue
options MSGSSZ=64 #size of a message segment
options MSGTQL=2048 #max messages in system
หลังจากทำการ complie เสร็จ ให้ทำการ restart


การตั้งเวลาสำหรับเคลียร์ log และ cache ของ Proxy
ใน การใช้งาน squid ไประยะหนึ่งจะมีการเก็บ cache มากขึ้น และ log ไฟล์ (access.log, cachelog, store.log) จะมีขนาดใหญ่ขึ้นอาจจะเต็มได้ ซึ่งก็จะทำให้ squid ของเราหยุดให้บริการได้ จำเป็นต้องมีการ เคลียร์ log ไฟล์ และ cache เต็ม มีวิธีการจัดการดังนี้

# killall squid
# cd /usr/local/squid/cache
# rm –rf *
# cd /usr/local/squid/logs
# rm –rf access.log cache.log store.log
# touch access.log cache.log store.log
# chmod 777 access.log cache.log store.log
# /usr/local/sbin/squid –z
#/usr/local/sbin/RunCache &


ถ้าต้องการตั้งเวลาให้ทำงานตามคำสั่งเหล่านี้โดยอัตโนมัติ ต้องมีการเขียน Script และให้ทำงานตามเวลาที่กำหนดด้วยดังนี้
# cd /root
# pico clcache.sh
พิมพ์คำสั่ง ดังนี้
#!/bin/sh
Killall squid
cd /usr/local/squid/cache
rm –rf *
cd /usr/local/squid/logs
rm –rf access.log cache.log store.log
touch access.log cache.log store.log
chmod 777 access.log cache.log store.log
/usr/local/sbin/squid –z
/usr/local/sbin/RunCache &

เสร็จ ก็ทำการ save จากนั้นใช้คำสั่ง
# chmod 700 clcache.sh
ต่อ ไปก็ตั้งเวลาให้ทำงานตามเวลาที่เรากำหนด โดยใช้ความสามารถของ crontab เข้ามาช่วย โดยกำหนดให้มีการรัน Script นี้ ทุกวันที่ 1 ของทุกเดือน เวลา 0.00 น.

# pico /etc/crontab เพิ่มบรรทัดต่อไปนี้ลงในท้ายไฟล์ โดยกดปุ่ม Shift +g
0 0 1 * * root /root/clcahe.sh
เสร็จ แล้วก็ save แล้วเพื่อให้ crontab ทำงาน เราต้องเพิ่มบรรทัด cron_enable= “YES” ลงในไฟล์ /etc/rc.conf ด้วย เสร็จแล้วก็ reboot ด้วยคำสั่ง shutdown –r now

ที่มา http://citec.us/forum/index.php?showtopic=24259&hl=

0 comments



Recommended Money Makers