1. 程式人生 > >GitLab安裝指南

GitLab安裝指南

登入賬戶,輸入密碼

Last login: Thu Dec  6 08:59:16 on console
w1:~ jiaguoshang$ ssh [email protected]
[email protected]'s password:
Last login: Wed Dec  5 18:02:02 2018 from gateway
ABRT 已檢測到 '1' 個問題。預瞭解詳細資訊請執行:abrt-cli list --since 1544004122
[[email protected] ~]#

1、配置yum源
vim /etc/yum.repos.d/gitlab-ce.repo
複製以下內容:

[gitlab-ce]
name=Gitlab CE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el$releasever/
gpgcheck=0
enabled=1
需要點選i鍵進入文字編輯狀態,點選 esc鍵退出編輯狀態,輸入:wq回車退出編輯並儲存,輸入:w!回車強制退出編輯並放棄儲存。
2、更新本地yum快取
sudo yum makecache

[[email protected] ~]# sudo yum makecache
已載入外掛:fastestmirror, langpacks
base                                                     | 3.6 kB     00:00
extras                                                   | 3.4 kB     00:00
gitlab-ce                                                | 2.9 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/8): extras/7/x86_64/other_db                            | 106 kB   00:00
(2/8): extras/7/x86_64/prestodelta                         |  33 kB   00:00
(3/8): updates/7/x86_64/filelists_db                       | 1.3 MB   00:00
(4/8): gitlab-ce/7/primary_db                              | 2.5 MB   00:01
(5/8): updates/7/x86_64/prestodelta                        | 173 kB   00:00
(6/8): updates/7/x86_64/other_db                           | 182 kB   00:00
(7/8): updates/7/x86_64/primary_db                         | 1.3 MB   00:03
(8/8): gitlab-ce/7/filelists_db                            | 202 MB   00:21
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.163.com
元資料快取已建立

3、下載最新的漢化包
由於漢化版本都低於英文版本,為了不產生不必要的麻煩就要先下載漢化包,檢視漢化包的版本號,根據漢化包的版本號來安裝制定版本的GitLab。若你安裝的版本是最新的比漢化包高太多,那麼你漢化時需要忽略數百到上千次的檔案。並且還要執行sudo touch /etc/gitlab/skip-auto-migrations然後才能重新整理配置。我想你不會選擇這種傻方法吧?

git clone https://gitlab.com/xhang/gitlab.git

下載完畢,切換到你下載的漢化包目錄(gitlab),檢視漢化包的版本號(vim VERSION)。
在這裡插入圖片描述
在這裡插入圖片描述
4、安裝指定版本GitLab社群版
(sudo yum install gitlab-ce #自動安裝最新版)
sudo yum install gitlab-ce-x.x.x #安裝指定版本

[[email protected] gitlab]# sudo yum install gitlab-ce-11.4.8
已載入外掛:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.cn99.com
 * extras: mirrors.163.com
 * updates: mirrors.163.com
正在解決依賴關係
--> 正在檢查事務
---> 軟體包 gitlab-ce.x86_64.0.11.4.7-ce.0.el7 將被 升級
---> 軟體包 gitlab-ce.x86_64.0.11.4.8-ce.0.el7 將被 更新
--> 解決依賴關係完成

依賴關係解決

=================================================================================================================================================
 Package                          架構                          版本                                      源                                大小
=================================================================================================================================================
正在更新:
 gitlab-ce                        x86_64                        11.4.8-ce.0.el7                           gitlab-ce                        435 M

事務概要
=================================================================================================================================================
升級  1 軟體包

總下載量:435 M
Is this ok [y/d/N]: y
Downloading packages:
No Presto metadata available for gitlab-ce
gitlab-ce-11.4.8-ce.0.el7.x86_64.rpm                      60% [=============================                   ] 9.7 MB/s | 265 MB  00:00:17 ETA

安裝成功會有這些標誌:

 Recipe: gitlab::gitlab-workhorse
  * service[gitlab-workhorse] action restart
    - restart service service[gitlab-workhorse]
Recipe: gitaly::enable
  * service[gitaly] action restart
    - restart service service[gitaly]

Running handlers:
Running handlers complete
Chef Client finished, 14/561 resources updated in 01 minutes 35 seconds
gitlab Reconfigured!
Checking for an omnibus managed postgresql: OK
Checking for a newer version of PostgreSQL to install
No new version of PostgreSQL installed, nothing to upgrade to
Ensuring PostgreSQL is updated: OK
Restarting previously running GitLab services

     _______ __  __          __
    / ____(_) /_/ /   ____ _/ /_
   / / __/ / __/ /   / __ `/ __ \
  / /_/ / / /_/ /___/ /_/ / /_/ /
  \____/_/\__/_____/\__,_/_.___/


Upgrade complete! If your GitLab server is misbehaving try running
  sudo gitlab-ctl restart
before anything else.
If you need to roll back to the previous version you can use the database
backup made during the upgrade (scroll up for the filename).

  驗證中      : gitlab-ce-11.4.8-ce.0.el7.x86_64                                                                                             1/1

已安裝:
  gitlab-ce.x86_64 0:11.4.8-ce.0.el7

完畢!
您在 /var/spool/mail/root 中有新郵件
GitLab常用命令
sudo gitlab-ctl start    # 啟動所有 gitlab 元件;
sudo gitlab-ctl stop        # 停止所有 gitlab 元件;
sudo gitlab-ctl restart        # 重啟所有 gitlab 元件;
sudo gitlab-ctl status        # 檢視服務狀態;
sudo gitlab-ctl reconfigure        # 啟動服務;
sudo vim /etc/gitlab/gitlab.rb        # 修改預設的配置檔案;
gitlab-rake gitlab:check SANITIZE=true --trace    # 檢查gitlab;
sudo gitlab-ctl tail        # 檢視日誌;

5、修改服務地址
sudo vim /etc/gitlab/gitlab.rb
在這裡插入圖片描述
注意:要修改這個紅框的地址。若你的伺服器是裝再區域網上,那麼要配置這個區域網伺服器的本機地址加上埠號。若你是裝再公網雲上,那麼你可以配置域名了。不配置正確地址這個地址你不能上傳和下載專案的。這個配置最關鍵,要多檢查。
6、重新整理配置,啟動服務看GitLab主頁是否能夠使用。
注意:伺服器啟動成功,需要等待2分鐘才能開啟主頁。

sudo gitlab-ctl reconfigure
sudo gitlab-ctl start

在這裡插入圖片描述
在這裡插入圖片描述
看到這個網頁說明你的GitLab基本安裝成功。
在這裡插入圖片描述
看到這個說明很可能伺服器再重啟中,等兩分鐘後再重新整理頁面。當然也可能是你的伺服器配置錯誤或配置檔案有衝突。若是後者需要你修改配置或執行忽略配置衝突命令(sudo touch /etc/gitlab/skip-auto-migrations)後重新重新整理配置。
若出現Unable to round-trip http request to upstream: dial tcp 192.163.1.156:8888: i/o timeout或包網路超時連結超時錯誤。那麼很可能是你伺服器服務配置錯誤,伺服器埠被佔用或埠被禁用。
ping IP地址(ping 192.168.1.156),ctrl+c鍵可以停止。
w1:~ jiaguoshang$ ping 192.168.1.156
PING 192.168.1.156 (192.168.1.156): 56 data bytes
64 bytes from 192.168.1.156: icmp_seq=0 ttl=62 time=3.490 ms
64 bytes from 192.168.1.156: icmp_seq=1 ttl=62 time=2.554 ms
64 bytes from 192.168.1.156: icmp_seq=7 ttl=62 time=8.155 ms
^C
— 192.168.1.156 ping statistics —
8 packets transmitted, 8 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 2.253/39.847/284.912/92.659 ms
使用ssh判斷

ssh是linux的標準配置並且最常用,可以用來判斷埠嗎?

用法: ssh -v -p port [email protected]

-v 除錯模式(會列印日誌).

-p 指定埠

username可以隨意
埠和ip可用的情況:


w1:~ jiaguoshang$ ssh -v -p 8888 [email protected]
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to 192.168.1.156 port 8888.
debug1: Connection established.
debug1: identity file /Users/jiaguoshang/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jiaguoshang/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jiaguoshang/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jiaguoshang/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jiaguoshang/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jiaguoshang/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jiaguoshang/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/jiaguoshang/.ssh/id_ed25519-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: ssh_exchange_identification: HTTP/1.1 400 Bad Request


debug1: ssh_exchange_identification: Server: nginx


debug1: ssh_exchange_identification: Date: Thu, 06 Dec 2018 03:24:33 GMT


debug1: ssh_exchange_identification: Content-Type: text/html


debug1: ssh_exchange_identification: Content-Length: 166


debug1: ssh_exchange_identification: Connection: close


debug1: ssh_exchange_identification: 


debug1: ssh_exchange_identification: <html>


debug1: ssh_exchange_identification: <head><title>400 Bad Request</title></head>


debug1: ssh_exchange_identification: <body bgcolor="white">


debug1: ssh_exchange_identification: <center><h1>400 Bad Request</h1></center>


debug1: ssh_exchange_identification: <hr><center>nginx</center>


debug1: ssh_exchange_identification: </body>


debug1: ssh_exchange_identification: </html>


ssh_exchange_identification: Connection closed by remote host
w1:~ jiaguoshang$ 

埠不可用的情況:


w1:~ jiaguoshang$ ssh -v -p 888 [email protected]
OpenSSH_7.6p1, LibreSSL 2.6.2
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 48: Applying options for *
debug1: Connecting to 192.168.1.156 port 888.
ssh: connect to host 192.168.1.156 port 888: Connection refused

因為我就遇到過埠沒有開通的情況,我折騰了大半天。
若出現埠被禁用可以使用firewall-cmd --zone=public --list-ports檢視開發埠列表。使用firewall-cmd --permanent --zone=public --add-port=8888/tcp開發防火牆的埠。

[[email protected] ~]# uname -a
Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
[[email protected] ~]# systemctl status firewalld
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; vendor preset: enabled)
   Active: active (running) since 二 2018-12-04 14:03:05 CST; 1 day 21h ago
     Docs: man:firewalld(1)
 Main PID: 46502 (firewalld)
   CGroup: /system.slice/firewalld.service
           └─46502 /usr/bin/python -Es /usr/sbin/firewalld --nofork --nopid

12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
12月 04 14:03:06 localhost.localdomain firewalld[46502]: WARNING: COMMAND_FAILED: '/usr/sbin/iptables -w2 -w --table filter --del...ailed:
Hint: Some lines were ellipsized, use -l to show in full.
[[email protected] ~]# uname -a
[[email protected] ~]# firewall-cmd --zone=public --list-ports
8888/tcp

7、修改root的密碼。

[[email protected] ~]# gitlab-rails console production
-------------------------------------------------------------------------------------
 GitLab:       11.4.8 (bdfeff3)
 GitLab Shell: 8.3.3
 postgresql:   9.6.8
-------------------------------------------------------------------------------------
Loading production environment (Rails 4.2.10)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user.password=12345678
=> 12345678
irb(main):003:0> user.password_confirmation=12345678
=> 12345678
irb(main):004:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: d9b1f1f7-1256-48ff-b18a-c07d9c98e504) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", gid://gitlab/User/1
=> true
irb(main):005:0> quit

注意: User.where(id: 1).中的1程式碼使用者列表的序號,1永遠都是超級管理員root使用者。若大於1就是非超級管理員賬戶,但是至少這個使用者存在才能設定成功。
你會發現要求的成員或命令批量加入的成員,使用的區域網IP伺服器,無法開啟從郵箱裡點選重置密碼連結:http://192.163.1.156:8888/users/password/edit?reset_password_token=tZ1opLbXrgS4Txz6Fx8g 。沒有辦法我是使用的上面命令重置普通成員賬戶的初始密碼,全數字型別。然後讓成員賬戶登入裡面修改密碼的。
在這裡插入圖片描述
在這裡插入圖片描述

8、禁用註冊功能。
在這裡插入圖片描述
把郵箱註冊的預設選擇勾選去掉
9、製作ssh登入用證書。
在這裡插入圖片描述
由於內容太多,關於漢化和刪除後重裝GitLab的內容在其它文章敘述了。