部署gitlab-01

林奮鬥的成長之路發表於2021-02-14

Gitlab Server 部署

1、環境配置

關閉防火牆、SELinux

開啟郵件服務

systemctl start  postfix
systemctl enable postfix
#ps:不開去郵箱可以不期待,不是必須操作

  

2、部署 Gitlab

1、安裝 gitlab 依賴包

centos7:
 ~]# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
# gitlab-ce 10.x.x以後的版本需要依賴policycoreutils-python

centos8:
 ~]# yum install -y curl openssh-server openssh-clients postfix cronie  policycoreutils-python-utils

  

2、新增官方源

~]# curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash

因為官方源太慢,可以使用國內清華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

 

3、安裝 Gitlab

 ~]# yum -y install gitlab-ce                    # 自動安裝最新版
 ~]# yum -y install gitlab-ce-x.x.x	     # 安裝指定版本Gitlab

4、配置 Gitlab

1、檢視Gitlab版本
]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 13.8.4
[root@node1 gitlab]# pwd
/opt/gitlab
[root@node1 gitlab]# ll
總用量 2580
drwxr-xr-x  2 root root     153 2月  14 21:02 bin
-rw-r--r--  1 root root  192450 2月  11 18:36 dependency_licenses.json
drwxr-xr-x 14 root root     168 2月  14 21:02 embedded
drwxr-xr-x  2 root root      32 2月  14 21:02 etc
drwxr-xr-x  2 root root       6 2月  11 18:37 init
-rw-r--r--  1 root root 2391185 2月  11 18:36 LICENSE
drwxr-xr-x  2 root root     306 2月  14 21:02 licenses
drwxr-xr-x  2 root root    8192 2月  14 21:02 LICENSES
drwxr-xr-x  2 root root       6 2月  11 18:37 service
drwxr-xr-x  2 root root       6 2月  11 18:37 sv
-rw-r--r--  1 root root   31942 2月  11 18:37 version-manifest.json
-rw-r--r--  1 root root   12135 2月  11 18:37 version-manifest.txt      #依賴包位置
2、Gitlab 配置登入連結
#設定登入連結
[root@qfedu.com ~]# vim /etc/gitlab/gitlab.rb
***
## GitLab URL
##! 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
# 沒有域名,可以設定為本機IP地址

32 external_url 'http://192.168.1.1'    #也可以加埠

***

 [root@node1 gitlab]# grep "^external_url" /etc/gitlab/gitlab.rb
 external_url 'http://192.168.1.1'  #繫結監聽的域名或IP

3、初始化 Gitlab

第一次使用配置時間較長

 ~]# gitlab-ctl reconfigure   
......

  Running handlers:
  Running handlers complete
  Chef Infra Client finished, 578/1549 resources updated in 02 minutes 57 seconds

  Notes:
  It seems you haven't specified an initial root password while configuring the GitLab instance.
  On your first visit to your GitLab instance, you will be presented with a screen to set a
  password for the default admin account with username `root`.

  gitlab Reconfigured!

  

4、啟動 Gitlab 服務
[root@node1 gitlab]# gitlab-ctl start
ok: run: alertmanager: (pid 14192) 65s
ok: run: gitaly: (pid 14079) 67s
ok: run: gitlab-exporter: (pid 14089) 67s
ok: run: gitlab-workhorse: (pid 14049) 68s
ok: run: grafana: (pid 14211) 64s
ok: run: logrotate: (pid 13583) 153s
ok: run: nginx: (pid 13560) 160s
ok: run: node-exporter: (pid 14064) 68s
ok: run: postgres-exporter: (pid 14203) 64s
ok: run: postgresql: (pid 13272) 215s
ok: run: prometheus: (pid 14174) 66s
ok: run: puma: (pid 13459) 178s
ok: run: redis: (pid 13101) 227s
ok: run: redis-exporter: (pid 14091) 66s
ok: run: sidekiq: (pid 13487) 172s

  

  [root@node1 gitlab]# lsof -i:80  #檢視git
  COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
  nginx 13560 root 7u IPv4 64606 0t0 TCP *:http (LISTEN)
  nginx 13561 gitlab-www 7u IPv4 64606 0t0 TCP *:http (LISTEN)
  nginx 13562 gitlab-www 7u IPv4 64606 0t0 TCP *:http (LISTEN)
  nginx 13563 gitlab-www 7u IPv4 64606 0t0 TCP *:http (LISTEN)
  nginx 13564 gitlab-www 7u IPv4 64606 0t0 TCP *:http (LISTEN)

5、Gitlab 的使用

在瀏覽器中輸入 http://192.168.1.1,然後 change password: ,並使用root使用者登入 即可 (後續動作根據提示操作)

 

 

 

5.1、Gitlab 命令列修改密碼

~]# gitlab-rails console production
irb(main):001:0>user = User.where(id: 1).first      # id為1的是超級管理員
irb(main):002:0>user.password = 'yourpassword'      # 密碼必須至少8個字元
irb(main):003:0>user.save!                          # 如沒有問題 返回true
exit                                                 # 退出

5.2、Gitlab服務管理

~]# gitlab-ctl start                      # 啟動所有 gitlab 元件;
~]# gitlab-ctl stop                       # 停止所有 gitlab 元件;
~]# gitlab-ctl restart                    # 重啟所有 gitlab 元件;
~]# gitlab-ctl status                     # 檢視服務狀態;
~]# gitlab-ctl reconfigure                # 初始化服務;
~]# vim /etc/gitlab/gitlab.rb             # 修改預設的配置檔案;
~]# gitlab-ctl tail                       # 檢視日誌;

 

相關文章