Ubuntu14.04搭建gitlab代碼管理平臺

Ubuntu14.04搭建gitlab版本管理平臺

1.安裝依賴包

sudo apt-get install curl openssh-server ca-certificates postfix

注:執行完成後,出現郵件配置,選擇Internet那一項(不帶Smarthost的)
然後需要填寫郵箱配置。

2.添加GitLab安裝包鏡像源

利用清華大學的鏡像(https://mirror.tuna.tsinghua.edu.cn/help/gitlab-ce/)來進行主程序的安裝

2.1 首先信任 GitLab 的 GPG 公鑰

curl https://packages.gitlab.com/gpg.key 2> /dev/null | sudo apt-key add - &>/dev/null

2.2 使用root用戶修改配置文件

sudo gedit /etc/apt/sources.list.d/gitlab-ce.list

添加下一行內容:
deb https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/ubuntu xenial main

3 安裝gitlab-ce

每次添加完軟件源後要必須要update一下。

sudo apt-get update
sudo apt-get install gitlab-ce

/**注意:安裝需要2GB存儲空間
0 upgraded, 1 newly installed, 0 to remove and 448 not upgraded.
Need to get 799 MB of archives.
After this operation, 2,090 MB of additional disk space will be used.
********************************************************************************/

安裝完成耗時半小時,出現以下界面:
It looks like GitLab has not been configured yet; skipping the upgrade script.

Thank you for installing GitLab!
GitLab was unable to detect a valid hostname for your instance.
Please configure a URL for your GitLab instance by setting external_url
configuration in /etc/gitlab/gitlab.rb file.
Then, you can start your GitLab instance by running the following command:
sudo gitlab-ctl reconfigure

For a comprehensive list of configuration options please see the Omnibus GitLab readme
https://gitlab.com/gitlab-org/omnibus-gitlab/blob/master/README.md

3.1 查看安裝的gitlab版本

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

版本爲:
12.10.3

4 配置GitLab IP地址

4.1 修改 externval_url 之後的域名

方法1:(使用GNU nano 2.2.6工具編輯gitlab.rb)
sudo -e /etc/gitlab/gitlab.rb
nano編輯器保存步驟:CTRL+X --> 按Y保存 --> 然後按回車
方法2:使用 vim gedit都可以。

域名值可以是本機 IP 或指向本機 IP的域名
默認未修改的值:
external_url ‘http://gitlab.example.com’
默認是端口80
修改後的值:
external_url ‘http://192.168.19.128’

其他參考配置(8080是自定義端口必須要要和 unicorn[‘port’]一致)
external_url ‘http://192.168.19.128:8080’
(這個端口同上的那個external_url 後的端口)
unicorn[‘port’] = 8080

5.啓動sshd和postfix服務

5.1 安裝sshd

已經安裝成功了可以忽略該步驟。
sudo apt-get install openssh-server

5.2 啓動sshd和postfix

sudo service sshd start 

如果無效者執行

sudo /etc/init.d/ssh start
#驗證sshd是否真正開啓
ps -e|grep sshd 

啓動postfix

sudo service postfix start

6 添加防火牆規則

sudo iptables -A INPUT -p tcp -m tcp --dport 80 -j ACCEPT

7 啓動各項服務

(只要修改 /etc/gitlab/gitlab.rb 必須執行該命令才能生效)

sudo gitlab-ctl reconfigure

前方注意: 採坑之旅開始!!!!!!!!!!!!!!

錯誤1:
如果安裝gitlab之前已經存在用戶名爲git的用戶,會啓動失敗。
解決辦法:process 35138 找到對應的進程kill掉,關閉用git賬號登錄的終端。

Running handlers:
There was an error running gitlab-ctl reconfigure:

account[GitLab user and group] (gitlab::users line 28) had an error: Mixlib::ShellOut::ShellCommandFailed: linux_user[GitLab user and group] (/opt/gitlab/embedded/cookbooks/cache/cookbooks/package/resources/account.rb line 51) had an error: Mixlib::ShellOut::ShellCommandFailed: Expected process to exit with [0], but received '8'
---- Begin output of ["usermod", "-s", "/bin/sh", "-d", "/var/opt/gitlab", "git"] ----
STDOUT:
STDERR: usermod: user git is currently used by process 35138
---- End output of ["usermod", "-s", "/bin/sh", "-d", "/var/opt/gitlab", "git"] ----
Ran ["usermod", "-s", "/bin/sh", "-d", "/var/opt/gitlab", "git"] returned 8

Running handlers complete
Chef Client failed. 7 resources updated in 09 seconds

錯誤2:
There was an error running gitlab-ctl reconfigure:

Multiple failures occurred:

  • Mixlib::ShellOut::ShellCommandFailed occurred in chef run:
    由於服務器是512MB的CPU運行內存,換至1G內存仍然報錯,換至2G運行內存時問題解決。所以解決辦法是換至大於等於2G CPU運行內存。(無效的解決辦法)
    無效的解決辦法參考:https://blog.csdn.net/qq_33126131/article/details/100675460

解決辦法步驟2:

sudo gitlab-ctl start 			# 啓動所有 gitlab 組件;
sudo gitlab-ctl stop 			# 停止所有 gitlab 組件;
sudo gitlab-ctl restart 		# 重啓所有 gitlab 組件;
sudo gitlab-ctl status	 	# 查看服務狀態;
sudo gitlab-ctl reconfigure  # 重新加載配置; 每次修改 /etc/gitlab/gitlab.rb 文件之後執行
sudo vim /etc/gitlab/gitlab.rb 	# 修改默認的配置文件;
sudo gitlab-ctl tail 		# 查看日誌;
sudo gitlab-ctl tail nginx/gitlab_acces.log 	查看 nginx 訪問日誌

參考:https://www.cnblogs.com/shikyoh/p/10688340.html

執行服務重啓重新配置後任然報錯:

錯誤3
關鍵信息: version `GLIBCXX_3.4.21’ not found
原因是14.04系統GCC版本是4.8太老,16.04是GCC5.4不存在該問題。
查看本地gcc版本:

gcc -v
gcc version 4.8.4 (Ubuntu 4.8.4-2ubuntu1~14.04.4)

執行以下命令檢查一下動態庫鏈接

strings /usr/lib/x86_64-linux-gnu/libstdc++.so.6 | grep GLIBC

發現沒有我們所需要的 GLIBCXX_3.4.21

sudo find / -name "libstdc++.so*"

參考(該文章使用32位庫,然而本機是64位的,執行會報錯): https://www.cnblogs.com/sddai/p/10318086.html

7.1報錯終極解決辦法

7.1.1下載libstdc++6_5.4.0


下載GCC5.4.0的C++標準庫替換現有的**/usr/lib/x86_64-linux-gnu/libstdc++.so.6**
64位系統的C++標準庫
http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.4.0-6ubuntu1~16.04.12_amd64.deb


32位系統的C++標準庫(不能使用 build報錯ELFCLASS32
http://archive.ubuntu.com/ubuntu/pool/main/g/gcc-5/libstdc++6_5.3.1-14ubuntu2_i386.deb
STDOUT: /opt/gitlab/embedded/bin/ruby: error while loading shared libraries: libstdc++.so.6: wrong ELF class: ELFCLASS32

7.1.2安裝libstdc++6_5.4.0

解壓 libstdc++6_5.4.0-6ubuntu1_16.04.12_amd64.deb
拷貝libstdc++6_5.4.0-6ubuntu1_16.04.12_amd64/data/usr/lib/x86_64-linux-gnu
到 /home/userid/Downloads/


 ll /usr/lib/x86_64-linux-gnu/libstdc++.so.6  #查看文件類型 是軟鏈接
cd /usr/lib/x86_64-linux-gnu/
ll ~/Downloadsx86_64-linux-gnu/libstdc++.so.6* -lh
sudo cp /home/userid/Downloads/x86_64-linux-gnu/libstdc++.so.6.0.21 ./ #拷貝下載的so到系統庫路徑
sudo mv libstdc++.so.6 libstdc++.so.6.bak 	#備份原始庫以備還原
sudo ln -s libstdc++.so.6.0.21 libstdc++.so.6   #軟鏈接到下載的libstdc++.so.6.0.21
file libstdc++.so.6.0.21  #查看文件類型是x86-64庫,沒問題
libstdc++.so.6.0.21: ELF 64-bit LSB  shared object, x86-64, version 1 (GNU/Linux), dynamically linked, BuildID[sha1]=ea2410532d6adcd154644705e40b941cf362bea7, stripped

7.1.3 重新配置gitlab

再次執行重新配置gitlab的命令:

sudo gitlab-ctl reconfigure

執行結果:

Running handlers:
Running handlers complete
Chef Client finished, 314/1303 resources updated in 02 minutes 52 seconds
gitlab Reconfigured!

成功解決!

8 檢查gitlab所有服務是否已啓動

再次查看服務狀態都已經正常了!!!

sudo gitlab-ctl status

共計15個服務。

run: alertmanager: (pid 59763) 119s; run: log: (pid 59530) 173s
run: gitaly: (pid 52920) 9375s; run: log: (pid 52436) 9900s
run: gitlab-exporter: (pid 59726) 121s; run: log: (pid 59354) 193s
run: gitlab-workhorse: (pid 59707) 122s; run: log: (pid 59247) 216s
run: grafana: (pid 59793) 118s; run: log: (pid 59703) 122s
run: logrotate: (pid 59291) 206s; run: log: (pid 59303) 205s
run: nginx: (pid 59260) 212s; run: log: (pid 59282) 209s
run: node-exporter: (pid 59720) 121s; run: log: (pid 59338) 197s
run: postgres-exporter: (pid 59785) 118s; run: log: (pid 59559) 169s
run: postgresql: (pid 52945) 9374s; run: log: (pid 52534) 9892s
run: prometheus: (pid 59740) 120s; run: log: (pid 59456) 178s
run: redis: (pid 52956) 9374s; run: log: (pid 52403) 9906s
run: redis-exporter: (pid 59728) 120s; run: log: (pid 59375) 185s
run: sidekiq: (pid 59202) 224s; run: log: (pid 59214) 223s
run: unicorn: (pid 59174) 230s; run: log: (pid 59197) 229s

9 配置gitlab 服務器

9.1 設置管理員密碼

首先在瀏覽器中輸入:http://192.168.19.168 登陸本地gitlab服務器。
第一次登錄必須輸入兩次 password 後,點擊按鈕 “Change your password” 按鈕後,才能跳轉到登錄/註冊頁面。
管理員密碼至少八個字符(1***1***):Password is too short (minimum is 8 characters)
管理員默認用戶名是:root

註冊
登錄
登錄進入系統後,創建一個 Group

9.2 添加ssh key

git倉庫之間的代碼傳輸協議主要使用ssh協議。而一般搭建gitlab的時候使用的git用戶是沒有密碼的,因此直接ssh是不能登錄的,就需要使用ssh-keygen上傳公鑰,使用非對稱加密傳輸。

添加ssh key

9.2.1 執行生成公鑰和私鑰的命令

ssh-keygen -t rsa

9.2.2 按3下回車鍵生成生成一對私鑰和公鑰

id_rsa.pub是公鑰,需要配置到git服務器以便於免密碼git pull
生成一對私鑰和公鑰,分別存在 /.ssh/id_rsa和/.ssh/id_rsa.pub

9.2.3 添加公鑰到gitlab配置

添加key到gitlab服務器配置中,Profile Settings –> SSH Keys –> Add SSH Keys。
然後把上一步中的id_rsa.pub中的內容拷貝出來粘貼到輸入框中,保存。

其他

新建的git項目默認存儲位置是:
默認存儲位置在**/var/opt/gitlab/git-data/repositories**, 需要root權限才能查看。
管理員默認用戶名是:root
默認密碼必須8位以上
查看版本命令:
cat /opt/gitlab/embedded/service/gitlab-rails/VERSION

登錄網址:
http://192.168.19.128/users/sign_in
在這裏插入圖片描述

登錄成功後的界面:
在這裏插入圖片描述

其他安裝方法
bitnami的一鍵安裝包下載地址:
https://downloads.bitnami.com/files/stacks/gitlab/12.10.3-0/bitnami-gitlab-12.10.3-0-linux-x64-installer.run

參考鏈接1:https://www.jianshu.com/p/8079a9a81ef3
參考鏈接2:
Ubuntu 搭建本地gitlab服務器 + smartgit圖形化git倉庫管理工具
https://blog.csdn.net/sunny_hu92/article/details/88421601

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章