環境介紹:
192.168.2.20
Node2、Gitlab
CentOS 7.5.1804
Docker 19.03.13
2核+CPU,4GB+內存(Gitlab低於4G內存會報502錯誤)
部署Gitlab倉庫:
– 拉取Gitlab鏡像
[root@k8s-node2 ~]# docker pull gitlab/gitlab-ce
Using default tag: latest
latest: Pulling from gitlab/gitlab-ce
35807b77a593: Pull complete
b32ac5d80a55: Pull complete
df336912e872: Pull complete
b793eccd1af3: Pull complete
f74a7e006150: Pull complete
0084a219e293: Pull complete
3af13cab3fdf: Pull complete
59278f51bfcb: Pull complete
Digest: sha256:7241af5bd54251aa412692cff1adf2d8c604425a03adad5300919b06bd4c6585
Status: Downloaded newer image for gitlab/gitlab-ce:latest
docker.io/gitlab/gitlab-ce:latest
[root@k8s-node2 ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
gitlab/gitlab-ce latest ca616a263319 Less than a second ago 2.29GB– 運行Gitlab容器
命令解釋:
- -i :以交互模式運行容器,通常與 -t 同時使用命令解釋
- -t :為容器重新分配一個偽輸入終端,通常與 -i 同時使用
- -d :後台運行容器,並返回容器ID
- -p:80:80 將容器內80端口映射至宿主機80端口,這是訪問gitlab的端口
- -p:222:22 將容器內22端口映射至宿主機222端口,這是訪問ssh的端口
- -v :/usr/local/gitlab-test/etc:/etc/gitlab 將容器/etc/gitlab目錄掛載到宿主機/usr/local/gitlab-test/etc目錄下,若宿主機內此目錄不存在將會自動創建,其他兩個掛載同這個一樣
- –restart always :容器自啟動
- –privileged=true :讓容器獲取宿主機root權限
- –name gitlab :設置容器名稱為gitlab
- gitlab/gitlab-ce :鏡像的名稱,這裡也可以寫鏡像ID
[root@k8s-node2 ~]# docker run -itd --name gitlab -p 443:443 -p 80:80 -p 222:22 --restart always -v /home/gitlab/config:/etc/gitlab -v /home/gitlab/logs:/var/log/gitlab -v /home/gitlab/data:/var/opt/gitlab gitlab/gitlab-ce
971e942b7a703fb82bcd308a3ad8c0f70912ea7abb14b46e8c63ca5b82ab6568docker run -v掛載目錄時,若本地沒有該目錄掛載時會自動創建。
[root@k8s-node2 ~]# ls /home/
gitlab
[root@k8s-node2 ~]# ls /home/gitlab/
config data logs[root@k8s-node2 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
971e942b7a70 gitlab/gitlab-ce "/assets/wrapper" About a minute ago Up About a minute (health: starting) 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:222->22/tcp gitlab – 修改gitlab.rb配置文件
注意:
修改gitlab.rb配置文件操作最好是在容器內進行修改(也可以在宿主機映射目錄中修改,記得修改完後進入容器驗證修改結果),在掛載到宿主機的文件上直接進行修改可能會出現配置更新不到容器內,或者是不能即時更新到容器內,導致gitlab啟動成功,但是無法訪問或其它問題。
[root@k8s-node2 ~]# vim /home/gitlab/config/gitlab.rb //gitlab.rb文件內容默認全部注釋
...
...
32 # external_url 'GENERATED_EXTERNAL_URL'
33 external_url 'http://192.168.1.20' //配置http協議所使用的gitlab訪問地址,可以寫域名。如果端口不寫的話默認為80端口
34 gitlab_rails['gitlab_ssh_host'] = '192.168.1.20' //配置ssh協議所使用的訪問地址和端口
35 gitlab_rails['gitlab_shell_ssh_port'] = 222 //此端口是docker run時22端口映射的222端口
36 ## Roles for multi-instance GitLab
– 重啟gitlab容器 [root@k8s-node2 ~]# docker restart gitlab
gitlab
訪問報錯:

注意:出現502報錯,請第一時間檢查內存大小,內存不足會提示502報錯。(服務器內存至少4G,不夠會出現502錯誤。)
原始內存大小:
[root@k8s-ndoe2 ~]# free -h
total used free shared buff/cache available
Mem: 1.9G 342M 482M 14M 1.1G 1.3G
Swap: 0B 0B 0B升級後內存大小:
[root@k8s-node2 ~]# free -h
total used free shared buff/cache available
Mem: 3.8G 2.9G 157M 25M 821M 613M
Swap: 0B 0B 0B訪問:

可以看到在升級完服務器內存大小後,就可以正常登錄Gitlab了。
登錄Gitlab倉庫:
Gitlab默認的管理員臨時密碼在gitlab容器中
/etc/gitlab/initial_root_password文件中,如果該路徑下沒有這個文件,我們就無法正常登錄到gitlab中去,可以試試下面兩種方法。
1.宿主機中搜索initial_root_password文件
[root@k8s-node2 ~]# find / -name initial_root_password
/mnt/data/volumes/e7d5b220d1dc98ea2229882865f58e643fef42d4f1c16a3a54458abd017b7c77/_data/initial_root_password
[root@k8s-node2 ~]# cat /mnt/data/volumes/e7d5b220d1dc98ea2229882865f58e643fef42d4f1c16a3a54458abd017b7c77/_data/initial_root_password
# WARNING: This value is valid only in the following conditions
# 1. If provided manually (either via `GITLAB_ROOT_PASSWORD` environment variable or via `gitlab_rails['initial_root_password']` setting in `gitlab.rb`, it was provided before database was seeded for the first time (usually, the first reconfigure run).
# 2. Password hasn't been changed manually, either via UI or via command line.
#
# If the password shown here doesn't work, you must reset the admin password following https://docs.gitlab.com/ee/security/reset_user_password.html#reset-your-root-password.
Password: LkhENj02qgKkT7DZplqE35TfdPThK3wuSCgHw0H+BOI=
# NOTE: This file will be automatically deleted in the first reconfigure run after 24 hours.可以看到上面搜索到的initial_root_password文件中顯示了gitlab的默認密碼。
2.重置gitlab管理員賬戶密碼
5分鐘帶你重置Gitlab管理員賬戶密碼:
https://blog.csdn.net/qq_44895681/article/details/120530904?spm=1001.2014.3001.5501

可以看到重置gitlab管理員賬號密碼後使用新的賬戶密碼成功登錄進gitlab中。 配置Gitlab界面語言為中文





原創文章,作者:投稿專員,如若轉載,請註明出處:https://www.506064.com/zh-hant/n/226349.html
微信掃一掃
支付寶掃一掃