GNU/Linux >> Belajar Linux >  >> Linux

Buat repositori YUM/DNF berbasis Nginx di Red Hat Enterprise Linux 8

Repositori perangkat lunak biasanya digunakan melalui internet dan dapat diakses oleh banyak pengguna di seluruh dunia. Namun, Anda dapat membuat repositori lokal Anda sendiri di server lokal dan menggunakannya sebagai pengguna tunggal, atau mengizinkan akses ke mesin lain di LAN Anda menggunakan server web atau FTP.

Keuntungan membuat repositori lokal adalah Anda tidak memerlukan koneksi internet untuk menginstal paket perangkat lunak atau pembaruan. Manfaat lainnya tentu saja kecepatan download. Karena paket diunduh melalui jaringan lokal, pembaruan berjalan dengan cepat.

Yellowdog Updater, Modified (YUM) atau Dandified YUM (DNF) adalah manajer paket perangkat lunak yang mengelola distribusi Linux berbasis RPM. Dengan YUM atau DNF, Anda dapat menginstal dan memperbarui grup komputer tanpa harus memperbarui setiap RPM secara manual.

Pada artikel ini, saya akan menjelaskan cara mengatur repositori YUM/DNF berbasis web lokal di Red Hat Enterprise Linux (RHEL) 8, menggunakan DVD instalasi atau file ISO. Saya juga akan menunjukkan cara menemukan dan menginstal paket perangkat lunak pada mesin RHEL 8 klien menggunakan server HTTP Nginx dan server web Apache. Untuk instruksi Apache, lihat Membuat repositori YUM/DNF berbasis Apache Anda sendiri di Red Hat Enterprise Linux 8 dan untuk instruksi FTP, lihat Membuat repositori YUM/DNF berbasis FTP Anda sendiri di Red Hat Enterprise Linux 8.

[Ingin mencoba Red Hat Enterprise Linux? Unduh sekarang secara gratis.]

Prasyarat

Anda perlu menyiapkan dua sistem Red Hat Enterprise Linux 8:satu server repo lokal dan satu mesin klien yang akan menggunakan repositori lokal dari server lokal. Hasilnya akan terlihat seperti ini:

  • Server Repositori Lokal:RHEL 8 [10.0.0.10]

  • Mesin Klien Lokal:RHEL 8 [10.0.0.11]

  • DVD instalasi RHEL 8

  • Server HTTP Nginx

Buat repositori Anda

Membuat repositori Anda melibatkan sejumlah langkah. Saya akan memandu Anda melewatinya.

Langkah 1:Pasang media Red Hat Enterprise Linux 8

Pertama, mount media lokal (DVD, USB stick, dll.) yang berisi Red Hat Enterprise Linux 8. Gunakan DVD instalasi:

$ sudo mount /dev/cdrom /mnt 
mount: /mnt: WARNING: device write-protected, mounted read-only.

Atau pasang gambar ISO:

$ sudo mount -o loop rhel-8.0-x86_64-dvd.iso /mnt

Langkah 2:Buat repositori YUM lokal dari media yang dipasang

Pindahkan file repo yang ada di /etc/yum.repos.d :

$ sudo mv /etc/yum.repos.d/*.repo /tmp/

Dari titik ini, lebih baik jika Anda melanjutkan sebagai pengguna root. Beralih ke pengguna super dengan su perintah.

Selanjutnya, buat direktori untuk repo:

# mkdir /local_repo

Gunakan direktori ini dengan Nginx atau Apache untuk menyajikan file melalui LAN.

Buat file konfigurasi repositori lokal baru, local-dvdrom.repo , di bawah /etc/yum.repos.d direktori:

# touch /etc/yum.repos.d/local-dvdrom.repo
# chmod  u+rw,g+r,o+r  /etc/yum.repos.d/local-dvdrom.repo

Langkah 3:Salin konten media ke direktori lokal

Salin file ISO secara lokal di bawah /local_repo direktori:

# cd /mnt
# tar cvf - . | (cd /local_repo/; tar xvf -)

Tunggu hingga file disalin, lalu verifikasi file telah disalin menggunakan:

# ls -l /local_repo/
total 56
dr-xr-xr-x. 4 root root    38 Apr  4  2019 AppStream
dr-xr-xr-x. 4 root root    38 Apr  4  2019 BaseOS
dr-xr-xr-x. 3 root root    18 Apr  4  2019 EFI
-r--r--r--. 1 root root  8266 Mar  1  2019 EULA
-r--r--r--. 1 root root  1455 Apr  4  2019 extra_files.json
-r--r--r--. 1 root root 18092 Mar  1  2019 GPL
dr-xr-xr-x. 3 root root    76 Apr  4  2019 images
dr-xr-xr-x. 2 root root   256 Apr  4  2019 isolinux
-r--r--r--. 1 root root   103 Apr  4  2019 media.repo
-r--r--r--. 1 root root  1669 Mar  1  2019 RPM-GPG-KEY-redhat-beta
-r--r--r--. 1 root root  5134 Mar  1  2019 RPM-GPG-KEY-redhat-release
-r--r--r--. 1 root root  1796 Apr  4  2019 TRANS.TBL

Langkah 4:Konfigurasi repositori YUM/DNF lokal

Edit file konfigurasi repo yang Anda buat sebelumnya:

# vim /etc/yum.repos.d/local-dvdrom.repo

Tempelkan konfigurasi ini ke dalamnya:

[LocalRepo_BaseOS]
name=LocalRepo_BaseOS
metadata_expire=-1
enabled=1
gpgcheck=1
baseurl=file:///local_repo/BaseOS/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

[LocalRepo_AppStream]
name=LocalRepo_AppStream
metadata_expire=-1
enabled=1
gpgcheck=1
baseurl=file:///local_repo/AppStream/
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

Instal paket yang diperlukan untuk membuat, mengonfigurasi, dan mengelola repositori lokal:

# yum repolist
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
LocalRepo_AppStream                              94 MB/s | 5.3 MB     00:00    
LocalRepo_BaseOS                                 97 MB/s | 2.2 MB     00:00    
repo id                              repo name                            status
LocalRepo_AppStream                  LocalRepo_AppStream                  4,672
LocalRepo_BaseOS                     LocalRepo_BaseOS                     1,658


# yum install createrepo  yum-utils
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Last metadata expiration check: 0:02:33 ago on Sat 05 Oct 2019 09:52:46 PM UTC.
Package dnf-utils-4.0.2.2-3.el8.noarch is already installed.
Dependencies resolved.
================================================================================
 Package              Arch      Version            Repository              Size
================================================================================
Installing:
 createrepo_c         x86_64    0.11.0-1.el8       LocalRepo_AppStream     76 k
Installing dependencies:
 createrepo_c-libs    x86_64    0.11.0-1.el8       LocalRepo_AppStream    101 k
 drpm                 x86_64    0.3.0-14.el8       LocalRepo_AppStream     71 k

Transaction Summary
================================================================================
Install  3 Packages

Total size: 249 k
Installed size: 556 k
Is this ok [y/N]: y
Downloading Packages:
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : drpm-0.3.0-14.el8.x86_64                               1/3 
  Installing       : createrepo_c-libs-0.11.0-1.el8.x86_64                  2/3 
  Installing       : createrepo_c-0.11.0-1.el8.x86_64                       3/3 
  Running scriptlet: createrepo_c-0.11.0-1.el8.x86_64                       3/3 
  Verifying        : createrepo_c-0.11.0-1.el8.x86_64                       1/3 
  Verifying        : createrepo_c-libs-0.11.0-1.el8.x86_64                  2/3 
  Verifying        : drpm-0.3.0-14.el8.x86_64                               3/3 
Installed products updated.

Installed:
  createrepo_c-0.11.0-1.el8.x86_64     createrepo_c-libs-0.11.0-1.el8.x86_64    
  drpm-0.3.0-14.el8.x86_64            

Complete!

Terakhir, jalankan createrepo perintah:

# createrepo /local_repo/
Directory walk started
Directory walk done - 6647 packages
Temporary output repo path: /local_repo/.repodata/
Preparing sqlite DBs
Pool started (with 5 workers)
Pool finished

Langkah 5:Uji dan verifikasi repositori lokal Anda

Pada langkah ini, Anda membersihkan file repositori sementara dan memverifikasi bahwa repositori lokal diaktifkan:

# yum clean all
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
12 files removed

# yum repolist
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
LocalRepo_AppStream                             120 MB/s | 5.3 MB     00:00    
LocalRepo_BaseOS                                103 MB/s | 2.2 MB     00:00    
repo id                              repo name                            status
LocalRepo_AppStream                  LocalRepo_AppStream                  4,672
LocalRepo_BaseOS                     LocalRepo_BaseOS                     1,658

Verifikasi bahwa repositori lokal telah dibuat:

# ls /local_repo/repodata/
26617821a5263fb13c7a49cc5e2d0b979b926eb17b9b4ed0b7df624e04c272f2-other.sqlite.bz2
5626e6dd41648dc6395def6889f4cc0e7f1006bb7d7eca748c9abd4c67fa5b9b-other.xml.gz
6290a72e46a90f98896c14f7664440de10c798d158ce0afe5f15a9f3896b7824-primary.xml.gz
a5c265589796231ed91b8b25a0473d05915bf62496495a004d321d042b26360c-filelists.sqlite.bz2
c8b51f43bdaa4f14cd5b083851cef1068e9284fa6557eb4552ba2ae22e7f72d5-primary.sqlite.bz2
ed21f77d28e263df02739a4bd55eb7247ffd0531c871bfe677d4b205dbffd5e8-filelists.xml.gz
repomd.xml

Anda dapat melihat bahwa repositori lokal menghasilkan file, jadi semuanya baik-baik saja saat ini.

Jika Anda membaca output perintah di atas dengan cermat, Anda mendapatkan pesan peringatan, This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register . Jika Anda ingin menyembunyikan atau mencegah pesan ini saat menjalankan dnf atau yum perintah kemudian edit file /etc/yum/pluginconf.d/subscription-manager.conf :

# vim /etc/yum/pluginconf.d/subscription-manager.conf

dan ubah parameter enabled=1 ke enabled=0 :

[main]
enabled=0

Siapkan server HTTP Nginx Anda

Seperti yang saya sebutkan sebelumnya, artikel ini mencakup pengaturan repositori Anda sendiri menggunakan server HTTP Nginx. Saya akan memandu Anda dalam menginstal dan mengonfigurasi Nginx untuk melayani repo Anda.

Instal Nginx

Untuk menginstal server HTTP Nginx menggunakan YUM:

# yum install nginx
Last metadata expiration check: 0:19:18 ago on Sun 06 Oct 2019 09:51:22 AM UTC.
Dependencies resolved.
=======================================================================================
 Package          Arch   Version                             Repository           Size
=======================================================================================
Installing:
 nginx            x86_64 1:1.14.1-8.module+el8+2505+fe936cef LocalRepo_AppStream 569 k
Installing dependencies:
 gd               x86_64 2.2.5-6.el8                         LocalRepo_AppStream 144 k
 jbigkit-libs     x86_64 2.1-14.el8                          LocalRepo_AppStream  55 k
 libX11           x86_64 1.6.7-1.el8                         LocalRepo_AppStream 612 k
 libX11-common    noarch 1.6.7-1.el8                         LocalRepo_AppStream 157 k
 libXau           x86_64 1.0.8-13.el8                        LocalRepo_AppStream  36 k
 libXpm           x86_64 3.5.12-7.el8                        LocalRepo_AppStream  58 k
 libjpeg-turbo    x86_64 1.5.3-7.el8                         LocalRepo_AppStream 155 k
 libtiff          x86_64 4.0.9-13.el8                        LocalRepo_AppStream 188 k
 libwebp          x86_64 1.0.0-1.el8                         LocalRepo_AppStream 273 k
 libxcb           x86_64 1.13-5.el8                          LocalRepo_AppStream 230 k
 nginx-all-modules
                  noarch 1:1.14.1-8.module+el8+2505+fe936cef LocalRepo_AppStream  23 k
 nginx-filesystem noarch 1:1.14.1-8.module+el8+2505+fe936cef LocalRepo_AppStream  24 k
 nginx-mod-http-image-filter
                  x86_64 1:1.14.1-8.module+el8+2505+fe936cef LocalRepo_AppStream  34 k
 nginx-mod-http-perl
                  x86_64 1:1.14.1-8.module+el8+2505+fe936cef LocalRepo_AppStream  45 k
 nginx-mod-http-xslt-filter
                  x86_64 1:1.14.1-8.module+el8+2505+fe936cef LocalRepo_AppStream  33 k
 nginx-mod-mail   x86_64 1:1.14.1-8.module+el8+2505+fe936cef LocalRepo_AppStream  64 k
 nginx-mod-stream x86_64 1:1.14.1-8.module+el8+2505+fe936cef LocalRepo_AppStream  85 k
 dejavu-fonts-common
                  noarch 2.35-6.el8                          LocalRepo_BaseOS     74 k
 dejavu-sans-fonts
                  noarch 2.35-6.el8                          LocalRepo_BaseOS    1.5 M
 fontconfig       x86_64 2.13.1-3.el8                        LocalRepo_BaseOS    275 k
 fontpackages-filesystem
                  noarch 1.44-22.el8                         LocalRepo_BaseOS     16 k
 libxslt          x86_64 1.1.32-3.el8                        LocalRepo_BaseOS    249 k
Enabling module streams:
 nginx                   1.14                                                         

Transaction Summary
=======================================================================================
Install  23 Packages

Total size: 4.8 M
Installed size: 15 M
Is this ok [y/N]: y

Konfigurasikan Nginx untuk memulai otomatis saat boot

Setelah Nginx diinstal, mulai dan aktifkan layanan untuk memulai otomatis saat boot dan verifikasi statusnya menggunakan perintah berikut:

# systemctl start nginx

# systemctl enable nginx
Created symlink /etc/systemd/system/multi-user.target.wants/nginx.service → /usr/lib/systemd/system/nginx.service.

# systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disa>
   Active: active (running) since Sun 2019-10-06 10:15:47 UTC; 22s ago
 Main PID: 3596 (nginx)
    Tasks: 3 (limit: 11528)
   Memory: 7.6M
   CGroup: /system.slice/nginx.service
           ├─3596 nginx: master process /usr/sbin/nginx
           ├─3597 nginx: worker process
           └─3598 nginx: worker process

Oct 06 10:15:47 server systemd[1]: Starting The nginx HTTP and reverse proxy server...
Oct 06 10:15:47 server nginx[3593]: nginx: the configuration file /etc/nginx/nginx.con>
Oct 06 10:15:47 server nginx[3593]: nginx: configuration file /etc/nginx/nginx.conf te>
Oct 06 10:15:47 server systemd[1]: Started The nginx HTTP and reverse proxy server.

Konfigurasikan firewall

Selanjutnya, Anda harus mengonfigurasi firewall agar Nginx dapat dijangkau:

# firewall-cmd --zone=public --permanent --add-service=http
success
# firewall-cmd --zone=public --permanent --add-service=https
success
# firewall-cmd --reload
success

Verifikasi bahwa Nginx aktif dan berjalan

Sekarang Anda dapat memverifikasi bahwa server Nginx Anda aktif dan berjalan dengan membuka localhost URL di browser web Anda. Halaman web Nginx default http://localhost/ harus ditampilkan.

Konfigurasi Nginx

Untuk mengkonfigurasi Nginx, buka file konfigurasi:

# vim /etc/nginx/nginx.conf

Sekarang, temukan server bagian dari file dan ubah sehingga terlihat seperti ini:

    server {
	listen       80 default_server;
        listen       [::]:80 default_server;
        server_name  _;
        root         /local_repo/;

        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;

        location / {
                allow all;
                sendfile on;
                sendfile_max_chunk 1m;
                autoindex on;
                autoindex_exact_size off;
                autoindex_format html;
                autoindex_localtime on;
        }
	  error_page 404 /404.html;
            location = /40x.html {
        }

	  error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }

Uji dan bersihkan

Sekarang, mulai layanan Nginx lagi dan uji statusnya:

# systemctl restart nginx

# systemctl status nginx

● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; enabled; vendor preset: disa>
   Active: active (running) since Sun 2019-10-06 10:15:47 UTC; 3 hours 51 min ago
Process: 24032 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
Process: 24033 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
Process: 24034 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
 Main PID: 24035 (nginx)
   Status: "Started, listening on: port 80"
    Tasks: 3 (limit: 2438)
   Memory: 3.9M
   CGroup: /system.slice/nginx.service
           ├─24035 nginx: master process /usr/sbin/nginx
           ├─24036 nginx: worker process
           └─24037 nginx: worker process

Oct 06 10:15:47 server systemd[1]: Starting The nginx HTTP and reverse proxy server...
Oct 06 10:15:47 server nginx[24033]: nginx: [warn] could not build optimal types_hash, you should increase either types_hash_max_si>
Oct 06 10:15:47 server nginx[24033]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Oct 06 10:15:47 server nginx[24033]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Oct 06 10:15:47 server nginx[24033]: nginx[24034]: nginx: [warn] could not build optimal types_hash, you should increase either types_hash_max_si
Oct 06 10:15:47 server systemd[1]: Started The nginx HTTP and reverse proxy server.

Semuanya baik.

Ubah izin dan setel SELinux

Lanjutkan konfigurasi keamanan dengan mengubah izin pada local_repo direktori dan mengkonfigurasi SELinux. Untuk mengubah izin:

# setfacl -R -m u:apache:rwx /local_repo/

Kemudian, periksa apakah SELinux menerapkan:

# getenforce
Enforcing

Jika Enforcing , ketik:

# chcon -Rt httpd_sys_content_t /local_repo/

Jika SELinux tidak disetel ke Enforcing, maka file tidak akan ditayangkan dari repo.

# setenforce enforcing

Dan buat perubahan permanen dengan mengedit file /etc/sysconfig/selinux dan atur nilai berikut:

SELINUX=enforcing

Siapkan klien

Sekarang, untuk mengonfigurasi repositori mesin klien Red Hat Enterprise Linux 8.

Tambahkan repo

Pada mesin klien, tambahkan repo lokal dari server ke konfigurasi YUM klien:

$ sudo vim /etc/yum.repos.d/local-rhel8.repo 

Kemudian rekatkan konfigurasi berikut (pastikan untuk mengubah alamat IP server sesuai dengan pengaturan Anda):

[LocalServerRepo]
name=LocalServerRepo
enabled=1
gpgcheck=0
baseurl=[http://](http://10.0.0.10/)[**10.0.0.10**](http://10.0.0.10/)[/](http://10.0.0.10/)

Uji repo

Uji LocalServerRepo dengan menginstal paket. Misalnya:

$ yum repolist
Not root, Subscription Management repositories not updated
LocalServerRepo                                 112 MB/s | 7.2 MB     00:00    
Last metadata expiration check: 0:00:02 ago on Sun 06 Oct 2019 01:04:21 PM UTC.
repo id                              repo name                            status
LocalServerRepo                      LocalServerRepo                      6,647

$ sudo yum install nano
Updating Subscription Management repositories.
Unable to read consumer identity
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
LocalServerRepo                                 103 MB/s | 7.2 MB     00:00    
Last metadata expiration check: 0:00:02 ago on Sun 06 Oct 2019 01:07:33 PM UTC.
Dependencies resolved.
================================================================================
 Package      Arch           Version              Repository               Size
================================================================================
Installing:
 nano         x86_64         2.9.8-1.el8          LocalServerRepo         580 k

Transaction Summary
================================================================================
Install  1 Package

Total download size: 580 k
Installed size: 2.2 M
Is this ok [y/N]: y
Downloading Packages:
nano-2.9.8-1.el8.x86_64.rpm                      19 MB/s | 580 kB     00:00    
--------------------------------------------------------------------------------
Total                                            17 MB/s | 580 kB     00:00     
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : nano-2.9.8-1.el8.x86_64                                1/1 
  Running scriptlet: nano-2.9.8-1.el8.x86_64                                1/1 
  Verifying        : nano-2.9.8-1.el8.x86_64                                1/1 
Installed products updated.

Installed:
  nano-2.9.8-1.el8.x86_64                                                       

Complete!

Itu hebat! Semuanya bekerja seperti yang diharapkan. Anda sekarang memiliki repositori YUM/DNF lokal berbasis Nginx di Red Hat Enterprise Linux 8, menggunakan DVD instalasi atau file ISO.


Linux
  1. Cara Membuat Repositori Red Hat Lokal

  2. Mengonfigurasi alamat IPv6 di Red Hat Enterprise Linux 7 dan 8

  3. Buat repositori YUM/DNF berbasis FTP di Red Hat Enterprise Linux 8

  1. Buat repositori YUM/DNF berbasis Apache di Red Hat Enterprise Linux 8

  2. Mengoptimalkan image ISO instalasi Red Hat Enterprise Linux

  3. Apa yang Dilakukan "touch /.autorelabel" Saat Kami Menyetel Ulang Kata Sandi Root Di Red Hat Enterprise Linux?

  1. Daftarkan Red Hat Enterprise Linux dan lampirkan langganan dengan Ansible

  2. Membangun image Red Hat Enterprise Linux 7 yang disesuaikan untuk Microsoft Azure

  3. Cara Mengecualikan Repositori Khusus untuk Pembaruan Yum di CentOS / Red Hat