温馨提示×

CentOS如何配置GitLab环境

小樊
43
2025-08-22 17:24:48
栏目: 智能运维

在CentOS上配置GitLab环境,可参考以下步骤:

安装依赖包

更新系统并安装必要依赖,如curlpolicycoreutils-pythonopenssh-server等:

sudo yum update -y
sudo yum install -y curl policycoreutils-python openssh-server postfix

配置网络和防火墙

启动SSH服务并设置开机自启,配置防火墙允许HTTP和HTTPS流量:

sudo systemctl enable sshd
sudo systemctl start sshd
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

添加GitLab仓库并安装

使用官方脚本添加GitLab软件源,然后安装GitLab社区版:

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install -y gitlab-ce

配置GitLab

编辑配置文件/etc/gitlab/gitlab.rb,设置外部URL、邮件服务等:

sudo vi /etc/gitlab/gitlab.rb
# 例如设置外部URL
external_url 'http://your_domain_or_ip'
# 若需邮件服务,配置SMTP信息
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.example.com"
# 其他SMTP配置...

保存后重新配置并启动GitLab:

sudo gitlab-ctl reconfigure
sudo gitlab-ctl start

访问GitLab

在浏览器中输入http://your_domain_or_ip,首次访问需创建管理员账户并设置密码。

0