温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Centos 6 安装 Gitlab和备份、迁移

发布时间:2020-10-06 23:09:02 来源:网络 阅读:1897 作者:qianghong000 栏目:建站服务器

官方安装教程

  • 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 缓存

sudo yum makecache

建立新版nginx的yum仓库

wget http://nginx.org/packages/centos/6/noarch/RPMS/nginx-release-centos-6-0.el6.ngx.noarch.rpm
rpm -ivh nginx-release-centos-6-0.el6.ngx.noarch.rpm

安装git

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

yum install vim curl openssh-server openssh-clients gcc-c++ zlib1g-dev zlib-devel curl-devel expat-devel gettext-devel opgcc perl-ExtUtils-MakeMaker
yum remove git

使用源码编译安装git

mkdir /tmp/git && cd /tmp/git
curl -O --progress https://www.kernel.org/pub/software/scm/git/git-2.8.5.tar.gz
tar zxvf git-2.8.5.tar.gz
cd git-2.8.5
./configure
make prefix=/usr/local all
# 安装到/usr/local/bin
make prefix=/usr/local install
# 验证git版本号
git --version
#查看git安装路径
which git
#创建软连接
ln -s /usr/local/bin/git /usr/bin/git

安装 GitLab 社区版

sudo yum install gitlab-ce #(自动安装最新版)
sudo yum install gitlab-ce-8.8.4-ce.0.el6 #(安装指定版本)


配置并启动GitLab

# vim /etc/gitlab/gitlab.rb 
# 找到 external_url 'http://000.00.00.00:8081' # 修改成你的地址
# 然后执行下面的命令,对GitLab进行编译。
sudo gitlab-ctl reconfigure
#启动gitlab
sudo gitlab-ctl restart


可能遇到的问题

Centos 6 安装 Gitlab和备份、迁移

解决方法:

是因为/etc/gitlab/gitlab.rb文件中的内容是:
external_url 'hostname'
将其修改为:
external_url='hostname'
即可,只需要在原来的配置项中添加个 ‘=’ 即可


登录GitLab

Username: root 
Password: 5iveL!fe

GitLab汉化

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

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

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

sudo gitlab-ctl reconfigure

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

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

sudo cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
9.3.5

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

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

# 导出9.3.5 版本的汉化补丁

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

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

# 停止 gitlab
sudo gitlab-ctl stop
sudo patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < ../9.3.5-zh.diff

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

sudo gitlab-ctl start

执行重新配置命令

sudo gitlab-ctl reconfigure

如果汉化中出现问题,请重新安装 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/
backups bootstrapped  git-data  gitlab-rails gitlab-shell  logrotate  nginx  postgresql  redis

 

修改配置示例:

#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对客户端透明。修改ssh port及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'

然后在命令行执行:

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

nginx配置

解决 80 端口被占用

upstream gitlab {
     server 114.55.111.111:8081 ;
}
server {
    #侦听的80端口
    listen       80;
    server_name  git.diggg.cn;
    location / {
        proxy_pass   http://gitlab;    #在这里设置一个代理,和upstream的名字一样
        #以下是一些反向代理的配置可删除
        proxy_redirect             off;
        #后端的Web服务器可以通过X-Forwarded-For获取用户真实IP
        proxy_set_header           Host $host;
        proxy_set_header           X-Real-IP $remote_addr;
        proxy_set_header           X-Forwarded-For $proxy_add_x_forwarded_for;
        client_max_body_size       10m; #允许客户端请求的最大单文件字节数
        client_body_buffer_size    128k; #缓冲区代理缓冲用户端请求的最大字节数
        proxy_connect_timeout      300; #nginx跟后端服务器连接超时时间(代理连接超时)
        proxy_send_timeout         300; #后端服务器数据回传时间(代理发送超时)
        proxy_read_timeout         300; #连接成功后,后端服务器响应时间(代理接收超时)
        proxy_buffer_size          4k; #设置代理服务器(nginx)保存用户头信息的缓冲区大小
        proxy_buffers              4 32k; #proxy_buffers缓冲区,网页平均在32k以下的话,这样设置
        proxy_busy_buffers_size    64k; #高负荷下缓冲大小(proxy_buffers*2)
        proxy_temp_file_write_size 64k; #设定缓存文件夹大小,大于这个值,将从upstream服务器传
    }
}

# 检查配置
/usr/local/nginx-1.5.1/sbin/nginx -tc conf/nginx.conf

# nginx 重新加载配置
/usr/local/nginx-1.5.1/sbin/nginx -s reload

运维

# 启动所有 gitlab 组件:
sudo gitlab-ctl start

# 停止所有 gitlab 组件:
sudo gitlab-ctl stop

# 重启所有 gitlab 组件:
sudo gitlab-ctl restart

# 查看服务状态
sudo gitlab-ctl status

# 启动服务
sudo gitlab-ctl reconfigure

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

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

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

# 检查gitlab
gitlab-rake gitlab:check SANITIZE=true --trace

# 查看日志
sudo gitlab-ctl tail

备份恢复

Gitlab 创建备份

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

gitlab-rake gitlab:backup:create

#如果使用源码安装的gitlab话,使用以下命令
sudo -u git -H bundle exec rake gitlab:backup:create RAILS_ENV=production

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

也可以使用SKIP变量来选择要备份的内容,SKIP变量的选项有:db, uploads (attachments), repositories, builds(CI build output logs), artifacts (CI build artifacts), lfs (LFS objects)。多个项之间用逗号隔开:

sudo gitlab-rake gitlab:backup:create SKIP=db,uploads1

backup命令执行之后,终端上会出现导出数据库及repo数据等的的操作日志。


Gitlab 修改备份文件默认目录

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

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

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

备份

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

恢复

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

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

# 停止相关数据连接服务
gitlab-ctl stop unicorn 
# ok: down: unicorn: 0s, normally up 

gitlab-ctl stop sidekiq
# ok: down: sidekiq: 0s, normally up

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

# 启动Gitlab
sudo gitlab-ctl start
# 恢复过程中没有权限
mkdir /var/opt/gitlab/backups
chown git /var/opt/gitlab/backups
chmod 700 /var/opt/gitlab/backups
# 恢复成功页面报没有权限的错误
sudo chown -R git:git /var/opt/gitlab/git-data/repositories
sudo chmod -R ug+rwX,o-rwx /var/opt/gitlab/git-data/repositories
sudo chmod -R ug-s /var/opt/gitlab/git-data/repositories
sudo find /var/opt/gitlab/git-data/repositories -type d -print0 | sudo xargs -0 chmod g+

迁移

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


错误处理

Error executing action `run` on resource 'bash[migrate gitlab-rails database]'

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

NameError: uninitialized constant Devise::Async



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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI