搭建GitLab服务器

《搭建GitLab服务器》

环境说明

操作系统: CentOS 7.2 64位

1. Gitlab简介

Gitlab是一个用Ruby on Rails开发的开源项目管理程序,可以通过WEB界面进行访问公开的或者私人项目。它和Github有类似的功能,能够浏览源代码,管理缺陷和注释。

2. 环境准备

## 更新软件包
yum update -y
## 安装sshd
yum install -y curl policycoreutils-python openssh-server
## 启用并启动sshd
systemctl enable sshd
systemctl start sshd
配置防火墙

编辑 /etc/sysctl.conf文件,在文件最后添加如下代码:

net.ipv4.ip_forward = 1

保存并退出

启用并启动防火墙:
systemctl enable firewalld
systemctl start firewalld
让防火墙允许HTTP的请求通过:
firewall-cmd --permanent --add-service=http
重启防火墙

一般情况下,可以使用systemctl status firewalld查看防火墙的状态。

systemctl reload firewalld
安装 postfix

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

安装

yum install -y postfix

修改文件/etc/postfix/main.cf,在119行,将 all 改为 ipv4,然后保存退出

inet_protocols = ipv4

启用并启动postfix

systemctl enable postfix 
systemctl start postfix

配置交换分区

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

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

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

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

mkswap /root/swapfile
swapon /root/swapfile

添加自启用

打开 /etc/fstab 文件,在文件最后添加新的一行如下命令,退出并保存。

/root/swapfile swap swap defaults 0 0

3. 安装GitLab

将软件源修改为国内源

由于网络环境的原因,将 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

安装GitLab

## 重新生成缓存
yum makecache
## 安装 GitLab
yum install -y gitlab-ce

4. 初始化GitLab

sudo gitlab-ctl reconfigure

5. 完成

直接使用http://IP访问GitLab。

此文章为瞎说开发那些事原创

    原文作者:Xiangdong_She
    原文地址: https://www.jianshu.com/p/d8beecaa8495
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞