在CentOS上配置GitLab服务器涉及多个步骤,包括安装必要的依赖项、配置网络设置、安装GitLab软件以及设置防火墙规则等。以下是详细的步骤:
1. 安装依赖项
首先,确保你的CentOS系统已经安装了必要的依赖项,包括 curl
、openssh-server
和 postfix
。这些是GitLab运行所必须的。
sudo yum install -y curl openssh-server postfix
2. 配置网络
修改GitLab的外部URL
编辑GitLab的配置文件 /etc/gitlab/gitlab.rb
,设置外部URL以指定GitLab服务器的地址和端口。
sudo vi /etc/gitlab/gitlab.rb
在文件中找到 external_url 'http://your_domain_or_ip:port'
这一行,将其中的 your_domain_or_ip
替换为你的服务器IP地址或域名,并将 port
替换为你自定义的端口号(例如8080)。
external_url 'http://your_server_ip:8080'
保存并关闭文件。
配置防火墙
确保开放GitLab所需的端口,包括HTTP(80)、HTTPS(443)和SSH(22)。
sudo firewall-cmd --permanent --zone=public --add-service=http sudo firewall-cmd --permanent --zone=public --add-service=https sudo firewall-cmd --permanent --zone=public --add-service=ssh sudo firewall-cmd --reload
3. 安装GitLab
添加GitLab的官方仓库并安装GitLab CE。
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash sudo yum install -y gitlab-ce
4. 配置并启动GitLab
在配置好 gitlab.rb
文件后,运行以下命令来重新配置并启动GitLab。
sudo gitlab-ctl reconfigure sudo gitlab-ctl start
5. 访问GitLab
配置完成后,你可以通过浏览器访问配置的外部URL(例如:http://your_server_ip:8080)。首次访问时,GitLab会引导你设置管理员账户和密码。
注意事项
- 外网访问:建议使用HTTPS协议来确保数据的安全性。
- 防火墙设置:务必检查服务器的网络配置,确保开放的端口不会与其他服务冲突。
- 自定义配置:如果需要自定义GitLab的其他功能(如SMTP邮件服务器、备份设置等),可以在
/etc/gitlab/gitlab.rb
中进一步配置。