在本文中,我們將使用一個簡單的 inotify + createrepo 腳本查看 rpm 工件存儲庫。 使用 apache httpd 通過 webdav 上傳工件。 為什麼 apache httpd 將寫在帖子的末尾。
因此,該解決方案必須滿足以下僅組織 RPM 存儲的要求:
-
免費
-
上傳到工件存儲庫後幾秒鐘後存儲庫中包的可用性。
-
易於安裝和維護
-
實現高可用性的能力
為什麼不
SonaType 連結 或紙漿 : -
儲存於
SonaType 連結 或紙漿 許多類型的工件導致這樣的事實SonaType 連結 或紙漿 成為單點故障。 -
高可用性
SonaType 連結 已經付款了。 -
紙漿 對我來說似乎是一個過度設計的解決方案。 -
文物在
SonaType 連結 存儲在 blob 中。 在突然停電的情況下,如果沒有備份,將無法恢復 blob。 我們有這個錯誤: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 從未恢復。
源代碼
→ 源代碼位於
主腳本如下所示:
#!/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 &
安裝
inotify-createrepo 僅適用於 CentOS 7 或更高版本。 無法讓它在 CentOS 6 上運行。
yum -y install yum-plugin-copr
yum copr enable antonpatsev/inotify-createrepo
yum -y install inotify-createrepo
systemctl start inotify-createrepo
配置
默認情況下 inotify-createrepo 監控一個目錄 /var/www/repos/rpm-repo/
.
您可以在文件中更改此目錄 /etc/inotify-createrepo.conf.
使用
將任何文件添加到目錄時 /var/www/repos/rpm-repo/
inotifywait 將創建一個文件 /tmp/need_create
. run_createrepo函數無限循環運行並監控文件 /tmp/need_create
. 如果文件存在,則運行 createrepo --update
.
文件中將出現一個條目:
/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
實現高可用性的能力
要從現有解決方案中獲得高可用性,我認為您可以使用 2 台服務器,Keepalived 用於 HA 和 Lsyncd 用於工件同步。
的WebDav
上傳文件有幾種方式:SSH、NFS、WebDav。 WebDav 似乎是一個現代而簡單的選擇。
對於 WebDav,我們將使用 Apache httpd。 為什麼 2020 年是 Apache httpd 而不是 nginx?
我想使用自動化工具來構建 Nginx + 模塊(例如 Webdav)。
有一個用於構建 Nginx + 模塊的項目 -
我提出了拉取請求
配置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>
我認為您將自己完成其餘的 Apache httpd 配置。
Apache httpd 前面的 Nginx
與 Apache 不同,Nginx 使用基於事件的請求處理模型,這意味著任意數量的客戶端只需要一個 HTTP 服務器進程。 您可以使用 nginx 並減少服務器負載。
nginx-front.conf 配置。 我認為您將自己完成其餘的 nginx 配置。
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;
}
}
通過 WebDav 下載文件
下載 rpm 非常容易。
curl -T ./nginx-1.16.1-1.el7.ngx.x86_64.rpm https://ваш-виртуальный-хост/rpm/
來源: www.habr.com