λͺ‡ κ°€μ§€ λͺ…λ ΉμœΌλ‘œ Nginxλ₯Ό μ‘°λ¦½ν•©λ‹ˆλ‹€.

ΠŸΡ€ΠΈΠ²Π΅Ρ‚!
제 이름은 Sergey이고 Tinkoff.ru ν”Œλž«νΌμ˜ API νŒ€μ—μ„œ 인프라 μ—”μ§€λ‹ˆμ–΄λ‘œ μΌν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.

이 κΈ°μ‚¬μ—μ„œλŠ” 우리 νŒ€μ΄ λ°ΈλŸ°μ„œλ₯Ό μ€€λΉ„ν•  λ•Œ μ§λ©΄ν–ˆλ˜ λ¬Έμ œμ— λŒ€ν•΄ μ΄μ•ΌκΈ°ν•˜κ² μŠ΅λ‹ˆλ‹€. Nginx에 λ‹€μ–‘ν•œ ν”„λ‘œμ νŠΈλ₯Ό μœ„ν•΄. λ˜ν•œ λŒ€λΆ€λΆ„μ˜ 문제λ₯Ό 극볡할 수 있게 ν•΄μ€€ 도ꡬ에 λŒ€ν•΄μ„œλ„ λ§μ”€λ“œλ¦¬κ² μŠ΅λ‹ˆλ‹€.

NginxλŠ” λ‹€κΈ°λŠ₯이며 ν™œλ°œνžˆ 개발되고 μžˆλŠ” ν”„λ‘μ‹œ μ„œλ²„μž…λ‹ˆλ‹€. λ§Žμ€ 수의 λͺ¨λ“ˆμ„ κ°–μΆ”κ³  있으며, 이것은 μ™„μ „ν•œ λͺ©λ‘μ΄ μ•„λ‹™λ‹ˆλ‹€. 각 ν”„λ‘œμ νŠΈλŠ” λ°ΈλŸ°μ„œμ˜ κΈ°λŠ₯κ³Ό Nginx 버전(예: http/2 및 grpc ν”„λ‘μ‹œ 쑴재) 및 λͺ¨λ“ˆ ꡬ성에 λŒ€ν•œ νŠΉμ • μš”κ΅¬ 사항을 λΆ€κ³Όν•©λ‹ˆλ‹€.

μ €ν¬λŠ” νŠΉμ • λ°°ν¬νŒμ—μ„œ μ‹€ν–‰λ˜λŠ”, ν•„μš”ν•œ λͺ¨λ“ˆ μ„ΈνŠΈκ°€ ν¬ν•¨λœ μ΅œμ‹  버전을 보고 μ‹ΆμŠ΅λ‹ˆλ‹€. Linuxλ³Έ κΈ€μ—μ„œλŠ” deb 및 rpm 기반 μ‹œμŠ€ν…œμ„ λ‹€λ£Ήλ‹ˆλ‹€. μ»¨ν…Œμ΄λ„ˆ 기반 μ‹œμŠ€ν…œμ€ κ³ λ €ν•˜μ§€ μ•ŠμŠ΅λ‹ˆλ‹€.

μš°λ¦¬λŠ” λ°ΈλŸ°μ„œμ˜ κΈ°λŠ₯을 μ‹ μ†ν•˜κ²Œ λ³€κ²½ν•˜κ³  μ‹ΆμŠ΅λ‹ˆλ‹€. 그리고 μ—¬κΈ°μ„œ μ¦‰μ‹œ 질문이 μƒκΉλ‹ˆλ‹€. κ°€λŠ₯ν•œ ν•œ 적은 μžμ›μ„ μ†ŒλΉ„ν•˜λ©΄μ„œ 이λ₯Ό λ‹¬μ„±ν•˜λŠ” 방법은 λ¬΄μ—‡μž…λ‹ˆκΉŒ? μœ ν•œν•œ 수의 μž…λ ₯ λ§€κ°œλ³€μˆ˜λ₯Ό μ§€μ •ν•  수 있고 좜λ ₯μ—μ„œ β€‹β€‹μ›ν•˜λŠ” OS에 λŒ€ν•œ deb/rpm νŒ¨ν‚€μ§€ ν˜•μ‹μ˜ μ•„ν‹°νŒ©νŠΈλ₯Ό μˆ˜μ‹ ν•  수 μžˆλ„λ‘ ν”„λ‘œμ„ΈμŠ€λ₯Ό μ„€μ •ν•˜λŠ” 것이 훨씬 더 μ’‹μŠ΅λ‹ˆλ‹€.

결과적으둜 λ‹€μŒκ³Ό 같은 μ—¬λŸ¬ κ°€μ§€ λ¬Έμ œκ°€ 곡식화될 수 μžˆμŠ΅λ‹ˆλ‹€.

  • 항상 μ΅œμ‹  λ²„μ „μ˜ Nginxκ°€ ν¬ν•¨λœ νŒ¨ν‚€μ§€κ°€ μžˆλŠ” 것은 μ•„λ‹™λ‹ˆλ‹€.
  • ν•„μˆ˜ λͺ¨λ“ˆμ΄ ν¬ν•¨λœ νŒ¨ν‚€μ§€κ°€ μ—†μŠ΅λ‹ˆλ‹€.
  • νŒ¨ν‚€μ§€λ₯Ό μˆ˜λ™μœΌλ‘œ μ»΄νŒŒμΌν•˜κ³  λΉŒλ“œν•˜λŠ” 것은 μ‹œκ°„μ΄ 많이 걸리고 맀우 μ§€λ£¨ν•©λ‹ˆλ‹€.
  • 이 Nginx μΈμŠ€ν„΄μŠ€κ°€ μ–΄λ–»κ²Œ μ‘°λ¦½λ˜λŠ”μ§€μ— λŒ€ν•œ μ„€λͺ…은 μ—†μŠ΅λ‹ˆλ‹€.

μ΄λŸ¬ν•œ 문제λ₯Ό ν•΄κ²°ν•˜λ €λ©΄ μ‚¬λžŒμ΄ 읽을 수 μžˆλŠ” ν˜•μ‹μ˜ 사양을 μž…λ ₯으둜 μ‚¬μš©ν•˜κ³  이λ₯Ό 기반으둜 ν•„μš”ν•œ κΈ°λŠ₯을 κ°–μΆ˜ Nginx νŒ¨ν‚€μ§€λ₯Ό μ‘°ν•©ν•˜λŠ” 도ꡬ가 ν•„μš”ν•©λ‹ˆλ‹€.

λ°©λŒ€ν•œ Githubμ—μ„œ μ ν•©ν•œ μ˜΅μ…˜μ„ μ°Ύμ§€ λͺ»ν•΄ μš°λ¦¬λŠ” 자체 도ꡬλ₯Ό λ§Œλ“€κΈ°λ‘œ κ²°μ •ν–ˆμŠ΅λ‹ˆλ‹€. nginx λΉŒλ”.

λͺ…μ„Έμ„œ

우리 λ„κ΅¬μ—μ„œλŠ” μ½”λ“œ ν˜•μ‹μœΌλ‘œ 사양에 λŒ€ν•œ μ„€λͺ…을 μƒμ„±ν•˜μ—¬ Git μ €μž₯μ†Œμ— 넣을 수 있기λ₯Ό μ›ν–ˆμŠ΅λ‹ˆλ‹€. 이λ₯Ό μœ„ν•΄ μš°λ¦¬λŠ” μ΄λŸ¬ν•œ μž‘μ—…μ— μ΅μˆ™ν•œ ν˜•μ‹μΈ yaml을 μ„ νƒν–ˆμŠ΅λ‹ˆλ‹€. 사양 예:

nginx_version: 1.14.1
output_package: deb
modules:
  - module:
      name: nginx-auth-ldap
      git_url: https://github.com/kvspb/nginx-auth-ldap.git
      git_branch: master
      dependencies:
        - libldap2-dev
  - module:
      name: ngx_http_substitutions_filter_module
      git_url: https://github.com/yaoweibin/ngx_http_substitutions_filter_module.git
  - module:
      name: headers-more-nginx-module
      web_url: https://github.com/openresty/headers-more-nginx-module/archive/v0.261.zip
  - module:
      name: nginx-module-vts
      git_url: https://github.com/vozlt/nginx-module-vts.git
      git_tag: v0.1.18
  - module:
      name: ngx_devel_kit
      git_url: https://github.com/simplresty/ngx_devel_kit.git
      git_tag: v0.3.0
  - module:
      name: ngx_cache_purge
      git_url: https://github.com/FRiCKLE/ngx_cache_purge.git
  - module:
      name: ngx_http_dyups_module
      git_url: https://github.com/yzprofile/ngx_http_dyups_module.git
  - module:
      name: nginx-brotli
      git_url: https://github.com/eustas/ngx_brotli.git
      git_tag: v0.1.2
  - module:
      name: nginx_upstream_check_module
      git_url: https://github.com/yaoweibin/nginx_upstream_check_module.git
  - module:
      name: njs
      git_url: https://github.com/nginx/njs.git
      git_tag: 0.2.5
      config_folder_path: nginx

μ—¬κΈ°μ„œλŠ” ν•„μˆ˜ λͺ¨λ“ˆ μ„ΈνŠΈκ°€ ν¬ν•¨λœ Nginx 버전 1.14.2의 deb νŒ¨ν‚€μ§€λ₯Ό 보고 μ‹Άλ‹€λŠ” 것을 λ‚˜νƒ€λƒ…λ‹ˆλ‹€. λͺ¨λ“ˆμ΄ μžˆλŠ” μ„Ήμ…˜μ€ 선택 μ‚¬ν•­μž…λ‹ˆλ‹€. 각각에 λŒ€ν•΄ λ‹€μŒμ„ μ„€μ •ν•  수 μžˆμŠ΅λ‹ˆλ‹€.

  • μ΄λ¦„μž…λ‹ˆλ‹€.
  • 받을 수 μžˆλŠ” μ£Όμ†Œ:
    • Git μ €μž₯μ†Œ. λΆ„κΈ°λ‚˜ νƒœκ·Έλ₯Ό μ§€μ •ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.
    • μ•„μΉ΄μ΄λΈŒ μ›Ή 링크.
    • μ•„μΉ΄μ΄λΈŒμ— λŒ€ν•œ 둜컬 링크.

일뢀 λͺ¨λ“ˆμ—λŠ” μΆ”κ°€ 쒅속성을 μ„€μΉ˜ν•΄μ•Ό ν•©λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ nginx-auth-ldapμ—λŠ” libldap2-devκ°€ μ„€μΉ˜λ˜μ–΄ μžˆμ–΄μ•Ό ν•©λ‹ˆλ‹€. λͺ¨λ“ˆμ„ μ„€λͺ…ν•  λ•Œ ν•„μš”ν•œ 쒅속성을 μ§€μ •ν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€.

ν™˜κ²½

저희 도ꡬλ₯Ό μ‚¬μš©ν•˜λ©΄ 컴파일, νŒ¨ν‚€μ§€ λΉŒλ“œ 및 기타 보쑰 μ†Œν”„νŠΈμ›¨μ–΄μ— ν•„μš”ν•œ μœ ν‹Έλ¦¬ν‹°κ°€ μ„€μΉ˜λœ ν™˜κ²½μ„ μ‹ μ†ν•˜κ²Œ 생성할 수 μžˆμŠ΅λ‹ˆλ‹€. ν•„μš”ν•œ λͺ¨λ“  것이 ν¬ν•¨λœ Docker μ»¨ν…Œμ΄λ„ˆκ°€ μ΄λŸ¬ν•œ λͺ©μ μ— μ΄μƒμ μž…λ‹ˆλ‹€(μ €μž₯μ†Œμ—λŠ” 이미 λͺ‡ κ°€μ§€ μƒ˜ν”Œ Docker 파일이 ν¬ν•¨λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€). ubuntu ΠΈ centos).

사양이 μž‘μ„±λ˜κ³  ν™˜κ²½μ΄ μ€€λΉ„λœ ν›„ 이전에 쒅속성을 μ„€μΉ˜ν•œ λΉŒλ”λ₯Ό μ‹œμž‘ν•©λ‹ˆλ‹€.

pip3 install -r requirements.txt
./main.py build -f [ΠΊΠΎΠ½Ρ„ΠΈΠ³_Ρ„Π°ΠΉΠ»].yaml -r [Π½ΠΎΠΌΠ΅Ρ€_Ρ€Π΅Π²ΠΈΠ·ΠΈΠΈ]

μ—¬κΈ°μ˜ κ°œμ • λ²ˆν˜ΈλŠ” 선택 사항이며 μ–΄μ…ˆλΈ”λ¦¬ 버전 관리에 μ‚¬μš©λ©λ‹ˆλ‹€. μ΄λŠ” νŒ¨ν‚€μ§€μ˜ 메타 정보에 κΈ°λ‘λ˜λ―€λ‘œ μ„œλ²„μ—μ„œ μ‰½κ²Œ μ—…λ°μ΄νŠΈν•  수 μžˆμŠ΅λ‹ˆλ‹€.
둜그λ₯Ό 톡해 무슨 일이 μΌμ–΄λ‚˜κ³  μžˆλŠ”μ§€ λͺ¨λ‹ˆν„°λ§ν•  수 μžˆμŠ΅λ‹ˆλ‹€. μ£Όμš” μ‚¬ν•­μ˜ μ˜ˆλŠ” λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

builder - INFO - Parse yaml file: example.config.yaml
builder - INFO - Download scripts for build deb package
builder - INFO - Downloading nginx src...
builder - INFO - --> http://nginx.org/download/nginx-1.14.1.tar.gz
builder - INFO - Downloading 3d-party modules...
builder - INFO - Module nginx-auth-ldap will download by branch
builder - INFO - -- Done: nginx-auth-ldap
builder - INFO - -- Done: ngx_http_substitutions_filter_module
builder - INFO - Module headers-more-nginx-module will downloading
builder - INFO - Module nginx-module-vts will download by tag
builder - INFO - -- Done: nginx-module-vts
builder - INFO - Module ngx_devel_kit will download by tag
builder - INFO - -- Done: ngx_devel_kit
builder - INFO - -- Done: ngx_cache_purge
builder - INFO - -- Done: ngx_http_dyups_module
builder - INFO - Downloading dependencies
builder - INFO - Building .deb package
builder - INFO - Running 'dh_make'...
builder - INFO - Running 'dpkg-buildpackage'...
dpkg-deb: building package 'nginx' in '../nginx_1.14.1-1_amd64.deb'.

λ”°λΌμ„œ λͺ‡ κ°€μ§€ λͺ…λ Ήλ§ŒμœΌλ‘œ ν™˜κ²½κ³Ό ν•„μš”ν•œ Nginx μ–΄μ…ˆλΈ”λ¦¬λ₯Ό μƒμ„±ν•˜λ©΄ μŠ€ν¬λ¦½νŠΈκ°€ μ‹€ν–‰λ˜λŠ” 디렉터리에 νŒ¨ν‚€μ§€κ°€ λ‚˜νƒ€λ‚©λ‹ˆλ‹€.

μž„λ² λ”©

λ˜ν•œ 도ꡬλ₯Ό CI/CD ν”„λ‘œμ„ΈμŠ€μ— 톡합할 μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. 예λ₯Ό λ“€μ–΄ μ˜€λŠ˜λ‚  μ‘΄μž¬ν•˜λŠ” λ§Žμ€ CI μ‹œμŠ€ν…œ 쀑 ν•˜λ‚˜κ°€ 이에 도움이 될 수 μžˆμŠ΅λ‹ˆλ‹€. νŒ€ μ‹œν‹° λ˜λŠ” κΉƒλž© CI.

결과적으둜 Git μ €μž₯μ†Œμ˜ 사양이 변경될 λ•Œλ§ˆλ‹€ μ•„ν‹°νŒ©νŠΈ λΉŒλ“œκ°€ μžλ™μœΌλ‘œ μ‹œμž‘λ©λ‹ˆλ‹€. κ°œμ • λ²ˆν˜ΈλŠ” λΉŒλ“œ μ‹€ν–‰ μΉ΄μš΄ν„°μ— μ—°κ²°λ˜μ–΄ μžˆμŠ΅λ‹ˆλ‹€.
μ‹œκ°„μ΄ μ’€ 더 있으면 둜컬 νŒ¨ν‚€μ§€ μ €μž₯μ†Œ, Nexus, Artifactory λ“±μœΌλ‘œ μ „μ†‘λ˜λ„λ‘ μ•„ν‹°νŒ©νŠΈλ₯Ό ꡬ성할 수 μžˆμŠ΅λ‹ˆλ‹€.

좔가적인 이점은 yaml ꡬ성 νŒŒμΌμ„ Ansible λ˜λŠ” λ‹€λ₯Έ μžλ™ ꡬ성 μ‹œμŠ€ν…œμ— μ—°κ²°ν•  수 있고 κ±°κΈ°μ—μ„œ λ°°ν¬ν•˜λ €λŠ” 버전 λ²ˆν˜Έμ™€ νŒ¨ν‚€μ§€ μœ ν˜•μ„ κ°€μ Έμ˜¬ 수 μžˆλ‹€λŠ” κ²ƒμž…λ‹ˆλ‹€.

λ‹€μŒ 단계

ν”„λ‘œμ νŠΈκ°€ 아직 μ™„λ£Œλ˜μ§€ μ•Šμ•˜μŠ΅λ‹ˆλ‹€. ν˜„μž¬ μš°λ¦¬κ°€ μž‘μ—…ν•˜κ³  μžˆλŠ” μž‘μ—…μ€ λ‹€μŒκ³Ό κ°™μŠ΅λ‹ˆλ‹€.

  • μš°λ¦¬λŠ” ꡬ성 κ°€λŠ₯성을 ν™•μž₯ν•˜λŠ” λ™μ‹œμ— κ°€λŠ₯ν•œ ν•œ λ‹¨μˆœν•˜κ²Œ μœ μ§€ν•©λ‹ˆλ‹€. 두 개만 ν•„μš”ν•˜κ³  λ‚˜λ¨Έμ§€λŠ” 기본적으둜 μ ν•©ν•˜λ‹€λ©΄ 천 개의 λ§€κ°œλ³€μˆ˜λ₯Ό μ •μ˜ν•˜κ³  μ‹Άμ§€ μ•Šμ„ κ²ƒμž…λ‹ˆλ‹€. μ—¬κΈ°μ—λŠ” 컴파일 ν”Œλž˜κ·Έ(이제 λ‚΄λΆ€ ꡬ성 파일 src/config.pyμ—μ„œ λ³€κ²½ν•  수 있음), μ„€μΉ˜ 경둜 및 μ‹œμž‘ μ‚¬μš©μžκ°€ ν¬ν•¨λ©λ‹ˆλ‹€.
  • λ‹€μ–‘ν•œ μ•„ν‹°νŒ©νŠΈ μ €μž₯μ†Œμ— νŒ¨ν‚€μ§€λ₯Ό μžλ™μœΌλ‘œ λ³΄λ‚΄λŠ” μ˜΅μ…˜μ„ μΆ”κ°€ν•˜κ³  μžˆμŠ΅λ‹ˆλ‹€.
  • λͺ¨λ“ˆμ„ λ‘œλ“œν•  λ•Œ μ‚¬μš©μž μ •μ˜ λͺ…령을 μ‹€ν–‰ν•©λ‹ˆλ‹€(예: github.com/nginx-modules/nginx_upstream_check_module λ¨Όμ € νŠΉμ • λ²„μ „μ˜ 패치λ₯Ό μ μš©ν•΄μ•Ό ν•©λ‹ˆλ‹€)
  • ν…ŒμŠ€νŠΈ μΆ”κ°€:
    • νŒ¨ν‚€μ§€κ°€ μ˜¬λ°”λ₯΄κ²Œ μ„€μΉ˜λ˜μ—ˆμŠ΅λ‹ˆλ‹€.
    • Nginxμ—λŠ” ν•„μˆ˜ 버전이 있으며 ν•„μˆ˜ ν”Œλž˜κ·Έ 및 λͺ¨λ“ˆλ‘œ λΉŒλ“œλ˜μ—ˆμŠ΅λ‹ˆλ‹€.
    • ν•„μš”ν•œ 경둜, 계정 등이 μƒμ„±λ©λ‹ˆλ‹€.

ν•˜μ§€λ§Œ 이제 이 도ꡬλ₯Ό μ‚¬μš©ν•˜κ³  κ°œμ„  사항을 μ œμ•ˆν•  μˆ˜λ„ μžˆμŠ΅λ‹ˆλ‹€. github.com/TinkoffCreditSystems/Nginx-builder μ–΄μ„œ μ˜€μ„Έμš”!

좜처 : habr.com

DDoS 보호, VPS VDS μ„œλ²„κ°€ μžˆλŠ” μ‚¬μ΄νŠΈλ₯Ό μœ„ν•œ μ•ˆμ •μ μΈ ν˜ΈμŠ€νŒ… κ΅¬μž… πŸ”₯ DDoS 곡격 λ°©μ§€ κΈ°λŠ₯이 νƒ‘μž¬λœ μ•ˆμ •μ μΈ μ›Ήμ‚¬μ΄νŠΈ ν˜ΈμŠ€νŒ…, VPS 및 VDS μ„œλ²„λ₯Ό κ΅¬λ§€ν•˜μ„Έμš” | ProHoster