Debian 11에서 Varnish 캐시를 설치하고 사용하는 방법
이 페이지에서
- 요구 사항\n
- Apache 웹 서버 설치 및 구성
- Varnish Server Debian 11 설치
- 니스 서버 구성
- Apache와 함께 작동하도록 Varnish 구성\n
- 니스 캐시 확인\n
- 결론
Varnish Cache는 강력한 오픈 소스이며 340만 개가 넘는 웹사이트에서 사용되는 가장 인기 있는 HTTP 가속기 중 하나입니다. 트래픽이 많은 동적 웹 사이트를 위해 특별히 설계된 리버스 캐싱 프록시로 사용할 수 있습니다. 웹 서버 앞에서 콘텐츠를 캐시하는 데 사용됩니다. 콘텐츠를 메모리에 캐싱하여 작동합니다. 사용자가 캐시된 페이지를 요청하면 Varnish는 백엔드 서버에서 동일한 페이지를 반복해서 요청하는 대신 캐시된 사본을 제공합니다. 많은 VPS 호스팅 공급자는 웹 사이트 성능을 향상시키기 위해 기술 스택의 일부로 사용합니다.
이 게시물은 Debian 11에서 Apache와 함께 Varnish Cache를 설치하는 방법을 보여줍니다.
요구 사항
- Debian 11을 실행하는 서버.\n
- 서버에 루트 암호가 구성되어 있습니다.\n
Apache 웹 서버 설치 및 구성
먼저 서버에 Apache 웹 서버를 설치해야 합니다. 다음 명령을 실행하여 설치할 수 있습니다.
apt install apache2 -y
Apache 웹 서버를 설치한 후 Apache 구성 파일을 편집하고 기본 포트를 다른 것으로 변경해야 합니다.
nano /etc/apache2/ports.conf
다음 줄을 찾으십시오.
Listen 80
그리고 다음 줄로 교체했습니다.
Listen 8080
완료되면 파일을 저장하고 닫습니다.
다음으로 Apache 기본 가상 호스트 구성 파일을 편집하고 기본 포트를 변경해야 합니다.
nano /etc/apache2/sites-available/000-default.conf
다음 줄을 찾으십시오.
<VirtualHost *:80>
그리고 다음 줄로 교체했습니다.
<VirtualHost *:8080>
파일을 저장하고 닫은 다음 Apache 서비스를 다시 시작하여 변경 사항을 적용합니다.
systemctl restart apache2
이제 다음 명령을 사용하여 Apache 수신 포트를 확인할 수 있습니다.
ss -antpl | grep apache2
다음 출력이 표시되어야 합니다.
LISTEN 0 511 *:8080 *:* users:(("apache2",pid=19315,fd=4),("apache2",pid=19314,fd=4),("apache2",pid=19313,fd=4),("apache2",pid=19312,fd=4),("apache2",pid=19311,fd=4),("apache2",pid=19310,fd=4))
바니시 서버 데비안 11 설치
기본적으로 최신 버전의 Varnish 캐시는 데비안 기본 리포지토리에서 사용할 수 없습니다. 따라서 APT에 Varnish 저장소를 추가해야 합니다.
먼저 다음 명령을 사용하여 필요한 종속 항목을 설치합니다.
apt install debian-archive-keyring curl gnupg apt-transport-https -y
그런 다음 다음 명령을 사용하여 Varnish GPG 키를 추가합니다.
curl -fsSL https://packagecloud.io/varnishcache/varnish70/gpgkey | gpg --dearmor -o /etc/apt/trusted.gpg.d/varnish.gpg
다음으로 Varnish 소스 파일을 만듭니다.
nano /etc/apt/sources.list.d/varnishcache_varnish70.list
다음 줄을 추가합니다.
deb https://packagecloud.io/varnishcache/varnish70/debian/ bullseye main deb-src https://packagecloud.io/varnishcache/varnish70/debian/ bullseye main
파일을 저장하고 닫은 후 다음 명령을 사용하여 리포지토리 캐시를 업데이트합니다.
apt update -y
다음으로 다음 명령을 사용하여 Varnish Cache를 설치합니다.
apt install varnish -y
Varnish Cache가 설치되면 다음 명령을 사용하여 Varnish 서버를 시작합니다.
systemctl restart varnish
다음 명령을 사용하여 Varnish 버전을 확인할 수도 있습니다.
varnishd -V
다음과 같은 결과가 표시됩니다.
varnishd (varnish-7.0.3 revision 6a4c6a5c7e66a664b140278c209f0b18c544cab8) Copyright (c) 2006 Verdens Gang AS Copyright (c) 2006-2022 Varnish Software
바니시 서버 구성
다음으로 default.vcl 파일을 편집하고 백엔드 서버를 정의해야 합니다.
nano /etc/varnish/default.vcl
백엔드 서버에 따라 다음 행을 변경하십시오.
backend default { .host = "127.0.0.1"; .port = "8080"; }
완료되면 파일을 저장하고 닫습니다.
Apache와 함께 작동하도록 Varnish 구성
다음으로 Varnish에 대한 사용자 지정 서비스 구성 파일을 만들어야 합니다. 다음 명령으로 만들 수 있습니다.
mkdir /etc/systemd/system/varnish.service.d
nano /etc/systemd/system/varnish.service.d/customport.conf
다음 줄을 추가합니다.
[Service] ExecStart= ExecStart=/usr/sbin/varnishd -a :80 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m
파일을 저장하고 닫은 후 다음 명령을 사용하여 systemd 데몬을 다시 로드합니다.
systemctl daemon-reload
그런 다음 다음 명령을 사용하여 Varnish 서비스를 다시 시작합니다.
systemctl restart varnish
이제 다음 명령을 사용하여 광택 캐시의 상태를 확인할 수 있습니다.
systemctl status varnish
다음 출력이 표시되어야 합니다.
? varnish.service - Varnish Cache, a high-performance HTTP accelerator Loaded: loaded (/lib/systemd/system/varnish.service; enabled; vendor preset: enabled) Drop-In: /etc/systemd/system/varnish.service.d ??customport.conf Active: active (running) since Fri 2022-12-30 05:31:51 UTC; 9s ago Process: 24637 ExecStart=/usr/sbin/varnishd -a :80 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m (> Main PID: 24638 (varnishd) Tasks: 217 Memory: 132.4M CPU: 535ms CGroup: /system.slice/varnish.service ??24638 /usr/sbin/varnishd -a :80 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m ??24652 /usr/sbin/varnishd -a :80 -a localhost:8443,PROXY -p feature=+http2 -f /etc/varnish/default.vcl -s malloc,256m Dec 30 05:31:50 debian11 systemd[1]: Starting Varnish Cache, a high-performance HTTP accelerator... Dec 30 05:31:51 debian11 varnishd[24638]: Version: varnish-7.0.3 revision 6a4c6a5c7e66a664b140278c209f0b18c544cab8 Dec 30 05:31:51 debian11 varnishd[24638]: Platform: Linux,5.10.0-20-amd64,x86_64,-junix,-smalloc,-sdefault,-hcritbit Dec 30 05:31:51 debian11 varnishd[24638]: Child (24652) Started Dec 30 05:31:51 debian11 varnishd[24638]: Child (24652) said Child starts Dec 30 05:31:51 debian11 systemd[1]: Started Varnish Cache, a high-performance HTTP accelerator.
이 시점에서 Varnish가 설치되고 포트 80에서 수신 대기합니다. 다음 명령으로 확인할 수 있습니다.
ss -antpl | grep :varnishd
다음과 같은 결과가 표시됩니다.
LISTEN 0 1024 0.0.0.0:80 0.0.0.0:* users:(("cache-main",pid=24652,fd=3),("varnishd",pid=24638,fd=3)) LISTEN 0 1024 127.0.0.1:8443 0.0.0.0:* users:(("cache-main",pid=24652,fd=7),("varnishd",pid=24638,fd=7)) LISTEN 0 10 127.0.0.1:39231 0.0.0.0:* users:(("varnishd",pid=24638,fd=11)) LISTEN 0 10 [::1]:36395 [::]:* users:(("varnishd",pid=24638,fd=10)) LISTEN 0 1024 [::]:80 [::]:* users:(("cache-main",pid=24652,fd=5),("varnishd",pid=24638,fd=5)) LISTEN 0 1024 [::1]:8443 [::]:* users:(("cache-main",pid=24652,fd=6),("varnishd",pid=24638,fd=6))
바니시 캐시 확인
이 시점에서 Varnish 캐시가 설치되어 실행 중입니다. 이제 CURL 명령을 사용하여 광택 캐시를 확인할 수 있습니다.
curl -I http://localhost/
다음 출력에서 바니시 캐시를 얻을 수 있습니다.
HTTP/1.1 200 OK Date: Fri, 30 Dec 2022 05:33:00 GMT Server: Apache/2.4.54 (Debian) Last-Modified: Fri, 30 Dec 2022 04:42:33 GMT Vary: Accept-Encoding Content-Type: text/html X-Varnish: 2 Age: 0 Via: 1.1 varnish (Varnish/7.0) ETag: W/"29cd-5f1043adffc4c-gzip" Accept-Ranges: bytes Connection: keep-alive
결론
축하합니다! Debian 11에서 Apache와 함께 Varnish Cache를 성공적으로 설치했습니다. 이제 Varnish 캐시를 프런트 엔드 서버로 사용하여 웹 사이트 로드 시간을 단축할 수 있습니다. 궁금한 점이 있으면 언제든지 문의해 주세요.