Git7:使用Gitlab管理远程仓库

1、安装

gitlab的源码安装极其复杂,如果要尝试源码安装可以参考如下文档:
https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md

也可以参考:http://54im.com/git/centos6-install-gitlab-ldap认证.html

rpm包的安装可以参考官网:
https://about.gitlab.com/downloads/

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

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

curl -O https://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

2、gitlab基本配置

# cat /etc/gitlab/gitlab.rb

external_url 'http://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_shell_ssh_port'] = 52113    #定义ssh端口配置,该端口需要与/etc/ssh/sshd_config文件中ssh监听的端口保持一致

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

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

3、gitlab的邮件配置

3.1、使用本地的postfix发送邮件

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

3.2、使用邮件发送模板

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"

3.3、使用腾讯企业邮箱配置发送邮件

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"

3.4、使用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"

4、启用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

5、更改仓库存储路径

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

5.1、新仓库修改存储路径

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

# vim /etc/gitlab/gitlab.rb
git_data_dir "/data/git-data"

5.2、使用了一段时间的仓库修改存储路径

如果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

6、gitlab数据备份与恢复

6.1、备份

gitlab备份的计划任务:

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

gitlab修改备份路径:

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

6.2、恢复

停止相关数据连接服务:

gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq

从指定编号备份中恢复:

gitlab-rake gitlab:backup:restore BACKUP=139351368

启动gitlab:

gitlab-ctl start

6.3、迁移

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

7、gitlab头像无法正常显示

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

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

然后执行:

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

8、gitlab查看日志

gitlab-ctl tail
posted @ 2018-07-16 23:08  breezey  阅读(2075)  评论(0编辑  收藏  举报