gitlab的部署、代碼克隆和提交、數據備份等

1.配置網卡及ubuntu倉庫源

1)配置網卡eth0,本地內網網卡無需指定網關和域名服務器

network:
    version: 2
    renderer: networkd
    ethernets:
        eth0:
            dhcp4: no
            addresses: [192.168.1.30/24]

2)配置網卡eth1,要保持如下兩個字節的嚴格縮進,不然會致使網卡起不來

root@ubuntu1804:~# vim /etc/netplan/02-netcfg.yaml 
network:
         version: 2
         renderer: networkd
         ethernets:
                 eth1:
                        dhcp4: yes
                        addresses: [192.168.10.107/24]
                        gateway4: 192.168.10.1
                        nameservers:
                                 addresses: [223.6.6.6]

3)配置阿里雲倉庫源

root@ubuntu1804:~# vim /etc/apt/sources.list
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

4)更新倉庫

root@ubuntu1804:~# apt update
root@ubuntu1804:~# apt update
Get:1 http://mirrors.aliyun.com/ubuntu bionic InRelease [242 kB]
Get:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB]                                  
Get:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB]                                   
Get:4 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease [242 kB] 
……

2.安裝gitlab包

1)下載gitlab-ce社區版包

root@ubuntu1804:~# ls /data/
gitlab-ce_11.11.5-ce.0_amd64.deb

2)安裝gitlab,要肯定gitlab包適合此版本ubuntu系統

root@ubuntu1804:/data# dpkg -i gitlab-ce_11.11.5-ce.0_amd64.deb
root@ubuntu1804:/data# dpkg -i gitlab-ce_11.11.5-ce.0_amd64.deb 
Selecting previously unselected package gitlab-ce.
(Reading database ... 69294 files and directories currently installed.)
Preparing to unpack gitlab-ce_11.11.5-ce.0_amd64.deb ...
Unpacking gitlab-ce (11.11.5-ce.0) …   #等待安裝完成

3)此時沒法識別主機,需修改git配置文件,指定主機

root@ubuntu1804:/data# vim /etc/gitlab/gitlab.rb 
    external_url 'http://192.168.1.30'  #修改指定的ip主機

4)配置完進行gitlab初始化

root@ubuntu1804:/data# gitlab-ctl reconfigure

3.命令操做

1)進入數據庫命令行

root@ubuntu1804:~# gitlab-psql
gitlabhq_production-# \db
                 List of tablespaces
        Name    |    Owner    | Location 
------------+-------------+----------
 pg_default | gitlab-psql | 
 pg_global  | gitlab-psql | 
(2 rows)

2)查看gitlab的運行狀態

root@ubuntu1804:~# gitlab-ctl status
run: alertmanager: (pid 4704) 1841s; run: log: (pid 4373) 1867s
run: gitaly: (pid 4475) 1844s; run: log: (pid 3483) 2026s
run: gitlab-monitor: (pid 4553) 1843s; run: log: (pid 4169) 1887s
run: gitlab-workhorse: (pid 4512) 1844s; run: log: (pid 4027) 1910s
run: logrotate: (pid 4073) 1900s; run: log: (pid 4089) 1899s
run: nginx: (pid 4040) 1906s; run: log: (pid 4060) 1905s
run: node-exporter: (pid 4537) 1843s; run: log: (pid 4146) 1892s
run: postgres-exporter: (pid 4727) 1840s; run: log: (pid 4409) 1863s
run: postgresql: (pid 3659) 2012s; run: log: (pid 3689) 2011s
run: prometheus: (pid 4578) 1842s; run: log: (pid 4245) 1875s
run: redis: (pid 3417) 2034s; run: log: (pid 3442) 2031s
run: redis-exporter: (pid 4561) 1842s; run: log: (pid 4202) 1881s
run: sidekiq: (pid 3967) 1920s; run: log: (pid 3983) 1916s
run: unicorn: (pid 3908) 1926s; run: log: (pid 3957) 1923s

3)gitlab服務命令行的啓動、中止、重啓

gitlab-ctl start/stop/restart gitlab

4)查看gitlab的nginx服務組件的日誌

root@ubuntu1804:~# gitlab-ctl tail nginx
==> /var/log/gitlab/nginx/current <==

==> /var/log/gitlab/nginx/access.log <==

==> /var/log/gitlab/nginx/error.log <==

==> /var/log/gitlab/nginx/gitlab_error.log <==

==> /var/log/gitlab/nginx/gitlab_access.log <==
192.168.1.1 - - [21/Jul/2019:10:36:00 +0800] "GET / HTTP/1.1" 302 99 "" "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3724.8 Safari/537.36"
……

4.瀏覽器訪問gitlab

1)設置新的密碼,默認登陸的用戶爲root

gitlab的部署、代碼克隆和提交、數據備份等

2)登陸後默認的界面

gitlab的部署、代碼克隆和提交、數據備份等

3)點擊setting,在點擊sign-up能夠設置是否容許建立新用戶

gitlab的部署、代碼克隆和提交、數據備份等

4)去掉對勾,禁止建立新帳戶

gitlab的部署、代碼克隆和提交、數據備份等

5)再點擊保存修改生效

gitlab的部署、代碼克隆和提交、數據備份等

6)此時登出帳號時,就沒有註冊用戶的選項,只能用已有的帳戶登陸

gitlab的部署、代碼克隆和提交、數據備份等

7)建立一個新用戶時會受到郵件通知

gitlab的部署、代碼克隆和提交、數據備份等

8)建立不一樣的項目、組、帳戶,將特定用戶放到特定的組,實現特定用戶對某些項目有查看權限

gitlab的部署、代碼克隆和提交、數據備份等

9)返回到項目列表,並進入一個項目

gitlab的部署、代碼克隆和提交、數據備份等

10)點擊New file

gitlab的部署、代碼克隆和提交、數據備份等

11)輸入一個索引測試頁面,再點擊提交

gitlab的部署、代碼克隆和提交、數據備份等

12)查看項目的clone地址

gitlab的部署、代碼克隆和提交、數據備份等

13)客戶端clone

root@ubuntu1804:/data/src# git clone http://192.168.1.30/root/web-page.git
Cloning into 'web-page'...
remote: Enumerating objects: 3, done.
remote: Counting objects: 100% (3/3), done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Unpacking objects: 100% (3/3), done.

14)項目代碼克隆成功

root@ubuntu1804:/data/src# ls
web-page
root@ubuntu1804:/data/src# cat web-page/index.html 
<h>hello jie!</h1>

15)在客戶端修改index.html

root@ubuntu1804:/data/src/web-page# cat index.html 
<h>hello jie!</h1>
<h>hello kobe!</h1>
<h>hello curry!</h1>
<h>hello rose!</h1>

16)先添加到本地暫存區(提交代碼到gitlab服務器時,命令都必須在克隆下來的文件夾環境中執行)

root@ubuntu1804:/data/src/web-page# git add index.html

17)在提到工做區

root@ubuntu1804:/data/src/web-page# git commit -m 'v6'
[master 1202723] v6
 1 file changed, 4 insertions(+), 1 deletion(-)

18)而後在直接提交到gitlab倉庫web端

root@ubuntu1804:/data/src/web-page# git push     #其中git pull爲獲取代碼到本地
Username for 'http://192.168.1.30': root     #要求輸入登陸gitlab的web端的用戶名                             
Password for 'http://root@192.168.1.30':    #再輸入登陸gitlab的web端的用戶密碼  
Counting objects: 3, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 268 bytes | 268.00 KiB/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To http://192.168.1.30/root/web-page.git
     ecc001d..1202723  master -> master     #提交完成

19)在web端gitlab倉庫查看,項目index.html內容被更改,說明成功提交

gitlab的部署、代碼克隆和提交、數據備份等

20)再次修改index.html文件,而後在上傳v7版本的index.html到gitlab的服務端

gitlab的部署、代碼克隆和提交、數據備份等

5.gitlab的一些基本命令操做(如下命令操做命令都必須在克隆下來的文件夾環境中執行,不然沒法執行令)

1)客戶端查看當前版本號爲v7

root@ubuntu1804:/data/src/web-page# git reset --hard HEAD
HEAD is now at 952e66b v7

2)查看v7版索引

root@ubuntu1804:/data/src/web-page# cat index.html 
<h>hello jie!</h1>
<h>hello kobe!</h1>
<h>hello curry!</h1>
<h>hello rose!</h1>
<h>hello jordan!</h1>
<h>hello jordan!</h1>
<h>hello howard!</h1>

3)若想回滾到v6版本,則操做以下命令進行回滾

root@ubuntu1804:/data/src/web-page# git reset --hard HEAD^
HEAD is now at 9cb6bf6 v6

4)再查看v6版本索引文件

root@ubuntu1804:/data/src/web-page# cat index.html 
<h>hello jie!</h1>
<h>hello kobe!</h1>
<h>hello curry!</h1>
<h>hello rose!</h1>
<h>hello jordan!</h1>
<h>hello jordan!</h1>

5)查看每次提交的目標代碼id號,

root@ubuntu1804:/data/src/web-page# git reflog
9cb6bf6 (HEAD -> master) HEAD@{0}: reset: moving to HEAD^
952e66b (origin/master, origin/HEAD) HEAD@{1}: reset: moving to HEAD
952e66b (origin/master, origin/HEAD) HEAD@{2}: commit: v7
9cb6bf6 (HEAD -> master) HEAD@{3}: commit: v6
03e27be (tag: v1.4) HEAD@{4}: commit: v7
1202723 HEAD@{5}: commit: v6
ecc001d HEAD@{6}: clone: from http://192.168.1.30/root/web-page.git

6)也可指定目標代碼id號,實現回滾

root@ubuntu1804:/data/src/web-page# git reset --hard 9cb6bf6

7)查看當前所屬的分支,默認爲master主分支

root@ubuntu1804:/data/src/web-page# git branch
* master

8)建立並切換到新分支

root@ubuntu1804:/data/src/web-page# git checkout -b operations
Switched to a new branch 'operations'

9)再次列出全部分支分支

root@ubuntu1804:/data/src/web-page# git branch
    master
* operations

10)切換回到主分支

root@ubuntu1804:/data/src/web-page# git checkout master
Switched to branch 'master'
Your branch is behind 'origin/master' by 1 commit, and can be fast-forwarded.
    (use "git pull" to update your local branch)
root@ubuntu1804:/data/src/web-page# git branch
* master
    operations

6.數據備份

1)備份前先要暫停gitlab的兩個數據服務,避免在備份時開發人員繼續提交代碼至gitlab中,致使數據不完整

root@ubuntu1804:~# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
root@ubuntu1804:~# gitlab-ctl stop nunicorn

2)手動建立備份

root@ubuntu1804:~# gitlab-rake gitlab:backup:create

gitlab的部署、代碼克隆和提交、數據備份等

3)gitlab默認備份數據名稱及路徑,爲壓縮文件

root@ubuntu1804:~# ll /var/opt/gitlab/backups/1563709800_2019_07_21_11.11.5_gitlab_backup.tar 
-rw------- 1 git git 92160 Jul 21 19:50 /var/opt/gitlab/backups/1563709800_2019_07_21_11.11.5_gitlab_backup.tar

4)在gitlab的web端目前存在的項目、用戶和組

gitlab的部署、代碼克隆和提交、數據備份等

5)先刪除掉幾個項目、用戶或組

gitlab的部署、代碼克隆和提交、數據備份等

7.客戶端數據恢復

1)在恢復數據以前也要先關閉gitlab的兩個數據服務

root@ubuntu1804:~# gitlab-ctl stop sidekiq
ok: down: sidekiq: 0s, normally up
root@ubuntu1804:~# gitlab-ctl stop unicorn
ok: down: unicorn: 0s, normally up

2)執行恢復備份數據命令

root@ubuntu1804:~# gitlab-rake gitlab:backup:restore /var/opt/gitlab/backups/1563709800_2019_07_21_11.11.5_gitlab_backup.tar

3)在開啓gitlab的兩個數據服務

oot@ubuntu1804:~# gitlab-ctl start sidekiq
ok: run: sidekiq: (pid 80094) 1s
root@ubuntu1804:~# gitlab-ctl start  unicorn
ok: run: unicorn: (pid 80191) 0s

4)gitlab的web端訪問測試,能夠看到刪除的項目、用戶、組所有恢復

gitlab的部署、代碼克隆和提交、數據備份等
gitlab的部署、代碼克隆和提交、數據備份等

相關文章
相關標籤/搜索