قالب وردپرس درنا توس
Home / How To / How to install GitBucket with Nginx on Ubuntu 20.04 LTS

How to install GitBucket with Nginx on Ubuntu 20.04 LTS



GitBucket is an open source Git web platform powered by Scala. It provides a Github-like user interface features such as Git storage hotel via HTTP and SSH, problems, wiki, database viewer, and pull requests. It comes with a rich set of features. Some of them are listed below:

  • Intuitive UI
  • Support for GitLFS
  • Support for Public and Private Git Storage Sites
  • Activity Timeline and Emails
  • API Compatibility with GitHub
  • Account and Group Management
  • 1
    9659008] In this tutorial we will explain how to install GitBucket with Nginx on Ubuntu 20.04.

    Prerequisites

    • A server running Ubuntu 20.04 with 2 GB of RAM.
    • A valid domain name pointed to your server. [19659003] A root password is configured on your server.

    Install Java

    GitBucket is based on Java so you need to install it in your system. You can install it with the following command:

      apt-get install default-jdk -y 

    Once installed, verify the Java version with the following command:

      java version 

    You should get the following 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)
    

    When you're done, you can move on to the next step.

    Installing and Configuring GitBucket

    Before you begin, it is a good idea to create separate users and groups to run GitBucket. You can create a new group and user named gitbucket with the following command:

      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

    Then create a new directory for GitBucket with the following command:

      mkdir / opt / gitbucket 

    Next, download the latest version of GitBucket inside the GitBucket directory:

      cd / opt / gitbucket 
    wget https://github.com/gitbucket/gitbucket/releases/download/4.33.0/gitbucket.warebrit19659016 marginNext, change the ownership of the GitBucket

      chown -R gitbucket: gitbucket / opt / gitbucket 

    GitBucket comes with an embedded H2 database. You can create a new database configuration file with the following command:

      nano /opt/gitbucket/database.confebrit19659016achteAdd the following lines: 

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

    Save and close the file when you are done.

    Create Systemd service file for GitBucket

    Then you need to create a systemd service file to manage the GitBucket service. You can create it with the following command:

      nano /etc/systemd/system/gitbucket.service Greece 19659016 achteAdd the following lines:     

      # GitBucket Service
    [Unit]
    Description = Manage Java service
    
    [Service]
    WorkingDirectory = / opt / gitbucket
    ExecStart = / usr / bin / java -Xms128m -Xmx256m -jar gitbucket.war
    User = gitbucket
    The group = gitbucket
    Type = simple
    Restart = on-error
    RestartSec = 10
    
    [Install]
    WantedBy = multi-user.target
    

    Save and close the file when you are done. Then reload the system daemon with the following command:

      systemctl daemon-reload 

    Then start the GitBucket service and enable it after system startup with the following command:

      systemctl start gitbucket 
    systemctl enable gitbucket

    status of the GitBucket service with the following command:

      systemctl status gitbucket 

    You should get the following output:

    ? gitbucket.service - Manage Java service
         Loaded: loaded (/etc/systemd/system/gitbucket.service; enabled; vendor setting: enabled)
         Active: active (running) since Thu 2020-05-14 02:27:13 UTC; Dozens ago
       Main PID: 93029 (java)
          Details: 36 (limit: 2282)
         Memory: 324.9 M
         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, with default settings
    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 - Start ...
    May 14 02:27:20 ubuntu2004 java [93029]: 02: 27: 20.691 [main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start is complete.
    May 14 02:27:20 ubuntu2004 java [93029]: 02: 27: 20.697 [main] WARN slick.util.AsyncExecutor - Having maxConnection> maxTreads 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 - Cannot use class liquibase.parser.core.ya>
    May 14 02:27:22 ubuntu2004 java [93029]: 02: 27: 22.161 [main] INFO l.servicelocator.ServiceLocator - Cannot use class liquibase.parser.core.js>
    

    At this point, GitBucket runs and listens on port 8080.

    Configure Nginx as a reverse proxy

    By default, GitBucket runs on port 8080. So it is a good idea to configure Nginx as a reverse proxy for GitBucket.

    First install Nginx web server with the following command:

      apt-get install nginx-y 

    Then create an Nginx virtual host configuration file for GitBucket: [19659015] nano / etc / nginx / sites-available / gitbucket [19659015] Add the following lines:

      upstream of the guitar bucket {
      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 /;
      }
    }
    

    Save and close the file. Then create a symbolic link to the site-activated directory: Ads

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

    Next, check Nginx for any syntax error with the following command:

      nginx -t 

    You should get the following output:

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

    Finally, restart the Nginx service to implement the changes:

      systemctl restart nginx 

    Secure GitBucket with Let & # 39; s Encrypt

    Then you must install the Certbot client to secure your GitBucket with Let & # 39; s Encrypt SSL.

    First add the Certbot repository with the following command:

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

    Then update the repository and install the Certbot client with the following command: [19659015] apt -get update -y
    apt-get install certbot python3-certbot-nginx -y

    Then run the following command to download and install Let & # 39; s Encrypt SSL for your site:

      certbot - nginx -d gitbucket.linuxbuz.com 

    You will be prompted to enter your email and accept the service:

      Save debug log to /var/log/letsencrypt/letsencrypt.log
    Selected plugins: Authenticator nginx, installer nginx
    Enter Email Address (Used for Emergency Renewal and Security Messages) (Enter & # 39; c & # 39; to
    cancel): [email protected]
    
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Read the terms of use at
    https://letsencrypt.org/documents/LE-SA-v1.2-November-15-2017.pdf. You must
    agree to register on the ACME server at
    https://acme-v02.api.letsencrypt.org/directory
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (A) gree / (C) ancel: A
    
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Should you be willing to share your email address with Electronic Frontier
    Foundation, a founding partner of Let & # 39; s Encrypt project and the nonprofit
    organization developing Certbot? We want to send an e-mail about our work
    web encryption, EFF news, campaigns and ways to support digital freedom.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    (Y) es / (N) o: Y
    Get a new certificate
    Perform the following challenges:
    http-01 challenge for gitbucket.linuxbuz.com
    Waiting for verification ...
    Cleaning of challenges
    Distribute certificates to VirtualHost / etc / nginx / sites-enabled / gitbucket
    

    Then select if you want to redirect HTTP traffic to HTTPS:

      Select whether you want to redirect HTTP traffic to HTTPS or remove HTTP access.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    1: No Redirect - Do not make any further changes to the web server configuration.
    2: Redirect - Makes all requests redirect to secure HTTPS access. Select this for
    new websites, or if you are sure your site is working on HTTPS. You can undo this
    change by editing your web server configuration.
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Select the appropriate number [1-2] and then [enter] (press & # 39; c & # 39; to cancel): 2
    

    Enter 2 and hit Enter to complete the installation. Ads

      Redirect all traffic on port 80 to ssl in / etc / nginx / sites-enabled / gitbucket
    
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    Congratulations! You have enabled https://gitbucket.linuxbuz.com
    
    You should test your configuration on:
    https://www.ssllabs.com/ssltest/analyze.html?d=gitbucket.linuxbuz.com
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    
    IMPORTANT NOTES:
     - Congratulations! Your certificate and chain have been saved to:
       /etc/letsencrypt/live/gitbucket.linuxbuz.com/fullchain.pem
       Your key file has been saved to:
       /etc/letsencrypt/live/gitbucket.linuxbuz.com/privkey.pem
       Your certificate expires 2020-08-12. To get a new or fine tuned
       version of this certificate in the future, simply run certbot again
       with the "certonly" option. Not to interactively renew * everything * off
       your certificates, run "certbot renew"
     - If you like Certbot, you can consider supporting our work by:
    
       Donate to ISRG / Let & # 39; s Encrypt: https://letsencrypt.org/donate
       Donate to EFF: https://eff.org/donate-le
    

    When you're done, you can move on to the next step.

    Accessing GitBucket

    Now open your browser and type the URL https://gitbucket.linuxbuz.com . You will be redirected to the following page:

     GitBucket

    Click Sign in the button. You should see GitBucket's login page:

     GitBucket Login

    Enter GitBucket's default username as root and password as root and click the Sign in button. You should see the GitBucket dashboard on the following page:

     GitBucket dashboard

    Then click Account Settings in the upper right corner to change the default root password:

     Account settings

    Enter a new secure password and click the Save button to update the root password.

     Administrator profile

    Conclusion

    Congratulations! you have successfully installed and secured GitBucket with Nginx as a reverse proxy on Ubuntu 20.04. You can now host your own Git archive with GitBucket.


Source link