티스토리 뷰

LAYER 4 & 7

squid 설치 및 셋팅

CHOMAN 2015. 6. 11. 17:53

스퀴드의 특징들

 

마이크로소프트를 지원하지만 Unix 환경을 추천함 (FreeBSD를 추천한다고 많이들 함)

RPM 버젼보다는 바이러니로 컴파일 하는것을 추천 (자기가 쓰고 싶은 기능을 추가가능함)

가능하면 높은사양으로 마추는것이 성능향상에 좋음
1. 메모리 (RAM)는 많을수록 좋음 (퍼포먼스 향상)
2. 많은 보조기억장치 (HDD)는 클수록 더 많은 자원이 할당되며 캐쉬 적중률도 높아지게 됨
3. 빠른 HDD 인터페이스와 CPU (부가사항)
squid 서버 구성시 고려사항
디스크 랜덤 검색 시간
메모리의 양
디스크 처리 양
프로세스의 성능

 

 

squid 대표적 기능

Web caching

 

미리 사용되어질 DATA들을 미리 squid가 저장하고 있다가 클라이언트에게 제공하는것
클라이언트가 모뎀이거나 대역폭이 좁은 경우 사용하면 좋다고 하는데 요즘시대엔 아닌듯?
squid는 data가 오래된것인지 새로운것인지 last-modified timestamp 라는걸 이용한다고 함 (타임스탬프)

 

 

squid 로 서비스 불가능한 프로토콜들... (버젼 2.5대)

 

SMTP
instant messaging
Internet Relay chat (IRC)

 

 

 

스퀴드 설치전 점검해볼 사항

 

file descriptor

 

[root@localhost ~]# ulimit -n
1024


- 아마 한 shell 유저나 프로세스가 열수있는 최대 파일의 갯수 일거다.

아래와 같이 한다 아마 65535가 최대치일듯? (적당하게 해주던가? 알아서 한다)

[일시적인 방법]  : 리부팅하면 원복됨

[root@localhost ~]# ulimit -n 65535

[root@localhost ~]# ulimit -Sn
2048

 

[root@localhost ~]# ulimit -Hn
2048 


 

리부팅시에도 유지하게끔 하자

 

vim /etc/security/limits.conf 열어서 아래열 추가

* - nofile 65535


리부팅하고 난뒤

 

[root@localhost bin]# /usr/local/squid/bin/squidclient -p80 mgr:info | grep 'file descri'
Maximum number of file descriptors: 65535
Available number of file descriptors: 65526
Reserved number of file descriptors: 100

정상적(?) 으로 된듯 하다? ㅋ

[root@localhost tools]# ulimit
unlimited

Ephemeral Port Range 수정

- 이건 squid 서버가 원본서버와의 만들수 있는 소켓 커넥션수 의 옵션조정인듯 함 (프록시에서 나가는 TCP/IP 스택? 범위?)

보통의 디폴트 값은 아래인데 약 3만개정도 인듯함.

[root@localhost ~]# sysctl -a | grep local
net.ipv4.ip_local_port_range = 32768 61000

 

[root@localhost ~]# cat /proc/sys/net/ipv4/ip_local_port_range
32768 61000

 

1024 부터 65000 까지하면 약 6만개정도 쓸수 있는듯?
net.ipv4.ip_local_port_range = 1024 65000

 

ulimit -a 명령어를 하면 아래 정보 확인 가능

 

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 38912
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 65535
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200                               
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 38912
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited





스퀴드 다운받기

wget http://www.squid-cache.org/Versions/v3/3.1/squid-3.1.4.tar.gz


rpm squid 삭제
rpm -e --force squid


squid 그룹 및 사용자 추가

 

groupadd -g 3128 squid
adduser -u 3128 -g squid -d /home/squid squid

 


squid 로그 및 캐쉬 디렉토리 생성

 

mkdir /home/squid/logs
mkdir /home/squid/cache



컴파일 옵션
./configure --prefix=/usr/local/squid --sysconfdir=/etc/squid --localstatedir=/home/squid --disable-ident --disable-ident-lookups --enable-x-accelerator-vary --enable-follow-x-forwarded-for --enable-useragent-log --enable-referer-log --enable-ssl --with-openssl{=/usr/lib/openssl/engines} --enable-linux-netfilter --enable-ipf-transparent --enable-storeio=ufs,aufs --with-maxfd=65536

./configure --prefix=/usr/local/squid --sysconfdir=/etc/squid --localstatedir=/home/squid --disable-ident --disable-ident-lookups --enable-x-accelerator-vary --enable-follow-x-forwarded-for --enable-useragent-log --enable-referer-log --enable-ssl --with-openssl --enable-storeio=ufs,aufs --with-maxfd=65536

make
make install

 

chmod 755 /etc/init.d/squid
chkconfig --add squid
chkconfig --level 2345 squid on
chown -R squid:squid /home/squid
/usr/local/squid/sbin/squid -z

 

 

squid 권한 설정

 

chown root:root /usr/local/squid
chmod 755 /usr/local/squid

cd /usr/local/squid/bin
chown root:root .
chown root:root *
chmod 755 .*
 
chown root:squid /usr/local/squid/etc
cd /usr/local/squid/etc
chmod 2775 .
chmod 775 *
chown root:squid .*

chown squid:squid /usr/local/squid/logs
chmod 770 /usr/local/squid/logs


mkdir /gome/squid/cache
chown squid:squid /home/squid/cache
chmod 700 /home/squid/cache

groupadd nogroup

 

 

squid 컴파일 옵션

 

--enable-err-language=Korean (squid error 시 한글메세지 출력)    

 


스퀴드 완전 삭제

 

/etc/init.d/squid stop
killall squid
rm -fr /etc/squid
rm -fr /usr/local/squid                       
userdel -r squid
groupdel squid

 

 

/etc/squid/squid.conf : squid 설정파일


vim /etc/hosts
- 고객 IP 고객도메인 명시해준다.

co.kr 및 com 주 도메인과 서브도메인들은 같은 그룹에 묶을것
- 묶어서 사용할것 뒤죽박죽 되면 찾기도 힘들뿐 아니라

 

1x5.xx.4.1x1 kensei.co.kr www.kensei.co.kr dica.kensei.co.kr kensei.com www.kensei.com dica.kense.com

 

 

vim /etc/crontab

 

*/20 * * * * root /etc/cron.20m
01 * * * * root cat /dev/null > /home/squid/logs/access.log
01 * * * * root cat /dev/null > /home/squid/logs/store.log

 

 

/etc/cron.20m/squid_restart.sh

 

/etc/init.d/squid new
sleep 5
/etc/init.d/squid start

 

 

vim /etc/squid.conf

 

 http_port 80 transparent

or

http_port 80 accel vhost
cache_peer xxx.xxx.xxx.42 parent 80 0

 

vim /etc/hosts
xxx.xxx.xxx.42 xx.co.kr (도메인 명시)

# 쿼리 리스트(단어)를 캐쉬서버에 저장하지 않는다.
acl QUERY urlpath_regex cgi-bin \? php php3 htm html jsp js css asp aspx swf jpg gif


vim /etc/sysctl - 아래열 추가

 

net.netfilter.nf_conntrack_tcp_timeout_established = 3600

net.ipv4.conf.lo.arp_ignore = 1
net.ipv4.conf.lo.arp_announce = 2
net.ipv4.conf.all.arp_ignore = 1
net.ipv4.conf.all.arp_announce = 2

# squid
fs.file-max = 65535
net.core.rmem_default = 262144
net.core.rmem_max = 262144
net.core.wmem_default = 262144
net.core.wmem_max = 262144
net.ipv4.tcp_rmem = 4096 87380 8388608
net.ipv4.tcp_wmem = 4096 65536 8388608
net.ipv4.tcp_mem = 4096 4096 4096
net.ipv4.tcp_low_latency = 1
net.core.netdev_max_backlog = 4000
net.ipv4.ip_local_port_range = 1024 65000
net.ipv4.tcp_max_syn_backlog = 16384

- sysctl -p (적용)

[보안설정]

 

acl localhost src 127.0.0.1/255.255.255.255
acl src_localhost src 127.0.0.0/24 116.125.30.202 (소스아이피)
acl to_localhost dst 127.0.0.0/24 116.125.30.202 (목적지아이피)

http_access allow localhost

http_access allow src_localhost

http_access deny !to_localhost
http_access allow all

 

 - 허용된 아이피를 제외하고는 프록시를 타고 나갈수 없음


보안설정
acl BLOCK_URI urlpath_regex -i \.exe \.\.\/ \.\.\. \.\. \.ida \.IDA \.cnf \.dll passwd boot \.exe cmd \.\./ default\.ida XXXXXX \/bin\/sh
acl all src 0.0.0.0/0.0.0.0
acl manager proto cache_object
acl localhost src 127.0.0.1/255.255.255.255
acl src_localhost src 127.0.0.0/24 211.110.10.101 : 소스아이피가 10.101만 허용
acl to_localhost dst 127.0.0.0/24 116.125.30.202 : 목적지 아이피가 30.202를 제외하곤 거절
acl to_localhost dst 127.0.0.0/8
http_access deny !src_localhost # src_localhost 에 명시된 소스 아이피가 아니면 거절하겠다
#http_access deny !to_localhost # dst_localhost 에 명시된 목적지 아이피가 아니면 거절하겠다
acl SSL_ports port 443
acl Safe_ports port 80 # http
acl Safe_ports port 21 # ftp
acl Safe_ports port 443 # https
acl Safe_ports port 1025-65535 # unregistered ports
acl CONNECT method CONNECT


error)

error) squid.conf 에 cache_effective_user squid 구문 추가해준다...

 

/var/log/message


May 20 09:28:46 localhost (squid): Cannot open '/home/squid/logs/access.log' for writing.#012#011The parent directory must be writeable by the#012#011user 'nobody', which is the cache_effective_user#012#011set in squid.conf.

/logs/squid.out
FATAL: Cannot open '/home/squid/logs/access.log' for writing.
The parent directory must be writeable by the
user 'nobody', which is the cache_effective_user
set in squid.conf.

 

localhost squid: Could not determine fully qualified hostname. Please set 'visible_hostname'

Squid Cache (Version 3.1.3): Terminated abnormally.
CPU Usage: 0.008 seconds = 0.004 user + 0.004 sys
Maximum Resident Size: 0 KB
Page faults with physical i/o: 0
2010/05/20 15:26:56| WARNING: -D command-line option is obsolete.
FATAL: Could not determine fully qualified hostname. Please set 'visible_hostname'

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/02   »
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28
글 보관함