수동 빌드 시 필요한 패키지 설치
dnf install -y gcc gcc-c++ perl autoconf automake make wget tar libtool-ltdl-devel libxml2-devel libcap-devel systemd-devel
squid proxy 6.12 버전 다운로드
wget https://github.com/squid-cache/squid/releases/download/SQUID_6_12/squid-6.12.tar.gz
압축해제
tar zxvf squid-6.12.tar.gz
squid proxy 빌드 설정
cd squid-6.12
./configure \
--prefix=/app \
--with-systemd \
--includedir=/app/squid/include \
--datadir=/app/squid/share \
--bindir=/app/squid/sbin \
--libexecdir=/app/squid/lib \
--localstatedir=/app/logs/squid \
--sysconfdir=/app/squid \
--enable-default-err-language=Korean \
--enable-err-language=Korean
- --prefix=/app
: 설치 경로를 /app으로 지정 - --with-systemd
: systemd 서비스 지원 활성화 - --includedir=/app/squid/include
: 헤더 파일 설치 경로 - --datadir=/app/squid/share
: 데이터 파일 설치 경로. - --bindir=/app/squid/sbin
: 실행 파일 설치 경로. - --libexecdir=/app/squid/lib
: 라이브러리 실행 파일 설치 경로. - --localstatedir=/app/logs/squid
: 로그 및 가변 데이터 저장 경로. - --sysconfdir=/app/squid
: 설정 파일 저장 경로. - --enable-default-err-language=Korean
: 기본 오류 메시지 언어를 한국어로 설정. - --enable-err-language=Korean
: 한국어 오류 메시지 지원 활성화.
컴파일 및 설치
make
make install
systemd 설정
vi /lib/systemd/system/squid.service
[Unit]
Description=Squid caching proxy
After=network.target network-online.target nss-lookup.target
[Service]
Type=notify
LimitNOFILE=16384
PIDFile=/app/logs/squid/run/squid.pid
EnvironmentFile=/etc/sysconfig/squid
ExecStartPre=/app/squid/lib/cache_swap.sh
ExecStart=/app/sbin/squid --foreground $SQUID_OPTS -f ${SQUID_CONF}
ExecReload=/usr/bin/kill -HUP $MAINPID
KillMode=mixed
NotifyAccess=all
[Install]
WantedBy=multi-user.target
[Unit]
- Description
: 서비스 설명 (Squid 캐싱 프록시) - After
: 네트워크 관련 서비스가 시작된 후 실행 (network.target, network-online.target, nss-lookup.target)
[Service]
- Type=notify
: 서비스가 systemd에 상태 알림 전송 - LimitNOFILE=16384
: 최대 열린 파일 수 제한 설정 - PIDFile=/app/logs/squid/run/squid.pid
: 프로세스 ID 파일 경로. - EnvironmentFile=/etc/sysconfig/squid
: 환경 변수 파일 로드. - ExecStartPre=/app/squid/lib/cache_swap.sh
: 서비스 시작 전 실행 스크립트 (캐시 스왑 초기화) - ExecStart
: Squid 실행 명령 (--foreground로 포그라운드 실행, $SQUID_OPTS로 옵션, -f ${SQUID_CONF}로 설정 파일 지정) - ExecReload
: 설정 재로드 (HUP 시그널로 재시작 없이 재로드) - KillMode=mixed
: 종료 시 메인 프로세스와 자식 프로세스 모두 종료 - NotifyAccess=all
: 모든 프로세스에서 systemd 알림 수신
[Install]:
- WantedBy=multi-user.target: 부팅 시 다중 사용자 모드에서 서비스 자동 시작
squid proxy 환경 변수 설정
vi /etc/sysconfig/squid
# default squid options
SQUID_OPTS=""
# Time to wait for Squid to shut down when asked. Should not be necessary
# most of the time.
SQUID_SHUTDOWN_TIMEOUT=200
# default squid conf file
SQUID_CONF="/app/squid/squid.conf"
캐시 디렉토리를 초기화 스크립트
vi /app/squid/lib/cache_swap.sh
#!/bin/bash
if [ -f /etc/sysconfig/squid ]; then
. /etc/sysconfig/squid
fi
SQUID_CONF=${SQUID_CONF:-"/app/squid/squid.conf"}
CACHE_SWAP=`sed -e 's/#.*//g' $SQUID_CONF | \
grep cache_dir | awk '{ print $3 }'`
for adir in $CACHE_SWAP; do
if [ ! -d $adir/00 ]; then
echo -n "init_cache_dir $adir... "
/app/sbin/squid -N -z -F -f $SQUID_CONF >> /app/logs/squid/squid.out 2>&1
fi
done
실행권한 부여
chmod +x /app/squid/lib/cache_swap.sh
설정파일 테스트
/app/sbin/squid -k parse -f /app/squid/squid.conf
squid proxy 실행
systemctl start squid
실행확인
공유 메모리 파일 에러 발생 시
FATAL: Ipc::Mem::Segment::create failed to shm_open(/squid-cf__metadata.shm): (17) File exists
해결 방법
공유 메모리 삭제 후 재실행
systemctl stop squid
rm -f /dev/shm/squid-*.shm
rm -f /app/logs/squid/run/squid.pid
systemctl start squid
'Server > Rocky Linux' 카테고리의 다른 글
[Proxy] Squid Proxy Health Check 설정 (1) | 2025.05.02 |
---|---|
[Proxy] Squid Proxy 설치 (Rocky 8.10) (0) | 2025.04.10 |
[Linux] 기본 환경구성 (Rocky 8.x, 9.x) (0) | 2025.03.28 |