在本文中,我们将使用一个简单的 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/
来源: habr.com