Instalasi Gitea
Pengenalan
Gitea adalah Git service self-hosted yang ringan dan mudah digunakan. Ditulis dalam bahasa Go, Gitea dapat berjalan di berbagai platform dengan resource minimal. Gitea menyediakan fitur lengkap seperti GitHub, termasuk Gitea Actions untuk CI/CD.
Keuntungan Gitea
- 🚀 Lightweight: Resource requirement minimal
- 🔧 Easy to Install: Single binary, mudah di-deploy
- 🔒 Self-hosted: Full control atas data dan infrastruktur
- 💰 Cost-effective: Open source, gratis
- ⚡ Fast: Performance yang sangat baik
- 🔄 CI/CD Built-in: Gitea Actions terintegrasi
- 🌍 Cross-platform: Support Linux, Windows, macOS
System Requirements
Minimum Requirements
- CPU: 1 core
- RAM: 512 MB
- Storage: 5 GB
- OS: Linux, Windows, macOS
- Database: SQLite (built-in), MySQL, PostgreSQL, MSSQL
Recommended for Production
- CPU: 2-4 cores
- RAM: 2-4 GB
- Storage: 50+ GB (tergantung jumlah repositories)
- OS: Linux (Ubuntu 20.04+, Debian 11+, CentOS 8+)
- Database: PostgreSQL atau MySQL
- Reverse Proxy: Nginx atau Caddy
Metode Instalasi
Ada beberapa cara menginstall Gitea:
- Binary Installation (Recommended) - Mudah dan cepat
- Docker - Portable dan isolated
- Docker Compose - Multi-container setup
- Package Manager - Dari distribution repository
- From Source - Untuk development
Method 1: Binary Installation
Persiapan
1. Update System
# Ubuntu/Debian
sudo apt update && sudo apt upgrade -y
# CentOS/RHEL
sudo yum update -y
2. Install Dependencies
# Ubuntu/Debian
sudo apt install -y git wget curl
# CentOS/RHEL
sudo yum install -y git wget curl
3. Create User
# Buat user dedicated untuk Gitea
sudo adduser \
--system \
--shell /bin/bash \
--gecos 'Git Version Control' \
--group \
--disabled-password \
--home /home/git \
git
4. Create Directory Structure
# Buat directories
sudo mkdir -p /var/lib/gitea/{custom,data,log}
sudo mkdir -p /etc/gitea
sudo mkdir -p /var/log/gitea
# Set ownership
sudo chown -R git:git /var/lib/gitea
sudo chown -R git:git /etc/gitea
sudo chown -R git:git /var/log/gitea
# Set permissions
sudo chmod -R 750 /var/lib/gitea
sudo chmod 770 /etc/gitea
Download dan Install Gitea
1. Download Binary
# Cek latest version di https://github.com/go-gitea/gitea/releases
# Contoh untuk version 1.21.0, architecture amd64
GITEA_VERSION="1.21.0"
ARCH="linux-amd64"
# Download
wget -O /tmp/gitea https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-${ARCH}
# Atau download latest
# wget -O /tmp/gitea https://dl.gitea.com/gitea/main/gitea-main-linux-amd64
2. Install Binary
# Verify download (optional)
wget -O /tmp/gitea.asc https://dl.gitea.com/gitea/${GITEA_VERSION}/gitea-${GITEA_VERSION}-${ARCH}.asc
gpg --keyserver keys.openpgp.org --recv 7C9E68152594688862D62AF62D9AE806EC1592E2
gpg --verify /tmp/gitea.asc /tmp/gitea
# Install binary
sudo mv /tmp/gitea /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea
# Verify installation
gitea --version
Setup Database
Option 1: SQLite (Untuk Development/Testing)
# SQLite sudah built-in, tidak perlu instalasi tambahan
# Gitea akan create database file otomatis
Option 2: PostgreSQL (Recommended untuk Production)
# Install PostgreSQL
sudo apt install -y postgresql postgresql-contrib
# Start service
sudo systemctl start postgresql
sudo systemctl enable postgresql
# Create database dan user
sudo -u postgres psql << EOF
CREATE USER gitea WITH PASSWORD 'your_secure_password';
CREATE DATABASE giteadb WITH OWNER gitea TEMPLATE template0 ENCODING UTF8 LC_COLLATE 'en_US.UTF-8' LC_CTYPE 'en_US.UTF-8';
GRANT ALL PRIVILEGES ON DATABASE giteadb TO gitea;
EOF
Option 3: MySQL/MariaDB
# Install MySQL
sudo apt install -y mysql-server
# Secure installation
sudo mysql_secure_installation
# Create database dan user
sudo mysql << EOF
CREATE DATABASE giteadb CHARACTER SET 'utf8mb4' COLLATE 'utf8mb4_unicode_ci';
CREATE USER 'gitea'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON giteadb.* TO 'gitea'@'localhost';
FLUSH PRIVILEGES;
EOF
Setup Systemd Service
1. Create Service File
sudo nano /etc/systemd/system/gitea.service
2. Paste Configuration
[Unit]
Description=Gitea (Git with a cup of tea)
After=syslog.target
After=network.target
After=postgresql.service # Atau mysql.service jika menggunakan MySQL
[Service]
# Modify these two values and uncomment them if you have
# repos with lots of files and get an HTTP error 500 because
# of that
###
#LimitMEMLOCK=infinity
#LimitNOFILE=65535
RestartSec=2s
Type=notify
User=git
Group=git
WorkingDirectory=/var/lib/gitea/
# If using Unix socket: tells systemd to create the /run/gitea folder
RuntimeDirectory=gitea
ExecStart=/usr/local/bin/gitea web --config /etc/gitea/app.ini
Restart=always
Environment=USER=git HOME=/home/git GITEA_WORK_DIR=/var/lib/gitea
# Security settings
NoNewPrivileges=true
PrivateTmp=true
PrivateDevices=true
ProtectHome=true
ProtectSystem=strict
ReadWritePaths=/var/lib/gitea /etc/gitea /var/log/gitea
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
AmbientCapabilities=CAP_NET_BIND_SERVICE
[Install]
WantedBy=multi-user.target
3. Enable dan Start Service
# Reload systemd
sudo systemctl daemon-reload
# Enable service (auto-start on boot)
sudo systemctl enable gitea
# Start service
sudo systemctl start gitea
# Check status
sudo systemctl status gitea
4. Check Logs
# View logs
sudo journalctl -u gitea -f
# Atau
sudo tail -f /var/log/gitea/gitea.log
Initial Configuration (Web Installer)
1. Access Web Interface
http://your-server-ip:3000
Anda akan diarahkan ke halaman instalasi.
2. Database Settings
Untuk PostgreSQL:
- Database Type:
PostgreSQL - Host:
localhost:5432 - Username:
gitea - Password:
your_secure_password - Database Name:
giteadb - SSL Mode:
disable(enable untuk production dengan SSL)
Untuk MySQL:
- Database Type:
MySQL - Host:
localhost:3306 - Username:
gitea - Password:
your_secure_password - Database Name:
giteadb
Untuk SQLite:
- Database Type:
SQLite3 - Path:
/var/lib/gitea/data/gitea.db
3. General Settings
Site Title: Gitea: Git with a cup of tea
Repository Root Path: /var/lib/gitea/data/gitea-repositories
Git LFS Root Path: /var/lib/gitea/data/lfs
Run As Username: git
Server Domain: your-domain.com (atau IP address)
SSH Server Port: 22
HTTP Port: 3000
Application URL: http://your-domain.com:3000/
Log Path: /var/log/gitea
4. Email Settings (Optional)
SMTP Host: smtp.gmail.com
SMTP Port: 587
From: noreply@your-domain.com
Username: your-email@gmail.com
Password: your-app-password
5. Server and Other Settings
- Enable Local Mode: ✅ (untuk disable external avatars)
- Enable OpenID Sign-In: ⬜
- Enable Self-Registration: ✅ (disable setelah create admin)
- Require Sign-In to View Pages: ⬜ (pilih sesuai kebutuhan)
- Enable CAPTCHA: ✅ (untuk security)
6. Administrator Account
Administrator Username: admin
Password: strong_password_here
Email: admin@your-domain.com
7. Install Gitea
Click Install Gitea button.
Post-Installation Configuration
1. Secure Configuration File
# Setelah instalasi selesai, secure config file
sudo chmod 750 /etc/gitea
sudo chmod 640 /etc/gitea/app.ini
2. Edit app.ini untuk Production Settings
sudo nano /etc/gitea/app.ini
Tambahkan/modifikasi settings berikut:
[server]
DOMAIN = your-domain.com
ROOT_URL = https://your-domain.com/
DISABLE_SSH = false
SSH_PORT = 22
START_SSH_SERVER = false
LFS_START_SERVER = true
OFFLINE_MODE = false
[database]
DB_TYPE = postgres
HOST = localhost:5432
NAME = giteadb
USER = gitea
PASSWD = your_secure_password
SSL_MODE = disable
[security]
INSTALL_LOCK = true
SECRET_KEY = <auto-generated>
INTERNAL_TOKEN = <auto-generated>
PASSWORD_HASH_ALGO = pbkdf2
[service]
DISABLE_REGISTRATION = true
REQUIRE_SIGNIN_VIEW = false
ENABLE_CAPTCHA = true
DEFAULT_KEEP_EMAIL_PRIVATE = true
[actions]
ENABLED = true
[log]
MODE = file
LEVEL = info
ROOT_PATH = /var/log/gitea
[session]
PROVIDER = file
PROVIDER_CONFIG = /var/lib/gitea/data/sessions
[picture]
DISABLE_GRAVATAR = true
ENABLE_FEDERATED_AVATAR = false
[repository]
ROOT = /var/lib/gitea/data/gitea-repositories
SCRIPT_TYPE = bash
DEFAULT_BRANCH = main
3. Restart Gitea
sudo systemctl restart gitea
sudo systemctl status gitea
Method 2: Docker Installation
Using Docker Run
1. Pull Image
docker pull gitea/gitea:latest
2. Create Volumes
# Create directories
mkdir -p ~/gitea/{data,config}
# Set permissions
chmod 750 ~/gitea/data
chmod 770 ~/gitea/config
3. Run Container
docker run -d \
--name gitea \
--restart always \
-p 3000:3000 \
-p 2222:22 \
-v ~/gitea/data:/data \
-v ~/gitea/config:/etc/gitea \
-v /etc/timezone:/etc/timezone:ro \
-v /etc/localtime:/etc/localtime:ro \
-e USER_UID=1000 \
-e USER_GID=1000 \
gitea/gitea:latest
4. Access Web Interface
http://localhost:3000
Using Docker Compose
1. Create docker-compose.yml
mkdir -p ~/gitea
cd ~/gitea
nano docker-compose.yml
2. Paste Configuration
version: "3"
networks:
gitea:
external: false
services:
server:
image: gitea/gitea:latest
container_name: gitea
environment:
- USER_UID=1000
- USER_GID=1000
- GITEA__database__DB_TYPE=postgres
- GITEA__database__HOST=db:5432
- GITEA__database__NAME=gitea
- GITEA__database__USER=gitea
- GITEA__database__PASSWD=gitea
restart: always
networks:
- gitea
volumes:
- ./gitea:/data
- /etc/timezone:/etc/timezone:ro
- /etc/localtime:/etc/localtime:ro
ports:
- "3000:3000"
- "2222:22"
depends_on:
- db
db:
image: postgres:15-alpine
restart: always
environment:
- POSTGRES_USER=gitea
- POSTGRES_PASSWORD=gitea
- POSTGRES_DB=gitea
networks:
- gitea
volumes:
- ./postgres:/var/lib/postgresql/data
ports:
- "5432:5432"
3. Start Services
docker-compose up -d
# Check logs
docker-compose logs -f
# Check status
docker-compose ps
Method 3: Behind Reverse Proxy (Nginx)
Setup Nginx
1. Install Nginx
sudo apt install -y nginx
2. Create Nginx Configuration
sudo nano /etc/nginx/sites-available/gitea
3. Paste Configuration
server {
listen 80;
server_name git.your-domain.com;
# Redirect to HTTPS
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
server_name git.your-domain.com;
# SSL Configuration (akan disetup dengan Certbot)
ssl_certificate /etc/letsencrypt/live/git.your-domain.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/git.your-domain.com/privkey.pem;
# SSL Settings
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
# Logging
access_log /var/log/nginx/gitea_access.log;
error_log /var/log/nginx/gitea_error.log;
# Large file upload support
client_max_body_size 100M;
location / {
proxy_pass http://localhost:3000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
# WebSocket support
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
# Timeouts
proxy_connect_timeout 600;
proxy_send_timeout 600;
proxy_read_timeout 600;
send_timeout 600;
}
}
4. Enable Site
# Enable site
sudo ln -s /etc/nginx/sites-available/gitea /etc/nginx/sites-enabled/
# Test configuration
sudo nginx -t
# Restart Nginx
sudo systemctl restart nginx
5. Setup SSL with Certbot
# Install Certbot
sudo apt install -y certbot python3-certbot-nginx
# Get certificate
sudo certbot --nginx -d git.your-domain.com
# Test auto-renewal
sudo certbot renew --dry-run
6. Update Gitea Configuration
sudo nano /etc/gitea/app.ini
Update:
[server]
DOMAIN = git.your-domain.com
ROOT_URL = https://git.your-domain.com/
HTTP_PORT = 3000
Restart Gitea:
sudo systemctl restart gitea
Verification
Check Service Status
# Systemd service
sudo systemctl status gitea
# Docker
docker ps | grep gitea
# Port listening
sudo netstat -tulpn | grep 3000
Test Access
# Local test
curl http://localhost:3000
# Remote test (replace with your domain/IP)
curl http://your-domain.com:3000
Create Test Repository
- Login ke Gitea web interface
- Click + (New Repository)
- Fill repository details
- Click Create Repository
- Test git operations:
git clone http://your-domain.com:3000/username/test-repo.git
cd test-repo
echo "# Test" > README.md
git add README.md
git commit -m "Initial commit"
git push origin main
Troubleshooting
Port Already in Use
# Check what's using port 3000
sudo lsof -i :3000
# Kill process if needed
sudo kill -9 <PID>
# Or change Gitea port in app.ini
[server]
HTTP_PORT = 3001
Permission Errors
# Fix ownership
sudo chown -R git:git /var/lib/gitea
sudo chown -R git:git /etc/gitea
sudo chown -R git:git /var/log/gitea
# Fix permissions
sudo chmod -R 750 /var/lib/gitea
sudo chmod 770 /etc/gitea
Database Connection Errors
# Test PostgreSQL connection
psql -U gitea -d giteadb -h localhost
# Test MySQL connection
mysql -u gitea -p -h localhost giteadb
# Check database service
sudo systemctl status postgresql
sudo systemctl status mysql
Service Won't Start
# Check detailed logs
sudo journalctl -u gitea -n 50 --no-pager
# Check configuration
gitea doctor check --config /etc/gitea/app.ini
# Test manual start
sudo -u git /usr/local/bin/gitea web --config /etc/gitea/app.ini
Security Best Practices
1. Disable Registration After Setup
[service]
DISABLE_REGISTRATION = true
2. Enable 2FA
- User Settings → Security → Two-Factor Authentication
- Setup with authenticator app
3. Regular Updates
# Backup before update
sudo systemctl stop gitea
sudo cp /usr/local/bin/gitea /usr/local/bin/gitea.backup
sudo cp /etc/gitea/app.ini /etc/gitea/app.ini.backup
# Download new version
wget -O /tmp/gitea https://dl.gitea.com/gitea/latest/gitea-latest-linux-amd64
# Update
sudo mv /tmp/gitea /usr/local/bin/gitea
sudo chmod +x /usr/local/bin/gitea
# Start and verify
sudo systemctl start gitea
gitea --version
4. Firewall Configuration
# UFW
sudo ufw allow 22/tcp
sudo ufw allow 3000/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
# firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --permanent --add-port=3000/tcp
sudo firewall-cmd --reload
5. Backup Strategy
# Create backup script
sudo nano /usr/local/bin/gitea-backup.sh
#!/bin/bash
BACKUP_DIR="/backup/gitea"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
# Backup Gitea data
tar -czf $BACKUP_DIR/gitea-data-$DATE.tar.gz /var/lib/gitea/data
# Backup configuration
cp /etc/gitea/app.ini $BACKUP_DIR/app.ini-$DATE
# Backup database (PostgreSQL)
sudo -u postgres pg_dump giteadb > $BACKUP_DIR/gitea-db-$DATE.sql
# Keep only last 7 days
find $BACKUP_DIR -name "gitea-*" -mtime +7 -delete
echo "Backup completed: $DATE"
# Make executable
sudo chmod +x /usr/local/bin/gitea-backup.sh
# Setup cron for daily backup
sudo crontab -e
# Add line:
0 2 * * * /usr/local/bin/gitea-backup.sh >> /var/log/gitea-backup.log 2>&1
Next Steps
Setelah instalasi berhasil:
- ✅ Penggunaan Gitea - Learn basic operations
- ✅ Setup Gitea Runner - Configure runners
- ✅ CI/CD Overview - Learn CI/CD concepts
- ✅ Workflow Implementation - Create pipelines
Congratulations! Gitea Anda sudah siap digunakan! 🎉