注:此文照搬官方文檔,英語還行的能夠移步官網html
官方文檔-安裝linux
官方文檔-註冊git
官方文檔-命令docker
# Linux x86-64
wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# Linux x86
wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-386
# Linux arm
wget -O /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-arm
複製代碼
chmod +x /usr/local/bin/gitlab-runner
複製代碼
curl -sSL https://get.docker.com/ | sh
複製代碼
useradd --comment 'GitLab Runner' --create-home gitlab-runner --shell /bin/bash
複製代碼
gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
gitlab-runner start
複製代碼
gitlab-runner register
複製代碼
Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
複製代碼
Please enter the gitlab-ci token for this runner
xxx
複製代碼
Please enter the gitlab-ci description for this runner
[hostame] my-runner
複製代碼
Please enter the gitlab-ci tags for this runner (comma separated):
my-tag,another-tag
複製代碼
Please enter the executor: ssh, docker+machine, docker-ssh+machine, kubernetes, docker, parallels, virtualbox, docker-ssh, shell:
shell
複製代碼
走到這裏,其實runner已經註冊完成了,這個時候能夠去gitlab的設置裏選擇CI/CD就能夠看到剛註冊的這個runner了shell
Please enter the Docker image (eg. ruby:2.1):
alpine:latest
複製代碼
後邊我要經過ci/cd把打好的包放在/www目錄下的,可是ci/cd運行時可能會報cp: cannot create directory ‘/www/xxx/xxx’: Permission denied,這是由於ci/cd運行時的用戶是gitlab-runner,而/www目錄是屬於root用戶的,因此咱們要把/www目錄的權限交給gitlab-runnervim
chown -hR gitlab-runner:gitlab-runner /www
複製代碼
若是CI/CD一直處於pending狀態的話,須要上服務器去重啓一下ruby
gitlab-runner restast
複製代碼
若是遇到其餘權限問題解決不了,能夠嘗試修改GitLab Runner的權限跟root保持一致bash
vim /etc/passwd
複製代碼
打開passwd文件後找到gitlab-runner用戶,將服務器
#修改前
gitlab-runner:x:601:601:GitLabRunner:/home/gitlab-runner:/bin/bash 權限組修改成跟root的一致
#修改後
gitlab-runner:x:0:0:GitLabRunner:/home/gitlab-runner:/bin/bash。(root的權限組名爲0)
複製代碼