How to Install Gitea Git Service on Ubuntu 18.04

Requirements

Launch Alibaba Cloud ECS Instance

apt-get update -y

Getting Started

apt-get install nginx mariadb-server git -y

Configure Database for Gitea

mysql_secure_installation
Enter current password for root (enter for none):
Set root password? [Y/n]: N
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y
mysql -u root -p
MariaDB [(none)]>SET GLOBAL innodb_file_per_table = ON;
MariaDB [(none)]>CREATE DATABASE gitea;
MariaDB [(none)]>CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'gitea';
MariaDB [(none)]>GRANT ALL ON gitea.* TO 'gitea'@'localhost' IDENTIFIED BY 'gitea' WITH GRANT OPTION;
MariaDB [(none)]>ALTER DATABASE gitea CHARACTER SET = utf8mb4 COLLATE utf8mb4_unicode_ci;
MariaDB [(none)]>FLUSH PRIVILEGES;
MariaDB [(none)]>EXIT;
nano /etc/mysql/mariadb.conf.d/50-server.cnf
innodb_file_format = Barracuda
innodb_large_prefix = 1
innodb_default_row_format = dynamic
systemctl restart mariadb

Install and Configure Gitea

wget https://github.com/go-gitea/gitea/releases/download/v1.5.1/gitea-1.5.1-linux-amd64
cp gitea-1.5.1-linux-amd64 /usr/local/bin/gitea
chmod 755 /usr/local/bin/gitea
adduser --system --shell /bin/bash --group  --disabled-password --home /home/gitea gitea
mkdir -p /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
chown gitea:gitea /etc/gitea /var/lib/gitea/{custom,data,indexers,public,log}
chmod 750 /var/lib/gitea/{data,indexers,log}
chmod 770 /etc/gitea

Create Systemd Service file for Gitea

nano /etc/systemd/system/gitea.service
[Unit]
Description=Gitea
After=syslog.target
After=network.target
After=mysql.service
[Service]
RestartSec=2s
Type=simple
User=root
Group=root
WorkingDirectory=/var/lib/gitea/
ExecStart=/usr/local/bin/gitea web -c /etc/gitea/app.ini
Restart=always
Environment=USER=root HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
[Install]
WantedBy=multi-user.target
systemctl start gitea
systemctl status gitea
¡ñ gitea.service - Gitea
Loaded: loaded (/etc/systemd/system/gitea.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2019-01-18 10:32:28 UTC; 5min ago
Main PID: 7015 (gitea)
Tasks: 8 (limit: 1114)
CGroup: /system.slice/gitea.service
©ž©€7015 /usr/local/bin/gitea web -c /etc/gitea/app.ini
Jan 18 10:32:28 ubuntu1804 systemd[1]: gitea.service: Service hold-off time over, scheduling restart.
Jan 18 10:32:28 ubuntu1804 systemd[1]: gitea.service: Scheduled restart job, restart counter is at 972.
Jan 18 10:32:28 ubuntu1804 systemd[1]: Stopped Gitea (Git with a cup of tea).
Jan 18 10:32:28 ubuntu1804 systemd[1]: Started Gitea (Git with a cup of tea).
Jan 18 10:32:28 ubuntu1804 gitea[7015]: 2019/01/18 10:32:28 [T] AppPath: /usr/local/bin/gitea
Jan 18 10:32:28 ubuntu1804 gitea[7015]: 2019/01/18 10:32:28 [T] AppWorkPath: /var/lib/gitea
Jan 18 10:32:28 ubuntu1804 gitea[7015]: 2019/01/18 10:32:28 [T] Custom path: /var/lib/gitea/custom
Jan 18 10:32:28 ubuntu1804 gitea[7015]: 2019/01/18 10:32:28 [T] Log path: /usr/local/bin/log
Jan 18 10:32:28 ubuntu1804 gitea[7015]: 2019/01/18 10:32:28 Serving [::]:3000 with pid 7015
systemctl enable gitea

Configure Nginx as a reverse proxy

rm /etc/nginx/sites-enabled/defaultnano /etc/nginx/sites-available/gitea
upstream gitea {
server 127.0.0.1:3000;
}
server {
listen 80 default_server;
listen [::]:80 default_server;
server_name 192.168.0.11;
root /var/lib/gitea/public;
access_log off;
error_log off;
location / {
try_files maintain.html $uri $uri/index.html @node;
}
location @node {
client_max_body_size 0;
proxy_pass http://localhost:3000;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header Host $http_host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_max_temp_file_size 0;
proxy_redirect off;
proxy_read_timeout 120;
}
}
ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
systemctl restart nginx
systemctl status nginx
¡ñ nginx.service - A high performance web server and a reverse proxy server
Loaded: loaded (/lib/systemd/system/nginx.service; enabled; vendor preset: enabled)
Active: active (running) since Sat 2019-01-19 04:40:31 UTC; 2min 6s ago
Docs: man:nginx(8)
Process: 3609 ExecReload=/usr/sbin/nginx -g daemon on; master_process on; -s reload (code=exited, status=0/SUCCESS)
Process: 3543 ExecStart=/usr/sbin/nginx -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Process: 3524 ExecStartPre=/usr/sbin/nginx -t -q -g daemon on; master_process on; (code=exited, status=0/SUCCESS)
Main PID: 3547 (nginx)
Tasks: 2 (limit: 1114)
CGroup: /system.slice/nginx.service
©À©€3547 nginx: master process /usr/sbin/nginx -g daemon on; master_process on;
©ž©€3610 nginx: worker process
Jan 19 04:40:30 ubuntu1804 systemd[1]: Starting A high performance web server and a reverse proxy server...
Jan 19 04:40:31 ubuntu1804 systemd[1]: nginx.service: Failed to parse PID from file /run/nginx.pid: Invalid argument
Jan 19 04:40:31 ubuntu1804 systemd[1]: Started A high performance web server and a reverse proxy server.
Jan 19 04:42:23 ubuntu1804 systemd[1]: Reloading A high performance web server and a reverse proxy server.
Jan 19 04:42:23 ubuntu1804 systemd[1]: Reloaded A high performance web server and a reverse proxy server.

Access Gitea Web Interface

Test Gitea

git config --global user.name "gitadmin"
git config --global user.email "hitjethva@gmail.com"
git clone http://192.168.0.11/gitadmin/devrepo.git
Cloning into 'devrepo'...
Username for 'http://192.168.0.11': gitadmin
Password for 'http://gitadmin@192.168.0.11':
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.
Checking connectivity... done.
cd devrepo/
touch test1 test2
git add .
git commit -m "Added two test file"
[master 9c31dbb] Added two test file
2 files changed, 0 insertions(+), 0 deletions(-)
create mode 100644 test1
create mode 100644 test2
git push origin master
Username for 'http://192.168.0.11': gitadmin
Password for 'http://gitadmin@192.168.0.11':
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 282 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.0.11/gitadmin/devrepo.git
224f30c..9c31dbb master -> master

Original Source

--

--

--

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

AWS Secrets Manager with Spring Boot

The Easiest Way You Can Learn JavaScript

GoDaddy redirect traffic without www. prefix to with www. prefix

Deploying Cross-AZ Windows Server Failover Clustering (WSFC) in Alibaba Cloud

Insight into the Future of Cloud Native: CNCF x Alibaba Cloud Native Technology Course

Zero to Hero: Set Up Your Mac for Software Development

Little boy with a cape, ready to become a code hero.

Building Event-driven Architectures with WSO2 Integration Platform — Part 1

How to manually exploit SQL Injection?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com

More from Medium

How to use Redis TimeSeries

We are in the era of API, and our services are exposed in APIs.

Null values in PostgreSQL

Query Laning in Apache Druid