gitlab 安装、配置、清空、卸载、重装

拥有回忆 提交于 2020-10-09 11:46:45

20200702 自行搭建 git 服务器后,如何管理总是一个麻烦事,所以,还是要安装一个 gitlab

按照 gitlab 官网安装 ce 版,其实应该是很简单的事情,步骤也很少。

正常情况下,安装、配置、运行,再学习 gitlab 使用

没有想到我折腾了一大圈!来回卸载、重装、重新配置!几乎所有该出现的问题,全都遇见了一轮!

我的环境: virtualBox 虚拟机 ubuntu Server 1804

gitlab 官网 https://about.gitlab.com/install/#ubuntu

gitlab ce 版本安装步骤 https://about.gitlab.com/install/#ubuntu?version=ce

清华大学开源软件镜像站 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/

Gitlab Community Edition 镜像使用帮助 https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/

1、 安装

  1. 安装必要的依赖 sudo apt-get install -y curl openssh-server ca-certificates

  2. 非必须 ( 如果开始学习或者后续需要使用邮箱开放注册的话,请安装 ) sudo apt-get install -y postfix

  3. 设置安装包和 gitlab 软件源 curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash

  4. 按照前面镜像使用帮助,设置清华 gitlab ce 软件源 上一步 bash 完成之后。会增加一个 gitlab ce 的软件源,如下:

     $ cd /etc/apt/sources.list.d
     $ ls
     gitlab_gitlab-ce.list
    

    $ vim gitlab_gitlab-ce.list 替换一下

     # this file was generated by packages.gitlab.com for
     # the repository at https://packages.gitlab.com/gitlab/gitlab-ce
    
     # by wzh 20200702
     # deb https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ bionic main
     # deb-src https://packages.gitlab.com/gitlab/gitlab-ce/ubuntu/ bionic main
     # TsingHua 
     deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main
     deb-src https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic main
    
  5. 开始安装 gitlab-ce

    gitlab 使用 ruby 的 rails 框架开发,已经自带了 web 服务器 所以不需要提前准备一个域名网站,直接使用 ip + 端口方式即可 后续在配置 nginx 映射到这个 ip 和端口即可

    $ sudo EXTERNAL_URL="http://127.0.0.1:8090" apt-get install gitlab-ce

    Reading package lists... Done Building dependency tree
    Reading state information... Done The following packages will be upgraded: gitlab-ce 1 upgraded, 0 newly installed, 0 to remove and 121 not upgraded. Need to get 740 MB of archives. After this operation, 139 kB disk space will be freed. Get:1 https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu bionic/main amd64 gitlab-ce amd64 13.1.2-ce.0 [740 MB] ...

    安装过程比较漫长,即使换成了清华的源,也很慢!

  6. 配置生效并开始运行 sudo gitlab-ctl reconfigure && sudo gitlab-ctl start

    这个过程也比较慢!这个 gitlab 确实比较庞大,涵盖的东西很多! gitlab-ctl start 也需要 root 权限,否则,会出现一大堆 warning

  7. 测试、验证 sudo ufw enable 8090

    sudo ufw status

    或者干脆 sudo ufw disable

    $ curl 127.0.0.1:8090 应该看到的是

     <html><body>You are being <a href="http://127.0.0.1:8090/users/sign_in">redirected</a>.</body></html
    

    浏览器测试一下 http://192.168.1.194:8090

    会自动重定向到以下 url

    http://192.168.1.194:8090/users/password/edit?reset_password_token=oN-Fu-KZgSPS-9qd7rzV

    如果顺利的到达这里,gitlab ce 就算 ok! 剩下就是学习使用了!

  8. 查看配置信息 $ sudo gitlab-ctl show-config 内容确实很多很多!

    	Starting Chef Client, version 14.14.29
    resolving cookbooks for run list: ["gitlab::show_config"]
    Synchronizing Cookbooks:
      - package (0.1.0)
      - redis (0.1.0)
      - postgresql (0.1.0)
      - monitoring (0.1.0)
      - registry (0.1.0)
      - mattermost (0.1.0)
      - consul (0.1.0)
      - gitaly (0.1.0)
      - praefect (0.1.0)
      - letsencrypt (0.1.0)
      - nginx (0.1.0)
      - runit (5.1.3)
      - acme (4.1.1)
      - crond (0.1.0)
      - gitlab (0.0.1)
    Installing Cookbook Gems:
    Compiling Cookbooks...
    ......
    
  9. 查看版本号

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

    13.1.2


    以下内容可以不必观看 以下过程希望不再经历!

2、常用命令

安装的时候都已经设置好了!不折腾的话,这些命令基本上用不上!

以下命令都需要 sudo

  • 查询 gitlab 服务 systemctl list-unit-files --type=service | grep gitlab

    gitlab-runsvdir.service enabled

    查询 gitlab 服务状态 systemctl status gitlab-runsvdir.service

  • 设置开机启动 systemctl enable gitlab-runsvdir.service

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

  • 启动/重启/停止 gilab 服务 gitlab-ctl start gitlab-ctl restart gitlab-ctl stop

  • 修改配置后,重新配置生效 gitlab-ctl reconfigure 一般连着使用 sudo gitlab-ctl reconfigure && sudo gitlab-ctl start

  • 查看 gitlab 配置 gitlab-ctl show-config

  • 卸载 gitlab gitlab-ctl uninstall

  • 清空 gitlab 配置,推倒重来 gitlab-ctl cleanse

  • 查看 gitlab 日志 gitlab-ctl tail

3、 异常情况

  1. 关机或者 reboot 之后,再次测试 $ curl 127.0.0.1:8090 看到的不是以上一条语句了,而是一大段

     ......
       <script>
         (function () {
           var goBack = document.querySelector('.js-go-back');
    
           if (history.length > 1) {
             goBack.style.display = 'inline';
           }
         })();
       </script>
     </body>
     </html>
    

浏览器打开 http://192.168.1.194:8090 ,立刻出现 502 !可恶之极!

502
Whoops, GitLab is taking too much time to respond.
  1. 后续来回折腾之后,发现自己掉坑底! 以上错误并非 gitlab 安装的不对,也不是 gitlab 出错了! 每次 reboot 之后, gitlab 服务启动需要花好长时间的! 本人反应比较快,直接就开始检查配置、服务状态...各种折腾!

4、 卸载、重装

  1. 查询 gitlab 安装包 $ dpkg --list |grep gitlab

     ii  gitlab-ce                              13.0.1-ce.0                                     amd64        GitLab Community Edition (including NGINX, Postgres, Redis)
     rc  gitlab-ee                              13.0.1-ee.0                                     amd64        GitLab Enterprise Edition (including NGINX, Postgres, Redis)
    
  2. $ ps -ef | grep gitlab

  3. 卸载 gitlab

sudo apt-get --purge remove gitlab-ce

	Reading package lists... Done
	Building dependency tree       
	Reading state information... Done
	The following packages will be REMOVED:
	  gitlab-ce*
	0 upgraded, 0 newly installed, 1 to remove and 121 not upgraded.
	After this operation, 1,947 MB disk space will be freed.
	Do you want to continue? [Y/n] y
	(Reading database ... 185411 files and directories currently installed.)
	Removing gitlab-ce (13.1.1-ce.0) ...
	(Reading database ... 113921 files and directories currently installed.)
	Purging configuration files for gitlab-ce (13.1.1-ce.0) ...
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/sv' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/service' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/init' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/etc' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/embedded/ssl/certs' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/embedded/service/gitlab-shell' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/embedded/service/gitlab-rails/public' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/embedded/service/gitlab-rails/config' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/embedded/cookbooks' not empty so not removed
	dpkg: warning: while removing gitlab-ce, directory '/opt/gitlab/embedded/bin' not empty so not removed
  1. 删除所有包含gitlab文件 sudo find / -name gitlab | xargs rm -rf sudo find / -name gitlab | xargs sudo rm -rf

  2. 确认一下 $ ps -ef | grep gitlab $ dpkg --list |grep gitlab

  3. 重新安装,步骤忽略

  4. lock-frontend 错误

    E: Could not get lock /var/lib/dpkg/lock-frontend - open (11: Resource temporarily unavailable)
    E: Unable to acquire the dpkg frontend lock (/var/lib/dpkg/lock-frontend), is another process using it?
    

    由于安装总是很慢,忍不住给他中断了几次! 然后,重新来过的时候,就看到了这个 lock-frontend !

    $ sudo cat /var/lib/dpkg/lock-frontend 内容是空的

    $ sudo rm /var/lib/dpkg/lock-frontend 直接删除后 , $ sudo apt update , 再来!

5、清空后再来

  1. 还没有学会 gitlab 操作的时候,总是会将配置和 注册用户搞得乱七八糟,这个时候就希望能重新 init !

    Delete all gitlab data, and start from scratch.

  2. 清空 gitlab 配置,推倒重来 $ sudo gitlab-ctl cleanse

         *******************************************************************
         * * * * * * * * * * *       STOP AND READ       * * * * * * * * * *
         *******************************************************************
         This command will delete *all* local configuration, log, and
         variable data associated with gitlab.
    
         You have 60 seconds to hit CTRL-C before configuration,
         logs, and local data for this application are permanently
         deleted.
         *******************************************************************
    
     ......
    
     Your config files have been backed up to /root/gitlab-cleanse-2020-07-02T10:41.
    
  3. 重新运行、测试 sudo gitlab-ctl reconfigure && sudo gitlab-ctl start

    $ curl 127.0.0.1:8090

     curl: (7) Failed to connect to 127.0.0.1 port 8090: Connection refused
    

    直接就 refused !会不会是 配置 127.0.0.1:8090 也 clean 了?

    $ cd /etc/gitlab/ $ ls

     gitlab-secrets.json  trusted-certs
    

    真的没有了啊!缺少了那个 gitlab.rb 配置文件!

    以前是这样子的

     gitlab.rb  gitlab-secrets.json  trusted-certs
    
  4. 所以,只好重新安装

sudo EXTERNAL_URL="http://127.0.0.1:8090" apt-get install gitlab-ce

  1. 写这个博客的时候,注意到:cleanse 的最后一句提示

    Your config files have been backed up to /root/gitlab-cleanse-2020-07-02T10:41.

但是, 有些 ubuntu 1804 在安装的时候,根本就没有设置过 root 密码,root 密码本身是随机生成的!

$ su
Password: 
su: Authentication failure

所以,真的需要去找回那个备份的话,首先要去找回 root 密码!

好在我这个 ubuntu 1804 版本比较早,当时是有设置过 root 密码的 可以用来证明:确实将之前的 3 个文件都 backup 过去了!

$ su
Password: 

# whoami
root

# cd /root
# ls
	gitlab-cleanse-2020-07-02T10:41
	
# cd gitlab-cleanse-2020-07-02T10\:41/

# ls
	gitlab.rb  gitlab-secrets.json  trusted-certs

6、查看、修改配置

  1. 查看版本号 $ cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

     13.1.2
    
  2. sudo vim gitlab.rb

    目前可能需要修改的好像只有这一条 external_url 'http://127.0.0.1:8090'

  3. 后续学习使用 gitlab,这个看着不错!

使用 gitlab

https://www.cnblogs.com/zdqc/p/9666994.html#auto-id-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!