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、 安裝
-
安裝必要的依賴 sudo apt-get install -y curl openssh-server ca-certificates
-
非必須 ( 如果開始學習或者後續需要使用郵箱開放註冊的話,請安裝 ) sudo apt-get install -y postfix
-
設置安裝包和 gitlab 軟件源 curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | sudo bash
-
按照前面鏡像使用幫助,設置清華 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
-
開始安裝 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] ...安裝過程比較漫長,即使換成了清華的源,也很慢!
-
配置生效並開始運行 sudo gitlab-ctl reconfigure && sudo gitlab-ctl start
這個過程也比較慢!這個 gitlab 確實比較龐大,涵蓋的東西很多! gitlab-ctl start 也需要 root 權限,否則,會出現一大堆 warning
-
測試、驗證 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! 剩下就是學習使用了!
-
查看配置信息 $ 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... ......
-
查看版本號
$ 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、 異常情況
-
關機或者 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.
- 後續來回折騰之後,發現自己掉坑底! 以上錯誤並非 gitlab 安裝的不對,也不是 gitlab 出錯了! 每次 reboot 之後, gitlab 服務啓動需要花好長時間的! 本人反應比較快,直接就開始檢查配置、服務狀態...各種折騰!
4、 卸載、重裝
-
查詢 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)
-
$ ps -ef | grep gitlab
-
卸載 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
-
刪除所有包含gitlab文件 sudo find / -name gitlab | xargs rm -rf sudo find / -name gitlab | xargs sudo rm -rf
-
確認一下 $ ps -ef | grep gitlab $ dpkg --list |grep gitlab
-
重新安裝,步驟忽略
-
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、清空後再來
-
還沒有學會 gitlab 操作的時候,總是會將配置和 註冊用戶搞得亂七八糟,這個時候就希望能重新 init !
Delete all gitlab data, and start from scratch.
-
清空 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.
-
重新運行、測試 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
-
所以,只好重新安裝
sudo EXTERNAL_URL="http://127.0.0.1:8090" apt-get install gitlab-ce
-
寫這個博客的時候,注意到: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、查看、修改配置
-
查看版本號 $ cat /opt/gitlab/embedded/service/gitlab-rails/VERSION
13.1.2
-
sudo vim gitlab.rb
目前可能需要修改的好像只有這一條 external_url 'http://127.0.0.1:8090'
-
後續學習使用 gitlab,這個看着不錯!