Gitlab Server 部署

1、環境準備

<code>1.系統版本:CentOS7.4 

2.Gitlab版本:gitlab-ee 11.0.1
3.初始化系統環境
4.關閉防火牆
[root@localhost ~]# systemctl stop iptables firewalld
[root@localhost ~]# systemctl disable iptables firewalld
5.開啟郵件服務
[root@vm1 ~]# systemctl start postfix
[root@vm1 ~]# systemctl enable postfix
6.關閉SELinux
[root@localhost ~]# sed -ri '/SELINUX=/cSELINUX=disabled' /etc/selinux/config
[root@localhost ~]# setenforce 0           # 臨時關閉SELinux
[root@localhost ~]# reboot
​/<code>

2、部署Gitlab

<code>1.安裝Gitlab社區版/企業版
2.安裝gitlab依賴包
[root@localhost ~]# yum install -y curl openssh-server openssh-clients postfix cronie policycoreutils-python
# gitlab-ce 10.x.x以後的版本需要依賴policycoreutils-python

3.開啟postfix,並設置開機自啟
[root@localhost ~]# systemctl start postfix;systemctl enable postfix

4.選擇添加yum源安裝gitlab(根據需求配置源)
(1)添加阿里源
# vim /etc/yum.repos.d/gitlab-ce.repo
[gitlab-ce]
name=gitlab-ce
baseurl=http://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7
Repo_gpgcheck=0
Enabled=1
Gpgkey=https://packages.gitlab.com/gpg.key

(2) 添加清華源
# vim 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


# vim gitlab-ee.repo
[gitlab-ee]
name=Gitlab EE Repository
baseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el$releasever/
gpgcheck=0
enabled=1

# vim runner_gitlab-ci-multi-runner.repo
[runner_gitlab-ci-multi-runner]
name=runner_gitlab-ci-multi-runner
baseurl=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/7/$basearch
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

[runner_gitlab-ci-multi-runner-source]
name=runner_gitlab-ci-multi-runner-source
baseurl=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/el/7/SRPMS
repo_gpgcheck=1
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/runner/gitlab-ci-multi-runner/gpgkey
sslverify=1
sslcacert=/etc/pki/tls/certs/ca-bundle.crt
metadata_expire=300

(3) 添加官方源
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.rpm.sh | sudo bash

5.安裝包下載
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/
https://mirrors.tuna.tsinghua.edu.cn/gitlab-ee/yum/el7/

6.根據需要選擇ce/ee
[root@localhost ~]# yum -y install gitlab-ce                   # 自動安裝最新版
[root@localhost ~]# yum -y install gitlab-ce-x.x.x # 安裝指定版本Gitlab

[root@localhost ~]# yum -y install gitlab-ce
warning: gitlab-ce-10.7.2-ce.0.el7.x86_64.rpm: Header V4 RSA/SHA1 Signature, key ID f27eab47: NOKEY
Preparing...                         ################################# [100%]
Updating / installing...
  1:gitlab-ce-10.7.2-ce.0.el7       ################################# [100%]
It looks like GitLab has not been configured yet; skipping the upgrade/>​

      *.                 *.
    ***                 ***
    *****               *****
  .******             *******
  ********           ********
  ,,,,,,,,,***********,,,,,,,,,
,,,,,,,,,,,*********,,,,,,,,,,,
.,,,,,,,,,,,*******,,,,,,,,,,,,
    ,,,,,,,,,*****,,,,,,,,,.
        ,,,,,,,****,,,,,,
          .,,,***,,,,
              ,*,.
 


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

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/<code>

###3、配置 Gitlab

1、查看Gitlab版本

<code>[root@localhost ~]# head -1 /opt/gitlab/version-manifest.txt
gitlab-ce 10.1.1/<code>

2、Gitlab 配置文登錄鏈接

<code>#設置登錄鏈接
[root@localhost ~]# 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地址
external_url 'http://172.17.0.61'
***
[root@localhost ~]# grep "^external_url" /etc/gitlab/gitlab.rb
external_url 'http://172.17.0.61'     #綁定監聽的域名或IP/<code>

3、初始化 Gitlab (第一次使用配置時間較長)

<code> [root@localhost ~]# gitlab-ctl reconfigure   
...../<code>

4、啟動 Gitlab 服務

<code>[root@vm1 ~]# gitlab-ctl start
ok: run: gitaly: (pid 22896) 2922s
ok: run: gitlab-monitor: (pid 22914) 2921s
ok: run: gitlab-workhorse: (pid 22882) 2922s
ok: run: logrotate: (pid 22517) 2987s
ok: run: nginx: (pid 22500) 2993s
ok: run: node-exporter: (pid 22584) 2974s
ok: run: postgres-exporter: (pid 22946) 2919s
ok: run: postgresql: (pid 22250) 3047s
ok: run: prometheus: (pid 22931) 2920s
ok: run: redis: (pid 22190) 3053s
ok: run: redis-exporter: (pid 22732) 2962s
ok: run: sidekiq: (pid 22472) 3005s
ok: run: unicorn: (pid 22433) 3011s
[root@vm1 ~]#
[root@vm1 ~]# lsof -i:80
COMMAND   PID       USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
nginx   22500       root   7u IPv4  50923     0t0 TCP *:http (LISTEN)
nginx   22501 gitlab-www   7u IPv4  50923     0t0 TCP *:http (LISTEN)
[root@vm1 ~]# /<code>

5、Gitlab 設置 HTTPS 方式

<code>如果想要以上的 https 方式正常生效使用,則需要把 letsencrypt 自動生成證書的配置打開,這樣在執行重
新讓配置生效命令 (gitlab-ctl reconfigure) 的時候會自動給域名生成免費的證書並自動在 gitlab 自帶的
nginx 中加上相關的跳轉配置,都是全自動的,非常方便。

letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['[email protected]']     # 這應該是一組要添加為聯繫人的電子郵件地址/<code>

6、Gitlab 添加smtp郵件功能

<code>[root@vm1 ~]# vim /etc/gitlab/gitlab.rb
postfix 並非必須的;根據具體情況配置,以 SMTP 的為例配置郵件服務器來實現通知;參考配置如下:
### Email Settings  
gitlab_rails['gitlab_email_enabled'] = true  
gitlab_rails['gitlab_email_from'] = '[email protected]'  
gitlab_rails['gitlab_email_display_name'] = 'gitlab.notice'  
gitlab_rails['gitlab_email_reply_to'] = '[email protected]'  
gitlab_rails['gitlab_email_subject_suffix'] = 'gitlab'  
### GitLab email server settings
###! Docs: https://docs.gitlab.com/omnibus/settings/smtp.html
###! **Use smtp instead of sendmail/postfix.**  
gitlab_rails['smtp_enable'] = true  
gitlab_rails['smtp_address'] = "smtp.qq.com"  
gitlab_rails['smtp_port'] = 465  
gitlab_rails['smtp_user_name'] = "[email protected]"  
gitlab_rails['smtp_password'] = "xxxxx"  
gitlab_rails['smtp_domain'] = "qq.com"  
gitlab_rails['smtp_authentication'] = "login"  
gitlab_rails['smtp_enable_starttls_auto'] = true  
gitlab_rails['smtp_tls'] = true

[root@vm1 ~]# grep -P "^[^#].*smtp_|user_email|gitlab_email" /etc/gitlab/gitlab.rb
gitlab_rails['gitlab_email_enabled'] = true
gitlab_rails['gitlab_email_from'] = '[email protected]'
gitlab_rails['gitlab_email_display_name'] = 'Admin'
gitlab_rails['gitlab_email_reply_to'] = '[email protected]'
gitlab_rails['gitlab_email_subject_suffix'] = '[gitlab]'
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.exmail.qq.com"
gitlab_rails['smtp_port'] = 25
gitlab_rails['smtp_user_name'] = "[email protected]"
gitlab_rails['smtp_password'] = "password"
gitlab_rails['smtp_domain'] = "domain.cn"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = false
user['git_user_email'] = "[email protected]"

[root@vm1 ~]# gitlab-ctl reconfigure #修改配置後需要初始化配置

......

[root@vm1 ~]# gitlab-ctl stop
ok: down: gitaly: 0s, normally up
ok: down: gitlab-monitor: 1s, normally up
ok: down: gitlab-workhorse: 0s, normally up
ok: down: logrotate: 1s, normally up
ok: down: nginx: 0s, normally up
ok: down: node-exporter: 1s, normally up
ok: down: postgres-exporter: 0s, normally up
ok: down: postgresql: 0s, normally up
ok: down: prometheus: 0s, normally up
ok: down: redis: 0s, normally up
ok: down: redis-exporter: 1s, normally up
ok: down: sidekiq: 0s, normally up
ok: down: unicorn: 1s, normally up

[root@vm1 ~]# gitlab-ctl start
ok: run: gitaly: (pid 37603) 0s
ok: run: gitlab-monitor: (pid 37613) 0s
ok: run: gitlab-workhorse: (pid 37625) 0s
ok: run: logrotate: (pid 37631) 0s
ok: run: nginx: (pid 37639) 1s
ok: run: node-exporter: (pid 37644) 0s
ok: run: postgres-exporter: (pid 37648) 1s
ok: run: postgresql: (pid 37652) 0s
ok: run: prometheus: (pid 37660) 1s
ok: run: redis: (pid 37668) 0s
ok: run: redis-exporter: (pid 37746) 0s
ok: run: sidekiq: (pid 37750) 1s
ok: run: unicorn: (pid 37757) 0s/<code>

7、Gitlab 發送郵件測試

<code>[root@vm1 ~]# gitlab-rails console 
Loading production environment (Rails 4.2.10)
irb(main):001:0> Notify.test_email('[email protected]', 'Message Subject', 'Message Body').deliver_now

Notify#test_email: processed outbound mail in 2219.5ms

Sent mail to [email protected] (2469.5ms)
Date: Fri, 04 May 2018 15:50:10 +0800
From: Admin <username>
Reply-To: Admin <username>
To: [email protected]
Message-ID: <[email protected]>
Subject: Message Subject
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8

Content-Transfer-Encoding: 7bit
Auto-Submitted: auto-generated
X-Auto-Response-Suppress: All


Message Body



=> #<:message:70291731344240 multipart:="" false="" headers:="" fri="" may="">, <from>>, <reply-to>>, , <message-id>>, <subject>, <mime-version>, <content-type>, <content-transfer-encoding>, <auto-submitted>, <x-auto-response-suppress>>
irb(main):002:0>quit /<x-auto-response-suppress>/<auto-submitted>/<content-transfer-encoding>/<content-type>/<mime-version>/<subject>/<message-id>
/<reply-to>/<from>/<username>/<username>/<code>

###3、gitlab的使用 在瀏覽器中輸入 http://192.168.60.119/ ,然後 change password: ,並使用root用戶登錄 即可 (後續動作根據提示操作)

1、gitlab 命令行修改密碼

<code>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 # 退出/<code>

2、gitlab服務管理

<code>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                         # 查看日誌;/<code>

3、登陸 Gitlab

Gitlab Server 部署

如果需要手工修改nginx的port ,可以在gitlab.rb中設置 nginx['listen_port'] = 8000 ,然後再次 gitlab-ctl reconfigure即可

登錄 gitlab 如下所示(首次登陸設置 root 密碼):

Gitlab Server 部署

創建項目組 group ,組名為plat-sp ,如下所示:

Gitlab Server 部署

Gitlab Server 部署

去掉用戶的自動註冊功能(安全): admin are -> settings -> Sign-up Restrictions 去掉鉤鉤,然後拉到最下面保存,重新登錄


Gitlab Server 部署


分享到:


相關文章: