gitlab安装--数据备份迁移恢复

gitlab安装以及数据备份恢复

查看版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
centos 7.6

1.添加镜像地址

#版本13.2.4  

vi /etc/yum.repos.d/gitlab-ce.repo
#---------------------------------------------------
[gitlab-ce]
name=gitlab-ce
# 清华大学的镜像源
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
repo_gpgcheck=0
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key

2.安装依赖

# 安装和配置openssh
sudo yum install curl policycoreutils-python openssh-server openssh-clients
sudo systemctl enable sshd
sudo systemctl start sshd
# 安装和配置邮件服务
sudo yum install postfix
sudo systemctl enable postfix
sudo systemctl start postfix

3.开始安装

#安装最新版本
yum install -y gitlab-ce

#指定版本安装
yum install -y gitlab-ce-13.2.4 

4.修改配置文件

vim /etc/gitlab/gitlab.rb
#修改url  改成自己需要的域名
external_url "http://gitlab.naxions.com"

在此配置文件中可以配置backup数据备份路径,数据的存放路径,已经gitlab-mail的配置

# mail的示例,根据自己公司的邮箱配置
### Email Settings
# gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
# gitlab_rails['gitlab_email_from'] = '[email protected]'
# gitlab_rails['gitlab_email_display_name'] = 'Example'
# gitlab_rails['gitlab_email_reply_to'] = '[email protected]'
# gitlab_rails['gitlab_email_subject_suffix'] = ''
# gitlab_rails['gitlab_email_smime_enabled'] = false
# gitlab_rails['gitlab_email_smime_key_file'] = '/etc/gitlab/ssl/gitlab_smime.key'
# gitlab_rails['gitlab_email_smime_cert_file'] = '/etc/gitlab/ssl/gitlab_smime.crt'
# gitlab_rails['gitlab_email_smime_ca_certs_file'] = '/etc/gitlab/ssl/gitlab_smime_cas.crt'

gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "sCJiYkQALH3uKFKK"
gitlab_rails['smtp_domain'] = "naxions.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true

5.保存,执行加载配置命令

gitlab-ctl reconfigure   #加载配置

gitlab-ctl restart #启动

禁止 Gitlab 开机自启动:systemctl disable gitlab-runsvdir.service

启用 Gitlab 开机自启动:systemctl enable gitlab-runsvdir.service

gitlab数据备份恢复(迁移也是同样的手法)

1.数据迁移必要条件

新服务器上安装的gitlab必须与旧服务器上版本一致,版本不一致在新服务器恢复数据时将发生错误

# 查看gitlab版本的命令为
gitlab-rake gitlab:env:info

2.数据迁移步骤

(1)旧服务器上备份数据

注意:备份产生很大的数据,需时刻关注磁盘空间是否够用

#备份命令  时间很久需要耐心等待
gitlab-rake gitlab:backup:create RAILS_ENV=production

备份后的文件一般是位于/var/opt/gitlab/backups下, 自动生成文件名如1662147741_2022_09_03_13.2.4_gitlab_backup.tar,其中1662147741为备份的时间点。自动生成文件名可能也为1662147741_2022_09_03_13.2.4_gitlab_backup.tar,其中2022_09_03为备份的日期,13.2.4为gitlab的版本号

(2)将生成的tar备份文件拷贝到新服务器上相应的目录下

可以利用scp进行直接拷贝,新服务器上目录一般是/var/opt/gitlab/backups

(3) 新服务器上恢复数据

#恢复数据前,备份文件必须有运行权限,需给拷贝过来的文件权限,负责会报错
chmod 755 1662147741_2022_09_03_13.2.4_gitlab_backup.tar

#恢复数据的命令为  删除后面的gitlab_backup.tar  恢复时间很久,需要耐心等待
gitlab-rake gitlab:backup:restore RAILS_ENV=production BACKUP=1662147741_2022_09_03_13.2.4

注意:BACKUP后面的时间点必须与原服务器备份后文件名中的时间点一致

(4)恢复数据过程中两步确认均选择yes

#第一个yes
Before restoring the database, we will remove all existing
tables to avoid future upgrade problems. Be aware that if you have
custom tables in the GitLab database these tables and all data will be
removed.

Do you want to continue (yes/no)? yes

#第二个yes
This task will now rebuild the authorized_keys file.
You will lose any data stored in the authorized_keys file.
Do you want to continue (yes/no)? yes

(5)重启服务 gitlab-ctl restart

迁移后可能存在的问题

1.删除project失败

错误信息:500 Whoops,something went wrong on our end.
解决方案:

1.#进入db控制台
[root@VM_1_17_centos ~]# gitlab-rails dbconsole
psql (10.7)
Type "help" for help.

gitlabhq_production=> 

2.#Reset CI/CD variables
Check the ci_group_variables and ci_variables tables:
Those are the variables that you need to delete.
----------------------------------------------------
执行:
gitlabhq_production=> SELECT * FROM public."ci_group_variables";
id | key | value | encrypted_value | encrypted_value_salt | encrypted_value_iv | group_id | protected | created_at | updated_at | masked | variable_type 
----+-----+-------+-----------------+----------------------+--------------------+----------+-----------+------------+------------+--------+---------------
(0 rows)

gitlabhq_production=> SELECT * FROM public."ci_variables";
id | key | value | encrypted_value | encrypted_value_salt | encrypted_value_iv | project_id | protected | environment_scope | masked | variable_type 
----+-----+-------+-----------------+----------------------+--------------------+------------+-----------+-------------------+--------+---------------
(0 rows)
3.#Reset Runner registration tokens
Clear all the tokens for projects, groups, and the whole instance:
执行:
gitlabhq_production=> UPDATE projects SET runners_token = null, runners_token_encrypted = null;
UPDATE 16
gitlabhq_production=> UPDATE namespaces SET runners_token = null, runners_token_encrypted = null;
UPDATE 27
gitlabhq_production=> UPDATE application_settings SET runners_registration_token_encrypted = null;
UPDATE 1
gitlabhq_production=> UPDATE ci_runners SET token = null, token_encrypted = null;
UPDATE 0

4.#退出DB控制台
gitlabhq_production=> exit

5.#重启服务
gitlab-ctl restart

2.Web-IDE打不开

错误信息:Error while loading project data. please try again.
错误原因:api/v4/projects/ u s e r {user}%2F user{project} 500 (Internal Server Error)
解决方案:同上。

3.点击admin area的任何设定时报错

错误信息:500 Whoops,something went wrong on our end.
解决方案:同上。

你可能感兴趣的:(gitlab,jenkins,gitlab,linux,服务器)