متقدم
البحث فيأدلة التثبيت
طريقة البحث
  • الصق رسالة الخطأ بين علامتي تنصيص، مثل "permission denied"، لتجد جدول الحل.
  • اختر مجالًا وجزءًا من الدليل (التثبيت، أول الإعدادات، الاستخدام اليومي، الأمان، الحلول) لتصل مباشرة إلى الخطوة الصحيحة.
  • "كلمتان" تجد العبارة بالضبط.
  • الكلمات العادية تجد الأسماء والنصوص والأمثلة.
  • ↑ ↓ للتنقل · Enter للفتح · Esc للإغلاق · / للبحث
جرّب:

الدليل 21GitHub Actions runner · Git and CI/CD

Install and set up a self-hosted GitHub Actions runner

GitHub gives you hosted runners for GitHub Actions, but many teams add self-hosted runners: machines in their own network that can reach private servers, use special hardware or build faster with a warm cache. This guide installs the runner on RHEL or Ubuntu as a service under its own user, gives it labels, uses it from a workflow, and explains the security rules that matter most — a self-hosted runner runs any code that a workflow sends to it.

  • 10 الدروس
  • 13 الأوامر

هذا الجزء لم يُترجم بعد. أنت ترى النص الإنجليزي.

$ مستخدم عادي# بصلاحية root (أو مع sudo)

21.1

Know it before you install

The runner is a small program that connects out to GitHub over HTTPS and asks for jobs. A job runs in the runner's _work folder as the runner's Linux user. You pick the runner in a workflow with runs-on and its labels.

ItemValue
Downloadgithub.com/actions/runner/releases (a .tar.gz for Linux x64 / arm64)
Folderfor example /opt/actions-runner/ (owned by the runner user)
Scriptsconfig.sh (register), run.sh (run in the foreground), svc.sh (install as a service)
Serviceactions.runner.<owner>-<repo>.<name>.service
Job folder/opt/actions-runner/_work/
Logs/opt/actions-runner/_diag/, journalctl -u actions.runner…
Networkoutbound HTTPS (443) to github.com and its API and download hosts; no inbound port

Levels: a runner can belong to one repository, an organization (shared by repos through runner groups) or an enterprise.

21.2

Prepare the machine (RHEL and Ubuntu)

Make a user for the runner (never run it as root), and install Git and tools your jobs need:

useradd -m -d /opt/actions-runner -s /bin/bash ghrunner
dnf -y install git tar curl jq
apt-get update && apt-get install -y git tar curl jq

If jobs build containers, install Docker (see the Docker guide). Adding ghrunner to the docker group makes every job root on this host — use such a runner only for trusted repositories.

21.3

Download and register the runner

In GitHub open Settings → Actions → Runners → New self-hosted runner (repository or organization), choose Linux. GitHub shows the exact commands with the current version and a registration token (valid one hour). As the runner user:

su - ghrunner
VER=2.329.0
curl -fsSL -o actions-runner.tar.gz https://github.com/actions/runner/releases/download/v$VER/actions-runner-linux-x64-$VER.tar.gz
tar -xzf actions-runner.tar.gz
exit
/opt/actions-runner/bin/installdependencies.sh
su - ghrunner
./config.sh --url https://github.com/ORG/REPO --token AAAAXXXXXXXXXXXXXXXXXXXXXXXXX --name build-01 --labels linux,x64,docker --work _work --unattended
√ Connected to GitHub
√ Runner successfully added

Use the version number GitHub shows on that page. installdependencies.sh installs the .NET libraries the runner needs (run it as root once).

21.4

Run it as a service

The service starts at boot and runs as ghrunner:

cd /opt/actions-runner
./svc.sh install ghrunner
./svc.sh start
./svc.sh status

In GitHub the runner now shows Idle (green).

الأوامر في هذا الدرس

21.5

First configuration: the settings to make first

WhatWhy
Own user, not rootA job can do everything this user can. config.sh refuses root on purpose.
Labels (--labels)Jobs pick the right machine: linux, gpu, prod-deploy …
Runner groups (organization)Only chosen repositories may use this runner.
--ephemeral for untrusted workThe runner takes one job and then removes itself — no left-overs between jobs.
A clean-up jobDelete old Docker images and _work folders (cron with docker system prune -af --filter until=72h).
Environment variablesProxy settings and paths go in /opt/actions-runner/.env (one KEY=value per line).

في العمل

For many runners, use Actions Runner Controller (ARC) in Kubernetes: every job gets a fresh runner Pod that disappears after the job.

الأوامر في هذا الدرس

21.6

Use it in a workflow

.github/workflows/ci.yml
name: ci
on:
  push:
    branches: [main]
  pull_request:
 
permissions:
  contents: read
 
jobs:
  test:
    runs-on: [self-hosted, linux, x64]
    steps:
      - uses: actions/checkout@v5
      - run: make test
  deploy:
    needs: test
    if: github.ref == 'refs/heads/main'
    runs-on: [self-hosted, linux, prod-deploy]
    environment: production
    steps:
      - uses: actions/checkout@v5
      - run: ./deploy.sh

A job needs a runner with all the labels in runs-on. The environment: production line lets you require a reviewer before the deploy job starts.

Daily commands on the runner machine:

cd /opt/actions-runner && ./svc.sh status
journalctl -u 'actions.runner.*' -f
ls /opt/actions-runner/_diag/
du -sh /opt/actions-runner/_work

Real uses at work:

  • Deploy to servers in a private network (no public SSH needed).
  • Fast builds with a warm cache, big CPUs, GPUs or ARM machines.
  • Run tests that need internal databases or services.

21.7

Make it safe

Security checklist:

  • Never use self-hosted runners for public repositories: anyone can open a pull request whose workflow runs code on your machine.
  • Ephemeral runners (or ARC) for jobs from pull requests; long-lived runners only for trusted branches.
  • Runner groups: limit which repositories and workflows may use a runner.
  • permissions: in every workflow as small as possible; secrets only in environments with reviewers.
  • Use OIDC to get cloud access (no long-lived keys on the runner).
  • No secrets left on disk; separate runners for production deploys.
  • Update the runner (it updates itself by default — do not turn that off) and the OS.

21.8

Update and remove

The runner updates itself when GitHub releases a new version. To remove it, get a removal token from the runner's page in GitHub, then:

cd /opt/actions-runner
./svc.sh stop
./svc.sh uninstall
su - ghrunner -c './config.sh remove --token AAAAXXXXXXXXXXXXXXXXXXXXXXXXX'
userdel -r ghrunner

21.9

Fix common problems

ProblemCauseFix
Job waits: "Waiting for a runner to pick up this job"No online runner has all the labels in runs-on.Compare labels; check the runner is Idle; check the runner group allows the repo.
Must not run with sudoconfig.sh was started as root.Run it as the runner user.
Http response code: NotFound from 'POST …' at configThe token expired (1 hour) or the URL is wrong.Get a new token; use the repo or org URL.
Runner shows OfflineService stopped, or no outbound HTTPS../svc.sh status; curl -I https://api.github.com.
Got permission denied while trying to connect to the Docker daemon socketThe runner user is not in the docker group.Add it (root risk!) or use rootless Podman/Buildah.
Disk fullOld work folders and images.Clean _work and Docker; use ephemeral runners.
Job fails with "command not found"The tool is not installed on the runner.Install it, or use container: / a setup action.

21.10

Next steps

1Why must a self-hosted runner never serve a public repository?

Anyone can open a pull request with a workflow that runs their code on your machine.

2What does --ephemeral do?

The runner takes one job and then removes itself, so nothing is left for the next job.

الأوامر في هذا الدرس

كل الأوامر في هذا الفصل