一、概述
上一篇我們將Gitlab的安裝部署和初始化設置部分全部講解完成了,接下來我們介紹Gitlab在日常工作中常遇見的問題進行梳理說明。
二、Gitlab的安裝和維護過程中常見問題
1、Gitlab訪問出現403"Forbidden"現象
問題原因分析:
可能因較多的並發導致的訪問被拒絕, Gitlab使用rack_attack做了並發訪問的限制!
解決辦法:
打開/etc/gitlab/gitlab.rb文件,查找 gitlab_rails['rack_attack_git_basic_auth'] 關鍵詞,取消注釋,
修改ip_whitelist白名單屬性,加入Gitlab部署的IP地址。
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb ...... gitlab_rails['rack_attack_git_basic_auth'] = { 'enabled' => true, 'ip_whitelist' => ["127.0.0.1","172.16.60.222"], //把gitlab服務器IP地址添加 'maxretry' => 10, 'findtime' => 60, 'bantime' => 3600 }
然后進行重新配置
[root@gitlab ~]# gitlab-ctl reconfigure
2、Gitlab訪問出現502的現象
Gitlab訪問出現:Whoops, GitLab is taking too much time to respond.
問題原因分析:
1)unicorn原8080默認端口被容器中別的進程已經占用,必須調整為沒用過的
2)gitlab的timeout設置過小,默認為60
解決辦法:
1)關閉gitlab服務
[root@gitlab ~]# gitlab-ctl stop
2)選擇一個沒有被系統占用的端口作為unicorn端口,比如8877端口(lsof -i:8877 確認此端口沒有被占用)
[root@gitlab ~]# vim /etc/gitlab/gitlab.rb unicorn['port'] = 8877 gitlab_workhorse['auth_backend'] = "http://localhost:8877"
3)重新生成配置,並進行重啟。
[root@gitlab ~]# gitlab-ctl reconfigure [root@gitlab ~]# gitlab-ctl restart
3、Gitlab啟動失敗,或重新安裝時出現卡的狀態
問題現象:在卸載gitlab然后再次安裝執行sudo gitlab-ctl reconfigure的時候往往會出現:ruby_block[supervise_redis_sleep] action run,會一直卡無法往下進行!
解決辦法:
1)按ctrl + c 強制結束
2)執行"systemctl restart gitlab-runsvdir" 命令
3)接着再執行"gitlab-ctl reconfigure"
如果Gitlab服務器重啟后,啟動"gitlab-ctl start"失敗,解決辦法相同。
[root@gitlab ~]# systemctl restart gitlab-runsvdir [root@gitlab ~]# gitlab-ctl reconfigure [root@gitlab ~]# gitlab-ctl start
4、Gitlab異常關機,導致gitlab啟動失敗!gitlab-runsvdir方式啟動沒反應(僵屍狀態)
問題現象:Gitlab部署的服務器異常斷電,機器重啟后,嘗試啟動gitlab服務,啟動失敗!通過gitlab-runsvdir方式啟動一直沒有反應!一直在卡頓狀態!日志也沒有任務輸入!
執行下面的啟動命令報錯: [root@gitlab ~]# gitlab-ctl start // 或者 "gitlab-ctl restart" fail: alertmanager: runsv not running fail: gitaly: runsv not running fail: gitlab-monitor: runsv not running fail: gitlab-workhorse: runsv not running fail: logrotate: runsv not running fail: nginx: runsv not running fail: node-exporter: runsv not running fail: postgres-exporter: runsv not running fail: postgresql: runsv not running fail: prometheus: runsv not running
報錯說
"runsv not running"
那么嘗試通過supervisor進程方式啟動gitlab,發現一直在卡頓中,根本沒有任何反應!
[root@gitlab ~]# systemctl restart gitlab-runsvdir
查看日志,發現也沒有任務啟動信息打印到日志中 (日志都是之前的)
[root@gitlab ~]# /usr/bin/gitlab-ctl tail
gitlab-runsvdir啟動在卡頓中,gitlab服務也沒有起來
[root@gitlab ~]# ps -ef|grep gitlab
解決方法:
通過Gitlab自己原生命令去啟動服務:
/opt/gitlab/embedded/bin/runsvdir-start
root@gitlab ~]# cat /etc/systemd/system/multi-user.target.wants/gitlab-runsvdir.service [Unit] Description=GitLab Runit supervision process After=multi-user.target [Service] ExecStart=/opt/gitlab/embedded/bin/runsvdir-start #最后通過這條命令啟動了Gitlab Restart=always [Install] WantedBy=multi-user.target 執行下面的啟動,雖然發現這個也會一直在卡頓中,但是不影響gitlab服務啟動。 [root@gitlab ~]# /opt/gitlab/embedded/bin/runsvdir-start 重新打開一個終端窗口,發現gitlab已經有新的日志信息打入了,gitlab也服務已經起來了 [root@gitlab ~]# /usr/bin/gitlab-ctl tail [root@gitlab ~]# ps -ef|grep gitlab 這時候關閉上面執行"/opt/gitlab/embedded/bin/runsvdir-start"的卡頓的終端窗口,發現gitlab也還是啟動狀態(ps -ef|grep gitlab) [root@gitlab ~]# ps -ef|grep gitlab [root@gitlab ~]# lsof -i:80 [root@gitlab ~]# gitlab-ctl status run: alertmanager: (pid 29804) 1640s; run: log: (pid 29789) 1640s run: gitaly: (pid 29795) 1640s; run: log: (pid 29781) 1640s run: gitlab-monitor: (pid 29799) 1640s; run: log: (pid 29785) 1640s run: gitlab-workhorse: (pid 29794) 1640s; run: log: (pid 29780) 1640s run: logrotate: (pid 29798) 1640s; run: log: (pid 29783) 1640s run: nginx: (pid 29800) 1640s; run: log: (pid 29786) 1640s run: node-exporter: (pid 29802) 1640s; run: log: (pid 29788) 1640s run: postgres-exporter: (pid 29805) 1640s; run: log: (pid 29790) 1640s run: postgresql: (pid 29796) 1640s; run: log: (pid 29782) 1640s run: prometheus: (pid 29797) 1640s; run: log: (pid 29784) 1640s run: redis: (pid 29818) 1640s; run: log: (pid 29793) 1640s run: redis-exporter: (pid 29817) 1640s; run: log: (pid 29792) 1640s run: sidekiq: (pid 29801) 1640s; run: log: (pid 29787) 1640s run: unicorn: (pid 29807) 1640s; run: log: (pid 29791) 1640s 查看日志也有新信息寫入,一切正常了! [root@gitlab ~]# /usr/bin/gitlab-ctl tail
5、Gitlab重新安裝,在執行"gitlab-ctl reconfigure"配置環節出現了下面報錯:
[root@gitlab ~]# gitlab-ctl reconfigure ......... ......... STDERR: sysctl: cannot open "/etc/sysctl.d/90-omnibus-gitlab-kernel.sem.conf": No such file or directory sysctl: cannot open "/etc/sysctl.d/90-omnibus-gitlab-net.core.somaxconn.conf": No such file or directory ---- End output of sysctl -e --system ---- Ran sysctl -e --system returned 255
問題原因分析:
丟失了報錯中的這兩個配置文件,進入/etc/sysctl.d目錄發現,這兩個文件都是通過鏈接到/opt/gitlab/embedded/etc/目錄下。
然而/opt/gitlab/embedded/etc/確實沒有這兩個文件。
[root@gitlab ~]# ll /etc/sysctl.d/ total 0 lrwxrwxrwx 1 root root 58 Nov 10 22:23 90-omnibus-gitlab-kernel.sem.conf -> /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.sem.conf lrwxrwxrwx 1 root root 61 Nov 10 22:23 90-omnibus-gitlab-kernel.shmall.conf -> /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.shmall.conf lrwxrwxrwx 1 root root 61 Nov 10 22:23 90-omnibus-gitlab-kernel.shmmax.conf -> /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.shmmax.conf lrwxrwxrwx 1 root root 66 Nov 10 22:25 90-omnibus-gitlab-net.core.somaxconn.conf -> /opt/gitlab/embedded/etc/90-omnibus-gitlab-net.core.somaxconn.conf lrwxrwxrwx. 1 root root 14 Oct 30 09:13 99-sysctl.conf -> ../sysctl.conf [root@gitlab ~]# ll /opt/gitlab/embedded/etc total 12 -rw-r--r-- 1 root root 24 Apr 12 23:18 90-omnibus-gitlab-kernel.shmall.conf -rw-r--r-- 1 root root 28 Apr 12 23:17 90-omnibus-gitlab-kernel.shmmax.conf -rwxr-xr-x 1 root root 196 Apr 12 23:16 gitconfig [root@gitlab ~]# ll /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.sem.conf ls: cannot access /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.sem.conf: No such file or directory [root@gitlab ~]# ll /opt/gitlab/embedded/etc/90-omnibus-gitlab-net.core.somaxconn.conf ls: cannot access /opt/gitlab/embedded/etc/90-omnibus-gitlab-net.core.somaxconn.conf: No such file or directory 解決方法一: 從別的備份機(或者在別的機器上重新安裝一次,"gitlab-ctl reconfigure"之后生成這兩個文件)將這兩個文件拷貝回來! 解決方法二: [root@gitlab ~]# vim /etc/gitlab/gitlab.rb # unicorn['port'] = 8080 修改為: unicorn['port'] = 8090 之后重新加載配置文件 [root@gitlab ~]# gitlab-ctl reconfigure 再次會報錯,然后再修改/etc/gitlab/gitlab.rb,修改為原來的配置 [root@gitlab ~]# vim /etc/gitlab/gitlab.rb # unicorn['port'] = 8080 再次重新加載配置文件就OK了! [root@gitlab ~]# gitlab-ctl reconfigure 再次查看,發現上面配置中報錯的兩個文件已經存在了 [root@gitlab ~]# ll /opt/gitlab/embedded/etc/ total 20 -rw-r--r-- 1 root root 30 Apr 12 23:33 90-omnibus-gitlab-kernel.sem.conf -rw-r--r-- 1 root root 24 Apr 12 23:18 90-omnibus-gitlab-kernel.shmall.conf -rw-r--r-- 1 root root 28 Apr 12 23:17 90-omnibus-gitlab-kernel.shmmax.conf -rw-r--r-- 1 root root 26 Apr 12 23:35 90-omnibus-gitlab-net.core.somaxconn.conf -rwxr-xr-x 1 root root 196 Apr 12 23:16 gitconfig [root@gitlab ~]# ll /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.sem.conf -rw-r--r-- 1 root root 30 Apr 12 23:33 /opt/gitlab/embedded/etc/90-omnibus-gitlab-kernel.sem.conf [root@gitlab ~]# ll /opt/gitlab/embedded/etc/90-omnibus-gitlab-net.core.somaxconn.conf -rw-r--r-- 1 root root 26 Apr 12 23:35 /opt/gitlab/embedded/etc/90-omnibus-gitlab-net.core.somaxconn.conf 最后再啟動gitlab [root@gitlab ~]# gitlab-ctl start
6、Gitlab更改默認Nginx
更換gitlab自帶Nginx,使用自行編譯Nginx來管理gitlab服務。
自行編譯的nginx服務和gitlab在同一台機器上 1)編輯gitlab配置文件禁用自帶Nignx服務器 [root@gitlab ~]# vim /etc/gitlab/gitlab.rb ... #設置nginx為false,關閉自帶Nginx nginx['enable'] = false ... 2)檢查默認nginx配置文件,並遷移至新Nginx服務 (即將下面兩個gitlab自帶nginx的配置文件遷移到自行編譯的新的nginx配置中) /var/opt/gitlab/nginx/conf/nginx.conf #nginx配置文件,包含gitlab-http.conf文件 /var/opt/gitlab/nginx/conf/gitlab-http.conf #gitlab核心nginx配置文件 [root@gitlab ~]# cp /var/opt/gitlab/nginx/conf/nginx.conf /etc/nginx/conf.d/ [root@gitlab ~]# cp /var/opt/gitlab/nginx/conf/gitlab-http.conf /etc/nginx/conf.d/ 3)重啟gitlab服務 [root@gitlab ~]# gitlab-ctl reconfigure [root@gitlab ~]# gitlab-ctl restart 重啟自行編譯的nginx服務 [root@gitlab ~]# service nginx restart 如果訪問報502。原因是nginx用戶無法訪問gitlab用戶的socket文件。 重啟gitlab需要重新授權 [root@gitlab ~]# chmod -R o+x /var/opt/gitlab/gitlab-rails
-----------------------------------------------------------書山有路勤為徑,學海無涯苦作舟-------------------------------------------------------------