在CentOS上搭建GitLab环境是一个相对复杂的过程,需要安装多个依赖项并进行配置。以下是一个基本的步骤指南,帮助你在CentOS 7上安装和配置GitLab。
更新系统:
sudo yum update -y
安装必要的依赖包:
sudo yum install -y curl policycoreutils-python openssh-server openssh-clients postfix wget
配置SSH服务:
sudo systemctl enable sshd
sudo systemctl start sshd
配置防火墙:
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld
安装Postfix(用于邮件通知,可选):
sudo yum install postfix -y
sudo systemctl enable postfix
sudo systemctl start postfix
添加GitLab的YUM源:
创建 /etc/yum.repos.d/gitlab-ce.repo
文件,内容如下:
[gitlab-ce]
name=GitLab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
gpgcheck=0
enabled=1
安装GitLab CE:
sudo yum install -y gitlab-ce
修改GitLab配置文件:
使用 vim
编辑 /etc/gitlab/gitlab.rb
文件,修改外部URL:
sudo vim /etc/gitlab/gitlab.rb
将 external_url 'http://your_server_ip'
修改为你的服务器IP地址或域名。
重新配置GitLab:
sudo gitlab-ctl reconfigure
启动GitLab服务:
sudo gitlab-ctl start
设置首页语言(可选):
用户登录后,进入 Preferences
-> Localization
,选择简体中文并保存。
打开浏览器,访问 http://your_server_ip
,按照提示设置root用户的密码。
修改监听端口:
编辑 /etc/gitlab/gitlab.rb
文件,修改 external_url
和 gitlab_rails['smtp_port']
,然后执行 sudo gitlab-ctl reconfigure
。
修改数据存储路径:
编辑 /etc/gitlab/gitlab.rb
文件,修改 git_data_dirs
和 backup_path
,然后执行 sudo gitlab-ctl reconfigure
。
以上步骤应该可以帮助你在CentOS 7上成功搭建GitLab环境。如果在安装过程中遇到问题,建议参考GitLab的官方文档或寻求在线帮助。