在CentOS上配置GitLab涉及多个步骤,包括安装必要的依赖包、配置网络设置、安装GitLab软件包、修改配置文件以及启动和验证GitLab服务。以下是详细的步骤:
首先,确保系统是最新的,并安装SSH、防火墙、Postfix、wget等必要的软件包。
sudo yum update -y
sudo yum install -y curl policycoreutils-python-utils openssh-server perl
sudo yum install -y firewalld wget vim
配置SSH服务开机自启动并启动SSH服务:
sudo systemctl enable sshd
sudo systemctl start sshd
配置防火墙以允许HTTP和HTTPS流量:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
添加GitLab的RPM镜像源并安装GitLab软件包。这里以清华大学镜像源为例:
wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
sudo rpm -i gitlab-ce-10.0.0-ce.0.el7.x86_64.rpm
修改GitLab的配置文件以指定服务器IP和自定义端口:
sudo vim /etc/gitlab/gitlab.rb
在编辑器中找到并修改以下配置项:
external_url 'http://your_server_ip:port'
替换为实际的服务器IP地址或域名及端口号。
如果需要,添加以下配置以允许HTTP和HTTPS流量:
gitlab_rails['gitlab_shell_ssh_port'] = 22
nginx['listen_port'] = 80
nginx['listen_https'] = 443
保存文件后,应用配置更改:
sudo gitlab-ctl reconfigure
重启GitLab服务以使配置生效:
sudo gitlab-ctl restart
访问GitLab页面以验证安装是否成功。默认情况下,GitLab通常监听8080端口,可以通过浏览器访问 http://your_server_ip:8080
。
请注意,上述步骤中的版本号和具体命令可能会因GitLab版本和CentOS版本的不同而有所差异。建议参考GitLab官方文档或相关教程以获取最准确的信息。