GNU/Linux >> Linux Esercitazione >  >> Linux

Crea un repository YUM/DNF basato su Nginx su Red Hat Enterprise Linux 8

I repository software sono generalmente utilizzati su Internet e possono essere consultati da più utenti in tutto il mondo. Tuttavia, puoi creare il tuo repository locale sul tuo server locale e usarlo come utente singolo, oppure consentire l'accesso ad altre macchine sulla tua LAN usando un server web o FTP.

Il vantaggio della creazione di un repository locale è che non è necessaria una connessione Internet per installare pacchetti software o aggiornamenti. Un altro vantaggio è, ovviamente, la velocità di download. Poiché i pacchetti vengono scaricati tramite una rete locale, gli aggiornamenti vengono eseguiti rapidamente.

Yellowdog Updater, Modified (YUM) o Dandified YUM (DNF) sono gestori di pacchetti software che gestiscono distribuzioni Linux basate su RPM. Con YUM o DNF, puoi installare e aggiornare gruppi di computer senza dover aggiornare manualmente ogni RPM.

In questo articolo spiegherò come configurare un repository YUM/DNF locale basato sul Web su Red Hat Enterprise Linux (RHEL) 8, utilizzando il DVD di installazione o il file ISO. Ti mostrerò anche come trovare e installare pacchetti software su macchine client RHEL 8 utilizzando il server HTTP Nginx e i server Web Apache. Per le istruzioni di Apache, vedere Creare il proprio repository YUM/DNF basato su Apache su Red Hat Enterprise Linux 8 e per le istruzioni FTP, vedere Creare il proprio repository YUM/DNF basato su FTP su Red Hat Enterprise Linux 8.

[Vuoi provare Red Hat Enterprise Linux? Scaricalo ora gratuitamente.]

Prerequisiti

Sarà necessario configurare due sistemi Red Hat Enterprise Linux 8:un server repo locale e una macchina client che utilizzerà il repository locale dal server locale. Il risultato sarà simile a questo:

  • Server di repository locale:RHEL 8 [10.0.0.10]

  • Macchina client locale:RHEL 8 [10.0.0.11]

  • DVD di installazione di RHEL 8

  • Server HTTP Nginx

Crea il tuo repository

La creazione del tuo repository prevede una serie di passaggi. Ti guiderò attraverso loro.

Fase 1:monta il supporto Red Hat Enterprise Linux 8

Innanzitutto, monta il supporto locale (il DVD, la chiavetta USB, ecc.) che contiene Red Hat Enterprise Linux 8. Usa il DVD di installazione:

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

Oppure monta l'immagine ISO:

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

Fase 2:crea un repository YUM locale dal supporto montato

Sposta i file repository esistenti che si trovano in /etc/yum.repos.d :

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

Da questo momento, è meglio se continui come utente root. Passa a superutente con su comando.

Quindi, crea una directory per il repository:

# mkdir /local_repo

Usa questa directory con Nginx o Apache per servire i file sulla LAN.

Crea il nuovo file di configurazione del repository locale, local-dvdrom.repo , sotto il /etc/yum.repos.d directory:

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

Fase 3:copia il contenuto multimediale nella directory locale

Copia i file ISO in locale sotto /local_repo directory:

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

Attendi fino a quando i file non vengono copiati, quindi verifica che i file siano stati copiati utilizzando:

# 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

Fase 4:configura il repository YUM/DNF locale

Modifica il file di configurazione del repository che hai creato in precedenza:

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

Incolla questa configurazione al suo interno:

[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

Installa i pacchetti richiesti per creare, configurare e gestire il repository locale:

# 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!

Infine, esegui createrepo comando:

# 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

Passaggio 5:testa e verifica il tuo repository locale

In questo passaggio, ripulisci i file del repository temporaneo e verifica che il repository locale sia abilitato:

# 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

Verifica che il repository locale sia stato creato:

# 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

Puoi vedere che il repository locale ha generato file, quindi a questo punto è tutto a posto.

Se leggi attentamente l'output del comando precedente, viene visualizzato il messaggio di avviso This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register . Se vuoi sopprimere o impedire questo messaggio durante l'esecuzione di dnf o yum comando quindi modifica il file /etc/yum/pluginconf.d/subscription-manager.conf :

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

e cambia il parametro enabled=1 su enabled=0 :

[main]
enabled=0

Configura il tuo server HTTP Nginx

Come accennato in precedenza, questo articolo copre la configurazione del proprio repository utilizzando il server HTTP Nginx. Ti guiderò attraverso l'installazione e la configurazione di Nginx per servire il tuo repository.

Installa Nginx

Per installare il server HTTP Nginx utilizzando 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

Configura Nginx per l'avvio automatico all'avvio

Una volta installato Nginx, avvia e abilita il servizio per l'avvio automatico all'avvio e verifica il suo stato utilizzando i seguenti comandi:

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

Configura il firewall

Successivamente, devi configurare il firewall in modo che sia possibile raggiungere Nginx:

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

Verifica che Nginx sia attivo e funzionante

Ora puoi verificare che il tuo server Nginx sia attivo e funzionante andando su localhost URL sul tuo browser web. La pagina Web predefinita di Nginx http://localhost/ dovrebbe essere visualizzato.

Configura Nginx

Per configurare Nginx, apri il file di configurazione:

# vim /etc/nginx/nginx.conf

Ora trova il server sezione del file e modificarlo in modo che assomigli a questo:

    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 {
        }
    }

Test e pulizia

Ora, avvia nuovamente il servizio Nginx e verifica il suo stato:

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

Tutto bene.

Cambia i permessi e imposta SELinux

Continua la configurazione della sicurezza modificando i permessi su local_repo directory e la configurazione di SELinux. Per modificare i permessi:

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

Quindi, controlla se SELinux sta applicando:

# getenforce
Enforcing

Se è Enforcing , digita:

# chcon -Rt httpd_sys_content_t /local_repo/

Se SELinux non è impostato su Enforcing, i file non verranno pubblicati dal repository.

# setenforce enforcing

E rendi permanente la modifica modificando il file /etc/sysconfig/selinux e impostando il seguente valore:

SELINUX=enforcing

Configura il client

Ora, per configurare il repository della macchina client di Red Hat Enterprise Linux 8.

Aggiungi il repository

Sulla macchina client, aggiungi i repository locali dal server alla configurazione YUM del client:

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

Quindi incolla la seguente configurazione (assicurati di modificare l'indirizzo IP del server in base alla tua configurazione):

[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/)

Testa il repository

Testare il LocalServerRepo installando un pacchetto. Ad esempio:

$ 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!

È grandioso! Tutto funziona come previsto. Ora hai un repository YUM/DNF locale basato su Nginx in Red Hat Enterprise Linux 8, utilizzando il DVD di installazione o il file ISO.


Linux
  1. Come creare un repository Red Hat locale

  2. Crea un repository YUM/DNF basato su FTP su Red Hat Enterprise Linux 8

  3. Crea un repository YUM/DNF basato su Apache su Red Hat Enterprise Linux 8

  4. Creazione di un'immagine Red Hat Enterprise Linux 7 personalizzata per Microsoft Azure

  5. Aspetti da considerare quando si esegue Red Hat Enterprise Linux su Azure

Scarica Red Hat Linux

RHEL 6 – Guida all'installazione del server Red Hat Enterprise Linux passo dopo passo

Red Hat Enterprise Linux (RHEL) 8 passaggi di installazione con schermate

Come installare Red Hat Enterprise Linux 8 (RHEL 8)

Come creare un repository Yum locale per i pacchetti MySQL Enterprise

Modificare la directory principale di Docker su Red Hat Linux?