반응형
    
    
    
  Nginx 가상 호스트 트래픽 상태 모듈을 통한 Nginx 모니터링(nginx-module-vts 모듈 추가)
nginx-module-vts는 서버 상태 및 성능 통계를 제공하는 Nginx 모듈입니다.
APT 저장소 설정
sudo sed -Ei 's/(archive|security)\.ubuntu\.com/mirror.kakao.com/g' /etc/apt/sources.list
sudo apt-get update
필요한 패키지 설치
sudo apt-get install -y build-essential libpcre3 libpcre3-dev zlib1g zlib1g-dev libssl-dev
sudo apt-get install -y gcc git wget vim
우분투에서 NGINX 1.24 버전을 설치하는 방법
필수 구성 요소 설치
sudo apt-get install -y curl gnupg2 ca-certificates lsb-release ubuntu-keyring
apt가 패키지의 신뢰성을 확인할 수 있도록 공식 nginx 서명 키를 가져오기
curl -fsSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor \
    | sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null
다운로드한 파일에 올바른 키가 포함되어 있는지 확인
gpg --dry-run --quiet --no-keyring --import --import-options import-show /usr/share/keyrings/nginx-archive-keyring.gpg
안정적인 nginx 패키지를 위한 적절한 리포지토리를 설정
echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
http://nginx.org/packages/ubuntu `lsb_release -cs` nginx" \
    | sudo tee /etc/apt/sources.list.d/nginx.list
sudo apt-get update
Nginx 설치
sudo apt-get install nginx
Nginx 버전 정보
nginx -v
$ nginx -v
nginx version: nginx/1.24.0
더보기
---
Nginx 1.22 설치
sudo apt-get install nginx=1.22.*
Nginx 버전 정보
nginx -v
$ nginx -v
nginx version: nginx/1.22.1
---
nginx-module-vts 모듈 다운로드
mkdir -p /usr/local/src/nginx-build
cd /usr/local/src/nginx-build
git clone https://github.com/vozlt/nginx-module-vts.git
Nginx 소스 코드 다운로드
wget https://nginx.org/download/nginx-1.24.0.tar.gz
tar -xzf nginx-1.24.0.tar.gz
cd nginx-1.24.0
./configure --with-compat --add-dynamic-module=../nginx-module-vts
make modules
더보기
---
Nginx에 nginx-module-vts를 추가하여 빌드
- 패키지 매니저로 설치한 Nginx의 경우에는 nginx -V 명령을 사용하여 현재 사용된 옵션을 확인하고, 그 옵션에 --add-dynamic-module=/path/to/nginx-module-vts를 추가합니다.
 
현재 사용된 옵션 확인
nginx -V
Configure 스크립트 수정
- Nginx의 configure 스크립트에 --add-dynamic-module 옵션을 사용하여 nginx-module-vts 모듈을 추가합니다.
 
--add-dynamic-module=../nginx-module-vts
./configure \
--prefix=/etc/nginx \
--sbin-path=/usr/sbin/nginx \
--modules-path=/usr/lib/nginx/modules \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/var/log/nginx/error.log \
--http-log-path=/var/log/nginx/access.log \
--pid-path=/var/run/nginx.pid \
--lock-path=/var/run/nginx.lock \
--http-client-body-temp-path=/var/cache/nginx/client_temp \
--http-proxy-temp-path=/var/cache/nginx/proxy_temp \
--http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp \
--http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp \
--http-scgi-temp-path=/var/cache/nginx/scgi_temp \
--user=nginx \
--group=nginx \
--with-compat \
--with-file-aio \
--with-threads \
--with-http_addition_module \
--with-http_auth_request_module \
--with-http_dav_module \
--with-http_flv_module \
--with-http_gunzip_module \
--with-http_gzip_static_module \
--with-http_mp4_module \
--with-http_random_index_module \
--with-http_realip_module \
--with-http_secure_link_module \
--with-http_slice_module \
--with-http_ssl_module \
--with-http_stub_status_module \
--with-http_sub_module \
--with-http_v2_module \
--with-mail \
--with-mail_ssl_module \
--with-stream --with-stream_realip_module \
--with-stream_ssl_module \
--with-stream_ssl_preread_module \
--with-cc-opt='-g -O2 -ffile-prefix-map=/data/builder/debuild/nginx-1.22.1/debian/debuild-base/nginx-1.22.1=. -flto=auto -ffat-lto-objects -flto=auto -ffat-lto-objects -fstack-protector-strong -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2 -fPIC' \
--with-ld-opt='-Wl,-Bsymbolic-functions -flto=auto -ffat-lto-objects -flto=auto -Wl,-z,relro -Wl,-z,now -Wl,--as-needed -pie' \
--add-dynamic-module=../nginx-module-vts
make -j$(nproc)
sudo make install
---
nginx-module-vts(ngx_http_vhost_traffic_status_module.so) 모듈 복사
cp objs/ngx_http_vhost_traffic_status_module.so /etc/nginx/modules/
$ ls -l /etc/nginx/modules/ngx_http_vhost_traffic_status_module.so 
-rw-r--r-- 1 root root 655776 Jan 12 10:25 /etc/nginx/modules/ngx_http_vhost_traffic_status_module.so
nginx-module-vts(ngx_http_vhost_traffic_status_module.so) 파일 권한 설정
chmod 644 /etc/nginx/modules/ngx_http_vhost_traffic_status_module.so
$ ls -l /etc/nginx/modules/ngx_http_vhost_traffic_status_module.so    
-rw-r--r-- 1 root root 657264 Jan 12 09:17 /etc/nginx/modules/ngx_http_vhost_traffic_status_module.so
nginx.conf 설정
vim /etc/nginx/nginx.conf
nginx-module-vts 모듈 설치
- load_module modules/ngx_http_vhost_traffic_status_module.so;
 - vhost_traffic_status_zone;
 
vim /etc/nginx/nginx.conf
$ vim /etc/nginx/nginx.conf
user  nginx;
worker_processes  auto;
error_log  /var/log/nginx/error.log notice;
pid        /var/run/nginx.pid;
#load modules
load_module modules/ngx_http_vhost_traffic_status_module.so;
events {
    worker_connections  1024;
}
http {
    include       /etc/nginx/mime.types;
    default_type  application/octet-stream;
    #extended status
    vhost_traffic_status_zone;
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';
    access_log  /var/log/nginx/access.log  main;
    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    keepalive_timeout  65;
    gzip on;
    gzip_disable "msie6";
    gzip_vary on;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_buffers 16 8k;
    gzip_http_version 1.1;
    gzip_types text/plain text/css text/xml text/javascript application/xml+rss application/json application/x-javascript application/xml;
    include /etc/nginx/conf.d/*.conf;
}
default.conf 설정
    location /vts_status {
        stub_status on;
        vhost_traffic_status_display;
        vhost_traffic_status_display_format html;
        allow 127.0.0.1;
        allow 10.255.255.0/24;
        deny all;
    }
vim /etc/nginx/conf.d/default.conf
$ vim /etc/nginx/conf.d/default.conf
server {
    listen       80;
    server_name  localhost;
    #access_log  /var/log/nginx/host.access.log  main;
    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }
    #error_page  404              /404.html;
    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}
    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    #location ~ \.php$ {
    #    root           html;
    #    fastcgi_pass   127.0.0.1:9000;
    #    fastcgi_index  index.php;
    #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
    #    include        fastcgi_params;
    #}
    # deny access to .htaccess files, if Apache's document root
    # concurs with nginx's one
    #
    #location ~ /\.ht {
    #    deny  all;
    #}
    location /nginx_status {
        stub_status on;
        access_log off;
    }
    location /vts_status {
        stub_status on;
        access_log off;
        vhost_traffic_status_display;
        vhost_traffic_status_display_format html;
    }
}
$ nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
http://localhost/nginx_status
Nginx 트래픽 상태 페이지

Nginx Vhost 트래픽 상태 페이지
http://localhost/vts_status

참고URL
- github.com : Nginx virtual host traffic status module
- nginx : download
- nginx : documentation(Ubuntu)
728x90
    
    
  반응형
    
    
    
  '리눅스' 카테고리의 다른 글
| Nginx 3rd Party Modules(NGINX 타사 모듈) (0) | 2024.01.12 | 
|---|---|
| nginx에서 사용할 수 있는 모듈을 확인하는 방법 (0) | 2024.01.12 | 
| Ansible Galaxy를 사용하는 방법 (0) | 2024.01.11 | 
| Ansible playbook에서 block, rescue, loop, always를 사용하는 방법(ansible-playbook) (0) | 2024.01.10 | 
| 우분투에서 패키지가 자동으로 업데이트되지 않도록 설정하는 방법 (0) | 2024.01.09 | 
