CentOS7安裝並啟動GitLab


1 - GitLab安裝

1.1 信息確認

[Anliven@node102 ~]$ uname -a
Linux node102 3.10.0-957.el7.x86_64 #1 SMP Thu Nov 8 23:39:32 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux
[Anliven@node102 ~]$ cat /etc/system-release
CentOS Linux release 7.5.1804 (Core) 
[Anliven@node102 ~]$ 

  

1.2 准備步驟

# 安裝依賴
sudo yum install -y curl policycoreutils-python openssh-server postfix
​
# 啟動SSH和postfix
sudo systemctl enable sshd
sudo systemctl start sshd
sudo systemctl enable postfix
sudo systemctl start postfix
​
# 開放端口, 防火牆未開啟就不用執行
sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --add-service=http --permanent
sudo firewall-cmd --reload

  

1.3 安裝方式1:Yum(外網下載)

curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
sudo yum install -y gitlab-ce

  

 

1.4 安裝方式2:下載並安裝rpm包

清華鏡像:https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/

 

 

 

 

注意:可以單獨下載RPM包,然后上傳到Server,要節約時間點。

wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/gitlab-ce-13.8.4-ce.0.el7.x86_64.rpm
rpm -i gitlab-ce-13.8.4-ce.0.el7.x86_64.rpm

 

 

2 - 初始化配置

GitLab默認的配置文件路徑:/etc/gitlab/

  • /etc/gitlab/gitlab.rb:主配置文件,包含外部URL、倉庫目錄、備份目錄等

  • /etc/gitlab/gitlab-secrets.json:(執行gitlab-ctl reconfigure命令行后生成),包含各類密鑰的加密信息

 

2.1 初始化配置

  • 配置首頁地址(需將設置的域名DNS解析到服務器IP,或者修改本地host將域名指向服務器IP)

[root@node102 ~]# cat /etc/gitlab/gitlab.rb |grep -v "#" |grep -Ev "^$"
external_url 'http://gitlab.example.com'
​
# 需要修改成自己的ip
external_url 'http://192.168.16.102'
  • 重新配置並啟動,使配置生效,並確認相關組件或進程的狀態

對比配置文件修改


[root@test102 ~]# gitlab-ctl diff-config
diff --git a/etc/gitlab/gitlab.rb b/opt/gitlab/etc/gitlab.rb.template
index 3e27e40..31c0b45 100644
--- a/etc/gitlab/gitlab.rb
+++ b/opt/gitlab/etc/gitlab.rb.template
@@ -20,7 +20,7 @@
 ##! URL on which GitLab will be reachable.
 ##! For more details on configuring external_url see:
 ##! https://docs.gitlab.com/omnibus/settings/configuration.html#configuring-the-external-url-for-gitlab
-external_url 'http://192.168.16.102'
+external_url 'GENERATED_EXTERNAL_URL'

  

放開防火牆端口

[root@test102 ~]# 
[root@node102 ~]#  firewall-cmd --zone=public --permanent --add-port=80/tcp
success
[root@node102 ~]# firewall-cmd --reload
success

  

重新應用配置文件

[root@node102 ~]# gitlab-ctl reconfigure
​
[root@node102 ~]# gitlab-ctl status
run: alertmanager: (pid 6469) 45s; run: log: (pid 6123) 128s
run: gitaly: (pid 6335) 50s; run: log: (pid 5516) 263s
run: gitlab-exporter: (pid 6380) 48s; run: log: (pid 5972) 146s
run: gitlab-workhorse: (pid 6358) 49s; run: log: (pid 5882) 174s
run: grafana: (pid 6529) 44s; run: log: (pid 6273) 74s
run: logrotate: (pid 5920) 159s; run: log: (pid 5929) 158s
run: nginx: (pid 5893) 171s; run: log: (pid 5905) 167s
run: node-exporter: (pid 6367) 49s; run: log: (pid 5960) 152s
run: postgres-exporter: (pid 6488) 45s; run: log: (pid 6150) 121s
run: postgresql: (pid 5632) 255s; run: log: (pid 5644) 254s
run: prometheus: (pid 6406) 47s; run: log: (pid 6080) 132s
run: redis: (pid 5471) 272s; run: log: (pid 5479) 271s
run: redis-exporter: (pid 6384) 48s; run: log: (pid 6003) 140s
run: sidekiq: (pid 5842) 183s; run: log: (pid 5853) 180s
run: unicorn: (pid 5803) 189s; run: log: (pid 5835) 186s

  

 

2.2 登錄

http://192.168.16.102 注意:這個地址是“external_url 'http://192.168.16.102'” 首次登錄顯示為密碼設置界面,設置管理員密碼,管理員賬號默認username是root 設置完成之后,刷新即可使用root賬號登錄,登陸后會進入歡迎界面。

 

 

 

 

 

 

 

 

 

 

 

 

 

2.3 GitLab個人中文界面

登錄后,點擊右上角用戶頭像---》Settings---》Preferences---》Localization部分的Language項目---》選擇“簡體中文”並保存更改---》刷新頁面。

 

 

 

 

 

 

 

2.4 更新管理員資料

 

 

 

 

 

 

 

2.5 查看管理員面板

Admin Area的主面板顯示整體數據,左側導航菜單可以查看具體的分類信息

 

 

 

 

 

 

 

2.6 創建新用戶

 

方式1:管理員直接創建用戶

Admin Area ---》New user,根據規則和需要分別設置Account、Access部分,Password部分可以由本人進行設置。

 

 

 

查看郵箱,點擊郵件中的鏈接,設置密碼並登陸

 

 

 

 

 

 

 

方式2:用戶直接注冊新的賬戶

在GitLab登錄界面,直接點擊“Register”,添加用戶相關信息。

 

 

 

 

 

 

3 - GitLab常用配置

3.1 配置Git存儲倉庫目錄

默認存儲目錄為/var/opt/gitlab/git-data/repositories

[root@test102 ~]# ll /var/opt/gitlab/git-data/
total 0
drwxrws--- 3 git root 45 Nov 27 13:53 
[root@test102 ~]#

  

如果要更新或增加存儲倉庫目錄,可以修改/etc/gitlab/gitlab.rb配置文件中git_data_dirs部分的內容,然后執行“gitlab-ctl reconfigure”命令使之生效。 例如:

git_data_dirs({
  "default" => {"path" => "/var/opt/gitlab/git-data"}
  "newrepo" => {"path" => "/mnt/nfs-01/git-data"}
})

  

特別注意:

  • 如果修改倉庫目錄,用戶有權限訪問,否則重新配置時會報錯。

  • 修改倉庫目錄后,必須將舊倉庫的數據遷移到新目錄下,否則相關項目會提示“沒有倉庫”。

sudo gitlab-ctl upgrade  # 組件更新(可選)
sudo gitlab-ctl stop  # 停止服務
sudo rsync -av <old-dir>  <new-dir>/  # 目錄同步(注意斜杠的作用)
ls <new-dir>  # 檢查文件及目錄層級
sudo gitlab-ctl start  # 啟動服務
sudo gitlab-ctl reconfigure  # 重配置

  

3.3 禁用創建組權限

GitLab默認所有的注冊用戶都可以創建組,在實際使用中,通常只會給指定的少部分用戶相關權限。 將/etc/gitlab/gitlab.rb中的gitlab_rails['gitlab_default_can_create_group']參數設為false,然后重載配置即可。

[root@test102 ~]# cat -n /etc/gitlab/gitlab.rb |grep "create_group"
    70  # gitlab_rails['gitlab_default_can_create_group'] = true

  

4 - 日志查看

gitlab-ctl tail     # 查看所有GitLab日志 
gitlab-ctl tail <module-name>    # 查看某個組件的日志
gitlab-ctl tail <module-name>/<log-name>    # 查看某個組件的某個類型日志

日志目錄:/var/log/gitlab/

 

5 - GitLab-ctl常用命令

gitlab-ctl reconfigure    # 重載配置
gitlab-ctl check-config    # 檢查配置並啟動
gitlab-ctl diff-config    # 將用戶配置與包可用配置進行比較
gitlab-ctl status    # 查看所有啟動組件的進程和狀態
gitlab-ctl service-list    # 查看所有服務
gitlab-ctl stop    # 停止GitLab服務
gitlab-ctl start    # 啟動GitLab服務 
gitlab-ctl restart    # 重啟GitLab服務 
gitlab-ctl once    # 如果GitLab服務已停止則啟動服務,如果GitLab服務已啟動則重啟GitLab服務

 

6 - 問題處理

修改root密碼

https://docs.gitlab.com/ce/security/reset_root_password.html

[root@node102 ~]# gitlab-rails console -e production
--------------------------------------------------------------------------------
 GitLab:       12.5.0 (1f0ab8978ef)
 GitLab Shell: 10.2.0
 PostgreSQL:   10.9
--------------------------------------------------------------------------------
Loading production environment (Rails 5.2.3)
irb(main):001:0> user = User.where(id: 1).first
=> #<User id:1 @root>
irb(main):002:0> user = User.find_by(email: 'admin@example.com')
=> #<User id:1 @root>
irb(main):003:0> user.password = 'secret_pass'
=> "secret_pass"
irb(main):004:0> user.password_confirmation = 'secret_pass'
=> "secret_pass"
irb(main):005:0> user.save!
Enqueued ActionMailer::DeliveryJob (Job ID: 90526cdc-8d61-458f-bb85-bd1f2797c5b1) to Sidekiq(mailers) with arguments: "DeviseMailer", "password_change", "deliver_now", #<GlobalID:0x00007fc0b4541088 @uri=#<URI::GID gid://gitlab/User/1>>
=> true
irb(main):006:0> exit
[root@node102 ~]# 

 

7 - 參考信息


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM