Peb sib sau peb Nginx nrog ob peb cov lus txib

Nyob zoo!
Kuv lub npe yog Sergey, Kuv ua haujlwm ua tus kws tsim kho vaj tsev nyob hauv API pab pawg ntawm tinkoff.ru platform.

Nyob rau hauv tsab xov xwm no kuv yuav tham txog cov teeb meem uas peb pab neeg tau ntsib thaum npaj balancers raws li Nginx rau ntau yam haujlwm. Kuv tseem yuav qhia koj txog cov cuab yeej uas tso cai rau kuv kov yeej lawv feem ntau.

Nginx yog ib tug multifunctional thiab nquag tsim npe neeg rau zaub mov. Nws nta ib tug loj tus naj npawb ntawm modules, qhov no tsis yog ib daim ntawv teev tag nrho. Txhua qhov project imposes tej yam uas yuav tsum tau nyob rau hauv lub functionality ntawm balancer thiab lub version ntawm Nginx (piv txwv li, lub xub ntiag ntawm http/2 thiab grpc proxying), thiab cov muaj pes tsawg leeg ntawm nws modules.

Peb xav pom ib qho tshiab nrog cov txheej txheem uas yuav tsum tau ua, khiav hauv ib qho tshwj xeeb Linux faib. Hauv peb qhov xwm txheej, cov no yog deb- thiab rpm-based systems. Qhov kev xaiv nrog cov thawv ntim tsis suav nrog hauv kab lus no.

Peb xav kom ceev ceev hloov cov functionality ntawm peb balancers. Thiab ntawm no cov lus nug tam sim ntawd tshwm sim: yuav ua li cas ua tiav qhov no thaum siv nyiaj tsawg li ntau tau? Nws yuav yog qhov zoo dua los teeb tsa cov txheej txheem kom peb tuaj yeem hais kom meej tus naj npawb ntawm cov tswv yim tsis raug, thiab ntawm qhov tso zis tau txais cov khoom cuav hauv daim ntawv deb / rpm pob rau qhov xav tau OS.

Yog li ntawd, ntau yam teeb meem tuaj yeem tsim tau:

  • Tsis muaj ib txwm pob khoom nrog qhov tseeb version ntawm Nginx.
  • Tsis muaj tej pob khoom uas yuav tsum tau modules.
  • Compiling thiab tsim ib pob manually yog lub sij hawm siv thiab downright tedious.
  • Tsis muaj kev piav qhia txog yuav ua li cas qhov no lossis qhov piv txwv Nginx tau sib sau ua ke.

Txhawm rau daws cov teeb meem no, qhov xav tau tshwm sim rau lub cuab yeej uas yuav siv los ua cov lus qhia tshwj xeeb hauv tib neeg nyeem tau thiab sib sau ua ke Nginx pob nrog cov haujlwm tsim nyog raws li nws.

Tsis nrhiav kev xaiv tsim nyog rau peb ntawm qhov loj ntawm Github, peb txiav txim siab los tsim peb tus kheej cov cuab yeej - nginx-neeg tsim khoom.

Π‘ΠΏΠ΅Ρ†ΠΈΡ„ΠΈΠΊΠ°Ρ†ΠΈΠΈ

Hauv peb lub cuab yeej, peb xav tsim cov lus piav qhia ntawm qhov tshwj xeeb hauv daim ntawv code, uas tuaj yeem muab tso rau hauv Git repository. Ua li no, peb xaiv hom kev paub txog tej yam - yaml. Specification piv txwv:

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

Ntawm no peb qhia tias peb xav pom ib pob deb nrog Nginx version 1.14.2 nrog rau cov txheej txheem tsim nyog. Tshooj nrog modules yog xaiv tau. Rau txhua tus ntawm lawv koj tuaj yeem teeb tsa:

  • Npe.
  • Chaw nyob qhov twg koj tuaj yeem tau txais nws:
    • Git repository. Koj tuaj yeem hais qhia ib ceg lossis tag.
    • Archive web link.
    • Local link mus rau lub archive.

Qee cov modules yuav tsum tau muab tso rau ntxiv, piv txwv li nginx-auth-ldap xav tau libldap2-dev ntsia. Cov kev vam meej tseem ceeb kuj tuaj yeem teev tau thaum piav qhia txog qhov module.

Ib puag ncig

Hauv peb lub cuab yeej koj tuaj yeem tau txais ib puag ncig sai nrog cov khoom siv hluav taws xob rau kev muab tso ua ke, pob khoom sib dhos thiab lwm yam kev pabcuam software. Lub thawv Docker nrog txhua yam koj xav tau yog qhov zoo tagnrho ntawm no (lub chaw cia khoom twb muaj ob peb piv txwv ntawm Docker cov ntaub ntawv rau ubuntu thiab centos).

Tom qab qhov kev qhia tshwj xeeb tau kos thiab ib puag ncig tau npaj, peb tso peb tus neeg tsim khoom, tau teeb tsa yav dhau los nws qhov kev vam meej:

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

Tus lej hloov kho ntawm no yog xaiv tau thiab yog siv rau kev sib sau ua ke. Nws tau sau rau hauv pob cov ntaub ntawv meta, ua kom yooj yim hloov kho ntawm servers.
Los ntawm cov cav koj tuaj yeem saib xyuas qhov tshwm sim. Nov yog ib qho piv txwv ntawm cov ntsiab lus tseem ceeb:

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'.

Yog li, tsuas yog ob peb lo lus txib, peb tsim ib puag ncig thiab qhov xav tau Nginx los ua ke, thiab cov pob tshwm nyob rau hauv phau ntawv teev npe los ntawm qhov twg tsab ntawv tau pib.

Embedded

Peb tseem tuaj yeem muab peb cov cuab yeej ua ke rau hauv cov txheej txheem CI / CD. Ib qho ntawm ntau lub tshuab CI niaj hnub no tuaj yeem pab nrog qhov no, piv txwv Teamcity los yog Gitlab CI.

Raws li qhov tshwm sim, txhua zaus qhov kev hloov pauv tshwj xeeb hauv Git repository, kev tsim cov khoom qub tau txiav tawm. Tus xov tooj hloov kho yog txuas mus rau lub tsev tso tawm txee.
Nrog rau lub sijhawm me ntsis ntxiv, koj tuaj yeem teeb tsa cov khoom ntiag tug xa mus rau koj lub chaw khaws khoom hauv zos, Nexus, Artifactory, thiab lwm yam.

Ib qho txiaj ntsig ntxiv yog tias yaml teeb tsa cov ntaub ntawv tuaj yeem txuas nrog Ansible lossis lwm qhov kev teeb tsa tsis siv neeg, thiab los ntawm qhov ntawd peb tuaj yeem nqa tus lej version thiab pob hom uas peb xav xa mus.

Dab tsi ntxiv

Qhov project tseem tsis tau tiav. Nov yog qhov peb tab tom ua haujlwm tam sim no:

  • Peb nthuav qhov muaj peev xwm ntawm kev teeb tsa, tab sis tib lub sijhawm ua kom nws yooj yim li sai tau. Koj tsis xav txhais ib txhiab tsis yog tias koj tsuas xav tau ob, thiab tus so haum los ntawm lub neej ntawd. Qhov no suav nrog cov chij sib sau (tam sim no koj tuaj yeem hloov lawv hauv cov ntaub ntawv teeb tsa sab hauv src/config.py), txoj kev teeb tsa, thiab tso tus neeg siv.
  • Peb tab tom ntxiv cov kev xaiv rau kev xa ib pob mus rau ntau qhov chaw khaws khoom qub.
  • Ua ib qho kev cai hais kom ua thaum thauj khoom module (piv txwv li, siv github.com/nginx-modules/nginx_upstream_check_module koj yuav tsum xub thov ib thaj ntawm ib tug tshwj xeeb version)
  • Ntxiv cov kev xeem:
    • Lub pob yog ntsia kom raug.
    • Nginx muaj qhov xav tau version thiab tsim nrog tus chij thiab modules xav tau.
    • Cov kev tsim nyog, cov nyiaj, thiab lwm yam yog tsim.

Tab sis koj tuaj yeem siv cov cuab yeej no tam sim no, thiab tseem qhia txog kev txhim kho - github.com/TinkoffCreditSystems/Nginx-builder nyob zoo!

Tau qhov twg los: www.hab.com

Ntxiv ib saib