最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會員登陸 & 注冊

gitlab 安轉(zhuǎn)及使用教程

2023-02-16 09:06 作者:bili_39183997178  | 我要投稿

gitlab

????????????? 它是一個開源的git倉庫服務(wù)器。用于實現(xiàn)代碼集中托管。

????????????? 分為企業(yè)版和CE社區(qū)版。

????????????? 部署方式:軟件包部署、容器部署。

????????????? 部署gitlab容器

# 安裝容器管理軟件podman
[root@git ~]# yum install -y podman
# 修改192.168.4.20的ssh端口號。因為gitlab容器也要用到22端口,有沖突。
# +17是打開文件時,光標(biāo)直接定位到第17行。
[root@git ~]# vim +17 /etc/ssh/sshd_config
?17? Port 2022
[root@git ~]# systemctl restart sshd
# ssh連接退出,再登陸時,需要指定端口號
[root@zzgrhel8 ~]# ssh -p2022 192.168.4.20
# 導(dǎo)入鏡像。一個鏡像可以創(chuàng)建很多容器。鏡像是只讀的,容器是可以改變的。
# 容器相當(dāng)于是精簡的虛擬機,可以像虛擬機一樣,對外提供服務(wù)?

[root@git ~]# podman load < gitlab_zh.tar
# 查看導(dǎo)入的鏡像
[root@git ~]# podman images
REPOSITORY??????????? TAG????? IMAGE ID?????? CREATED?????? SIZE
localhost/gitlab_zh?? latest?? 1f71f185271a?? 3 years ago?? 1.73 GB

# 容器如果出現(xiàn)故障,首先的排錯方法是重啟它;如果無效,刪掉重建。
# 為了刪容器,不丟失數(shù)據(jù),需要把容器需要的數(shù)據(jù)保存在宿主機上。在哪臺主機上啟動容器,哪臺主機就是宿主機。
# 在192.168.4.20上創(chuàng)建用于保存容器數(shù)據(jù)的目錄
[root@git ~]# mkdir -p /srv/gitlab/{config,logs,data}
[root@git ~]# ls /srv/gitlab/
config? data? logs

# gitlab容器需要/etc/resolv.conf文件。不存在則創(chuàng)建它
[root@git ~]# touch /etc/resolv.conf
# 創(chuàng)建容器
# -d后臺運行。-h gitlab設(shè)置容器的主機名。--name gitlab是podman ps查看到的容器名;-p指定發(fā)布的端口號,當(dāng)訪問宿主機443/80/22端口時,這樣的請求就發(fā)給容器的相關(guān)端口;--restart always是開機自啟;-v是映射路徑,將容器中指定的路徑,映射到宿主機,以便保存容器產(chǎn)生的數(shù)據(jù);最后的gitlab_zh是鏡像名。
[root@git ~]# podman 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/logs:/var/log/gitlab -v /srv/gitlab/data:/var/opt/gitlab gitlab_zh
# 查看容器
[root@git ~]# podman ps
# 如果一切正常,幾分鐘后,可以訪問http://192.168.4.20/

附:如果容啟動失敗,再次創(chuàng)建有以下錯誤:

Error: error creating container storage: the container name "gitlab" is already in use by "ca425e33d7ff2d282cbec1033023851cff285fe9b819ed50d47a08a875372fde". You have to remove that container to be able to reuse that name.: that name is already in use

則:

[root@git ~]# podman rm gitlab
[root@git ~]# podman 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/logs:/var/log/gitlab -v /srv/gitlab/data:/var/opt/gitlab gitlab_zh


配置gitlab

????????????? 第一次登陸時,要求改密碼。密碼需要是復(fù)雜密碼,如1234.com。修改之后,登陸的用戶名是root。

????????????? 改變顯示配置。


gitlab中主要的概念

????????????? 用戶:為使用gitlab的用戶創(chuàng)建的賬號。

????????????? 組:用戶的集合。一般可以為部門創(chuàng)建組。將來可以在項目上為組授權(quán),組 中所有的用戶都會得到相應(yīng)的權(quán)限。

????????????? 項目:用于保存代碼文件的空間。

????????????? 創(chuàng)建用戶


填寫截圖上的幾項后,其他使用默認(rèn)配置,點保存。

創(chuàng)建好用戶后,點擊編輯,可以為他/她設(shè)置密碼:


保存修改后,退出當(dāng)前賬號,使用新賬號登陸測試。第一次登陸時,也是要求修改密碼,新密碼可以設(shè)置與舊密碼一樣。新建的jerry用戶因為權(quán)限較小,所以看到的界面,沒有root的功能多。

容器的刪除

# 查看容器的名字和ID號,刪除時,使用名字或ID號均可
[root@git ~]# podman ps
# 強制刪除容器
[root@git ~]# podman rm -f gitlab
# 新建容器
[root@git ~]# podman 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/logs:/var/log/gitlab -v /srv/gitlab/data:/var/opt/gitlab gitlab_zh

????????????? 創(chuàng)建組。注意,需要使用root賬號



點擊“創(chuàng)建群組”

????????????? 將jerry加到devops組中,角色是“主程序員”


客戶端上傳代碼到gitlab服務(wù)器

查看項目路徑,采用http方式上傳

????????????? 查看項目說明


????????????? 切換jerry用戶,設(shè)置jerry的密碼。



????????????? 在客戶端192.168.4.10上下載項目,編寫代碼并上傳

[root@develop ~]# git clone http://192.168.4.20/devops/myproject.git
正克隆到 'myproject'...
warning: 您似乎克隆了一個空倉庫。
[root@develop ~]# ls??? # 本地出現(xiàn)一個myproject目錄
anaconda-ks.cfg? myproject

# 創(chuàng)建說明文件并上傳。一般來說,git服務(wù)器在首頁默認(rèn)可以顯示readme文件的內(nèi)容
[root@develop ~]# cd myproject/
[root@develop myproject]# vim README.md
- 這是我的第1個測試項目
```
echo 'Hello World!'
```
[root@develop myproject]# git add .??? # 保存到暫存區(qū)
[root@develop myproject]# git commit -m "init data"? # 確認(rèn)到版本庫
# 將master分支推送到origin倉庫。origin是默認(rèn)倉庫名。
[root@develop myproject]# git push -u origin master
Username for 'http://192.168.4.20': jerry?? # 用戶名
Password for 'http://jerry@192.168.4.20': 1234.com?? # 密碼
# 在服務(wù)器上刷新web頁面


# 將來就可以重得操作:寫代碼、確認(rèn)到版本庫、上傳到服務(wù)器
[root@develop myproject]# cp /etc/hosts .
[root@develop myproject]# git add .
[root@develop myproject]# git commit -m "add hosts"
[root@develop myproject]# git push?? # 不需要再使用-u選項
Username for 'http://192.168.4.20': jerry
Password for 'http://jerry@192.168.4.20': 1234.com


# 模擬另一個客戶端同步數(shù)據(jù)
[root@zzgrhel8 ~]# ssh 192.168.4.10
[root@develop ~]# cd /var/tmp/
[root@develop tmp]# git clone http://192.168.4.20/devops/myproject.git
[root@develop tmp]# ls
myproject
[root@develop tmp]# cd myproject/
[root@develop myproject]# ls
hosts? readme.md

# 在家目錄的myproject中上傳新文件
[root@develop myproject]# cp /etc/issue .
[root@develop myproject]# ls
hosts? issue? readme.md
[root@develop myproject]# git add .
[root@develop myproject]# git commit -m "add issue"
[root@develop myproject]# git push
Username for 'http://192.168.4.20': jerry
Password for 'http://jerry@192.168.4.20': 1234.com

# 在/tmp/myproject中同步數(shù)據(jù)
[root@develop myproject]# git pull
[root@develop myproject]# ls
hosts? issue? readme.md

使用ssh免密推送代碼

????????????? 本質(zhì)上與ssh免密登陸服務(wù)器一樣。

1.????????? 在客戶端192.168.4.10上生成密鑰對

[root@develop myproject]# ssh-keygen?? # 三個問題,都直接回車

1.????????? 將公鑰保存到gitlab服務(wù)器

# 查看并復(fù)制公鑰內(nèi)容
[root@develop myproject]# cat ~/.ssh/id_rsa.pub

在gitlab上切換Jerry用戶登陸

把jerry的公鑰粘貼到密鑰框中

1.將推送代碼的方式改為ssh

查看ssh路徑

在192.168.4.10上將推送代碼的路徑改為ssh的方式

# 查看倉庫信息,當(dāng)前是http方式
[root@develop myproject]# git remote -v
origin http://192.168.4.20/devops/myproject.git (fetch)
origin http://192.168.4.20/devops/myproject.git (push)

# 刪除http的路徑
[root@develop myproject]# git remote remove origin

# 添加ssh路徑
[root@develop myproject]# git remote add origin git@192.168.4.20:devops/myproject.git

# 查看修改后的路徑
[root@develop myproject]# git remote -v
origin git@192.168.4.20:devops/myproject.git (fetch)
origin git@192.168.4.20:devops/myproject.git (push)

# 推送代碼測試
[root@develop myproject]# cp /etc/passwd .
[root@develop myproject]# git add .
[root@develop myproject]# git commit -m "add passwd"
[root@develop myproject]# git push -u origin master? # 不再需要密碼
[root@develop myproject]# git push



gitlab 安轉(zhuǎn)及使用教程的評論 (共 條)

分享到微博請遵守國家法律
卫辉市| 日土县| 邵阳县| 乾安县| 永顺县| 丰原市| 安康市| 剑阁县| 日照市| 新沂市| 庆安县| 新竹市| 双柏县| 祁东县| 大安市| 韶关市| 子洲县| 武鸣县| 呼玛县| 莱阳市| 太仆寺旗| 彭水| 江永县| 奈曼旗| 奉节县| 莱西市| 苗栗县| 涪陵区| 定陶县| 石狮市| 毕节市| 龙口市| 曲周县| 易门县| 晴隆县| 宜丰县| 清徐县| 临沧市| 东乌珠穆沁旗| 牙克石市| 丽水市|