打赏

星辰大海ゞ

That which does not kill us makes us stronger!

导航

Gitlab安装与备份恢复

Gitlab代码迁移

单个工程项目:

1. 获取旧服务器上代码工程的地址,克隆工程的裸仓库到本地

git clone –bare git@old_url:root/project3.git

2. 在新服务器上创建新的空工程

比如,新创建的空工程地址是:git@destination_url:root/project3.git
创建完后,需要先临时关闭master分支保护,否则报错

3. 推送本地裸仓库镜像到新服务器

git push –mirror git@destination_url:root/project3.git

 


 

GitLab用户配置:

1、清缓存
删除保存在本地的git账户
git credential-manager uninstall
缓存账户
git config --global credential.helper wincred删除保存在本地的git账户

2、设置用户名
git config --global user.name username

3、设置邮箱 (注意:没有双引号)
git config --global user.email aa@unissoft-grp.com

4、存储信息
git config --global credential.helper store

5、查看配置
git config --list


 

GitHub是2008年由Ruby on Rails编写而成,与业界闻名的Github类似;但要将代码上传到GitHub上面,而且将项目设为私有还要收费。GitLab是一个用于仓库管理系统的开源项目,使用Git作为代码管理工具,可通过Web界面进行访问公开的或者私人项目,非常适合在团队内部使用。

在gitlab中有三个版本,分别是CE(社区版)、EE(企业版)、OM(RPM包完整版,里面包括nginx、redis等其它软件,比较大)。

一、安装方法这里分为两种

1、官方安装说明:https://about.gitlab.com/installation/ (推荐)

将EXTERNAL_URL="http://gitlab.example.com" 修改成自己的IP或域名

# EXTERNAL_URL="http://wjoyxt.cnblogs.com" yum install -y gitlab-ee-10.7.0

2、使用清华大学开源镜像repo源一键安装:https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/ 或手动下载rpm包下载: https://mirrors.tuna.tsinghua.edu.cn/

# yum install gitlab-ce 或 yum install gitlab-ee        #自动安装最新版
# yum install gitlab-ce-x.x.x                                  #安装指定版本

 

查看已安装的版本号:

# cat /opt/gitlab/embedded/service/gitlab-rails/VERSION 

按需要修改主配置文件:

# cat /etc/gitlab/gitlab.rb | grep -v ^# | grep -v ^$

external_url 'http://10.35.46.21:9999'
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/home/data/gitlabBackup"
gitlab_rails['backup_archive_permissions'] = 0644
gitlab_rails['backup_keep_time'] = 5184000
git_data_dirs({
   "default" => {
     "path" => "/home/data/gitlabData"
    }
 })

重新加载配置文件
# gitlab-ctl reconfigure

顺便说一下卸载:

# yum remove -y gitlab-ee

# rm -fr /opt/gitlab  /var/opt/gitlab 

设置开机启动:

# systemctl enable gitlab-runsvdir.service

二、备份操作

Gitlab的备份目录路径设置,默认备份到 /var/opt/gitlab/backups

# vim /etc/gitlab/gitlab.rb
gitlab_rails['manage_backup_path'] = true
gitlab_rails['backup_path'] = "/data/gitlab/backups"    //gitlab备份目录
gitlab_rails['backup_archive_permissions'] = 0644       //生成的备份文件权限
gitlab_rails['backup_keep_time'] = 7776000              //备份保留天数为3个月(即90天,这里是7776000秒)
 
# mkdir -p /data/gitlab/backups
# chown -R git.git /data/gitlab/backups
# chmod -R 777 /data/gitlab/backups
  
如上设置了gitlab备份目录路径为/data/gitlab/backups,最后使用下面命令重载gitlab配置文件,是上述修改生效!
# gitlab-ctl reconfigure

进行手动备份:

# gitlab-rake gitlab:backup:create    产生的备份文件格式类似:  1536734284_2018_09_12_10.7.0-ee_gitlab_backup.tar

开启计划任务实现自动备份:

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

注意:环境变量CRON=1的作用是如果没有任何错误发生时, 不显示备份时的所有进度输出

 

三、恢复操作

1、停止相关数据连接服务
# gitlab-ctl stop unicorn
# gitlab-ctl stop sidekiq

# gitlab-ctl status  确认以上两个服务状态为:down:

2、进行恢复Gitlab的恢复操作会先将当前所有的数据清空,然后再根据备份数据进行恢复,需要指定备份文件的编号,即 _gitlab_backup.tar 前面的部分

# gitlab-rake gitlab:backup:restore BACKUP=1536734284_2018_09_12_10.7.0-ee

3、启动gitlab

# gitlab-ctl start

 

四、Gitlab迁移

迁移如同备份与恢复的步骤一样, 只需要将老服务器/var/opt/gitlab/backups目录下的备份文件拷贝到新服务器上的/var/opt/gitlab/backups即可(如果你没修改过默认备份目录的话). 但是需要注意的是新服务器上的Gitlab的版本必须与创建备份时的Gitlab版本号相同. 比如新服务器安装的是最新的10.7.0版本的Gitlab, 那么迁移之前, 最好将老服务器的Gitlab 升级为10.7.0再进行备份。

 

启用HTTPS方法:https://docs.gitlab.com/omnibus/settings/nginx.html#enable-https

                        https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/doc/settings/nginx.md#enable-https

 

五、Gitlab汉化

注意:进行之前先备份目录/opt/gitlab/embedded/service/gitlab-rails,用于汉化失败进行恢复

# git clone https://gitlab.com/xhang/gitlab.git

# gitlab-ctl stop

# cd gitlab ; git diff origin/10-7-stable  origin/10-7-stable-zh > 10.7.diff

# yum -y install patch

# cp -r /opt/gitlab/embedded/service/gitlab-rails{,.bak}

# patch -d /opt/gitlab/embedded/service/gitlab-rails -p1 < 10.7.diff

# gitlab-ctl start

 

gitlab-runner

# gitlab-runner --help

USAGE:

   gitlab-runner[global options] command [command options] [arguments...]

COMMANDS

名称

作用

exec

显示runner配置文件

list

 

run

运行多个runner服务

register

注册一个新的runner

install

安装服务

uninstall

卸载服务

start

启动一个服务

stop

停止一个服务

restart

重启

status

一个服务状态

run-single

运行单独的一个runner

unregister

注销特定的runner

verify

验证所有注册的runner

 

 

常用命令

说明

sudo gitlab-ctl reconfigure

重新加载配置,每次修改/etc/gitlab/gitlab.rb文件之后执行

sudo gitlab-ctl status

查看 GitLab 状态

sudo gitlab-ctl start

启动 GitLab

sudo gitlab-ctl stop

停止 GitLab

sudo gitlab-ctl restart

重启 GitLab

sudo gitlab-ctl tail

查看所有日志

sudo gitlab-ctl tail nginx/gitlab_acces.log

查看 nginx 访问日志

sudo gitlab-ctl tail postgresql

查看 postgresql 日志

 

 

 

参考资料: http://www.cnblogs.com/supery007/p/9053774.html

                http://www.cnblogs.com/kevingrace/p/5985918.html

 

posted on 2018-09-12 11:24  星辰大海ゞ  阅读(591)  评论(0编辑  收藏  举报