Gitlab 安装、卸载、配置及仓库迁移

一、安装

安装主要有在线和离线两种安装方式,这里主要讲离线安装,如果想在线安装可以参考本文仓库移植里面的gitlab升级选项。

1. 下载(可以使用浏览器下载,也可以使用wget下载

下载地址:
https://packages.gitlab.com/gitlab/gitlab-ce/
如果网络不好,我共享网盘链接给大家:
链接:https://pan.baidu.com/s/1km0-6SruoAe3Lkg80O3RSA 提取码:dupv

2. 安装依赖包
sudo apt-get install curl openssh-server ca-certificates postfix
3. 安装gitlab
sudo dpkg -i gitlab-ce_9.0.0-ce.0_amd64.deb
4. 配置并启动(参考本文第三大标题,在此不再赘述
5. 查看版本
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

二、卸载

1. 移除服务

sudo gitlab-ctl uninstall

2. 清除gitlab所使用的包

sudo gitlab-ctl cleanse

3. 移除gitlab账号信息

sudo gitlab-ctl remove-accounts

4. 移除gitlab (注:这里卸载的是 ce)

sudo dpkg -P gitlab-ce
一般情况下git使用到的目录主要是下面几个:
  • /opt/gitlab holds application code for GitLab and its dependencies.
  • /var/opt/gitlab holds application data and configuration files that gitlab-ctl reconfigure writes to.
  • /etc/gitlab holds configuration files for omnibus-gitlab. These are the only files that you should ever have to edit manually.
  • /var/log/gitlab contains all log data generated by components of omnibus-gitlab.

三、配置

1. 地址和端口

  • 备份并修改配置文件
cp /etc/gitlab/gitlab.rb  /etc/gitlab/gitlab.rb.bak


# http地址配置(找到这一行 # external_url 'GENERATED_EXTERNAL_URL')
external_url 'http://192.168.X.X:80XX'
# ssh地址配置
gitlab_rails['gitlab_ssh_host'] = 'ssh.域名或IP地址'
gitlab_rails['gitlab_shell_ssh_port'] = 443

  • 启动gitlab
sudo gitlab-ctl reconfigure  #改过gitlab.rb文件,使用做的修改生效 
sudo gitlab-ctl start        #启动

2. 仓库存储路径

一般情况下我们不愿意把gitlab的仓库存放在系统盘里面,所以我们需要配置在其他路径

  • 找到gitlab.rb下面的git_data_dirs选项,修改如下:
git_data_dirs({
  "default" => { "path" => "/file/git-data" },            //默认存储目录
  "alternative" => { "path" => " /home/gitlab-data" }     //备用存储目录
})

  • 重新启动gitlab
itlab-ctl stop
sudo gitlab-ctl reconfigure  #改过gitlab.rb文件,使用做的修改生效 
sudo gitlab-ctl start        #启动

四、仓库迁移

(一)gitlab版本同步

注意:gitlab数据迁移首要条件是两个gitlab版本需要一致,不一致的需要升级旧版本保证一致。

1. 在升级前一定要做好备份,记录自己当前gitlab的版本号
[root@localhost ~]# yum list | grep gitlab-ce
gitlab-ce.x86_64                           9.3.6-ce.0.el7              installed
2. 备份文件(gitlab-rake gitlab:backup:create)
[root@localhost ~]# gitlab-rake gitlab:backup:create
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
 * dev/dubbo ... [DONE]
 * dev/dubbo.wiki ...  [SKIPPED]
 * dev/dubbox-master ... [DONE]
 * dev/dubbox-master.wiki ...  [SKIPPED]
 * MobileTerminal/MobileDoc ... [SKIPPED]
 * MobileTerminal/MobileDoc.wiki ...  [SKIPPED]
 * TrakCare/Doc ... [SKIPPED]
 * TrakCare/Doc.wiki ...  [SKIPPED]
 * PerationMaintenance/PMDoc ... [DONE]
 * PerationMaintenance/PMDoc.wiki ...  [DONE]
 * doc/his ... [DONE]
 * doc/his.wiki ...  [SKIPPED]
 * PerationMaintenance/image ... [SKIPPED]
 * PerationMaintenance/image.wiki ...  [SKIPPED]
done
Dumping uploads ... 
done
Dumping builds ... 
done
Dumping artifacts ... 
done
Dumping pages ... 
done
Dumping lfs objects ... 
done
Dumping container registry images ... 
[DISABLED]
Creating backup archive: 1552552057_2019_03_14_9.3.6_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
done
done
done
done
done
done
Deleting old backups ... skipping
在目录/var/opt/gitlab/backups/下会生成一个备份文件如:1552552057_gitlab_backup.tar,其中1552552057即为此次备份都版本号,注意保留该文件,最好拷贝到其他目录
3. 升级gitlab

注意:由于升级不能跨大版本号,因此只能升级到当前大版本号到最高版本,方可升级到下一个大版本号

3.1. 在线升级
  • 配置gitlab-yum源
[root@localhost ~]# cat << EOF > /etc/yum.repos.d/gitlab-ce.repo
> [gitlab-ce]
> name=gitlab-ce
> baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
> repo_gpgcheck=0
> gpgcheck=0
> enable=1
> gpgkey=https://packages.gitlab.com/gpg.key
> EOF
  • yum install安装
[root@localhost ~]# yum install gitlab-ce-9.5.9
已加载插件:fastestmirror, langpacks
gitlab-ce                                                                                                                                                                                                                               | 2.9 kB  00:00:00     
gitlab-ce/primary_db                                                                                                                                                                                                                    | 2.7 MB  00:00:01     
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
正在解决依赖关系
--> 正在检查事务
---> 软件包 gitlab-ce.x86_64.0.9.3.6-ce.0.el7 将被 升级
---> 软件包 gitlab-ce.x86_64.0.9.5.9-ce.0.el7 将被 更新
--> 解决依赖关系完成

依赖关系解决

===============================================================================================================================================================================================================================================================
 Package                                                      架构                                                      版本                                                                源                                                            大小
===============================================================================================================================================================================================================================================================
正在更新:
 gitlab-ce                                                    x86_64                                                    9.5.9-ce.0.el7                                                      gitlab-ce                                                    381 M

事务概要
===============================================================================================================================================================================================================================================================
升级  1 软件包

总下载量:381 M
Is this ok [y/d/N]: Y
Downloading packages:
No Presto metadata available for gitlab-ce
gitlab-ce-9.5.9-ce.0.el7.x86_6 FAILED                                                                            18% [==================-                                                                                    ]  659 B/s |  70 MB 137:35:05 ETA 
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm: [Errno 12] Timeout on https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
gitlab-ce-9.5.9-ce.0.el7.x86_6 FAILED                                                                            21% [======================                                                                                 ]  646 B/s |  83 MB 134:19:56 ETA 
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm: [Errno 12] Timeout on https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
gitlab-ce-9.5.9-ce.0.el7.x86_6 FAILED                                                                            81% [===================================================================================-                   ]  411 B/s | 311 MB  50:00:08 ETA 
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm: [Errno 12] Timeout on https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm: (28, 'Operation too slow. Less than 1000 bytes/sec transferred the last 30 seconds')
正在尝试其它镜像。
gitlab-ce-9.5.9-ce.0.el7.x86_64.rpm                                                                                                                                                                                                     | 381 MB  00:01:52     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
gitlab preinstall: Automatically backing up only the GitLab SQL database (excluding everything else!)
Dumping database ... 
Dumping PostgreSQL database gitlabhq_production ... [DONE]
done
Dumping repositories ...
[SKIPPED]
Dumping uploads ... 
[SKIPPED]
Dumping builds ... 
[SKIPPED]
Dumping artifacts ... 
[SKIPPED]
Dumping pages ... 
[SKIPPED]
Dumping lfs objects ... 
[SKIPPED]
Dumping container registry images ... 
[DISABLED]
Creating backup archive: 1552553362_2019_03_14_9.3.6_gitlab_backup.tar ... done
Uploading backup archive to remote storage  ... skipped
Deleting tmp directories ... done
done
Deleting old backups ... skipping
  正在更新    : gitlab-ce-9.5.9-ce.0.el7.x86_64 [############################################################################################################################                                                                            ] 1/2  正在更新    : gitlab-ce-9.5.9-ce.0.el7.x86_64 [##############################################################################################################################                                     正在更新    : gitlab-ce-9.5.9-ce.0.el7.x86_64                                                                                                                                                                                               1/2 


       *.                  *.
      ***                 ***
     *****               *****
    .******             *******
    ********            ********
   ,,,,,,,,,***********,,,,,,,,,
  ,,,,,,,,,,,*********,,,,,,,,,,,
  .,,,,,,,,,,,*******,,,,,,,,,,,,
      ,,,,,,,,,*****,,,,,,,,,.
         ,,,,,,,****,,,,,,
            .,,,***,,,,
                ,*,.

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


gitlab: Thank you for installing GitLab!
gitlab: To configure and start GitLab, RUN THE FOLLOWING COMMAND:

sudo gitlab-ctl reconfigure

gitlab: GitLab should be reachable at http://192.168.x.x:8090/gitlab
gitlab: Otherwise configure GitLab for your system by editing /etc/gitlab/gitlab.rb file
gitlab: And running reconfigure again.
gitlab: 
gitlab: For a comprehensive list of configuration options please see the Omnibus GitLab readme
gitlab: https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md
gitlab: 
  清理        : gitlab-ce-9.3.6-ce.0.el7.x86_64                                                                                                                                                                           2/2 
Checking PostgreSQL executables: OK
Shutting down all GitLab services except those needed for migrations
ok: down: gitaly: 1s, normally up
ok: down: gitlab-monitor: 0s, normally up
ok: down: gitlab-workhorse: 1s, normally up
ok: down: logrotate: 0s, normally up
ok: down: nginx: 1s, normally up
ok: down: node-exporter: 0s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 0s, normally up
ok: down: redis: 1s, normally up
ok: down: redis-exporter: 0s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 0s, normally up
ok: run: postgresql: (pid 3362) 1s
ok: run: redis: (pid 3370) 0s
run: postgresql: (pid 3362) 1s; run: log: (pid 866) 3488369s
run: redis: (pid 3370) 0s; run: log: (pid 897) 3488369s
Reconfiguring GitLab to apply migrations


  * Moving existing certificates found in /opt/gitlab/embedded/ssl/certs

  * Symlinking existing certificates found in /etc/gitlab/trusted-certs
gitlab Reconfigured!
Checking for an omnibus managed postgresql: OK
Checking if we already upgraded: OK
The latest version 9.6.3 is already running, nothing to do
Ensuring PostgreSQL is updated: OK
Restarting previously running GitLab services
ok: run: gitaly: (pid 4046) 2s
ok: run: gitlab-monitor: (pid 4086) 1s
ok: run: gitlab-workhorse: (pid 4068) 2s
ok: run: logrotate: (pid 4120) 1s
ok: run: nginx: (pid 4126) 0s
ok: run: node-exporter: (pid 4177) 0s
ok: run: postgres-exporter: (pid 4184) 1s
ok: run: postgresql: (pid 3362) 72s
ok: run: prometheus: (pid 4094) 3s
ok: run: redis: (pid 3370) 71s
ok: run: redis-exporter: (pid 4194) 0s
ok: run: sidekiq: (pid 4203) 1s
ok: run: unicorn: (pid 4216) 0s

Upgrade complete! If your GitLab server is misbehaving try running

   sudo gitlab-ctl restart

before anything else. If you need to roll back to the previous version you can
use the database backup made during the upgrade (scroll up for the filename).
  验证中      : gitlab-ce-9.5.9-ce.0.el7.x86_64                                                                                                                                                                           1/2 
  验证中      : gitlab-ce-9.3.6-ce.0.el7.x86_64                                                                                                                                                                           2/2 

更新完毕:
  gitlab-ce.x86_64 0:9.5.9-ce.0.el7                                                                                                                                                                                           

完毕!
3.2. 离线升级
  • 关闭部分服务
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
gitlab-ctl stop nginx
  • 升级并重启
rpm -Uvh gitlab-ce-10.0.4-ce.0.el7.x86_64.rpm
gitlab-ctl reconfigure
gitlab-ctl restart
4. 导入备份数据
4.1. 查看权限并授权
  • 把之前备份的文件拷贝到/var/opt/gitlab/backups/
ls -lh /var/opt/gitlab/backups/
chmod 777 /var/opt/gitlab/backups/1540775659_2018_10_29_11.2.3_gitlab_backup.tar
4.2. 停止相关数据连接服务(注意此时gitlab依旧是打开状态,不然无法导入)
gitlab-ctl stop unicorn
gitlab-ctl stop sidekiq
4.3. 恢复gitlab数据(注意:BACKUP后面是文件名的前缀,文件名称后缀统一是“_gitlab_backup.tar”
gitlab-rake gitlab:backup:restore BACKUP=1540775659_2018_10_29_11.2.3
yes-->yes
4.4. 启动gitlab
gitlab-ctl start

参考链接

————————————————
https://www.cnblogs.com/m2ez/p/7063606.html
https://www.jianshu.com/p/45be958bf5f9
https://blog.csdn.net/qq_36949713/article/details/89025198
https://blog.csdn.net/love8753/article/details/88557036

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 203,937评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,503评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 150,712评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,668评论 1 276
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,677评论 5 366
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,601评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,975评论 3 396
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,637评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,881评论 1 298
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,621评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,710评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,387评论 4 319
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,971评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,947评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,189评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 44,805评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,449评论 2 342

推荐阅读更多精彩内容