基于 CentOS 7 搭建 GitLab

⒈更新软件包

1 yum update -y  

⒉安装 ssh服务并启动

yum install -y curl policycoreutils-python openssh-server
systemctl enable sshd
systemctl start sshd

⒊配置防火墙

  打开 /etc/sysctl.conf 文件,在文件最后添加以下内容并保存

net.ipv4.ip_forward = 1

  执行以下命令

systemctl enable firewalld
systemctl start firewalld    启用并启动防火墙

firewall-cmd --permanent --add-service=http  放通HTTP
systemctl reload firewalld  重启防火墙

  在实际使用中,可以使用 systemctl status firewalld 命令查看防火墙的状态。

⒋安装 postfix

  GitLab 需要使用 postfix 来发送邮件。当然,也可以使用 SMTP 服务器,具体步骤请参考 官方教程

  1.安装postfix

yum install -y postfix

  2.打开 /etc/postfix/main.cf 文件,在第 119 行附近找到 inet_protocols = all,将 all 改为 ipv4 并保存(配置案例上写的IPv4结果写成IPv4还报错,改成ipv4正常了)

inet_protocols = ipv4

  3.启用并启动 postfix

systemctl enable postfix 
systemctl start postfix

⒌配置 swap 交换分区

  由于 GitLab 较为消耗资源,我们需要先创建交换分区,以降低物理内存的压力。
  在实际生产环境中,如果服务器配置够高,则不必配置交换分区。

  1.新建 2 GB 大小的交换分区:

dd if=/dev/zero of=/root/swapfile bs=1M count=2048

  2.格式化为交换分区文件并启用:

mkswap /root/swapfile
swapon /root/swapfile

  3.添加自启用。打开 /etc/fstab 文件,在文件最后添加以下内容并保存

/root/swapfile swap swap defaults 0 0

⒍安装 GitLab

  1.将软件源修改为国内源

  由于网络环境的原因,将 repo 源修改为清华大学

  在  /etc/yum.repos.d 目录下新建  gitlab-ce.repo 文件并保存。内容如下:
[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1

  2.刷新yum

  刚才修改过了 yum 源,因此先重新生成缓存:
(此步骤执行时间较长,一般需要 3~5 分钟左右,请耐心等待)

yum makecache

  3.安装 GitLab

yum install -y gitlab-ce

⒎初始化GitLab

  1.打开 /etc/gitlab/gitlab.rb 文件,在第 13 行附近找到 external_url 'http://gitlab.example.com',将单引号中的内容改为自己的域名(带上协议头,末尾无斜杠),并按 Ctrl + S 保存。

  例如:

external_url 'http://www.coreqi.cn'

  2.特别重要!使用如下命令初始化 GitLab:此步骤执行时间较长,一般需要 5~10 分钟左右,请耐心等待)

sudo gitlab-ctl reconfigure
 
  至此,我们已经成功地在 CentOS 7 上搭建了 GitLab。
  • 在实际生产中,建议使用 2 核 4 GB 或更高配置的 服务器。点击这里 可以查看 GitLab 官方推荐的配置和可承载人数对应表。

猜你喜欢

转载自www.cnblogs.com/fanqisoft/p/11289941.html