Simpla rpm-deponejo uzante Inotify kaj webdav

En ĉi tiu afiŝo ni rigardos la rpm-artefaktan stokadon uzante simplan skripton kun inotify + createrepo. Alŝuto de artefaktoj estas farita per webdav uzante apache httpd. Kial apache httpd estos skribita al la fino de la afiŝo.

Do, la solvo devas plenumi la sekvajn postulojn por organizi nur RPM-stokadon:

  • Senpaga

  • Havebleco de la pakaĵo en la deponejo kelkajn sekundojn post alŝutado al la artefakto-deponejo.

  • Facila instali kaj konservi

  • Kapablo fari altan haveblecon

    Kial ne SonaType NexusPulpo:

  • Stokado en SonaType NexusPulpo multaj specoj de artefaktoj kondukas al tio, ke SonaType NexusPulpo fariĝi ununura punkto de fiasko.

  • Alta havebleco en SonaType Nexus estas pagita.

  • Pulpo Ŝajnas al mi tro komplika solvo.

  • Artefaktoj en SonaType Nexus estas konservitaj en blob. Se estas subita elektropaneo, vi ne povos restarigi la blob se vi ne havas sekurkopion. Ni havis ĉi tiun eraron: ERROR [ForkJoinPool.commonPool-worker-2] *SYSTEM [com.orientechnologies.orient.core.storage](http://com.orientechnologies.orient.core.storage/).fs.OFileClassic - $ANSI{green {db=security}} Error during data read for file 'privilege_5.pcl' 1-th attempt [java.io](http://java.io/).IOException: Bad address. Blob neniam estis reestigita.

Fontkodo

→ Fontkodo troviĝas tie

La ĉefa manuskripto aspektas jene:

#!/bin/bash

source /etc/inotify-createrepo.conf
LOGFILE=/var/log/inotify-createrepo.log

function monitoring() {
    inotifywait -e close_write,delete -msrq --exclude ".repodata|.olddata|repodata" "${REPO}" | while read events 
    do
      echo $events >> $LOGFILE
      touch /tmp/need_create
    done
}

function run_createrepo() {
  while true; do
    if [ -f /tmp/need_create ];
    then
      rm -f /tmp/need_create
      echo "start createrepo $(date --rfc-3339=seconds)"
      /usr/bin/createrepo --update "${REPO}"
      echo "finish createrepo $(date --rfc-3339=seconds)"
    fi
    sleep 1
  done
}

echo "Start filesystem monitoring: Directory is $REPO, monitor logfile is $LOGFILE"
monitoring >> $LOGFILE &
run_createrepo >> $LOGFILE &

fikso

Inotify-createrepo funkcias nur ĉe CentOS 7 aŭ pli alta. Ne povis funkcii ĝin sur CentOS 6.

yum -y install yum-plugin-copr
yum copr enable antonpatsev/inotify-createrepo
yum -y install inotify-createrepo
systemctl start inotify-createrepo

Agordo

Defaŭlte, inotify-createrepo kontrolas la dosierujon /var/www/repos/rpm-repo/.

Vi povas ŝanĝi ĉi tiun dosierujon en la dosiero /etc/inotify-createrepo.conf.

Uzo

Aldonante ajnan dosieron al dosierujo /var/www/repos/rpm-repo/ inotifywait kreos la dosieron /tmp/need_create. La funkcio run_createrepo funkcias en senfina buklo kaj kontrolas la dosieron /tmp/need_create. Se la dosiero ekzistas, ĝi ruliĝas createrepo --update.

Eniro aperos en la dosiero:

/var/www/repos/rpm-repo/ CREATE nginx-1.16.1-1.el7.ngx.x86_64.rpm
start createrepo 2020-03-02 09:46:21+03:00
Spawning worker 0 with 1 pkgs
Spawning worker 1 with 0 pkgs
Spawning worker 2 with 0 pkgs
Spawning worker 3 with 0 pkgs
Workers Finished
Saving Primary metadata
Saving file lists metadata
Saving other metadata
Generating sqlite DBs
Sqlite DBs complete
finish createrepo 2020-03-02 09:46:22+03:00

Kapablo fari altan haveblecon

Por fari altan haveblecon el ekzistanta solvo, mi pensas, ke vi povas uzi 2 servilojn, Keepalived por HA kaj Lsyncd por sinkronigi artefaktojn. Lsyncd - demono kiu kontrolas ŝanĝojn en loka dosierujo, agregas ilin, kaj post certa tempo rsync komencas sinkronigi ilin. Detaloj kaj aranĝo estas priskribitaj en la afiŝo "Rapida sinkronigo de miliardo da dosieroj".

WebDav

Vi povas alŝuti dosierojn en pluraj manieroj: SSH, NFS, WebDav. WebDav ŝajnas esti moderna kaj simpla opcio.

Por WebDav ni uzos Apache httpd. Kial Apache httpd en 2020 kaj ne nginx?

Mi ŝatus uzi aŭtomatajn ilojn por konstrui Nginx +-modulojn (ekzemple Webdav).

Estas projekto por konstrui Nginx + modulojn - Nginx-konstruanto. Se vi uzas nginx + wevdav por alŝuti dosierojn, vi bezonas modulon nginx-dav-ext-modulo. Kiam vi provas konstrui kaj uzi Nginx kun nginx-dav-ext-modulo kun la helpo Nginx-konstruanto ni ricevos eraron Uzita de http_dav_module anstataŭ nginx-dav-ext-module. La sama cimo estis fermita somere nginx: [emerg] nekonata direktivo dav_methods.

Mi faris Pull-peton Aldonu kontrolon git_url por enigita, refactorigita —with-{}_module и if module == "http_dav_module" aldoni --kun. Sed ili ne estis akceptitaj.

Agordo webdav.conf

DavLockDB /var/www/html/DavLock
<VirtualHost localhost:80>
    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/html
    ErrorLog /var/log/httpd/error.log
    CustomLog /var/log/httpd/access.log combined

    Alias /rpm /var/www/repos/rpm-repo
    <Directory /var/www/repos/rpm-repo>
        DAV On
        Options Indexes FollowSymlinks SymLinksifOwnerMatch IncludesNOEXEC
        IndexOptions NameWidth=* DescriptionWidth=*
        AllowOverride none
        Require all granted
    </Directory>
</VirtualHost>

Mi pensas, ke vi mem povas fari la reston de la Apache httpd-agordo.

Nginx antaŭ Apache httpd

Male al Apache, Nginx uzas modelon pri pettraktado bazita en evento, kiu postulas nur unu HTTP-servilan procezon por iu ajn nombro da klientoj. Vi povas uzi nginx kaj redukti la ŝarĝon sur la servilo.

Agordo nginx-front.conf. Mi pensas, ke vi povas fari la reston de la agordo de nginx mem.

upstream nginx_front {
    server localhost:80;
}

server {
    listen 443 ssl;
    server_name ваш-виртуальных-хост;
    access_log /var/log/nginx/nginx-front-access.log main;
    error_log /var/log/nginx/nginx-front.conf-error.log warn;

    location / {
        proxy_pass http://nginx_front;
    }
}

Alŝuto de dosieroj per WebDav

Ŝargado de rpm estas tre simpla.

curl -T ./nginx-1.16.1-1.el7.ngx.x86_64.rpm https://ваш-виртуальный-хост/rpm/

fonto: www.habr.com

Aldoni komenton