在正式开始安装之前,先更新软件包并打开相关服务的权限。
yum update -yyum install -y curl policycoreutils-python openssh-server启用并启动 sshd:
systemctl enable sshd
systemctl start sshd打开 /etc/sysctl.conf 文件,在文件最后添加新的一行并按 Ctrl + S 保存:
net.ipv4.ip_forward = 1启用并启动防火墙:
systemctl enable firewalld
systemctl start firewalld放通 HTTP:
firewall-cmd --permanent --add-service=http重启防火墙:
systemctl reload firewalld在实际使用中,可以使用 systemctl status firewalld 命令查看防火墙的状态。
GitLab 需要使用 postfix 来发送邮件。当然,也可以使用 SMTP 服务器,具体步骤请参考 官方教程。
安装:
yum install -y postfix打开 /etc/postfix/main.cf 文件,在第 119 行附近找到 inet_protocols = all,将 all 改为 ipv4 并按 Ctrl + S 保存:
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 文件,在文件最后添加新的一行并按 Ctrl + S 保存:
/root/swapfile swap swap defaults 0 0由于网络环境的原因,将 repo 源修改为[清华大学]。
在 /etc/yum.repos.d 目录下新建 gitlab-ce.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刚才修改过了 yum 源,因此先重新生成缓存: (此步骤执行时间较长,一般需要 3~5 分钟左右,请耐心等待)
yum makecache安装 GitLab: (此步骤执行时间较长,一般需要 3~5 分钟左右,请耐心等待)
yum install -y gitlab-ce打开 /etc/gitlab/gitlab.rb 文件,在第 13 行附近找到 external_url 'http://gitlab.example.com',将单引号中的内容改为自己的域名(带上协议头,末尾无斜杠),并按 Ctrl + S 保存。
例如:
external_url 'http://work.myteam.com'记得将域名通过 A 记录解析到 <您的 CVM IP 地址> 哦。
特别重要!
使用如下命令初始化 GitLab: (此步骤执行时间较长,一般需要 5~10 分钟左右,请耐心等待)
sudo gitlab-ctl reconfigure现在可以在这里(http://<您的IP 地址>/)访问 GitLab 了。
设置密码并登录,默认账号为root

使用ssh-keygen生成密钥
ssh-keygen -t rsa -C "$your_email"
cat ~/.ssh/id_rsa.pub
生成的密钥复制进gitlab用户下
git config --global user.name "用户名" git config --global user.email "用户邮箱" git remote add origin git@192.168.0.97:feiyu/testfeiu.git git add test.html git commit -m "edit" git remote add origin git@192.168.0.97:feiyu/testfeiu.git git push -u origin master
如果出错,可以先将远程的项目pull下来,再开始操作
git pull origin master