4

How To Install Gogs Git service on Ubuntu 20.04|18.04

 3 years ago
source link: https://computingforgeeks.com/install-gogs-self-hosted-git-service-on-ubuntu/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
How To Install Gogs Git service on Ubuntu 20.04|18.04
Search

This tutorial will cover all the steps required to Install Gogs self-hosted Git service on Ubuntu 20.04|18.04|16.04 server. Gogs project which is written in Go aims to build a simple, stable and extensible self-hosted Git service with a painless setup process. Gogs is distributed as an independent binary distribution and runs on all platforms that Go supports, including Linux, macOS, Windows, and ARM.

Gogs has excellent performance and is very light. It has very minimal RAM and CPU utilization. A VPS with 1 CPU core and 256MB RAM is enough to start using the service.

Features of Gogs

Gogs self-hosted Git service has the following set of features ( from Git )

  • Activity timeline
  • SMTP/LDAP/Reverse proxy authentication
  • Account/Organization/Repository management
  • Repository Git hooks/deploy keys
  • SSH and HTTP/HTTPS protocols
  • Reverse proxy with sub-path
  • Add/Remove repository collaborators
  • Web editor for repository files and wiki
  • Migrate and mirror repository and its wiki
  • Repository/Organization webhooks (including Slack and Discord)
  • Repository issues pull requests, wiki, and protected branches
  • Two-factor authentication
  • Gravatar and Federated avatar with custom source
  • Jupyter Notebook
  • Administration panel
  • Mail service
  • Supports MySQL, PostgreSQL, SQLite3, MSSQL and TiDB (via MySQL protocol)
  • Multi-language support (29 languages)

Gogs Open Source Components

Gogs components include:

Install Gogs Git service on Ubuntu 20.04|18.04

Follow these steps to have Gogs installed on your Ubuntu server.

Step 1: Install MariaDB Database Server

Gogs requires a MySQL server to store data. We will install MariaDB server using the following commands:

sudo apt update
sudo apt install mariadb-server mariadb

Once the database server has been installed, login to MariaDB console as root user

$ mysql -u root -p

Set global variables below

SET GLOBAL innodb_file_per_table = ON;

Then create gogs database

DROP DATABASE IF EXISTS gogs;
CREATE DATABASE IF NOT EXISTS gogs CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;

Create a dedicated database user to manage gogs database.

$ mysql -u root -p
GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY "StrongPassword";
FLUSH PRIVILEGES;
\q

Step 2: Download Gogs from Github

Check Gogs releases page  https://github.com/gogs/gogs/releases for the latest release.

sudo apt install wget curl vim -y
curl -s https://api.github.com/repos/gogs/gogs/releases/latest | grep browser_download_url | grep '\linux_amd64.tar.gz' | cut -d '"' -f 4 | wget -i -

Extract the downloaded file

tar xvf gogs_*_linux_amd64.tar.gz

Step 3: Configure Gogs self-hosted Git service

Create git user to run gogs service

$ sudo adduser git
Adding user `git' ...
Adding new group `git' (1001) ...
Adding new user `git' (1001) with group `git' ...
Creating home directory `/home/git' ...
Copying files from `/etc/skel' ...
Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully
Changing the user information for git
Enter the new value, or press ENTER for the default
	Full Name []: 
	Room Number []: 
	Work Phone []: 
	Home Phone []: 
	Other []: 
Is the information correct? [Y/n] y

Create logs directory

sudo mkdir /var/log/gogs
sudo chown -R git:git /var/log/gogs/

Copy gogs systemd service file to /etc/systemd/system directory

sudo cp gogs/scripts/systemd/gogs.service /etc/systemd/system

You can edit the file to set customize the settings:

sudo vim /etc/systemd/system/gogs.service

If you have a different service using port,3000 you can set a custom port

ExecStart=/home/git/gogs web -port 3001

Move the gogs directory content inside /home/git

sudo mv gogs /home/git/

Change ownership of /home/git/to user.git

sudo chown -R git:git /home/git/

Reload systemd and start gogs service

sudo systemctl daemon-reload
sudo systemctl start gogs

Enable the service to start on boot

sudo systemctl enable gogs

You can check service status by running

$ systemctl status gogs
● gogs.service - Gogs
     Loaded: loaded (/etc/systemd/system/gogs.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-10-26 23:12:31 UTC; 13s ago
   Main PID: 3404 (gogs)
      Tasks: 8 (limit: 2343)
     Memory: 41.4M
     CGroup: /system.slice/gogs.service
             └─3404 /home/git/gogs/gogs web

Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Log mode: Console (Trace)
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [ INFO] Gogs 0.12.3
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Work directory: /home/git/gogs
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Custom path: /home/git/gogs/custom
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Custom config: /home/git/gogs/custom/conf/app.ini
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Log path: /home/git/gogs/log
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Build time: 2020-10-07 03:03:48 UTC
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [TRACE] Build commit: f0e3cd90f8d7695960eeef2e4e54b2e717302f6c
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [ INFO] Run mode: Development
Oct 26 23:12:31 jmutai-ubuntu-01 gogs[3404]: 2021/10/26 23:12:31 [ INFO] Listen on http://0.0.0.0:3000

Typing command gogs on the terminal as git user should print help page.

$ gogs/gogs
NAME:
   Gogs - A painless self-hosted Git service

USAGE:
   gogs [global options] command [command options] [arguments...]

VERSION:
   0.12.3

COMMANDS:
   web      Start web server
   serv     This command should only be called by SSH shell
   hook     Delegate commands to corresponding Git hooks
   cert     Generate self-signed certificate
   admin    Perform admin operations on command line
   import   Import portable data as local Gogs data
   backup   Backup files and database
   restore  Restore files and database from backup
   help, h  Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version

Step 4: Configure Gogs self-hosted Git service

Open the URL http://serverip:3000/install to finish the installation of Gogs

Set database authentication

The username and password provided should match the ones provided in the Database configuration section. If the database server is on a different host, provide the IP address under the Host section.

Set Application General Settings

Provide application URL, this can be a routable server IP address or domain name that resolves to the IP. The same should be set for SSH.

Disable User self-registration

You can disable User self-registration under “Server and Other Services Settings”. This means the admin user will manually create user accounts.

You can optionally create an admin user account. By default, root user will gain admin access automatically.

When done with the configurations, click the “Install Gogs” button to finish the installation. On a successful installation, you should be logged into Gogs administration console.

Create additional user accounts

To add user accounts, Open Admin Panel at the top right panel

You can then use “Create New Account” link to add a new user to Gogs.

Step: 5 Test Gogs self-hosted Git service

Create a new repository called test-repo

Try cloning the repo

$ git clone http://192.168.18.40:3000/jmutai/test-repo.git
Cloning into 'test-repo'...
Username for 'http://192.168.18.40:3000': jmutai
Password for 'http://[email protected]:3000': <Enter Password>
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (4/4), done

To avoid Password Authentication, add your SSH public key under “Your Profile > SSH keys > Add Key

Provide key name, and paste your SSH public key into the content box.

An ssh git clone should not ask for a password

$ git clone [email protected]:jmutai/test-repo.git
Cloning into 'test-repo'...
Warning: Permanently added '192.168.18.40' (ECDSA) to the list of known hosts.
remote: Counting objects: 4, done.
remote: Compressing objects: 100% (3/3), done.
remote: Total 4 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (4/4), done.

Step 6: Configure Nginx Reverse Proxy

If you would like to access Gogs using a domain name without a port, you need to configure Apache or NGINX reverse proxy

sudo apt install nginx

Create a VirtualHost reverse proxy configuration file

sudo vim /etc/nginx/conf.d/gogs.conf
server {
    listen 80;
    server_name git.example.com;

    location / {
        proxy_pass http://localhost:3000;
    }
}

If using SSL and would like to have http to https redirect, use:

server {
	listen 80;
        server_name  git.example.com;
	location / {
        	rewrite     ^ https://git.example.com$request_uri? permanent;
    }
}

server {
        listen       443 ssl;
        server_name git.example.com;
	ssl_certificate /etc/letsencrypt/live/git.example.com/fullchain.pem;
	ssl_certificate_key /etc/letsencrypt/live/git.example.com/privkey.pem;

        location / {
            proxy_pass http://localhost:3000;
        }
}

Replace git.example.com with your actual domain name. For more reading on Gogs administration and usage, check out the Official Documentation.

Related:


Recommend

  • 135

    简体中文 Visi...

  • 39

    Easy to install Simply run the binary for your platform. Or ship Gogs with

  • 20

    jenkins+gogs实现自动化部署(序) 距离上次博客已经有一年多的时间了,不想给自己找太多的理由,总结一句还是太懒了。去年5月份换了家传统行业的公司,刚来就分配到了一个项目组负责移动端的项目,跟之前的开发模式不太一样,因为是甲方公司...

  • 9

    jenkins+gogs实现Android项目自动化部署(三) 上一篇项目主要介绍了jenkins+gogs实现JavaWeb项目自动化部署,这一篇重点介绍下Android项目的自动部署。另外注意下这一篇主要介绍在宿主机(jenkins安装所在的服务器)上打包,也就是远程打包部署,可能...

  • 21

    jenkins+gogs实现JavaWeb项目自动化部署(二) 上一篇文章主要介绍了jenkins和gogs的安装,这一篇重点介绍如何实现JavaWeb项目的自动化部署。 我们的目标是把war包传到应用服务器上,然后关闭tomcat,再启动tomcat。先看下面我们的打包...

  • 18

    jenkins+gogs实现JavaWeb项目自动化部署(一) 关于jenkins和gogs这两个环境的搭建我这里简单的介绍下,以下均在centos7环境下。 一、jenkins安装 我是拿的这篇博客的

  • 5

    jenkins+gogs实现iOS项目自动化部署(四) 本篇是CI系列的最后一篇,主题是介绍jenkins如何实现iOS项目的自动化部署,在上一篇jenkins+gogs实现Android项目自动化部署(三)...

  • 12
    • server.51cto.com 4 years ago
    • Cache

    用Gogs搭建属于自己的Git服务器

      背景 我们都知道,像码云、GitHub就是一个免费托管开源代码的远程仓库。但是对于公司来说,既不想公开源代码,又舍不得给交保护费,...

  • 3
    • www.lpime.cn 3 years ago
    • Cache

    gogs:恢复某个用户下的仓库

    gogs gogs: 如何恢复repository 进入git的repository目录,将其中某个project mv为其它名字,...

  • 3

    Using a Different System? Setup...

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK