一、gitlab簡介
gitlab是一個用於倉庫管理系統的開源項目,使用git作為代碼管理工具,並在此基礎上搭建web服務。
【管理命令】 gitlab-ctl stop
gitlab-ctl start
gitlab-ctl restart
二、gitlab私有倉庫的搭建
安裝配置,搭建web服務
[root@localhost ~]# rz #上傳安裝包 [root@localhost ~]# ls #查看安裝是否上傳 gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm [root@localhost ~]# yum install gitlab-ce-8.9.5-ce.0.el7.x86_64.rpm -y #安裝軟件包 [root@localhost ~]# vim /etc/gitlab/gitlab.rb #編輯配置文件 external_url 'http://192.168.42.9' #將localhost改為主機ip
[root@localhost ~]# gitlab-ctl reconfigure #重新配置gitlab
Running handlers:
Running handlers complete
Chef Client finished, 226/314 resources updated in 02 minutes 15 seconds
gitlab Reconfigured!
【注意】一定要關閉httpd,因為gitlab也用80端口
三、gitlab使用演示
瀏覽器訪問ip地址
創建用戶,創建組,這里就不多加贅述了
創建new project
shell端執行操作命令,去web端查看
[root@localhost lion]# git clone http://192.168.42.9/root/lion.git #克隆遠程主機倉庫
[root@localhost lion]# cd lion #切換目錄,創建文件並提交 [root@localhost lion]# ls -a . .. .git [root@localhost lion]# touch he [root@localhost lion]# echo 'hepang' >> he [root@localhost lion]# git add . [root@localhost lion]# git commit -m v1 [master (root-commit) f502b87] v1 1 file changed, 1 insertion(+) create mode 100644 he [root@localhost lion]# git log commit f502b8792b5c054de4fff7f5628317d7b559ebf8 Author: Your Name <you@example.com> Date: Thu May 23 23:02:07 2019 -0400 v1 [root@localhost lion]# cat he hepang [root@localhost lion]# git push -u origin master #推送到遠程主機 (gnome-ssh-askpass:8551): Gtk-WARNING **: cannot open display: error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass' Username for 'http://192.168.42.9': root (gnome-ssh-askpass:8559): Gtk-WARNING **: cannot open display: error: unable to read askpass response from '/usr/libexec/openssh/gnome-ssh-askpass' Password for 'http://root@192.168.42.9': Counting objects: 3, done. Writing objects: 100% (3/3), 204 bytes | 0 bytes/s, done. Total 3 (delta 0), reused 0 (delta 0) To http://192.168.42.9/root/lion.git * [new branch] master -> master Branch master set up to track remote branch master from origin.
三、Linux免密使用gitlab
第一步:查看web端gitlab的秘鑰地址
第二步:在本機生成秘鑰文件並查看公鑰
[root@ken webss]# ssh-keygen [root@ken webss]# cat /root/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDGFGu/W0rx9XiTM6aehm71Vz30TzsLUb5/mCnLjUeJ1sZMS5MONeDR+AoYbXsbXE4vmZfMunEwqIKnduMctieWd/F0//+4FtOWmp0XAkJgatml4bqjvJ1ARxVyDOrXxQKsElC7MmRqw6ghONcoToytZbnXP9J9if6HHiU4sYVxJUKSAFngmk1Ta8DBwC7cvrVS7TFreCq2q0WIQPak2YHt3PUGZkt/LFrWqCJcWYI5dE3/++sWpalLFJQev0jRL6DQDGfxQmxS5AmeMZvFa3d0FUJLVpzzMjNh+2hIT8IJoaA0BSmowGUtFGc++HBqMvXPohIQTBL3aD4uf6aK4ct9 root@ken
第三步:復制秘鑰信息填寫進web服務端
第四步:點擊提交之后再次下載倉庫信息
注意這里git clone之后寫的是ssh的信息,不是http的連接信息了
回車之后可以看到沒有輸入任何東西就直接下載完成
[root@ken k]# git clone git@10.220.5.137:webg1/webss.git Cloning into 'webss'... remote: Counting objects: 6, done. remote: Compressing objects: 100% (3/3), done. remote: Total 6 (delta 0), reused 0 (delta 0) Receiving objects: 100% (6/6), done.
[root@ken k]# ls
webss
Gitlab在window中的使用
第一步:准備文件
你需要首先在網上下載下面的這個客戶端工具
第二步:安裝
第三步:創建一個文件夾作為工作目錄並進入目錄之后
右擊鼠標有兩個選項,一個是bash一個是圖形化,我選擇bash,會出現如下的界面
第四步:生成秘鑰信息,進行免密登錄
在這個界面輸入ssh-keygen一直點回車生成秘鑰信息
第五步:把公鑰信息輸入到web服務端
可以從上面的信息中看到秘鑰信息保存在哪了,現在我們去c盤找
復制這個公鑰里面的信息
第六步:本地下載倉庫
使用git clone 加上你的項目ssh信息
第七步:本地查看
發現已經有了倉庫信息了,現在你就可以開始寫程序了
第八步:測試
進入到包含.git的目錄並在此右擊打開bash,執行創建分支操作,並建立test.txt測試文件
第九步:上傳文件
和linux中一樣執行如下命令
第十步:在web中查看
可以看到我們剛才在window中創建的文件也已經被上傳上來了