Gitlab安装和迁移

Gitlab做迁移,有一些麻烦,有如下结论:
1:Gitlab版本要完全一致,mysql版本最好一致(不能相差太大),服务器版本可以不一样(例如:迁移前环境为centos6.5,迁移后环境为centos7.4)
2: 以前如果是用的mysql,那么迁移后也需要用到mysql,缺省情况下,当你安装了gitlab的omnibus安全包后,缺省是不提供mysql2的gem,因此你无法配置为使用mysql数据库,只有Gitlab的OmniBus EE版本可以使用mysql数据库

一、准备工作
1:安装mysql,这里需要和原服务器一样版本的mysql,按需安装。
2: 安装相关依赖

yum -y update
yum whatprovides libmysqlclient*
yum install gcc automake autoconf libtool make
yum install gcc gcc-c++
yum install ruby-devel
yum -y group install "development tools"
yum -y install vim cmake wget
yum -y install readline-devel gdbm-devel openssl-devel expat-devel sqlite-devel libyaml-devel libffi-devel libxml2-devel libxslt-devel libicu-devel system-config-firewall-tui python-devel xmlto logwatch perl-ExtUtils-CBuilder

3:按需卸载gitlab版本
gitlab-ctl stop
rpm -qa|grep git 查看后删除
find / -name "gitlab" | xargs rm -rf
find / -name gitlab |xargs rm -rf

上面工作做好后重启机器

二、正式安装

#cent7 对应的安装包 rpm
具体要下载哪些版本去这个地方下载https://www.gitlab.com.cn/downloads/archives/
例如我的是:

curl -O https://downloads-packages.s3.amazonaws.com/centos-6.5/gitlab-7.2.1_omnibus-1.el6.x86_64.rpm

#安装对应的 openssh服务
yum install openssh-server
#设置开机启动
systemctl enable sshd
#启动sshd服务
systemctl start sshd

安装对应的 postfix服务同样设置开机启动和启动服务
yum install postfix
systemctl enable postfix
systemctl start postfix

#使用rpm 源安装,gitlab omnibus安装包
rpm -i gitlab-7.2.1_omnibus-1.el6.x86_64.rpm
#安装完成之后会出现complete,并提示你配置gitlab

#安装完成之后,配置gitlab
gitlab-ctl reconfigure

#设置服务器的防火墙允许http,和ssh服务
firewall-cmd --permanent --add-service=http

#重新启动防火墙
systemctl reload firewalld

#给gitlab服务绑定域名
vim /etc/gitlab/gitlab.rb
#填写你指定的绑定域名和端口,默认是80端口
external_url 'http://gitlab.ciika.com'

#重新启动一下服务
gitlab-ctl restart

#浏览器,打开绑定的域名及端口,访问
#默认的用户名是 root,密码是 5iveL!fe 登陆成功之后,会修改密码

三、恢复数据:
准备工作:

1:数据库赋权:

GRANT ALL PRIVILEGES ON *.* TO 'gitlab'@'127.0.0.1' identified by 'gitlab';
flush PRIVILEGES;

2:修改链接为mysql

gitlab_rails['db_adapter'] = 'mysql2'
gitlab_rails['db_encoding'] = 'utf8'
gitlab_rails['db_pool'] = 10
gitlab_rails['db_host'] = '127.0.0.1'
gitlab_rails['db_port'] = '3306'
gitlab_rails['db_database'] = 'gitlabhq_production'
gitlab_rails['db_username'] = 'gitlab'
gitlab_rails['db_password'] = 'gitlab'
postgresql['enable'] = false

3:修改config,由mysql改成postgres
/opt/gitlab/embedded/service/gitlab-rails/.bundle/config
修改后为:

BUNDLE_WITHOUT: development:test:postgres

4:安装mysql2

cd /opt/gitlab/embedded/bin/
./gem install -i /opt/gitlab/embedded/service/gem/ruby/2.1.0 mysql2 -v0.3.16

一定要注意-v0.3.16,如果后续报错(Could not find mysql2-0.3.16 in any of the sources),就是这里的版本弄错了

5:检查
gitlab-rake gitlab:check
这里一定要是成功的,如果不成功,看看那个依赖没有安装

6: 初始化Mysql数据,输入yes即可
gitlab-rake gitlab:setup

导入数据:
首先把之前备份的数据放置到/var/opt/gitlab/backups目录下
格式需要为xxx_gitlab_backup.tar
gitlab-rake gitlab:backup:restore
耐心的等待各个仓库的导出,成功后即可用之前的用户名和密码登录

可能会遇到如下报错:
Error: "You have to install development tools first."

Restoring repositories ...
rake aborted!
ActiveRecord::StatementInvalid: PG::Error: ERROR: relation "projects" does not exist
LINE 1: SELECT "projects".* FROM "projects" ORDER BY "projects"."...
^
: SELECT "projects".* FROM "projects" ORDER BY "projects"."id" ASC LIMIT 1000
PG::Error: ERROR: relation "projects" does not exist
LINE 1: SELECT "projects".* FROM "projects" ORDER BY "projects"."...
^
Tasks: TOP => gitlab:backup:repo:restore
(See full trace by running task with --trace)

如果在添加SSH KEY的时候报错:ssh key Fingerprint cannot be generated
编辑<path-to-gitlab>/app/models/key.rb
例如我的是:
/opt/gitlab/embedded/service/gitlab-rails/app/models/key.rb
原本是:cmd_output, cmd_status = popen(%W(ssh-keygen -lf #{file.path}), '/tmp')
改成:cmd_output, cmd_status = popen(%W(ssh-keygen -E md5 -lf #{file.path}), '/tmp')
重启问题解决

标签: none

添加新评论