ปลดล็อคคอขวดให้ Squid (squid 2.x centos 5)
มีโอกาสรับหน้าที่ดูแล server ชั่วคราวมาสักระยะ ก็ได้สังเกตเห็นว่า เอะทำเป็นเน็ตเราก็มีแบนวิทไม่ใช่น้อยๆ แต่ทำไมเวลาคนใช้เยอะแล้วมันอืดจัง (เกือบๆ ๒๐๐) ทั้งที่ทราฟฟิคถูกใช้ไปไม่ถึง 1 ใน 3 ด้วยซ้ำ เลยลองหาข้อมูลและมั่วๆ เอา ตอนนี้แก้ปัญหานั้นได้แล้ว เลยบันทึกกันลืมซะหน่อย …
แก้ไข Open File Limit ของ Squid
โดยการเพิ่มคำสั่ง ulimit -HSn xxxx บรรทัดแรกสุดหลังคอมเม้นในไฟล์ /etc/init.d/squid (xxxx คือจำนวนไฟล์ที่ให้ squid เปิดได้ ในที่นี้ ต้องใช้ ถึง 60000 เลยทีเดียว แต่ สำหรับทั่วไปใส่ 16384 น่าจะเพียงพอ)
คำสั่ง
nano /etc/init.d/squid
แล้วก็จัดการใส่ตามนี้ครับ
#!/bin/bash
# squid This shell script takes care of starting and stopping
# Squid Internet Object Cache
#
# chkconfig: – 90 25
# description: Squid – Internet Object Cache. Internet object caching is \
# a way to store requested Internet objects (i.e., data available \
# via the HTTP, FTP, and gopher protocols) on a system closer to the \
# requesting site than to the source. Web browsers can then use the \
# local Squid cache as a proxy HTTP server, reducing access time as \
# well as bandwidth consumption.
# pidfile: /var/run/squid.pid
# config: /etc/squid/squid.confulimit -HSn 16384
PATH=/usr/bin:/sbin:/bin:/usr/sbin
export PATH
# Source function library.
. /etc/rc.d/init.d/functions# Source networking configuration.
. /etc/sysconfig/network
เสร็จแล้วทำการบันทึก ctrl+o enter
ออกจากโปรแกรม nano ctrl+x
ทำในไฟล์ squid.conf ด้วยโดยใช้คำสั่ง
nano /etc/squid/squid.conf
หาบรรทัด max_filedesc xxxx แล้วทำการแก้ไขค่าให้เหมือนกับด้านบน ถ้าไม่มีบรรทัดนี้ก็ให้เพิ่ม แล้วบันทึก
ตัวอย่าง
max_filedesc 16384
แก้ไขอีกที่นำครับ
nano /etc/security/limits.conf
เพิ่ม * – nofile 16384 ลงไปท้ายไฟล์ แล้วทำการบันทึก
เมื่อทำทุกอย่างเสร็จแล้วก็ให้เริ่มระบบใหม่สักครั้ง
shutdown -r now
เป็นอันเสร็จ
ปล. ค่าสูงสุด 65536