首页 帮助中心 香港云服务器 Linux云服务器安装和使用GitLab的教程
Linux云服务器安装和使用GitLab的教程
时间 : 2024-10-30 13:52:25 编辑 : 华纳云 阅读量 : 331

需有一台已经分配好公网IP的云服务器,切满足GitLab的硬件要求:至少2GB RAM(推荐4GB或更多)和至少20GB的可用存储空间。以下是在Linux云服务器上安装和使用GitLab的详细步骤。

对于Ubuntu服务器,使用以下命令安装依赖:

sudo apt-get update
sudo apt-get install -y curl openssh-server ca-certificates postfix
```

对于CentOS服务器,使用以下命令安装依赖:

sudo yum install -y curl openssh-server postfix
sudo yum install -y https://download.docker.com/linux/centos/docker-ce.repo
sudo yum install -y docker-ce
sudo systemctl start docker
sudo systemctl enable docker
```

配置服务器。设置linux云服务器的主机名,并更新`/etc/hosts`文件以反映新的主机名:

sudo hostnamectl set-hostname gitlab-server
echo "127.0.0.1 gitlab-server" | sudo tee -a /etc/hosts
```

配置防火墙允许HTTP和HTTPS访问:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
```

下载GitLab软件包。使用Docker安装GitLab,首先安装Docker(如果尚未安装):

对于Ubuntu服务器:

sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo systemctl restart docker
```

拉取GitLab的Docker镜像:

sudo docker pull gitlab/gitlab-ce:latest
```

配置GitLab。创建一个名为`gitlab.yml`的配置文件,用于配置GitLab的参数:

```yaml
gitlab:
  external_url: 'http://your_server_ip'
  gitlab_rails:
    gitlab_default_can_create_group: false
```

根据实际情况修改`external_url`为云服务器IP或域名,并设置PostgreSQL数据库的用户名和密码。启动GitLab服务:

sudo docker run --detach \
  --hostname gitlab.example.com \
  --publish 443:443 --publish 80:80 --publish 22:22 \
  --name gitlab \
  --restart always \
  --volume $GITLAB_HOME/config:/etc/gitlab \
  -volume $GITLAB_HOME/logs:/var/log/gitlab \
  --volume $GITLAB_HOME/data:/var/opt/gitlab \
  --volume /etc/localtime:/etc/localtime:ro \
  gitlab/gitlab-ce:latest
```

这里的`$GITLAB_HOME`是你为GitLab配置的一个目录,用于存放配置、日志和数据文件。根据实际情况修改这个目录的路径。

访问GitLab。在浏览器中输入云服务器IP或域名,应该能够看到GitLab的登录页面。使用默认的`root`账号和密码`5iveL!fe`登录。登录后,可以根据自己的需求进行进一步的配置和定制,如需要帮助可以联系华纳云技术团队。

华纳云 推荐文章
在Debian上怎么安装和配置GitLab GitLab备份数据及验证备份完整性方法
活动
客服咨询
7*24小时技术支持
技术支持
渠道支持