【gitlab CI/CD实践2】docker安装gitlab-

2020-05-30  本文已影响0人  iamChel

前提:1.服务器能连外网

           2.服务器已经安装好docker-ce

一.安装gitlab

[root@localhost ~]# mkdir -p /opt/gitlab/config /opt/gitlab/logs /opt/gitlab/data

[root@localhost ~]# docker pull gitlab/gitlab-ce:12.9.0-ce.0

[root@localhost ~]# docker run -d  -p 443:443 -p 80:80 -p 222:22 --name gitlab --restart always -v /opt/gitlab/config:/etc/gitlab -v /opt/gitlab/logs:/var/log/gitlab -v /opt/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce:12.9.0-ce.0

[root@localhost config]# docker exec -it gitlab bash

root@416a1bfe8f29:/# vim /etc/gitlab/gitlab.rb

29 external_url 'http://192.168.66.222:80'

1155 nginx['listen_port'] = 80

:wq

root@416a1bfe8f29:/# gitlab-ctl reconfigure

[root@localhost config]# docker restart 416a1bfe8f29

浏览器访问:http://192.168.66.222:80即可登录,首次登录要强制修改密码,否则无法登录,默认登录用户为root


二.安装gitlab-runner

[root@localhost ~]# mkdir -p /opt/gitlab-runner-01/config

[root@localhost ~]# docker pull gitlab/gitlab-runner:v12.6.0

[root@localhost ~]# docker run  -t -id --restart always --name gitlab-runner-01 -v /opt/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:v12.6.0


三.gitlab-runner注册

知识点

GitLabRunner 类型

shared: 运行整个平台项目的作业(gitlab)

group: 运行特定group下的所有项目的作业(group)

specific:运行指定的项目作业(project)

locked: 无法运行项目作业

paused: 不会运行作业

步骤一:去gitlab网页,进入系统设置-> Runners,获取shared类型runnertoken

步骤二:注册

方式1: 启动容器交互式注册

备注:其中有删除线的为URL和token

[root@localhost ~]# docker run --restart always -itd --name gitlab-runner-01 -v /opt/gitlab-runner/config:/etc/gitlab-runner gitlab/gitlab-runner:v12.6.0

[root@localhost ~]# docker exec -it gitlab-runner-01 bash

[root@localhost ~]# gitlab-runner register

Runtime platform                                    arch=amd64 os=linux pid=6 revision=ac8e767a version=12.6.0

Running in system-mode.

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com/):

http://192.168.66.222

Please enter the gitlab-ci token for this runner:oQMz4sA3WgB7LaGSaZvH

Please enter the gitlab-ci description for this runner:

[00e4f023b5ae]: gitlab-runner-01

Please enter the gitlab-ci tags for this runner (comma separated):

buildRegistering runner... succeeded                     runner=4tutaeWW

Please enter the executor: parallels, virtualbox, docker-ssh+machine, kubernetes, docker+machine, custom, docker, docker-ssh, shell, ssh:

Shell

Runner registered successfully. Feel free to start it, but if it's running already the config should be automatically reloaded!

方式二:直接注册

1.自动注册

[root@localhost ~]# docker run -itd --restart always --name gitlab-runner-01 -v /opt/gitlab-runner-01/config:/etc/gitlab-runner gitlab/gitlab-runner:v12.6.0

[root@localhost ~]# docker exec -it gitlab-runner-01 bash

[root@localhost ~]# gitlab-runner register --non-interactive --executor "shell" --url "http://192.168.66.222" --registration-token "oQMz4sA3WgB7LaGSaZvH" --description "gitlab-runner-01" --tag-list "build" --run-untagged="true" --locked="false" --access-level="not_protected"

效果:出现gitlabrunner了

上一篇下一篇

猜你喜欢

热点阅读