在Ubuntu上搭建GitLab,你可以选择使用官方提供的GitLab包或者使用Docker来安装。以下是两种常见的安装方法:
更新系统包列表
sudo apt update
安装必要的依赖包
sudo apt install -y curl openssh-server ca-certificates tzdata perl
添加GitLab官方GPG密钥
curl https://packages.gitlab.com/gpg.key | sudo apt-key add -
创建GitLab仓库
sudo apt install -y gnupg2
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys F6E65AC044F831AC80A06380C8B3C55A6F3EFCDE
sudo sh -c 'echo "deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/gitlab.list'
安装GitLab CE(社区版)
sudo apt update
sudo EXTERNAL_URL="http://your_server_ip_or_domain" apt install gitlab-ce
如果你需要安装GitLab EE(企业版),可以使用以下命令:
sudo EXTERNAL_URL="http://your_server_ip_or_domain" apt install gitlab-ee
配置GitLab
安装完成后,GitLab会自动配置。你可以通过浏览器访问http://your_server_ip_or_domain
来访问GitLab。
安装Docker 如果你还没有安装Docker,可以按照以下步骤进行安装:
sudo apt update
sudo apt install -y docker.io
sudo systemctl start docker
sudo systemctl enable docker
添加GitLab官方Docker镜像
curl https://packages.gitlab.com/gpg.key | sudo apt-key add -
sudo sh -c 'echo "deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu $(lsb_release -cs) main" > /etc/apt/sources.list.d/gitlab.list'
sudo apt update
sudo apt install -y docker-compose
下载GitLab Docker镜像
docker pull gitlab/gitlab-ce:latest
创建GitLab配置文件
在你的主目录下创建一个.gitlab-ci.yml
文件,用于配置CI/CD管道。
启动GitLab容器
docker run --detach \
--hostname your_server_ip_or_domain \
--publish 80:80 \
--publish 443:443 \
--publish 22:22 \
--name gitlab \
--restart always \
--volume /srv/gitlab/config:/etc/gitlab \
--volume /srv/gitlab/logs:/var/log/gitlab \
--volume /srv/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
配置GitLab
安装完成后,GitLab会自动配置。你可以通过浏览器访问http://your_server_ip_or_domain
来访问GitLab。
通过以上步骤,你应该能够在Ubuntu上成功搭建GitLab。