Gitlab私服环境搭建

12/20/2019 Gitlab

# 环境

  • 阿里云 ECS 2c 4g
  • CentOS Linux release 7.7.1908 (Core)
  • 非生产环境,已开启全部端口

以下是官方建议

GitLab Installation

We strongly recommend downloading the Omnibus package installation since it is quicker to install, easier to upgrade, and it contains features to enhance reliability not found in other methods. We also strongly recommend at least 4GB of free RAM to run GitLab.

# gitlab私服搭建

# 安装和配置必要的依赖项

在CentOS 7(和RedHat / Oracle / Scientific Linux 7)上,以下命令还将在系统防火墙中打开HTTP,HTTPS和SSH访问。

sudo yum install -y curl policycoreutils-python openssh-server
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
1
2
3
4
5
6
7

接下来,安装Postfix发送通知电子邮件。如果要使用其他解决方案发送电子邮件,请跳过此步骤并在安装GitLab之后配置外部SMTP服务器。

sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix
1
2
3

注:此处在systemctl start postfix发生一个错误

Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.

个人解决办法 执行systemctl status postfix.service,发现Failed to start Postfix Mail Transport Agent.然后修改配置文件vim /etc/postfix/main.cf 原本此处为inet_protocols = all,修改成以下,问题得以解决

inet_protocols = ipv4 inet_interfaces = all

在Postfix安装过程中,可能会出现一个配置屏幕。选择“ Internet网站”,然后按Enter。使用服务器的外部DNS作为“邮件名”,然后按Enter。如果出现其他屏幕,请继续按Enter接受默认设置。

# 添加GitLab软件包存储库并安装软件包

添加GitLab软件包存储库。这里面就有个选择了,社区版或者企业版

官方是这么建议的

如果您有兴趣使用GitLab,即使您不确定是否会订阅GitLab Enterprise Edition许可证 ,我们也建议您 下载并安装GitLab Enterprise Edition。您仍然可以使用GitLab社区版的所有功能,而无需许可证或注册。

所以至于你想安装什么版本 自行选择 以下都会有注释

# 企业版就是gitlab-ee,应该很好区分
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash
# 社区版gitlab-ce
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
1
2
3
4

接下来,安装GitLab软件包。将https://gitlab.example.com更改为您要访问GitLab实例的URL。安装将自动配置并在该URL上启动GitLab。

对于https://URL,GitLab将自动通过Let's Encrypt请求证书,这需要入站HTTP访问和有效的主机名。您也可以使用自己的证书或仅使用http://。

这里我为了方便直接用http加上外网ip了,可以自己根据需求调整

# 企业版
sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ee
# 社区版
sudo EXTERNAL_URL="https://gitlab.example.com" yum install -y gitlab-ce
1
2
3
4

这里不出意外的话,要下载好久,我的安装大小为1.6g。静待片刻...

其实也可以不使用官方地址下载,比如配置清华源,速度应该能快上不少,传送门 (opens new window)

# 浏览到主机名并登录

简单来说,在安装完成之后,理论上就可以直接输入http://ip进行访问,初次需要设置密码,默认用户名为root,然后即可以登录到gitlab的web管理界面了,之后的大家就都知道了,不多赘述。

# 配置

至于配置,比如修改端口号(默认80),可以去修改配置文件/etc/gitlab/gitlab.rb,具体百度,这里不贴了。

gitlab-ctl常用命令

  1. 重新加载配置并启动 sudo gitlab-ctl reconfigure
  2. 重启gitlab sudo gitlab-ctl restart
  3. 查看gitlab运行状态 sudo gitlab-ctl status
  4. 停止gitlab服务 sudo gitlab-ctl stop
  5. 查看gitlab运行日志 sudo gitlab-ctl tail

更多gitlab-ctl用法直接输入gitlab-ctl,下面都会列举出来。

# 最后

以上内容很多都是官方文档机翻过来的,其实官方文档非常详细,提供了很多很多的安装文档,还有docker的安装方式,但是我不喜欢docker,就没有用docker安装了,有兴趣的或者看完该文章仍没有解决问题的,可以直接参考官方文档。传送门 (opens new window)