持續集成與自動化部署 - gitlab部署 (四)

1 gitlab部署

部署gitlab參考鏈接

GitLab是一個利用 Ruby on Rails 開發的開源應用程序,實現一個自託管的Git項目倉庫,可通過Web界面進行訪問公開的或者私人項目。
GitLab擁有與Github類似的功能,能夠瀏覽源代碼,管理缺陷和註釋。可以管理團隊對倉庫的訪問,它非常易於瀏覽提交過的版本並提供一個文件歷史庫。它還提供一個代碼片段收集功能可以輕鬆實現代碼複用,便於日後有需要的時候進行查找。

1.基礎環境準備

[root@salt-node4 ~]# yum -y install curl policycoreutils openssh-server openssh-clients postfix
[root@salt-node4 ~]# systemctl start postfix

2.安裝gitlab-ce

注:由於網絡問題,國內用戶,建議使用清華大學的鏡像源進行安裝:

[root@salt-node4 ~]# 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
gpgcheck=0
enabled=1
gpgkey=https://packages.gitlab.com/gpg.key
[root@salt-node4 ~]# yum makecache
[root@salt-node4 ~]# yum install gitlab-ce

3.配置並啓動gitlab-ce

[root@linux-node2 ~]# gitlab-ctl reconfigure

可以使用gitlab-ctl管理gitlab,例如查看gitlab狀態:

[root@linux-node2 ~]# gitlab-ctl status
run: gitlab-workhorse: (pid 12171) 231s; run: log: (pid 7817) 555s
run: logrotate: (pid 12175) 230s; run: log: (pid 7832) 548s
run: nginx: (pid 12181) 230s; run: log: (pid 7823) 549s
run: postgresql: (pid 12186) 229s; run: log: (pid 7683) 587s
run: redis: (pid 12194) 229s; run: log: (pid 7600) 592s
run: sidekiq: (pid 12198) 229s; run: log: (pid 7806) 558s
run: unicorn: (pid 14967) 6s; run: log: (pid 7774) 560s

關閉gitlab:

[root@salt-node4 ~]#   gitlab-ctl stop

啓動gitlab:

[root@salt-node4 ~]#  gitlab-ctl start

重啓gitlab:

[root@salt-node4 ~]#  gitlab-ctl restart

4.修改gitlab密碼

默認用戶名密碼都是root ,登錄過後會提示你修改密碼。

5.gitlab關閉註冊

Admin Area > 右上角齒輪  > settings > sign up 關閉即可

6.創建一個組

持續集成與自動化部署 - gitlab部署 (四)

7.創建一個項目

項目建立前必須有組

持續集成與自動化部署 - gitlab部署 (四)

持續集成與自動化部署 - gitlab部署 (四)

8. 添加gitlab客戶端的ssh公鑰到服務器裏

步驟 settings > SSH Keys

持續集成與自動化部署 - gitlab部署 (四)

9. 客戶端 git pull 拉取代碼

客戶端模擬上傳代碼

[www@salt-node4 ~]$ git clone [email protected]:web/web_demo.git   # 選擇ssh方式的。
Cloning into 'web_demo'...
remote: Counting objects: 6, done.
remote: Compressing objects: 100% (2/2), done.
remote: Total 6 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (6/6), done.

[www@salt-node4 ~]$ cd web_demo/
[www@salt-node4 web_demo]$ touch index.html
[www@salt-node4 web_demo]$ echo wangfei >index.html 
[www@salt-node4 web_demo]$ git add index.html
[www@salt-node4 web_demo]$ git commit -m "add index.html"
[master 933b21a] add index.html
 1 file changed, 1 insertion(+)
 create mode 100644 index.html

[www@salt-node4 web_demo]$ git push
Counting objects: 4, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (3/3), 280 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:web/web_demo.git
   8699ef8..933b21a  master -> master

客戶端拉代碼

[www@salt-node4 code]$ git config --global user.name "wangfei"      
[www@salt-node4 code]$ git config --global user.email "[email protected]" 
[www@salt-node4 code]$ git clone [email protected]:web/web_demo.git

10. 修改gitlab path路徑裏的主機名爲ip地址

[root@salt-node4 web_demo]# vim /etc/gitlab/gitlab.rb
...
13 external_url 'http://10.0.0.204'
...

重啓gitlab服務

[root@salt-node4 web_demo]#  gitlab-ctl reconfigure

測試

持續集成與自動化部署 - gitlab部署 (四)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章