参考内容
一、服务器准备
准备两台服务器,配置要求4核8G,CentOS7系统,分别用于搭建gitlab核gitlab-runner。
二 、安装docker
1、安装yum-utils工具
yum install yum-utils
2、配置yum docker-ce仓库
yum-config-manager --add-repo http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
3、刷新yum仓库缓存
yum makecache fast
4、安装docker-ce
yum install docker-ce -y
5、启动docker和设置docker自启动
systemctl enable docker
systemctl start docker
6、使用hello-world镜像测试docker是否成功安装
docker run hello-world
三、安装docker compose
1、执行命令下载和授权docker-compose
sudo curl -L https://github.com/docker/compose/releases/download/1.25.5/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose && sudo chmod +x /usr/local/bin/docker-compose
执行docker-compose命令检查是否安装成功。如输出docker-compose的帮助文档,说明安装成功
四、安装gitlab
1、下载gitlab镜像
docker pull registry.cn-shenzhen.aliyuncs.com/dotnet-vincent/gitlab:latest
2、在当前目录新建文件docker-compose.yml,写入以下内容(把脚本中的ip替换掉)
web:
image: 'gitlab/gitlab-ce:latest'
restart: always
hostname: 'centos 7 在局域网的ip'
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://centos 7 在局域网的ip'
# Add any other gitlab.rb configuration here, each on its own line
gitlab_rails['gitlab_ssh_host'] = 'centos 7 在局域网的ip'
gitlab_rails['gitlab_shell_ssh_port'] = 26013
ports:
- '80:80'
- '443:443'
- '26013:22'
volumes:
- '$GITLAB_HOME/config:/etc/gitlab'
- '$GITLAB_HOME/logs:/var/log/gitlab'
- '$GITLAB_HOME/data:/var/opt/gitlab'
3、设置gitlab数据存放路径
export GITLAB_HOME=/srv/gitlab
4、授权执行权限给文件
chmod +x docker-compose.yml
5、启动容器
docker-compose up -d
6、查看docker容器
docker ps
7、查看gitlab密码
sudo docker exec -it 343beeb645c2 grep ‘Password:’ /etc/gitlab/initial_root_password(把id换成上一步查的CONTAINER ID)
8、关闭防火墙
参考关闭防火墙
9、登录gitlab
浏览器输入ip地址,端口号80
10、将gitlab设置为中文
五、安装gitlab-runner
1、添加gitlab官方库
curl -L https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.rpm.sh | sudo bash
2、执行安装命令
yum install gitlab-runner
3、注册gitlab-runner
gitlab-runner register
Enter the GitLab instance URL (for example, https://gitlab.com/):
输入下图位置中的地址
Enter the registration token:
输入下图中的令牌
Enter a description for the runner:
输入runner描述
Enter tags for the runner (comma-separated):
输入标签,输入什么标签就会根据标签执行流水线
Enter an executor: parallels, kubernetes, docker, docker-ssh, ssh, virtualbox, docker+machine, docker-ssh+machine, custom, shell:
输入用什么来构建镜像,我这里用的是docker
Please enter the default Docker image (e.g. ruby:2.6):
输入用什么docker镜像来构建
4、如果报错:Cannot connect to the Docker daemon at tcp://docker:2375. Is the docker daemon running?
打开config.tom配置文件,我这里在/etc/gitlab-runner目录下,修改volumes 如下
volumes = ["/cache","/usr/bin/docker:/usr/bin/docker","/var/run/docker.sock:/var/run/docker.sock"]
然后重启gitlab-runner服务即可:
gitlab-runner restart
如果还有奇奇怪怪的问题,就执行
sudo gitlab-runner run