docker搭建gitlab服務端
Git:分散式版本控制工具
Git:分散式版本控制工具
-
安裝
# yum install -y git
-
提交程式碼需要配置[[email protected]個人資訊
[[email protected] python]# git config --global user.name "zhangzhg"
[[email protected] python]# git config --global user.email "[email protected]"
3、設定編寫程式碼說明的編輯器是vim
-
檢視
[[email protected] python]# git config --list
[[email protected] python]# cat ~/.gitconfig
-
建立工作區
[[email protected] ~]# mkdir mycode
-
初始化版本庫
[[email protected] ~]# cd mycode
[[email protected] mycode]# git init .
-
編寫程式檔案
[[email protected] mycode]# echo 'hello world' > hi.txt
[[email protected] mycode]# git status 檢視狀態
-
新增跟蹤檔案(所有檔案)到版本庫
[[email protected] mycode]# git add .
[[email protected] mycode]# git status
-
提交檔案到版本庫
[[email protected] mycode]# git commit -m "add hi.txt"
[[email protected] mycode]# git status
-
修改hi.txt
[[email protected] mycode]# echo "new line" >> hi.txt
[[email protected] mycode]# git add .
[[email protected] mycode]# git commit -m "modify hi.txt"
-
恢復hi.txt到以前版本
[[email protected] mycode]# git log
檢視第一次提交的ID號,它的顯示如下:
commit 48c488c8efb45b2c31afa225c0d7ad281ecb6b11
Author: MrZhangzhg <[email protected]>
Date: Mon Jul 16 11:23:39 2018 +0800
add hi.txt
[[email protected] mycode]# git checkout 48c488c8efb45b2c31afa225c0d7ad281ecb6b11
-
如果有誤加入到版本庫的檔案,可以查到它,並刪除
[[email protected] mycode]# git ls-files 檢視版本庫中的檔案
[[email protected] mycode]# git rm hi.txt
[[email protected] mycode]# git commit -m "delete hi.txt"
搭建gitlab伺服器
-
建立一臺虛擬機器,記憶體加到4G
node1.tedu.cn 192.168.4.1
-
把docker程式和映象拷貝到虛擬機器中
[[email protected] phase5]# scp -r docker 192.168.4.1:/root
3、安裝docker
[[email protected] ~]# rpm -ihv docker/docker_pkgs/*rpm
-
啟動服務
[[email protected] ~]# systemctl start docker
[[email protected] ~]# systemctl enable docker
5、匯入映象
[[email protected] ~]# docker load < docker/images/gitlab_zh.tar
-
為了方便gitlab容器的執行,將node1的ssh服務切換成2222埠
[[email protected] ~]# vim /etc/ssh/sshd_config
Port 2222
[[email protected] ~]# systemctl restart sshd
7、重新登陸到node1
[[email protected] nsd2018]# ssh node1 -p 2222
8、啟動新容器。將將容器的443、80、22埠釋出出去。當容器意外停止的時候,將其重啟。再將容器的配置目錄、日誌目錄、資料目錄對映到本/srv/gitlab目錄。
[[email protected] ~]# docker run -d -h gitlab --name gitlab -p 443:443 -p 80:80 -p 22:22 --restart always -v /srv/gitlab/config:/etc/gitlab -v /srv/gitlab/log:/var/log/gitlab -v /srv/gitlab/data gitlab_zh:latest
-
配置gitlab
-
訪問http://192.168.4.1,第一次訪問需要設定密碼,密碼必須8位以上。如1234.com
-
登陸時,使用者名稱是root,密碼是1234.com
-
建立群組,群組路徑和名字填寫devops,型別為公開
-
建立群組後,右下角有建立專案,點選以建立專案
-
拉取專案測試
[[email protected] tmp]# cd /tmp/
[[email protected] tmp]# git clone http://192.1689.4.1/devops/core_py.git
以下是三種情況的使用說明:第一是先在gitlab上建立專案,然後clone到本地,最後在本地進入目錄開始編寫程式碼;第二種情況是本地已有一個目錄,但是還沒有加入到版本庫管理;第三種情況是本地已有目錄,並且已經通過git init初始化過版本庫了
-
建立使用者、授權可以向專案中提交程式碼。
點選Web頁面上方的扳手圖示,點選新建使用者。新建使用者時不能設定密碼,建立成功後,點選“編輯”可以設定。
-
root使用者將新建的使用者加入到群組中,並且設定新使用者為“主程式設計師”,使用者就可以上傳程式碼
-
在本地配置新使用者,實現ssh上傳程式碼
-
在gitlab的web頁面上登出root使用者,用新使用者登陸,首次登陸需要修改密碼,新老密碼可以一樣。
-
使用者在本地生成ssh金鑰
[[email protected] ~]# ssh-keygen -t rsa -C "[email protected]" -b 4096
-
檢視金鑰內容
[[email protected] ~]# cat /root/.ssh/id_rsa.pub
-
在gitlab頁面上點選左側邊欄的ssh金鑰,把第(3)步檢視到的金鑰內容貼上進來
-
本地上傳程式碼測試
(1)建立本地版本庫
[[email protected] ~]# mkdir myproject
[[email protected] ~]# cd myproject/
[[email protected] myproject]# cp /etc/hosts .
[[email protected] myproject]# git init
[[email protected] myproject]# git add .
[[email protected] myproject]# git commit -m "init myproject"
(2)上傳程式碼
[[email protected] myproject]# git remote rename origin old-origin
如果出現以下錯誤,可以忽略
error: 不能重新命名配置小節 'remote.origin' 到 'remote.old-origin'
[[email protected] myproject]# git remote add origin [email protected]:devops/core_py.git
[[email protected] myproject]# git push -u origin --all
-
如果有程式碼的修改,只要git add / git commit /git push即可
[[email protected] myproject]# cp /etc/passwd .
[[email protected] myproject]# git add .
[[email protected] myproject]# git commit -m "add new file passwd"
[[email protected] myproject]# git push
-
安裝
# yum install -y git
-
提交程式碼需要配置個人資訊
[[email protected] python]# git config --global user.name "zhangzhg"
[[email protected] python]# git config --global user.email "[email protected]"
3、設定編寫程式碼說明的編輯器是vim
[[email protected] python]# git config --global core.editor vim
-
檢視
[[email protected] python]# git config --list
[[email protected] python]# cat ~/.gitconfig
-
建立工作區
[[email protected] ~]# mkdir mycode
-
初始化版本庫
[[email protected] ~]# cd mycode
[[email protected] mycode]# git init .
[[email protected] mycode]# ls -a
-
編寫程式檔案
[[email protected] mycode]# echo 'hello world' > hi.txt
[[email protected] mycode]# git status 檢視狀態
-
新增跟蹤檔案(所有檔案)到版本庫
[[email protected] mycode]# git add .
[[email protected] mycode]# git status
-
提交檔案到版本庫
[[email protected] mycode]# git commit -m "add hi.txt"
[[email protected] mycode]# git status
-
修改hi.txt
[[email protected] mycode]# echo "new line" >> hi.txt
[[email protected] mycode]# git add .
[[email protected] mycode]# git commit -m "modify hi.txt"
-
恢復hi.txt到以前版本
[[email protected] mycode]# git log
檢視第一次提交的ID號,它的顯示如下:
commit 48c488c8efb45b2c31afa225c0d7ad281ecb6b11
Author: MrZhangzhg <[email protected]>
Date: Mon Jul 16 11:23:39 2018 +0800
add hi.txt
[[email protected] mycode]# git checkout 48c488c8efb45b2c31afa225c0d7ad281ecb6b11
-
如果有誤加入到版本庫的檔案,可以查到它,並刪除
[[email protected] mycode]# git ls-files 檢視版本庫中的檔案
[[email protected] mycode]# git rm hi.txt
[[email protected] mycode]# git commit -m "delete hi.txt"
搭建gitlab伺服器
-
建立一臺虛擬機器,記憶體加到4G
node1.tedu.cn 192.168.4.1
-
把docker程式和映象拷貝到虛擬機器中
[[email protected] phase5]# scp -r docker 192.168.4.1:/root
3、安裝docker
[[email protected] ~]# rpm -ihv docker/docker_pkgs/*rpm
-
啟動服務
[[email protected] ~]# systemctl start docker
[[email protected] ~]# systemctl enable docker
5、匯入映象
[[email protected] ~]# docker load < docker/images/gitlab_zh.tar
-
為了方便gitlab容器的執行,將node1的ssh服務切換成2222埠
[[email protected] ~]# vim /etc/ssh/sshd_config
Port 2222
[[email protected] ~]# systemctl restart sshd
7、重新登陸到node1
[[email protected] nsd2018]# ssh node1 -p 2222
8、啟動新容器。將將容器的443、80、22埠釋出出去。當容器意外停止的時候,將其重啟。再將容器的配置目錄、日誌目錄、資料目錄對映到本/srv/gitlab目錄。
[[email protected] ~]# docker run -d -h gitlab --name gitlab -p 443:443 -p 80:80 -p 22:22 --restart always -v /srv/gitlab/config:/etc/gitlab -v /srv/gitlab/log:/var/log/gitlab -v /srv/gitlab/data gitlab_zh:latest
-
配置gitlab
-
訪問http://192.168.4.1,第一次訪問需要設定密碼,密碼必須8位以上。如1234.com
-
登陸時,使用者名稱是root,密碼是1234.com
-
建立群組,群組路徑和名字填寫devops,型別為公開
-
建立群組後,右下角有建立專案,點選以建立專案
-
拉取專案測試
[[email protected] tmp]# cd /tmp/
[[email protected] tmp]# git clone http://192.1689.4.1/devops/core_py.git
以下是三種情況的使用說明:第一是先在gitlab上建立專案,然後clone到本地,最後在本地進入目錄開始編寫程式碼;第二種情況是本地已有一個目錄,但是還沒有加入到版本庫管理;第三種情況是本地已有目錄,並且已經通過git init初始化過版本庫了
-
建立使用者、授權可以向專案中提交程式碼。
點選Web頁面上方的扳手圖示,點選新建使用者。新建使用者時不能設定密碼,建立成功後,點選“編輯”可以設定。
-
root使用者將新建的使用者加入到群組中,並且設定新使用者為“主程式設計師”,使用者就可以上傳程式碼
-
在本地配置新使用者,實現ssh上傳程式碼
-
在gitlab的web頁面上登出root使用者,用新使用者登陸,首次登陸需要修改密碼,新老密碼可以一樣。
-
使用者在本地生成ssh金鑰
[[email protected] ~]# ssh-keygen -t rsa -C "[email protected]" -b 4096
-
檢視金鑰內容
[[email protected] ~]# cat /root/.ssh/id_rsa.pub
-
在gitlab頁面上點選左側邊欄的ssh金鑰,把第(3)步檢視到的金鑰內容貼上進來
-
本地上傳程式碼測試
(1)建立本地版本庫
[[email protected] ~]# mkdir myproject
[[email protected] ~]# cd myproject/
[[email protected] myproject]# cp /etc/hosts .
[[email protected] myproject]# git init
[[email protected] myproject]# git add .
[[email protected] myproject]# git commit -m "init myproject"
(2)上傳程式碼
[[email protected] myproject]# git remote rename origin old-origin
如果出現以下錯誤,可以忽略
error: 不能重新命名配置小節 'remote.origin' 到 'remote.old-origin'
[[email protected] myproject]# git remote add origin [email protected]:devops/core_py.git
[[email protected] myproject]# git push -u origin --all
-
如果有程式碼的修改,只要git add / git commit /git push即可
[[email protected] myproject]# cp /etc/passwd .
[[email protected] myproject]# git add .
[[email protected] myproject]# git commit -m "add new file passwd"
[[email protected] myproject]# git push