基于CentOS7搭建GitLab
1、准备环境
在正式开始安装之前,先更新软件包并打开相关服务的权限
- 更新软件包
yum update -y
1.1 安装sshd
- 安装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 reload firewalld
在实际的使用,可以使用 systemctl status firewalld 命令查看防火墙的状态
1.2 安装postfix
GitLab需要使用postfix来发送邮件。当然,也可以使用SMTP服务器,具体步骤请参考官方教程。
- 安装
yum install -y postfix
打开 /etc/postfix/main.cf 文件,在第119行附近找到 inet_protocols = all ,将 all 改为 ipv4 并保存
inet_protocols = ipv4
- 启用并启动postfix:
systemctl enable postfix
systemctl start postfix
1.3 配置swap交换分区
由于GitLab较为消耗资源,需要先创建交换分区,一降低物理内存的压力,在实际生产环境中,如果服务器配置够高,则不必配置交换分区
- 新建2GB大小的交换分区
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
2、安装GitLab
2.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.2 安装GitLab
刚才修改了yum源,因此先重新生成缓存(此步骤执行时间较长,一般需要3~5分钟)
yum makecache
- 安装GitLab
(此步骤执行时间较长,一般需要 3~5 分钟左右,请耐心等待)
yum install -y gitlab-ce
3、初始化GitLab
3.1 配置GitLab的域名(非必需)
打开 /etc/gitlab/gitlab.rb 文件,在第13行附近找到 external_url ‘http://gitlab.example.com’,将单引号中的内容改为自己的域名(带上协议头、末尾无斜杠),并保存
例如
external_url 'http://work.myteam.com'
记得将域名通过A记录解析到 IP地址 哦
3.2 初始化GitLab
- 使用如下命令初始化GitLab:
(此步骤执行时间较长,一般需要 5~10 分钟左右,请耐心等待)
sudo gitlab-ctl reconfigure
4、GitLab安装已完成
至此,已经成功在CentOS7上搭建了GitLab,现在可以通过IP地址方位GitLab了