是一个基于Git实现的在线代码仓库托管软件,你可以用gitlab自己搭建一个类似于Github一样的系统,一般用于在企业、学校等内部网络搭建git私服。
在 CentOS 7(和 RedHat/Oracle/Scientific Linux 7)上,下面的命令也会在系统防火墙中打开 HTTP、HTTPS 和 SSH 访问。这是一个可选步骤,如果您打算仅从本地网络访问 GitLab,则可以跳过它。
sudo yum install -y curl policycoreutils-python openssh-server perl
# 如果未启用,则启用OpenSSH服务器守护程序:sudo systemctl status sshd
sudo systemctl enable sshd
sudo systemctl start sshd
# 检查是否需要打开防火墙:sudo systemctl status firewalld
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo systemctl reload firewalld接下来,安装 Postfix 以发送通知电子邮件。如果您想使用其他解决方案发送电子邮件,请跳过此步骤并在安装 GitLab 后配置外部 SMTP 服务器。
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix在 Postfix 安装过程中,可能会出现一个配置屏幕。选择“Internet 站点”并按 Enter。
将您服务器的外部 DNS 用于“邮件名称”,然后按 Enter。如果出现其他屏幕,请继续按 Enter 接受默认值。
添加 GitLab 包存储库。
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash接下来,安装 GitLab 包。确保您已正确设置 DNS,并更改https://gitlab.example.com为您要访问 GitLab 实例的 URL。安装将在该 URL 上自动配置和启动 GitLab。
对于https://URL,GitLab 将使用 Let’s Encrypt自动请求证书,这需要入站 HTTP 访问和有效的主机名。您也可以使用自己的证书或仅使用http://(不带s)。
如果您想为初始管理员用户 ( root)指定自定义密码,请查看文档。如果未指定密码,将自动生成随机密码。
sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ee除非您在安装过程中提供了自定义密码,否则将随机生成一个密码并在/etc/gitlab/initial_root_password. 使用此密码和用户名root登录。有关安装和配置的详细说明,请参阅我们的文档。
完成安装后,请考虑建议的后续步骤,包括身份验证选项和注册限制。
uname -a
可以看到我这里是 Linux VM-0-14-centos 3.10.0-1160.31.1.el7.x86_64 #1 SMP Thu Jun 10 13:32:12 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux,那么就需要下载el7.x86_64.rpm的社区安装包。这里我下载了截至2021/8/17最新的安装包(gitlab-ce-13.12.10-ce.0.el7.x86_64.rpm)。
下载包(这里推荐先本地下载,再上传服务器,下载地址:下载):
wget --content-disposition https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/7/gitlab-ce-13.12.10-ce.0.el7.x86_64.rpm/download.rpm这里我是本地下载,再上传服务器的,上传的目录为(/home/lib)

rpm -Uvh /home/libgitlab-ce-13.12.10-ce.0.el7.x86_64.rpmvim /etc/gitlab/gitlab.rb
如上图,我的域名为 https://git.zhaifanhua.com
# 使配置生效
sudo gitlab-ctl reconfigure
# 重新启动服务
sudo gitlab-ctl restart由于Gitlab在安装的时候内部集成了Nginx,一般情况下,采用外部Nginx反向代理的思路来统一管理。
vim /etc/gitlab/gitlab.rb
nginx['listen_port'] = 7000external_url 'http://域名/gitlab'gitlab-ctl reconfigure
gitlab-ctl restartvim /etc/nginx/nginx.confhttp {
...
server {
listen 80;
server_name 192.168.3.101;
charset utf-8;
add_header Strict-Transport-Security "max-age=63072000" always;
#-------------代码------------------
location /gitlab {
# 设置最大允许上传单个的文件大小
client_max_body_size 1024m;
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# 反向代理到 gitlab 内置的 nginx
proxy_pass http://127.0.0.1:7000;
index index.html index.htm;
}
}
...
}# 检测配置是否正确
nginx -t
# 重启nginx
nginx -s reload # or service nginx restart# 禁止 Gitlab 开机自启动
systemctl disable gitlab-runsvdir.service
# 启用 Gitlab 开机自启动
systemctl enable gitlab-runsvdir.service
gitlab-ctl start # 启动所有 gitlab 组件;
gitlab-ctl stop # 停止所有 gitlab 组件;
gitlab-ctl restart # 重启所有 gitlab 组件;
gitlab-ctl status # 查看服务状态;
vim /etc/gitlab/gitlab.rb # 修改gitlab配置文件;
gitlab-ctl reconfigure # 重新编译gitlab的配置;
gitlab-rake gitlab:check SANITIZE=true --trace # 检查gitlab;
gitlab-ctl tail # 查看日志;
gitlab-ctl tail nginx/gitlab_access.log