ติดตั้ง GitLab CE บน VPS Ubuntu ฟรี

ติดตั้ง GitLab CE บน VPS Ubuntu ฟรี

มิถุนายน 2026 · อ่าน 10 นาที

GitLab Community Edition คือ self-hosted Git platform ที่ให้ทุกอย่างครบในตัว ทั้ง repository, merge request, CI/CD pipeline, issue tracker และ container registry ติดตั้งบน VPS ส่วนตัวทำให้ code ไม่ต้องออกนอกองค์กรและประหยัดค่า subscription เมื่อทีมโตขึ้น

⚠️ ความต้องการ RAM: GitLab CE ต้องการ RAM อย่างน้อย 4 GB (แนะนำ 8 GB) และ CPU 2 cores+ เพราะ service หลายตัวรันพร้อมกัน ควรเลือก VPS spec สูงพอก่อนติดตั้ง

ติดตั้ง GitLab CE ผ่าน Package

sudo apt update
sudo apt install -y curl ca-certificates tzdata perl

# เพิ่ม GitLab repository
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

# ติดตั้งพร้อมตั้ง URL
sudo EXTERNAL_URL="https://gitlab.yourdomain.com" apt install gitlab-ce

Configure GitLab (/etc/gitlab/gitlab.rb)

sudo nano /etc/gitlab/gitlab.rb
# URL หลัก
external_url 'https://gitlab.yourdomain.com'

# SSL อัตโนมัติจาก Let's Encrypt
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['[email protected]']

# Email (ใช้ SMTP)
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.yourdomain.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "yourpassword"
gitlab_rails['smtp_tls'] = false
gitlab_rails['smtp_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'

# จำกัด signup (ถ้าต้องการ)
gitlab_rails['gitlab_signup_enabled'] = false
# Apply config
sudo gitlab-ctl reconfigure

รับ Root Password และเข้า Admin

# root password อยู่ที่นี่ (มีอายุ 24 ชั่วโมง)
sudo cat /etc/gitlab/initial_root_password

# เข้า https://gitlab.yourdomain.com
# user: root
# pass: (จากไฟล์ด้านบน)
# เปลี่ยน password ทันทีหลัง login ครั้งแรก

ตั้ง GitLab Runner (CI/CD)

# ติดตั้ง Runner
curl -sL https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh | sudo bash
sudo apt install gitlab-runner -y

# Register runner
sudo gitlab-runner register
# ใส่ GitLab URL: https://gitlab.yourdomain.com
# ใส่ token จาก Settings > CI/CD > Runners
# เลือก executor: shell หรือ docker

ตั้ง Backup อัตโนมัติ

# Backup ทันที
sudo gitlab-backup create

# ตั้ง cron backup รายวัน
sudo crontab -e
# เพิ่ม:
0 2 * * * /opt/gitlab/bin/gitlab-backup create CRON=1 2>/dev/null

# Backup เก็บที่ /var/opt/gitlab/backups/
ls /var/opt/gitlab/backups/
Tip: GitLab ใช้ /etc/gitlab/gitlab-secrets.json เก็บ encryption keys ต้อง backup ไฟล์นี้แยกจาก backup หลัก เพราะถ้าไม่มีจะ restore ไม่ได้แม้มี backup

สำหรับ VPS ที่ใช้รัน GitLab ต้องการ spec ดีพอสมควร ผู้ให้บริการ VPS อย่าง asiagb.com มีแพ็กเกจ VPS สำหรับทีมพัฒนาโดยเฉพาะ รองรับโหลดสูงพร้อม SSD NVMe ที่ทำให้ GitLab ตอบสนองเร็วแม้มีหลาย CI/CD pipeline รัน


ตรวจสอบว่า GitLab ทำงานถูกต้อง

# ดู service status ทั้งหมด
sudo gitlab-ctl status

# ตรวจ web server
curl -I https://gitlab.yourdomain.com

# ดู logs realtime
sudo gitlab-ctl tail

# ตรวจ health endpoint
curl https://gitlab.yourdomain.com/-/health
Tip: sudo gitlab-rake gitlab:check ตรวจสุขภาพ GitLab ครบทุก component และแนะนำวิธีแก้ถ้ามีปัญหา ควรรันหลังติดตั้งและหลัง upgrade

แก้ปัญหาที่พบบ่อย

Error: "502 Bad Gateway" หลังติดตั้ง

GitLab ยังโหลด service อยู่ รอ 2-3 นาทีหลัง reconfigure แล้วลองใหม่ ถ้าไม่หาย ตรวจ RAM:

free -h
sudo gitlab-ctl status
sudo gitlab-ctl tail puma

SSL Certificate ไม่ออก (Let's Encrypt fail)

Port 80 ต้องเปิดและ DNS ต้องชี้มาที่ VPS ก่อน reconfigure:

sudo ufw allow 80
sudo ufw allow 443
# ตรวจ DNS
dig +short gitlab.yourdomain.com
sudo gitlab-ctl reconfigure

GitLab ช้ามากหลังเปิดตัว

ปกติสำหรับ RAM น้อย ลด worker count ใน gitlab.rb:

# /etc/gitlab/gitlab.rb
puma['worker_processes'] = 2
sidekiq['concurrency'] = 5
sudo gitlab-ctl reconfigure

Push/Pull Git ช้า (SSH)

ตรวจ authorized_keys file permission และ sshd config:

sudo gitlab-rake gitlab:shell:check
ls -la /var/opt/gitlab/.ssh/authorized_keys

คำถามที่พบบ่อย

GitLab CE กับ GitHub ต่างกันอย่างไร?

GitHub คือ cloud service สาธารณะ GitLab CE คือ software ที่ติดตั้งบน server ตัวเอง ข้อดีคือ data อยู่ใน control ตัวเอง ไม่มี limit สำหรับ private repo และ CI/CD ไม่คิด minutes แยก ข้อเสียคือต้องดูแล server เอง

GitLab CE รองรับ Container Registry ไหม?

ได้ GitLab CE มี Container Registry ในตัว เปิดใช้ใน gitlab.rb ด้วย registry_external_url ทีมสามารถ push Docker image ไปเก็บที่ GitLab registry แล้วดึงใช้ใน CI/CD pipeline ได้เลย

Upgrade GitLab CE ทำยังไง?

ทำผ่าน apt ได้เลย แต่ต้อง backup ก่อนเสมอ และ upgrade ทีละ major version ไม่ข้าม:

sudo apt update
sudo apt install gitlab-ce
sudo gitlab-ctl reconfigure