GitLab是一个基于Web的Git仓库管理工具,它提供了Git仓库管理、代码审查、持续集成和持续部署(CI/CD)等功能。GitLab分为两个版本:GitLab Community Edition(CE)和GitLab Enterprise Edition(EE)。GitLab Community Edition(CE) 是一个开源版本,提供了GitLab的核心功能,适合个人开发者和小团队免费使用。
这一次我们建在LinuxMint中基于dock镜像和docker-compose规约文件来搭建属于我们自己的私有化git仓库。
安装docker和docker-compose
因为是基于docker镜像的安装,首先需要确保系统中安装了docker,LinuxMint的仓库源中已经包含了docker的包,直接apt命令安装就可以了
sean@sean-virtual-machine:~$ sudo apt search docker.io
p docker.io - Linux container runtime
v docker.io-doc -
执行sudo apt install -y docker.io安装docker。
sean@sean-virtual-machine:~$ sudo apt install -y docker.io
正在读取软件包列表... 完成
正在分析软件包的依赖关系树... 完成
正在读取状态信息... 完成
将会同时安装下列软件:
bridge-utils containerd git git-man liberror-perl pigz runc ubuntu-fan
建议安装:
aufs-tools cgroupfs-mount | cgroup-lite debootstrap docker-doc rinse
git-daemon-run | git-daemon-sysvinit git-doc git-email git-gui gitk gitweb
git-cvs git-mediawiki git-svn
下列【新】软件包将被安装:
bridge-utils containerd docker.io git git-man liberror-perl pigz runc
ubuntu-fan
升级了 0 个软件包,新安装了 9 个软件包,要卸载 0 个软件包,有 0 个软件包未被升级。
需要下载 79.3 MB 的归档。
解压缩后会消耗 304 MB 的额外空间。
--- 略 ---
正在设置 git-man (1:2.34.1-1ubuntu1.11) ...
正在设置 containerd (1.7.12-0ubuntu2~22.04.1) ...
Created symlink /etc/systemd/system/multi-user.target.wants/containerd.service → /l
ib/systemd/system/containerd.service.
正在设置 ubuntu-fan (0.12.16) ...
Created symlink /etc/systemd/system/multi-user.target.wants/ubuntu-fan.service → /l
ib/systemd/system/ubuntu-fan.service.
正在设置 docker.io (24.0.7-0ubuntu2~22.04.1) ...
正在添加组"docker" (GID 138)...
完成。
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /lib/s
ystemd/system/docker.service.
Created symlink /etc/systemd/system/sockets.target.wants/docker.socket → /lib/syste
md/system/docker.socket.
正在设置 git (1:2.34.1-1ubuntu1.11) ...
正在处理用于 man-db (2.10.2-1) 的触发器 ...
创建/etc/docker/daemon.json文件并添加仓库源
sean@sean-virtual-machine:~$ sudo nano /etc/docker/daemon.json
sean@sean-virtual-machine:~$ cat /etc/docker/daemon.json
{
"registry-mirrors": [
"https://docker.m.daocloud.io",
"https://docker.1panel.live"
]
}
重启docker的服务
sean@sean-virtual-machine:~$ sudo systemctl daemon-reload
sean@sean-virtual-machine:~$ sudo systemctl restart docker
为非root用户添加执行docker命令不用再前面添加sudo
sean@sean-virtual-machine:~$ sudo usermod -aG docker $USER && newgrp docker
安装docker-compose
下载并将其存放在
/usr/local/bin/docker-compose 目录中,再赋执行权。
sean@sean-virtual-machine:~$ sudo curl -SL https://github.com/docker/compose/releases/download/v2.29.6/docker-compose-linux-x86_64 -o /usr/local/bin/docker-compose
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 60.8M 100 60.8M 0 0 42768 0 0:24:51 0:24:51 --:--:-- 69705
sean@sean-virtual-machine:~$ sudo chmod +x /usr/local/bin/docker-compose
开始安装
为确保后面的安装可以相对比较顺利,先下载gitlab镜像。在执行安装
sean@sean-virtual-machine:~$ docker pull gitlab/gitlab-ce
Using default tag: latest
latest: Pulling from gitlab/gitlab-ce
6414378b6477: Pull complete
0af91ae00c25: Pull complete
7a317d43b6ef: Pull complete
1f15c0ea835f: Pull complete
856860282c5d: Pull complete
2c8dfa329a1f: Pull complete
a4a0cc47fc3a: Pull complete
78d95747b42a: Pull complete
f70c86441ca3: Pull complete
Digest: sha256:c5e575f13858c69d882217d8e40024250c36a171228a78da5a3d2d19d3890ff5
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest
编写docker-compose文件docker-compose.yml。
vim docker-compose.yml
version: '3'
services:
gitlab:
image: 'gitlab/gitlab-ce:latest'
container_name: gitlab
restart: always
environment:
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://192.168.41.131'
gitlab_rails['gitlab_shell_ssh_port'] = 222
ports:
- '8080:8080'
- '222:222'
volumes:
- './config:/etc/gitlab'
- './logs:/var/log/gitlab'
- './data:/var/opt/gitlab'
创建好三个目录,用于挂载容器里面的目录出来,包括配置、日志和数据。
sean@sean-virtual-machine:~/gitlab$ mkdir config logs data
用创建好的编排规约文件启动gitlab服务
sean@sean-virtual-machine:~/gitlab$ docker-compose up -d
WARN[0000] /home/sean/gitlab/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
[+] Running 2/2
✔ Network gitlab_default Created 0.1s
✔ Container gitlab Started
查看容器服务的启动情况
sean@sean-virtual-machine:~/gitlab$ docker-compose ps -a
WARN[0000] /home/sean/gitlab/docker-compose.yml: the attribute `version` is obsolete, it will be ignored, please remove it to avoid potential confusion
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
gitlab gitlab/gitlab-ce:latest "/assets/wrapper" gitlab 37 seconds ago Up 36 seconds (health: starting) 22/tcp, 80/tcp, 0.0.0.0:222->222/tcp, :::222->222/tcp, 443/tcp, 0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
在浏览器打开 http://服务器IP:8080 来到登录界面
在服务器中挂载配置文件目录中有一个initial_root_password文件,查看该文件,可以得到gitla系统root用户的初始密码。
使用root用户和上面步骤查询到的密码登录到gitlab后台。在后台首页找到【Configure GitLab】点击进去,先在后面的页面修改一下语言为中文。再使用GitLab
页面中先点击【Settings】打开子菜单,再点击【Preferences】,在页面里面打开【Localization】标签,将里面的【Default language】下面的下拉菜单选择【Chinese, Simplified - 简体中文 (93% translated)】,最后点击下方的【Save changes】。完成配置中文界面的步骤。
在来修改root用户的密码,点击用户头像,然后选择【Edit prfile】。进入到修改个人信息的界面。
点击左边菜单栏中的【Password】,进入修改密码的页面,填写当前密码和两次新密码,点击【Save password】保存密码。设置密码又强度校验,需要8位或以上且有大小写字母和特殊符号,没有常见弱密码单词等。
修改完成后,自动回到登录界面,输入用户名和新的密码重新登录。
这是登录后,会发现还是英文,那是因为上面的配置只是修改了GitLab的全体新创建用户默认使用中文,root用户自己的界面还没有修改为中文,再次点击头像,这次在子菜单中选择【Preferences】
页面往下拉,找到【Localization】,修改【Language】为【Chinese, Simplified - 简体中文 (93% translated)】点击下方的【Save changes】保存配置。
刷新页面,就变成中文了,可以开始使用您的GitLab了。