nginx_upstream_check_module 설치

hongo·2023년 9월 10일
0

Nginx upstream 서버 헬스체크 모니터링을 위해 nginx_upstream_check_module을 설치해보자.

모듈 github clone

Nginx pro라면, 디폴트로 upstream_check_module을 사용할 수 있지만, 커뮤니티 버전은 직접 깃허브에서 upstream_check_module을 클론해와야한다.

https://github.com/yaoweibin/nginx_upstream_check_module 에 접속해 git clone을 해오자.

Nginx 다운로드

clone해온 모듈을 Nginx에 patch한 뒤, 컴파일을 해줘야한다.

sudo apt install nginx를 하면 모듈을 patch할 수 없기에 직접 nginx 압축 파일을 설치해주자.

wget 'http://nginx.org/download/nginx-1.20.10.tar.gz'

1.20.10버전외에, 1.11.1, 1.16.1 버전 설치를 시도해봤지만, 잘 되지 않았다! 1.11.1은 특정 헤더가 삭제된 것 같고... 1.16.1은 patch까진 잘 되지만 막상 Nginx를 실행하니 upstream 모듈이 잘 적용되지 않았다. ㅠㅠ

1.20.10버전은... 해보니까 잘 되더라...ㅎ

Nginx 파일을 깔았다면, 압축을 해제하고, upstream모듈을 patch한다.

tar -xzvf nginx-1.0.14.tar.gz
cd nginx-1.0.14/
patch -p1 < /{path}/nginx_upstream_check_module/check_1.20.1+.patch

nginx-1.20.10과 호환되는 버전인 check_1.20.1+.patch를 patch해준다. check_1.20.1+.patch외에도 여러 버전의 check.patch파일이 있으니 자신의 nginx와 맞는 버전의 파일을 patch해주자.

patch가 잘 되었다면, nginx에 설치한 upstream모듈을 add해주자.

sudo apt install gcc
sudo apt-get install libpcre3-dev
sudo apt-get install zlib1g-dev

./configure --add-module=/{path}/nginx_upstream_check_module

Nginx 컴파일

모듈을 잘 적용해주었으니 nginx를 컴파일 해준다.

sudo apt install make

make
make install

make install까지 해주면 /usr/local/에 nginx폴더가 생성된다.

/usr/local/nginx/sbin에 들어와 ./nginx -V명령어를 쳤을 때 아래와 같이 나오면 upstream모듈이 잘 적용된 것이다.

$./nginx -V
nginx version: nginx/1.16.1
configure arguments: --add-module=../nginx_http_upstream_check_module

Nginx설정 파일에서 upstream check 설정 추가

이제 nginx.conf파일에서 upstream check 설정을 추가해준다.

upstream cluster {
    server 1.1.1.1:8080;
    server 1.1.1.2:8080;

    check interval=3000 rise=2 fall=5 timeout=4000 type=http;
    check_http_send "HEAD / HTTP/1.0\r\n\r\n"; # 헬스체크 요청 방법
    check_http_expect_alive http_2xx http_3xx; # 헬스체크 up 판단 기준
}

위와 같이 설정을 추가할 수 있다.

  • check interval : ms마다 헬스 체크 수행
  • rise : 헬스 체크 n번 이상 rise이면 up인 상태로 간주
  • fall : 헬스 체크 n번 이상 fall이면 down인 상태로 간주
  • timeout : request의 timeout 제한 ms
  • type : 헬스 체크 프로토콜 타입

자세한 설명은 https://github.com/yaoweibin/nginx_upstream_check_module에서 확인하자.

Nginx 실행

/usr/local/nginx/sbin/nginx를 쳐서 Nginx를 실행할 수 있다.

-s 옵션으로 reload와 stop도 가능하다.

/usr/local/nginx/sbin/nginx -s reload
/usr/local/nginx/sbin/nginx -s stop

2개의 댓글

comment-user-thumbnail
2023년 9월 10일

오 엔진엑스 전문가이신가봐요

1개의 답글