一、安装docker
1.更新系统
dnf update
shell
# 最后出现这个标识就说明更新系统成功
Complete!
2.添加docker源
dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
shell
# 最后出现这个标识就说明添加成功
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo
3.安装docker,并允许卸载已经安装的软件(建议不加,避免出现卸载其他软件所需的依赖,而导致其他软件使用异常)
yum install -y docker-ce --allowerasing
shell
# 最后出现这个标识就说明安装成功
Complete!
4.启动 Docker
systemctl start docker
5.查看 Docker 启动状态
systemctl status docker
active说明docker已经启动。
shell
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor preset: disabled)
Active: active (running) since Sun 2024-04-21 06:37:45 EDT; 51s ago
Docs: https://docs.docker.com
Main PID: 88635 (dockerd)
Tasks: 9
Memory: 34.3M
CGroup: /system.slice/docker.service
└─88635 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Apr 21 06:37:45 node-05 systemd[1]: Starting Docker Application Container Engine...
Apr 21 06:37:45 node-05 dockerd[88635]: time="2024-04-21T06:37:45.248538814-04:00" level=info msg="Starting up"
Apr 21 06:37:45 node-05 dockerd[88635]: time="2024-04-21T06:37:45.306599084-04:00" level=info msg="Loading containers: start."
Apr 21 06:37:45 node-05 dockerd[88635]: time="2024-04-21T06:37:45.753676236-04:00" level=info msg="Loading containers: done."
6.设置 Docker 开机自启
systemctl enable docker
二、安装GitLab
1.查找GitLab
docker search gitlab
2.拉取gitlab镜像
docker pull gitlab/gitlab-ce:latest
如果查找的镜像没有自己想要的,直接使用拉取gitlab/gitlab-ce:latest
这个官方最新镜像。
shell
# 看到一下信息,说明镜像拉取成功,也可以通过docker images查看拉取的镜像,如果能看到gitlab/gitlab-ce镜像,说明拉取成功
latest: Pulling from gitlab/gitlab-ce
7021d1b70935: Pull complete
84ce88366b95: Pull complete
e1c92fb77de1: Pull complete
719e91a15767: Pull complete
d680b9b016aa: Pull complete
f0027cb8bf12: Pull complete
8090ecb94c61: Pull complete
2d67bfd969b5: Pull complete
216d686bfe05: Pull complete
Digest: sha256:7c1182ba8d3f30fb82a4c1d2fcc4da35e23929775564642a2310941bc92de1a7
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest
3.启动gitlab
注意先使用一下命令创建挂载卷目录:mkdir -p ./software/gitlab/{logs,data,config},这样就可以不用进入容易查看gitlab的一些目录。
docker run -d \
--hostname gitlab.orkasgb.com \
-p 8443:443 -p 8090:80 -p 8022:22 \
--restart always --name gitlab \
-v /orkasgb/software/gitlab/config:/etc/gitlab \
-v /orkasgb/software/gitlab/log:/var/log/gitlab \
-v /orkasgb/software/gitlab/data:/var/opt/gitlab \
--privileged=true gitlab/gitlab-ce \
参数解释:
-d #后台运行,全称:detach
-p 8443:443 #将容器内部端口向外映射,全称:publish
-p 8090:80 #将容器内80端口映射至宿主机8090端口,这是访问gitlab的端口,全称:publish
-p 8022:22 #将容器内22端口映射至宿主机8022端口,这是访问ssh的端口,全称:publish
--restart always #容器自启动
--name gitlab #设置容器名称为gitlab
-v /orkasgb/software/gitlab/config:/etc/gitlab #将容器/etc/gitlab目录挂载到宿主机/usr/local/gitlab/etc目录下,若宿主机内此目录不存在将会自动创建
-v /orkasgb/software/gitlab/log:/var/log/gitlab #与上面一样
-v /orkasgb/software/gitlab/data:/var/opt/gitlab #与上面一样
--privileged=true #让容器获取宿主机root权限
gitlab/gitlab-ce #镜像的名称,这里也可以写镜像ID
4.查看启动日志
docker logs gitlab
shell
- acme (4.1.6)
# 如果没有明显错误,说明启动正常
Installing cookbook gem dependencies:
Compiling cookbooks...
/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/selinux_distro_helper.rb:2: warning: already initialized constant SELinuxDistroHelper::REDHAT_RELEASE_FILE
/opt/gitlab/embedded/cookbooks/package/libraries/helpers/selinux_distro_helper.rb:2: warning: previous definition of REDHAT_RELEASE_FILE was here
/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/selinux_distro_helper.rb:3: warning: already initialized constant SELinuxDistroHelper::OS_RELEASE_FILE
/opt/gitlab/embedded/cookbooks/package/libraries/helpers/selinux_distro_helper.rb:3: warning: previous definition of OS_RELEASE_FILE was here
/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/secrets_helper.rb:4: warning: already initialized constant SecretsHelper::SECRETS_FILE
/opt/gitlab/embedded/cookbooks/package/libraries/helpers/secrets_helper.rb:4: warning: previous definition of SECRETS_FILE was here
/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/secrets_helper.rb:5: warning: already initialized constant SecretsHelper::SECRETS_FILE_CHEF_ATTR
/opt/gitlab/embedded/cookbooks/package/libraries/helpers/secrets_helper.rb:5: warning: previous definition of SECRETS_FILE_CHEF_ATTR was here
/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/helpers/secrets_helper.rb:6: warning: already initialized constant SecretsHelper::SKIP_GENERATE_SECRETS_CHEF_ATTR
/opt/gitlab/embedded/cookbooks/package/libraries/helpers/secrets_helper.rb:6: warning: previous definition of SKIP_GENERATE_SECRETS_CHEF_ATTR was here
/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/gitlab_cluster.rb:16: warning: already initialized constant GitlabCluster::CONFIG_PATH
/opt/gitlab/embedded/cookbooks/package/libraries/gitlab_cluster.rb:16: warning: previous definition of CONFIG_PATH was here
/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/libraries/gitlab_cluster.rb:17: warning: already initialized constant GitlabCluster::JSON_FILE
/opt/gitlab/embedded/cookbooks/package/libraries/gitlab_cluster.rb:17: warning: previous definition of JSON_FILE was here
Loading Cinc Auditor profile files:
Loading Cinc Auditor input files:
Loading Cinc Auditor waiver files:
[2024-04-21T11:29:49+00:00] INFO: Generating default secrets
10.进入到gitlab容器进行基础信息配置
docker exec -it gitlab bash
10.1 编辑gitlab.rb
cd /etc/gitlab
vi ./gitlab.rb
- 修改
external_url为node-05
- 修改
gitlab_rails['gitlab_ssh_host']为node-05
- 修改
gitlab_rails['gitlab_shell_ssh_port']为8022
10.2 编辑gitlab.yml
cd /opt/gitlab/embedded/service/gitlab-rails/config
vim gitlab.yml
- 修改port为8022
- 修改url为node-05
10.3.重置账户密码信息,在容器内部,使用gitlab-rails console -e production重置密码。
- 链接数据库:
gitlab-rails console -e production
- 获取用户:
user = User.where(id:1).first
- 修改用户账号:
user.username = 'gitlab'
- 修改用户密码:
user.password = 'gitlab123'
- 保存用户:
user.save!
11.保存配置后,重启
重启配置:gitlab-ctl reconfigure
或者直接重启gitlab:gitlab-ctl restart gitlab