CentOS   发布时间:2022-05-09  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Centos 6 搭建安装 Gitlab大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

官方安装教程

  • gitlab / gitlab-ce

  • 官网下载:https://www.gitlab.cc/downloads

  • 官网安装说明:https://doc.gitlab.cc/ce/install/requirements.html

  • 开源版本和企业版本对比:https://www.gitlab.cc/features/#enterprise

解决官方无法安装的情况

  • Gitlab Community Edition 镜像使用帮助

  • 在阿里云上通过Omnibus一键安装包安装Gitlab

编辑源

使用清华大学 TUNA 镜像源打开网址将内容复制到gitlab-ce.repo文件中,编辑路径vim

/etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

更新本地 YUM 缓存

sudoyummakecache

安装git

如果已经用yum安装过git,并且版本低于2.7.4,要先卸载掉旧的版本

yumremovegit
yuminstallcurl-develexpat-develgettext-developgccperl-ExtUtils-MakeMaker

使用源码编译安装git

mkdir/tmp/git&&cd/tmp/git
curl-O--progresshttps://www.kernel.org/pub/software/scm/git/git-2.8.5.tar.gz
tarzxvfgit-2.8.5.tar.gz
cdgit-2.8.5
./configure
makeprefix=/usr/localall
#安装到/usr/local/bin
makeprefix=/usr/localinstall
#验证git版本号
git--version
#查看git安装路径
whichgit
#创建软连接
ln-s/usr/local/bin/git/usr/bin/git

安装 GitLab 社区版

sudoyuminstallgitlab-ce#(自动安装最新版)
sudoyuminstallgitlab-ce-8.8.4-ce.0.el6#(安装指定版本)

更改配置

vim/etc/gitlab/gitlab.rb
#找到external_url'http://000.00.00.00:8081'#修改成你的地址

配置并启动GitLab

#打开`/etc/gitlab/gitlab.rb`,#将`external_url='http://git.example.com'`修改为自己的IP地址:`http://xxx.xx.xxx.xx`,#然后执行下面的命令,对GitLab进行编译。
sudogitlab-ctlreconfigure

登录GitLab

Username:root
Password:5iveL!fe

GitLab汉化

Gitlab中文社区版地址:https://gitlab.com/xhang/gitlab

1.使用 marbleqi 制作的汉化增量补丁包

注: 使用该汉化补丁包需要重新配置编译资源文件

sudogitlab-ctlreconfigure

2. 手动导出汉化补丁包汉化

请先使用官方包安装或升级完成,确认当前版本。

sudocat/opt/gitlab/embedded/service/gitlab-rails/VERSION
9.3.5

假设当前版本为 v9.3.5,并确认汉化版本库是否包含该版本的汉化标签(-zh结尾),也就是是否包含 v9.3.5-zh。

#克隆汉化版本库
gitclonehttps://gitlab.com/xhang/gitlab.git
#如果已经克隆过,则进行更新
gitfetch

# 导出9.3.5 版本的汉化补丁

gitdiffv9.3.5v9.3.5-zh>../9.3.5-zh.diff

然后上传 9.0.0-zh.diff 文件到服务器。

#停止gitlab
sudogitlab-ctlstop
sudopatch-d/opt/gitlab/embedded/service/gitlab-rails-p1<../9.3.5-zh.diff

确定没有 .rej 文件,重启 GitLab 即可。

sudogitlab-ctlstart

执行重新配置命令

sudogitlab-ctlreconfigure

如果汉化中出现问题,请重新安装 GitLab(注意备份数据)。


此时访问http://192.168.0.80就是全中文页面了

Centos 6 搭建安装 Gitlab


GitLab配置更改

gitlab安装完成后,根据自己的环境,要修改配置。

如:

gitlab修改Nginx端口,绑定IP

gitlab修改ssh端口

gitlab修改访问url

gitlab修改数据库类型(这个没必要,因为这里的数据库只存储些用户名,gitlab代码放在/var/opt/gitlab/git-data/下)

gitlab修改redis,gunicorn配置等等

所有的配置在/etc/gitlab/gitlab.rb中修改,修改完配置后执行gitlab-ctl reconfigure生效

gitlab所有的工程目录都在/var/opt/gitlab/

#ls/var/opt/gitlab/
backupsbootstrappedgit-datagitlab-railsgitlab-shelllogrotateNginxpostgresqlredis

修改配置示例:

#grep-v'#'gitlab.rb|grep-v^$
external_url'http://gitlab.sec.com'
gitlab_rails['gitlab_shell_ssh_port']=2222
Nginx['listen_addresses']=['10.18.103.1']
修改url是别人通过url拉取代码,IP对客户端透明。修改sshport及Nginx绑定IP等为环境需要解决冲突。

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'

然后在命令行执行:

sudogitlab-ctlreconfigure
sudogitlab-rakecache:clearRAILS_ENV=production

Nginx配置

解决80端口被占用

upstreamgitlab{
server114.55.111.111:8081;
}
server{
#侦听的80端口
listen80;
server_namegit.diggg.cn;
location/{
proxy_passhttp://gitlab;#在这里设置一个代理,和upstream的名字一样
#以下是一些反向代理的配置可删除
proxy_redirectoff;
#后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
proxy_set_headerHost$host;
proxy_set_headerX-Real-IP$remote_addr;
proxy_set_headerX-Forwarded-For$proxy_add_x_forwarded_for;
client_max_body_size10m;#允许客户端请求的最大单文件字节数
client_body_buffer_size128k;#缓冲区代理缓冲用户端请求的最大字节数
proxy_connect_timeout300;#Nginx跟后端服务器连接超时时间(代理连接超时)
proxy_send_timeout300;#后端服务器数据回传时间(代理发送超时)
proxy_read_timeout300;#连接成功后,后端服务器响应时间(代理接收超时)
proxy_buffer_size4k;#设置代理服务器(Nginx)保存用户头信息的缓冲区大小
proxy_buffers432k;#proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
proxy_busy_buffers_size64k;#高负荷下缓冲大小(proxy_buffers*2)
proxy_temp_file_write_size64k;#设定缓存文件夹大小,大于这个值,将从upstream服务器传
}
}

#检查配置
/usr/local/Nginx-1.5.1/sbin/Nginx-tcconf/Nginx.conf

#Nginx重新加载配置
/usr/local/Nginx-1.5.1/sbin/Nginx-sreload

运维

#启动所有gitlab组件:
sudogitlab-ctlstart

#停止所有gitlab组件:
sudogitlab-ctlstop

#重启所有gitlab组件:
sudogitlab-ctlrestart

#查看服务状态
sudogitlab-ctlstatus

#启动服务
sudogitlab-ctlreconfigure

#修改默认的配置文件
sudovim/etc/gitlab/gitlab.rb

#查看版本
sudocat/opt/gitlab/embedded/service/gitlab-rails/VERSION

#echo"vm.overcommit_memory=1">>/etc/sysctl.conf
#sysctl-p
#echonever>/sys/kernel/mm/transparent_hugepage/enabled

#检查gitlab
gitlab-rakegitlab:checkSANITIZE=true--trace

#查看日志
sudogitlab-ctltail

备份恢复

Gitlab 创建备份

使用Gitlab一键安装包安装Gitlab非常单,同样的备份恢复与迁移也非常简单,用一条命令即可创建完整的Gitlab备份:

gitlab-rakegitlab:backup:create

以上命令将在/var/opt/gitlab/backups目录下创建一个名称类似为xxxxxxxx_gitlab_backup.tar的压缩包,这个压缩包就是Gitlab整个的完整部分,其中开头的xxxxxx是备份创建的时间戳。

Gitlab 修改备份文件默认目录

修改/etc/gitlab/gitlab.rb来修改默认存放备份文件的目录:

gitlab_rails['backup_path']='/mnt/backups'

修改后使用gitlab-ctl reconfigure命令重载配置文件。

备份

02***/usr/bin/gitlab-rakegitlab:backup:create
02***/opt/gitlab/bin/gitlab-rakegitlab:backup:create

恢复

首先进入备份 gitlab 的目录,这个目录是配置文件中的gitlab_rails['backup_path'],默认为/var/opt/gitlab/backups

然后停止 unicorn 和 sidekiq ,保证数据库没有新的连接,不会有写数据情况。

#停止相关数据连接服务
#ok:down:unicorn:0s,normallyup
gitlab-ctlstopunicorn
#ok:down:sidekiq:0s,normallyup
gitlab-ctlstopsidekiq

#从xxxxx编号备份中恢复
#然后恢复数据,1406691018为备份文件的时间戳
gitlab-rakegitlab:backup:restoreBACKUP=xxxxxx

#启动Gitlab
sudogitlab-ctlstart

迁移

把备份文件拷贝到gitlab的备份目录下,根据上面gitlab恢复步骤即可。


错误处理

Errorexecutingaction`run`onresource'bash[migrategitlab-railsdatabase]'

https://gitlab.com/gitlab-org/gitlab-ce/issues/2052#note_1667899

NameError:uninitializedconstantDevise::Async



本文参考:http://www.cnblogs.com/chinajava/p/5870683.html

大佬总结

以上是大佬教程为你收集整理的Centos 6 搭建安装 Gitlab全部内容,希望文章能够帮你解决Centos 6 搭建安装 Gitlab所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: