GitLab CI Runner Self-Hosted Installation is a common requirement for VPS administrators. This guide provides practical instructions that you can follow on Ubuntu 22.04/24.04 or Debian 12, though most steps apply to other distributions as well.
Pipeline Configuration
Performance benchmarks show that properly tuned gitlab-ci can handle significantly more concurrent connections than the default configuration. The key improvements come from adjusting worker processes and connection pooling.
# .github/workflows/deploy.yml
name: Deploy to Production
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: |
docker build -t myapp:latest .
- name: Deploy
run: |
ssh deploy@server 'cd /opt/myapp && docker compose pull && docker compose up -d'
Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.
Build and Test Setup
When scaling this setup, consider vertical scaling (adding more RAM/CPU) first, as it's simpler to implement. Horizontal scaling adds complexity but may be necessary for high-traffic applications.
# Set up deployment pipeline
mkdir -p /opt/myapp
cd /opt/myapp
# Create deployment script
cat << 'EOF' > deploy.sh
#!/bin/bash
set -euo pipefail
echo "Deploying version: $1"
docker pull myapp:$1
docker compose down
DOCKER_TAG=$1 docker compose up -d
echo "Deployment complete"
EOF
chmod +x deploy.sh
Make sure to restart the service after applying these changes. Some settings require a full restart rather than a reload to take effect.
- Enable automatic security updates for critical patches
- Review log files weekly for anomalies
- Test your backup restore procedure monthly
- Keep your system packages updated regularly
Deployment Automation
Security should be a primary consideration when configuring gitlab-ci. Always use strong passwords, keep software updated, and restrict network access to only the necessary ports and IP addresses.
# .github/workflows/deploy.yml
name: Deploy to Production
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Build
run: |
docker build -t myapp:latest .
- name: Deploy
run: |
ssh deploy@server 'cd /opt/myapp && docker compose pull && docker compose up -d'
Note that file paths may vary depending on your Linux distribution. The examples here are for Debian/Ubuntu; adjust paths accordingly for RHEL/CentOS-based systems.
Common Issues and Solutions
- Permission denied errors: Ensure files and directories have the correct ownership. Use
chown -Rto fix ownership andchmodfor permissions. - High memory usage: Review the configuration for memory-related settings. Reduce worker counts or buffer sizes if running on a low-RAM VPS.
- Slow performance: Check for disk I/O bottlenecks with
iostat -x 1and network issues withmtr. Review application logs for slow queries or requests.
Wrapping Up
Following this guide, your gitlab-ci setup should be production-ready. Keep an eye on resource usage as your traffic grows and don't forget to test your backup and recovery procedures periodically.