导读 GitLab是一个利用Ruby on Rails开发的开源应用程序,实现一个自托管的Git项目仓库,可通过Web界面进行访问公开的或者私人项目。
安装

gitlab的源码安装极其复杂,如果要尝试源码安装可以参考如下文档:

rpm包的安装可以参考官网:

也可以自己下载好rpm包,直接安装。安装方法如下:

yum install -y postfix
yum install -y cronie
service postfix start
chkconfig postfix on
lokkit -s http -s ssh

curl -O //downloads-packages.s3.amazonaws.com/centos-6.6/gitlab-7.9.4_omnibus.1-1.el6.x86_64.rpm

rpm -vih gitlab-7.9.4_omnibus.1-1.el6.x86_64.rpm

gitlab-ctl reconfigure

安装完成后,在浏览器输入gitlab的IP地址,即可访问,默认帐号密码为:root/5iveL!fe

gitlab基本配置
# cat /etc/gitlab/gitlab.rb

external_url '//git.hongxin.com'    #指定gitlab服务器地址
nginx['enable'] = false    #不启用gitlab自带的nginx
#nginx['listen_addresses'] = ['192.168.1.202']    #gitlab的nginx监听地址
unicorn['port'] = 8080                  #修改unicorn的默认端口,即gitlab服务的默认端口。可启用此端口,而关闭gitlab自带的nginx,使用其他nginx来代理该端口
gitlab_rails['gitlab__ssh_port'] = 52113    #定义ssh端口配置,该端口需要与/etc/ssh/sshd_config文件中ssh监听的端口保持一致

gitlab的所有工程目录都在/var/opt/gitlab下,数据仓库存放在/var/opt/gitlab/git-data/下

配置完成以后,执行gitlab-ctl reconfigure来载入配置,并启动gitlab

gitlab的邮件配置
使用本地的postfix发送邮件
service potfix start
vim /etc/gitlab/gitlab.rb
gitlab_rails['gitlab_email_from'] = 'gitlab@example.com'  #定义发邮件的邮箱名称,默认使用本机的postfix发送邮件

使用邮件发送模板
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "完整邮件账户"
gitlab_rails['smtp_password'] = "密码"
gitlab_rails['smtp_domain'] = "邮件账户所在域"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true  # 这个很重要,而且是官方文档里没提及的 
#修改gitlab配置的发信人,否则会抛出"553 Mail from must equal authorized user"的错误
gitlab_rails['gitlab_email_from'] = '完整邮件账户'
user["git_user_email"] = "xxxxxxx"
使用腾讯企业邮箱配置发送邮件
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465

gitlab_rails['smtp_user_name'] = "tech@gongmall.com"
gitlab_rails['smtp_password'] = "tech@gongmall.com的密码"

gitlab_rails['smtp_domain'] = "gongmall.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = 'tech@gongmall.com'
user["git_user_email"] = "xxxxxxx"
使用163邮箱来发送gitlab的邮件
# cat /etc/gitlab/gitlab.rb
#配置smtp
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.163.com"
gitlab_rails['smtp_port'] = 25
#配置邮箱帐号密码
gitlab_rails['smtp_user_name'] = "yan_ruo_gu@163.com"
gitlab_rails['smtp_password'] = "xxxxxxx"
#配置邮箱域
gitlab_rails['smtp_domain'] = '163.com'
gitlab_rails['smtp_authentication'] = :login  #有的配置成:plain
gitlab_rails['smtp_enable_starttls_auto'] = true #是否开启tls认证
#修改gitlab配置的发信人,否则会抛出"553 Mail from must equal authorized user"的错误
gitlab_rails['gitlab_email_from'] = "yan_ruo_gu@163.com"
user["git_user_email"] = "xxxxxxx"
启用gitlab的https

#生成密钥对

cd /etc/gitlab/ssl
openssl genrsa -des3 -out server.key 1024
openssl rsa -in server.key -out server.key    #去除server.key的加密口令
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt

# vim /etc/gitlab/gitlab.rb
nginx['redirect_http_to_https'] = true
nginx['ssl_certificate'] = "/etc/gitlab/ssl/server.crt"
nginx['ssl_certificate_key'] = "/etc/gitlab/ssl/server.key"

gitlab-ctl reconfigure
更改仓库存储路径

gitlab默认的仓库路径是/var/opt/gitlab/git-data/repositories,一般服务器上/var的空间不是很足,所以要把仓库配置到其他路径。

新仓库修改存储路径

如果是刚安装好gitlab,还没开始使用,修改配置即可:

# vim /etc/gitlab/gitlab.rb
git_data_dir "/data/git-data"
使用了一段时间的仓库修改存储路径

如果gitlab已经在使用,除了修改配置,还需要如下步骤:

gitlab-ctl stop 
rsync -av /var/opt/gitlab/git-data/repositories /data/git-data/

# vim /etc/gitlab/gitlab.rb
git_data_dir "/data/git-data"
gitlab-ctl start
gitlab-ctl reconfigure
gitlab数据备份与恢复
备份

gitlab备份的计划任务:

0 2 * * * /opt/gitlab/bin/gitlab-rake gitlab:backup:create

gitlab修改备份路径:

# vim /etc/gitlab/gitlab.rb
gitlab_rails['backup_path'] = '/mnt/backups'
恢复

停止相关数据连接服务:

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

从指定编号备份中恢复:

gitlab-rake gitlab:backup:restore BACKUP=139351368

启动gitlab:

gitlab-ctl start
迁移

把备份文件拷贝到gitlab的备份目录下,执行恢复操作即可

gitlab头像无法正常显示

在配置文件/etc/gitlab/gitlab.rb中添加如下项:

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

然后执行:

gitlab-ctl reconfigure
gitlab-rake cache:clear RAILS_ENV=production
gitlab查看日志
gitlab-ctl tail

原文来自:

本文地址://q13zd.cn/gitlab-remote-warehouse.html编辑:向云艳,审核员:逄增宝

Linux大全:

Linux系统大全:

红帽认证RHCE考试心得: