GitLab的安装

在阿里云上折腾了一天的 GitLab ,编译安装时各种被墙,无法正常安装,最后使用了官网的rpm包安装方式解决了问题。

GitLab的两种安装方法:

编译安装
优点:可定制性强。数据库既可以选择MySQL,也可以选择PostgreSQL;服务器既可以选择Apache,也可以选择Nginx。
缺点:国外的源不稳定,被墙时,依赖软件包难以下载。配置流程繁琐、复杂,容易出现各种各样的问题。依赖关系多,不容易管理,卸载GitLab相对麻烦。

通过rpm包安装
优点:安装过程简单,安装速度快。采用rpm包安装方式,安装的软件包便于管理。
缺点:数据库默认采用PostgreSQL,服务器默认采用Nginx,不容易定制。

安装 GitLab

进入进入gitlab官方网站,选择对应的操作系统 — CentOS 6 (and RedHat/Oracle/Scientific Linux 6),按照官方提示进行安装。

1.安装配置必要的依赖。在Centos 6 和 7 中,以下的命令将会打开HTTP和SSH在系统防火墙中的可访问权限。

sudo yum install curl openssh-server openssh-clients postfix cronie
sudo service postfix start
sudo chkconfig postfix on
sudo lokkit -s http -s ssh

2.由于在线安装脚本内容被墙,可以在服务器上搭建个shadowsocks客户端进行安装(又需要稍微折腾一下)。

curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install gitlab-ce

或者将安装包下载在本地,然后通过scp或者ftp再上传到服务器进行安装。

curl -O https://packages.gitlab.com/gitlab/gitlab-ce/packages/el/6/gitlab-ce-8.6.4-ce.0.el6.x86_64.rpm/download
rpm -i gitlab-ce-8.6.4-ce.0.el6.x86_64.rpm

3.配置和启动GitLab。用 vim 打开 /etc/gitlab/gitlab.rb ,将 external_url = 'http://git.example.com' 修改为自己的IP地址:http://xxx.xx.xxx.xxx,然后执行下面的命令,对GitLab进行编译。

sudo gitlab-ctl reconfigure

4.打开 http://xxx.xx.xxx.xxx ,使用gitlab。

出现的问题

1.在浏览器中访问GitLab出现502错误
原因:内存不足。
解决办法:检查系统的虚拟内存是否随机启动了,如果系统无虚拟内存,则增加虚拟内存,再重新启动系统。

2.GitLab头像无法正常显示
原因:gravatar被墙
解决办法:
编辑 /etc/gitlab/gitlab.rb,将

#gitlab_rails['gravatar_plain_url'] = 'http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'

修改为:

gitlab_rails['gravatar_plain_url'] = 'http://gravatar.duoshuo.com/avatar/%{hash}?s=%{size}&d=identicon'

然后在命令行执行:

sudo gitlab-ctl reconfigure 
sudo gitlab-rake cache:clear RAILS_ENV=production

参考资料

GitLab的安装方式