.png)
웹 캐시 서버 nuster 입문 -1 (기본)
2022-10-05 last update
6 minutes reading 우분투 CentOS 리눅스 도커 infrastructurenuster란?
Nuster는 HAProxy를 바탕으로 개발한 캐시 서버로 HAProxy와 호환성이 있다.
그리고 HAProxy의 ACL을 이용하여 세세한 캐시 규칙을 정의할 수 있다.
사양이 변경될 수 있으므로 최신 버전은 https://github.com/jiangwenyuan/nuster/blob/master/README.md를 참조하십시오.
홈페이지
htps : // 기주 b. 코 m/지안구에니안/누s테 r
특징
메커니즘
TCP/HTTP 로드 밸런서 및 캐시 서버에서 사용 가능
client - nuster(http/https load balancer, cache server) - App [- nuster(tcp load balancer)] - DB
설정
설치
make TARGET=linux2628 USE_LUA=1 LUA_INC=/usr/include/lua5.3 USE_OPENSSL=1 USE_PCRE=1 USE_ZLIB=1
make install PREFIX=/usr/local/nuster/bin
lua, ssl, zlib 필요하지 않은 경우 매개 변수에서 제거
TARGET: linux2628, linux26, linux24, linux24e, linux22, solaris, freebsd, openbsd, cygwin, custom, generic
도커
docker pull nuster/nuster
docker run -d -v /path/to/nuster.cfg:/etc/nuster/nuster.cfg:ro -p 8080:8080 nuster/nuster
구성
최소한의 파일
global
nuster cache on
daemon
nbproc 2
defaults
retries 3
option redispatch
option dontlognull
timeout client 300s
timeout connect 300s
timeout server 300s
frontend web1
bind *:8080
mode http
default_backend app1
backend app1
balance roundrobin
mode http
nuster cache
nuster-rule all ttl 0
server s1 10.0.0.101:8080
server s2 10.0.0.102:8080
server s3 10.0.0.103:8080
섹션
make TARGET=linux2628 USE_LUA=1 LUA_INC=/usr/include/lua5.3 USE_OPENSSL=1 USE_PCRE=1 USE_ZLIB=1
make install PREFIX=/usr/local/nuster/bin
docker pull nuster/nuster
docker run -d -v /path/to/nuster.cfg:/etc/nuster/nuster.cfg:ro -p 8080:8080 nuster/nuster
global
nuster cache on
daemon
nbproc 2
defaults
retries 3
option redispatch
option dontlognull
timeout client 300s
timeout connect 300s
timeout server 300s
frontend web1
bind *:8080
mode http
default_backend app1
backend app1
balance roundrobin
mode http
nuster cache
nuster-rule all ttl 0
server s1 10.0.0.101:8080
server s2 10.0.0.102:8080
server s3 10.0.0.103:8080
자세한 내용은 HAProxy configuration
캐시로 기본 설정
nuster cache on
설정 nuster cache on
및 nuster-rule
설정 자세한 내용은 htps : // 기주 b. 코 m/지안구에니앙/누s테 r/bぉb/마s테 r/레아 D메. md#ぢれc치ゔぇs
시작
/usr/local/nuster/bin/haproxy -f nuster.conf
예
구성 발췌에서
tcp load balancer로
frontend mysql-lb
bind *:3306
mode tcp
default_backend mysql-cluster
backend mysql-cluster
balance roundrobin
mode tcp
server s1 10.0.0.101:3306
server s2 10.0.0.102:3306
server s3 10.0.0.103:3306
http load balancer로
frontend web-lb
bind *:80
mode http
default_backend apps
backend apps
balance roundrobin
mode http
server s1 10.0.0.101:8080
server s2 10.0.0.102:8080
server s3 10.0.0.103:8080
https
frontend web
bind *:8080 ssl crt XXX.pem # HTTPSリクエストを受ける
# bind *:8080
mode http
default_backend app
backend app
balance roundrobin
nuster cache off
nuster-rule all
mode http
#server a1 10.0.0.101:8002 # HTTPでbackendと通信
server a2 10.0.0.101:8003 ssl verify none # HTTPSでbackendと通信
클라이언트, 백엔드 서버 모두 HTTPS 가능
user == https ==> nuster == https ==> backend
user == https ==> nuster == http ==> backend
user == http ==> nuster == https ==> backend
user == http ==> nuster == http ==> backend
POST 캐싱
frontend web1
bind *:8080
mode http
use_backend app1a if { path /search }
default_backend app1b
backend app1a
balance roundrobin
mode http
option http-buffer-request
nuster cache
# /searchの結果を60秒間キャッシングする
nuster-rule rpost ttl 60 if METH_POST
backend app1b
#***
캐싱 예
cache /a.jpg, expire 안함
nuster-rule r1 ttl 0 if { path /a.jpg }
static 파일을 cache
acl static path_beg -i /static/ /images/ /css/
nuster-rule static_files ttl 0 if static
사용자별로 /mypage를 cache: key에 sessionId 넣기
acl pathB path /mypage
nuster-rule r2 key method.scheme.host.path.delimiter.query.cookie_sessionId ttl 60 if pathB
요청이 /a.html이고 응답에 cache header가 있으면 /a.html을 cache
http-request set-var(txn.pathC) path
acl pathC var(txn.pathC) -m str /a.html
acl resHdrCache1 res.hdr(cache) yes
nuster-rule r3 if pathC resHdrCache1
connection이 100을 초과하면 /heavy를 100초 cache
acl heavypage path /heavy
acl tooFast be_conn ge 100
nuster-rule heavy ttl 100 if heavypage tooFast
cache 전에 response에 header를 넣어
http-response set-header X-ASDF fdsa
cache 전에 압축
backend app
filter compression
compression algo gzip
compression type text/html text/plain text/css text/javascript
nuster cache
nuster-rule all
캐시 삭제
웹 캐시 서버 nuster 입문-2(Purge)에서 소개
frontend mysql-lb
bind *:3306
mode tcp
default_backend mysql-cluster
backend mysql-cluster
balance roundrobin
mode tcp
server s1 10.0.0.101:3306
server s2 10.0.0.102:3306
server s3 10.0.0.103:3306
frontend web-lb
bind *:80
mode http
default_backend apps
backend apps
balance roundrobin
mode http
server s1 10.0.0.101:8080
server s2 10.0.0.102:8080
server s3 10.0.0.103:8080
frontend web
bind *:8080 ssl crt XXX.pem # HTTPSリクエストを受ける
# bind *:8080
mode http
default_backend app
backend app
balance roundrobin
nuster cache off
nuster-rule all
mode http
#server a1 10.0.0.101:8002 # HTTPでbackendと通信
server a2 10.0.0.101:8003 ssl verify none # HTTPSでbackendと通信
user == https ==> nuster == https ==> backend
user == https ==> nuster == http ==> backend
user == http ==> nuster == https ==> backend
user == http ==> nuster == http ==> backend
frontend web1
bind *:8080
mode http
use_backend app1a if { path /search }
default_backend app1b
backend app1a
balance roundrobin
mode http
option http-buffer-request
nuster cache
# /searchの結果を60秒間キャッシングする
nuster-rule rpost ttl 60 if METH_POST
backend app1b
#***
nuster-rule r1 ttl 0 if { path /a.jpg }
acl static path_beg -i /static/ /images/ /css/
nuster-rule static_files ttl 0 if static
acl pathB path /mypage
nuster-rule r2 key method.scheme.host.path.delimiter.query.cookie_sessionId ttl 60 if pathB
http-request set-var(txn.pathC) path
acl pathC var(txn.pathC) -m str /a.html
acl resHdrCache1 res.hdr(cache) yes
nuster-rule r3 if pathC resHdrCache1
acl heavypage path /heavy
acl tooFast be_conn ge 100
nuster-rule heavy ttl 100 if heavypage tooFast
http-response set-header X-ASDF fdsa
backend app
filter compression
compression algo gzip
compression type text/html text/plain text/css text/javascript
nuster cache
nuster-rule all
웹 캐시 서버 nuster 입문-2(Purge)에서 소개