Skip to content

实战-Terraform部署GitLab-成功测试

实战:Terraform 部署GitLab(泽阳-博客分享-成功测试)-2022.5.7

image-20220507101128416

目录

[TOC]

实验环境

bash
win10笔记本2台centos7.6虚机(1台用作部署gitlabserver(需要具有docker/terraform环境),一台用作跑gitlabrunner)Terraform版本:v1.1.8docker版本:v20.10.11gitlab版本:gitlab/gitlab-ce:14.9.3-ce.0gitlab-ruuner版本:gitlab-runner-14.9.1-1.x86_64.rpm

实验软件

链接:https:/root/remote-vscode[root@devops remote-vscode]#lsgitlab.tf

image-20220505075932960
  • 先确认本地主机端口是否被占用
bash
[root@devops remote-vscode]#netstat -antlp|grep80[root@devops remote-vscode]#netstat -antlp|grep443[root@devops remote-vscode]#netstat -antlp|grep2222

image-20220505080500941

2.使用terraform部署gitlab

  • 准备好terraform需要用到的配置文件

cat main.tf :

yaml
# 定义provider(main.tf)terraform {required_providers {docker ={source ="kreuzwerker/docker"version ="~>2.13.0"}}}

cat gitlab.tf:

yaml
resource "docker_image""gitlab"{name ="gitlab/gitlab-ce:14.9.3-ce.0"keep_locally =true 
}resource "docker_container""gitlab"{image =docker_image.gitlab.namename ="devops_tutorial_gitlab"ports {#本次课程目前只用到80端口internal =80external =80}ports {internal =443external =443}ports {internal =22external =2222}volumes{container_path ="/etc/gitlab"#gitlab配置文件host_path ="/data/devops4/gitlab/config"}volumes{container_path ="/var/log/gitlab"#gitlab日志文件host_path ="/data/devops4/gitlab/logs"}volumes{container_path ="/var/opt/gitlab"#gitlab数据host_path ="/data/devops4/gitlab/data"}}
  • terraform init
bash
[root@devops remote-vscode]#terraform init

image-20220505080143458

  • terraform plan
bash
[root@devops remote-vscode]#terraform plan

image-20220505080233500

  • terraform apply
bash
[root@devops remote-vscode]#terraform apply

image-20220505082423560

⚠️ 注意:gitlab的镜像很大的,需要2.45GB,因此这里需要等好久,耐心等待即可!(如果实在不行,可先用docker把近线拉取下下来,再执行terraroem命令)

image-20220505100138221

image-20220505100125352

3.验证

  • 查看容器状态
bash
[root@devops remote-vscode]#docker ps

image-20220505095632295

  • 查看gitlab容器日志
bash
[root@devops remote-vscode]#docker logs -f 790a4c992c45

image-20220505095607680

  • 网页验证

登录http:CONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES790a4c992c45gitlab/gitlab-ce:14.9.3-ce.0"/assets/wrapper"12minutesagoUp12minutes(healthy) 0.0.0.0:80->80/tcp,0.0.0.0:443->443/tcp,0.0.0.0:2222->22/tcp devops_tutorial_gitlab[root@devops remote-vscode]#docker exec devops_tutorial_gitlab cat /etc/gitlab/initial_root_password# WARNING:This value is valid only in the following conditions# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`,it was provided before database was seeded for the first time (usually,the first reconfigure run).# 2. Password hasn't been changed manually,either via UI or via command line.## If the password shown here doesn't work,you must reset the admin password following https:Password:cO/jgYrZ1JBxjHxVwCjXbh/a2HxTRMGpuLUfo9XYLJM=# NOTE:This file will be automatically deleted in the first reconfigure run after 24 hours.[root@devops remote-vscode]#

点击头像-Preferences-Passsword,修改密码:

image-20220505100831950

使用修改后的额密码登录gitlab:

image-20220505100959731

image-20220505103358968

结束。😘

注意事项

1.登录gitlab报502错误问题

image-20220507102603453

2.解决容器名解析问题

image-20220505144856493

这边打开后,会出现问题:

image-20220505144826455

有几种解决办法:

1.修改容器里的配置

2.在自己笔记本的hosts里添加域名解析

方法1:修改容器里的配置

bash
[root@devops remote-vscode]#docker psCONTAINERIDIMAGECOMMANDCREATEDSTATUSPORTSNAMES790a4c992c45gitlab/gitlab-ce:14.9.3-ce.0"/assets/wrapper"5hoursagoUp5hours(healthy) 0.0.0.0:80->80/tcp,0.0.0.0:443->443/tcp,0.0.0.0:2222->22/tcp devops_tutorial_gitlab[root@devops remote-vscode]#docker exec -it devops_tutorial_gitlab bashroot@790a4c992c45:/#vim/etc/gitlab/gitlab.rb取消注释这行,并将这里的`GENERATED_EXTERNAL_URL`替换为gitlab所在虚拟机的ip即可:

image-20220505145847977

image-20220505150227098

执行生效命令:

bash
root@790a4c992c45:/#gitlab-ctlreconfigure

这里需要稍等一会儿:

image-20220505150537563

重新配置后,我们再次来验证下效果:

image-20220505150657554

image-20220505150714352

这边可以看到,以上那个问题被解决了。😘

方法2:在自己笔记本的hosts里添加域名解析

bash
#C:\WINDOWS\System32\drivers\etc172.29.9.101790a4c992c45

3.一台虚机是可以同时充当几个runner的

bash
gitlab-runnerregister\--non-interactive\--url"http:--registration-token"9Yni-g-svEdGJqZrs2Vv"\--executor"shell"\--description"buildrunner"\--tag-list"build,k8s,go"\--run-untagged="true"\--locked="false"\--access-level="not_protected"

image-20220505164550813

image-20220507104150260

image-20220507104225875

4.gitlab不能跨大版本升级

例如,你是12版本,你只能先升级到12最新版本,然后再升级到1版本,再升级到13最新版本,再升级到14版本! ---2022.5.5

5.gitlab runnergit版本问题

后续gitlab-ci跑流水线实验时会出问题,因此要升级到2版本以上的!

image-20220507122815955

注意:使用yum remove git后,gitlab-runner会自动被删除的!

image-20220506133220004

image-20220506133201824

因此,升级git版本后,再使用rm -ivh命令安装gitlab-runner时,需要依赖,因此要用yum来安装,但yum安装后是会默认安装老版本git的,因此后面需要先删除/usr/bin/git再执行如下命令ln -s /usr/local/git/bin/git /usr/bin/git即可!

bash
yuminstall-ygitlab-runner-14.9.1-1.x86_64.rpm

关于我

我的博客主旨:

  • 排版美观,语言精炼;
  • 文档即手册,步骤明细,拒绝埋坑,提供源码;
  • 本人实战文档都是亲测成功的,各位小伙伴在实际操作过程中如有什么疑问,可随时联系本人帮您解决问题,让我们一起进步!
  1. 个人微信二维码:x2675263825 (舍得), qq:2675263825。

    image-20211002091450217

  2. 个人微信公众号:《云原生架构师实战》

    image-20211002141739664

  3. 个人csdn

    https:

    版权:此文章版权归 One 所有,如有转载,请注明出处!

    链接:可点击右上角分享此页面复制文章链接

上次更新时间:

最近更新