GNU/Linux >> Linux Esercitazione >  >> Ubuntu

Come installare GitBucket con Nginx su Ubuntu 20.04 LTS

GitBucket è una piattaforma web Git open source basata su Scala. Fornisce un'interfaccia utente simile a Github, come l'hosting di repository Git tramite HTTP e SSH, problemi, wiki, visualizzatore di repository e richieste pull. Viene fornito con un ricco set di funzionalità. Alcuni di essi sono elencati di seguito:

  • Interfaccia utente intuitiva
  • Supporto per GitLFS
  • Supporta repository Git pubblici e privati
  • Cronologia delle attività e notifiche e-mail
  • Compatibilità API con GitHub
  • Gestione account e gruppi

In questo tutorial spiegheremo come installare GitBucket con Nginx su Ubuntu 20.04.

Prerequisiti

  • Un server che esegue Ubuntu 20.04 con 2 GB di RAM.
  • Un nome di dominio valido puntato al tuo server.
  • Sul tuo server è configurata una password di root.

Installa Java

GitBucket è basato su Java, quindi dovrai installarlo nel tuo sistema. Puoi installarlo con il seguente comando:

apt-get install default-jdk -y

Una volta installato, verifica la versione Java utilizzando il seguente comando:

java -version

Dovresti ottenere il seguente output:

openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)

Una volta terminato, puoi procedere al passaggio successivo.

Installa e configura GitBucket

Prima di iniziare, è una buona idea creare un utente e un gruppo separati per eseguire GitBucket. Puoi creare un nuovo gruppo e utente chiamato gitbucket con il seguente comando:

groupadd -g 555 gitbucket
useradd -g gitbucket --no-user-group --home-dir /opt/gitbucket --no-create-home --shell /usr/sbin/nologin --system --uid 555 gitbucket

Quindi, crea una nuova directory per GitBucket con il seguente comando:

mkdir /opt/gitbucket

Quindi, scarica l'ultima versione di GitBucket all'interno della directory GitBucket:

cd /opt/gitbucket
wget https://github.com/gitbucket/gitbucket/releases/download/4.33.0/gitbucket.war

Quindi, cambia la proprietà della directory GitBucket:

chown -R gitbucket:gitbucket /opt/gitbucket

GitBucket viene fornito con un database H2 incorporato. Puoi creare un nuovo file di configurazione del database con il seguente comando:

nano /opt/gitbucket/database.conf

Aggiungi le seguenti righe:

db {
  url = "jdbc:h2:${DatabaseHome};MVCC=true"
  user = "sa"
  password = "sa"
}

Salva e chiudi il file quando hai finito.

Crea file di servizio Systemd per GitBucket

Successivamente, dovrai creare un file di servizio systemd per gestire il servizio GitBucket. Puoi crearlo usando il seguente comando:

nano /etc/systemd/system/gitbucket.service

Aggiungi le seguenti righe:

# GitBucket Service
[Unit]
Description=Manage Java service

[Service]
WorkingDirectory=/opt/gitbucket
ExecStart=/usr/bin/java -Xms128m -Xmx256m -jar gitbucket.war
User=gitbucket
Group=gitbucket
Type=simple
Restart=on-failure
RestartSec=10

[Install]
WantedBy=multi-user.target

Salva e chiudi il file quando hai finito. Quindi, ricarica il demone systemd usando il seguente comando:

systemctl daemon-reload

Quindi, avvia il servizio GitBucket e abilitalo all'avvio dopo il riavvio del sistema con il seguente comando:

systemctl start gitbucket
systemctl enable gitbucket

Successivamente, verifica lo stato del servizio GitBucket con il comando seguente:

systemctl status gitbucket

Dovresti ottenere il seguente output:

? gitbucket.service - Manage Java service
     Loaded: loaded (/etc/systemd/system/gitbucket.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2020-05-14 02:27:13 UTC; 10s ago
   Main PID: 93029 (java)
      Tasks: 36 (limit: 2282)
     Memory: 324.9M
     CGroup: /system.slice/gitbucket.service
             ??93029 /usr/bin/java -Xms128m -Xmx256m -jar gitbucket.war

May 14 02:27:19 ubuntu2004 java[93029]: 2020-05-14 02:27:19.868:INFO:oejs.session:main: DefaultSessionIdManager workerName=node0
May 14 02:27:19 ubuntu2004 java[93029]: 2020-05-14 02:27:19.868:INFO:oejs.session:main: No SessionScavenger set, using defaults
May 14 02:27:19 ubuntu2004 java[93029]: 2020-05-14 02:27:19.875:INFO:oejs.session:main: node0 Scavenging every 600000ms
May 14 02:27:20 ubuntu2004 java[93029]: 02:27:20.261 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
May 14 02:27:20 ubuntu2004 java[93029]: 02:27:20.691 [main] INFO  com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
May 14 02:27:20 ubuntu2004 java[93029]: 02:27:20.697 [main] WARN  slick.util.AsyncExecutor - Having maxConnection > maxThreads can result in d>
May 14 02:27:20 ubuntu2004 java[93029]: 02:27:20.721 [main] INFO  g.core.servlet.InitializeListener - Check version
May 14 02:27:20 ubuntu2004 java[93029]: 02:27:20.721 [main] INFO  g.core.servlet.InitializeListener - Start schema update
May 14 02:27:22 ubuntu2004 java[93029]: 02:27:22.156 [main] INFO  l.servicelocator.ServiceLocator - Can not use class liquibase.parser.core.ya>
May 14 02:27:22 ubuntu2004 java[93029]: 02:27:22.161 [main] INFO  l.servicelocator.ServiceLocator - Can not use class liquibase.parser.core.js>

A questo punto, GitBucket è in esecuzione e in ascolto sulla porta 8080.

Configura Nginx come proxy inverso

Per impostazione predefinita, GitBucket è in esecuzione sulla porta 8080. Quindi è una buona idea configurare Nginx come proxy inverso per GitBucket.

Innanzitutto, installa il server web Nginx con il seguente comando:

apt-get install nginx -y

Quindi, crea un file di configurazione dell'host virtuale Nginx per GitBucket:

nano /etc/nginx/sites-available/gitbucket

Aggiungi le seguenti righe:

upstream gitbucket {
  server 127.0.0.1:8080 weight=100 max_fails=5 fail_timeout=5;
}

server {
  listen          80;
  server_name     gitbucket.linuxbuz.com;

  location / {
        proxy_set_header X-Forwarded-Host $host;
        proxy_set_header X-Forwarded-Server $host;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_pass http://gitbucket/;
  }
}

Salva e chiudi il file. Quindi, crea un collegamento simbolico alla directory abilitati ai siti:

ln -s /etc/nginx/sites-available/gitbucket /etc/nginx/sites-enabled/

Quindi, controlla Nginx per eventuali errori di sintassi con il seguente comando:

nginx -t

Dovresti ottenere il seguente output:

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Infine, riavvia il servizio Nginx per implementare le modifiche:

systemctl restart nginx

Proteggi GitBucket con Let's Encrypt

Successivamente, dovrai installare il client Certbot per proteggere il tuo GitBucket con Let's Encrypt SSL.

Innanzitutto, aggiungi il repository Certbot utilizzando il seguente comando:

add-apt-repository ppa:ahasenack/certbot-tlssni01-1875471

Quindi, aggiorna il repository e installa il client Certbot con il seguente comando:

apt-get update -y
apt-get install certbot python3-certbot-nginx -y

Quindi, esegui il comando seguente per scaricare e installare Let's Encrypt SSL per il tuo sito Web:

certbot --nginx -d gitbucket.linuxbuz.com

Ti verrà chiesto di fornire la tua email e di accettare i termini del servizio:

Saving debug log to /var/log/letsencrypt/letsencrypt.log
Plugins selected: Authenticator nginx, Installer nginx
Enter email address (used for urgent renewal and security notices) (Enter 'c' to
cancel): [email protected]

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Please read the Terms of Service at
https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
agree in order to register with the ACME server at
https://acme-v02.api.letsencrypt.org/directory
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(A)gree/(C)ancel: A

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Would you be willing to share your email address with the Electronic Frontier
Foundation, a founding partner of the Let's Encrypt project and the non-profit
organization that develops Certbot? We'd like to send you email about our work
encrypting the web, EFF news, campaigns, and ways to support digital freedom.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
(Y)es/(N)o: Y
Obtaining a new certificate
Performing the following challenges:
http-01 challenge for gitbucket.linuxbuz.com
Waiting for verification...
Cleaning up challenges
Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/gitbucket

Quindi, seleziona se reindirizzare o meno il traffico HTTP su HTTPS:

Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
1: No redirect - Make no further changes to the webserver configuration.
2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for
new sites, or if you're confident your site works on HTTPS. You can undo this
change by editing your web server's configuration.
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2

Digita 2 e premi Invio per completare l'installazione.

Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/gitbucket

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Congratulations! You have successfully enabled https://gitbucket.linuxbuz.com

You should test your configuration at:
https://www.ssllabs.com/ssltest/analyze.html?d=gitbucket.linuxbuz.com
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

IMPORTANT NOTES:
 - Congratulations! Your certificate and chain have been saved at:
   /etc/letsencrypt/live/gitbucket.linuxbuz.com/fullchain.pem
   Your key file has been saved at:
   /etc/letsencrypt/live/gitbucket.linuxbuz.com/privkey.pem
   Your cert will expire on 2020-08-12. To obtain a new or tweaked
   version of this certificate in the future, simply run certbot again
   with the "certonly" option. To non-interactively renew *all* of
   your certificates, run "certbot renew"
 - If you like Certbot, please consider supporting our work by:

   Donating to ISRG / Let's Encrypt:   https://letsencrypt.org/donate
   Donating to EFF:                    https://eff.org/donate-le

Una volta terminato, puoi procedere al passaggio successivo.

Accedi a GitBucket

Ora apri il tuo browser web e digita l'URL https://gitbucket.linuxbuz.com. Verrai reindirizzato alla seguente pagina:

Fai clic su Firma dentro pulsante. Dovresti vedere la pagina di accesso di GitBucket:

Fornisci il nome utente predefinito di GitBucket come root e la password come root e fai clic su Firma dentro pulsante. Dovresti vedere la dashboard di GitBucket nella pagina seguente:

Quindi, fai clic su Account Impostazioni nell'angolo in alto a destra per modificare la password di root predefinita:

Fornisci una nuova password sicura e fai clic su Salva pulsante per aggiornare la password di root.

Conclusione

Congratulazioni! hai installato e protetto con successo GitBucket con Nginx come proxy inverso su Ubuntu 20.04. Ora puoi ospitare il tuo repository Git utilizzando GitBucket.


Ubuntu
  1. Come installare Seafile con Nginx su Ubuntu 20.04 LTS

  2. Come installare MediaWiki con Nginx su Ubuntu 16.04

  3. Come installare Seafile con Nginx su Ubuntu 18.04 LTS

  4. Come installare Nginx con Google PageSpeed ​​su Ubuntu 20.04

  5. Come distribuire Modsecurity con Nginx su Ubuntu 20.04 LTS

Come installare osTicket con Nginx su Ubuntu 18.04 LTS

Come installare phpMyAdmin con Nginx (LEMP) su Ubuntu 18.04 LTS

Come installare Nginx con il modulo Ngx_Pagespeed su Ubuntu 16.04 LTS

Come installare Joomla con Nginx su Ubuntu 18.04 LTS

Come installare phpMyAdmin con Nginx su Ubuntu 18.04 LTS

Come installare phpMyAdmin con Nginx su Ubuntu 20.04 LTS