『壹』 linux怎麼掛載git伺服器
一般來講需要搭建版本管理和持續集成伺服器,版本管理伺服器有svn,git等,持續集成伺服器有jenkin,hudson等
『貳』 如何用linux搭建git伺服器,如果使用git
這個簡單,你可以看看廖雪峰的git教程,http://www.liaoxuefeng.com/wiki/我就是在上面學的。花了2天時間,基本上掌握了。
如果你學Linux可以看看劉遄老師的博客www.linuxprobe.com上面還是很多干貨。
『叄』 如何搭建linux git伺服器與客戶端
1.創建Gitblit安裝目錄 首先我們將在我們的伺服器上建立一個目錄,並在該目錄下安裝最新的Gitblit。 $ sudo mkdir -p /opt/gitblit $ cd /opt/gitblit 創建gitblit目錄 2. 並解壓 現在,我們將從Gitblit官方站點最新版的Gitblit。
『肆』 本地git軟體怎麼連接linux伺服器地址
1、前期准備
伺服器上配置好的git
git客戶端
1.1
在伺服器上安裝git (本機所使用的linux是ubuntu)
在伺服器輸入命令:sudo apt-get install git即可 然後創建名字為git的用戶組和用戶
1.2
下載客戶端 在瀏覽器地址欄輸入:https://git-for-windows.github.io/
回車後
點擊Download進行下載
2、具體操作
2.1
在合適的位置創建一個目錄充當git遠程倉庫(本機位置為/usr/testgit),然後使用init命令初始化倉庫
在命令終端輸入:
sudo git init –bare
2.2
將git init生成的目錄所屬者改為git
輸入命令:sudo chown -R git:git *
至此伺服器端的操作完成。
在客戶端合適位置使用git 客戶端從伺服器資源
2.3
首先打開git客戶端
點擊Git Bash Here 後出現
在git客戶端命名終端輸入:
git clone git@xxxxxx:/rrrrr 其中xxxxxx是遠程伺服器的地址 rrrrr為git倉庫所在位置
如果配置正確你選中的目錄下會出現名字為testgit的文件夾 testgit文件夾下隨意創建若干個文件
2.3
在git客戶端上使用命令 git add 111.txt 222.txt 333.txt 或者使用git add .(將本文件夾下所有文件都add) 該命令的作用是告訴git把文件添加到git倉庫
2.4
然後使用git commit命令將文件提交到git倉庫
-m 後面的內容為本次提交文件的一些注釋內容
此時文件還沒有從本地倉庫上傳到遠程伺服器倉庫
2.5
使用push命令將本地倉庫中的內容提交到遠程倉庫
在git客戶端命令終端輸入:git push origin master
至此本地倉庫中的文件上傳已經上傳到遠程伺服器倉庫。
在其他文件夾下再次使用 git clone 命令 從遠程伺服器同步倉庫
『伍』 如何在linux上使用hexo搭建git博客
安裝前提
安裝 Hexo 非常簡單。需要預先安裝:
Node.js
Git
在 Ubuntu 14.04/15.04 上安裝配置 Node.js v4.0.0 http://www.linuxidc.com/Linux/2015-10/123951.htm
如何在CentOS 7安裝Node.js http://www.linuxidc.com/Linux/2015-02/113554.htm
Ubuntu 14.04下搭建Node.js開發環境 http://www.linuxidc.com/Linux/2014-12/110983.htm
Git 伺服器搭建與客戶端安裝 http://www.linuxidc.com/Linux
Ubuntu下Git伺服器的搭建與使用指南 http://www.linuxidc.com/Linux/2015-07/120617.htm
准備條件做好了之後就可以開始安裝Hexo了
安裝Hexo
打開Git Bash 執行命令
1
$ npm install -g hexo-cli
創建博客
Hexo安裝完成後,分別執行如下命令,Hexo會自動生成需要的文件夾
1
2
3
$ hexo init <folder> ##<folder> 為你指定的文件地址
$ cd <folder>
$ npm install
例如:需要將博客搭建在本地的D:\my_hexo下,則分別執行命令:hexo init D:\my_hexo ,cd D:\my_hexo,npm install
執行完命令後如果沒有問題我們就可以執行啟動命令來查看我們的博客了.
本地預覽
1
2
3
$ hexo server ## 啟動服務,默認埠4000
$ hexo server -p xxxx ## 自定義埠啟動服務
$ hexo clean ## 清除緩存,在頁面顯示不正常的時候可以執行此命令
然後在瀏覽器輸入http://127.0.0.1:4000/ 即可訪問
創建Repository
登錄github 點擊右上角的」+」,Create a new repository
Create a new repository
復制剛剛新建的https連接:https://github.com/Admol/admol.github.io.git
打開你hexo目錄下的_config.yml
設置deploy信息,如:
1
2
3
4
deploy:
type: git
repository: https://github.com/Admol/admol.github.io.git
branch: master
設置SSH key
檢驗是否已存在key
分別執行命令
1
2
cd ~
cd .ssh
再執行命令 ls 查看是有已有key文件,一般存在key的話都會顯示id_rsa.pub 和 id_dsa.pub這兩個文件,沒有key什麼都不會顯示
添加一個 SSH key
執行命令(已有key的可以跳過步驟2):
1
2
3
$ ssh-keygen -t rsa -C "[email protected]"
## t 指定密鑰類型,默認是 rsa ,可以省略。 -C 設置注釋文字,比如郵箱或其他。
然後會提示你 Enter Enter file in which to save the key (/c/Users/you/.ssh/id_rsa): [Press enter,這里是輸入一個文件名用來保存ssh key,也可以什麼都不輸,會使用默認的id_rsa.pub 和 id_dsa.pub
回車之後,需要輸入兩次密碼(該密碼是你push文件的時候要輸入的密碼,而不是github的密碼)
輸入密碼之後,看見如下顯示信息,添加SSH key成功.
Github 設置 SSH key
登錄github,點擊Settings,然後點擊 SSH keys ,在這個頁面你可以管理你所有的ssh keys
然後點擊Add SSH key
用文本編輯器打開剛剛添加的key文件id_rsa.pub,復制裡面的所有的內容
回到github頁面,將復制的內容粘貼到剛剛那個頁面的key對應的文本框裡面,title 可以隨便填寫
測試ssh key 是否添加成功
在命令行輸入:
1
$ ssh -T [email protected]
會出現一段警告代碼,輸入yes回車,然後會要求你輸入剛剛設置的密碼,然後它會和你說:Hi,帥哥....約嗎
到此SSH key就設置完畢了
部署到Github
打開命令窗口,回到你的hexo博客目錄下,如別執行如下命令:
1
2
hexo generate
hexo deploy
等待命令執行完畢後,可以查看代碼是否已提交到github上,然後在瀏覽器輸入admol.github.io就可以訪問了
新建頁面
1
$ hexo new page 'pageName'
執行命令後可以在你本地的/source 目錄下看見以為你新增頁面名為名的文件夾
顯示頁面
打開文件後可以對index.md 進行編輯.然後打開/themes/jacman目錄下的_config.yml文件(自己正在使用的主題),
添加剛剛新增的頁面:
1
2
3
4
5
menu:
首頁: /
統計: /archives
關於: /about
pageName: /pageName ##前面的pageName可以自定義,後面的pageName必須寫剛剛新增的頁面名稱
新建文章
1
$ hexo new [layout] 'name'
[layout] 為可選,不寫默認為post. /source 目錄下的文件夾名稱即為 layout 名
安裝主題
1
$ git clone https://github.com/JamesPan/hexo-theme-icarus.git themes/icarus
更換主題
首先下載主題,然後打開根目錄下的 _cinfig.yml ,修改 theme: 要更換的主題名
修改主題顏色
打開 /themes/jacman目錄下的_config.yml文件,修改:
1
2
theme_color:
theme: '色值'
修改logo圖片
打開主題下的 _config.yml 文件,修改:
1
2
3
4
imglogo:
enable: false ## 是否顯示logo
src: img/logo.gif ## logo圖片地址
favicon: img/qq.ico ## 頁面左上角圖標
Hexo 版本升級
1
$ npm update hexo -g
『陸』 如何搭建linux git伺服器
首先我們分別在Git伺服器和客戶機中安裝Git服務程序(剛剛實驗安裝過就不用安裝了):
[root@linuxprobe ~]# yum install git
Loaded plugins: langpacks, proct-id, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
Package git-1.8.3.1-4.el7.x86_64 already installed and latest version
Nothing to do
然後創建Git版本倉庫,一般規范的方式要以.git為後綴:
[root@linuxprobe ~]# mkdir linuxprobe.git
修改Git版本倉庫的所有者與所有組:
[root@linuxprobe ~]# chown -Rf git:git linuxprobe.git/
初始化Git版本倉庫:
[root@linuxprobe ~]# cd linuxprobe.git/
[root@linuxprobe linuxprobe.git]# git --bare init
Initialized empty Git repository in /root/linuxprobe.git/
其實此時你的Git伺服器就已經部署好了,但用戶還不能向你推送數據,也不能克隆你的Git版本倉庫,因為我們要在伺服器上開放至少一種支持Git的協議,比如HTTP/HTTPS/SSH等,現在用的最多的就是HTTPS和SSH,我們切換至Git客戶機來生成SSH密鑰:
[root@linuxprobe ~]# ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
65:4a:53:0d:4f:ee:49:4f:94:24:82:16:7a:dd:1f:28 [email protected]
The key's randomart image is:
+--[ RSA 2048]----+
| .o+oo.o. |
| .oo *.+. |
| ..+ E * o |
| o = + = . |
| S o o |
| |
| |
| |
| |
+-----------------+
將客戶機的公鑰傳遞給Git伺服器:
[root@linuxprobe ~]# ssh--id 192.168.10.10
[email protected]'s password:
Number of key(s) added: 1
Now try logging into the machine, with: "ssh '192.168.10.10'"
and check to make sure that only the key(s) you wanted were added.
此時就已經可以從Git伺服器中克隆版本倉庫了(此時目錄內沒有文件是正常的):
[root@linuxprobe ~]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
warning: You appear to have cloned an empty repository.
[root@linuxprobe ~]# cd linuxprobe
[root@linuxprobe linuxprobe]#
初始化下Git工作環境:
[root@linuxprobe ~]# git config --global user.name "Liu Chuan"
[root@linuxprobe ~]# git config --global user.email "[email protected]"
[root@linuxprobe ~]# git config --global core.editor vim
向Git版本倉庫中提交一個新文件:
[root@linuxprobe linuxprobe]# echo "I successfully cloned the Git repository" > readme.txt
[root@linuxprobe linuxprobe]# git add readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
#
# Initial commit
#
# Changes to be committed:
# (use "git rm --cached ..." to unstage)
#
# new file: readme.txt
#
[root@linuxprobe linuxprobe]# git commit -m "Clone the Git repository"
[master (root-commit) c3961c9] Clone the Git repository
Committer: root
1 file changed, 1 insertion(+)
create mode 100644 readme.txt
[root@linuxprobe linuxprobe]# git status
# On branch master
nothing to commit, working directory clean
但是這次的操作還是只將文件提交到了本地的Git版本倉庫,並沒有推送到遠程Git伺服器,所以我們來定義下遠程的Git伺服器吧:
[root@linuxprobe linuxprobe]# git remote add server [email protected]:/root/linuxprobe.git
將文件提交到遠程Git伺服器吧:
[root@linuxprobe linuxprobe]# git push -u server master
Counting objects: 3, done.
Writing objects: 100% (3/3), 261 bytes | 0 bytes/s, done.
Total 3 (delta 0), reused 0 (delta 0)
To [email protected]:/root/linuxprobe.git
* [new branch] master -> master
Branch master set up to track remote branch master from server.
為了驗證真的是推送到了遠程的Git服務,你可以換個目錄再克隆一份版本倉庫(雖然在工作中毫無意義):
[root@linuxprobe linuxprobe]# cd ../Desktop
[root@linuxprobe Desktop]# git clone [email protected]:/root/linuxprobe.git
Cloning into 'linuxprobe'...
remote: Counting objects: 3, done.
remote: Total 3 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (3/3), done.
[root@linuxprobe Desktop]# cd linuxprobe/
[root@linuxprobe linuxprobe]# cat readme.txt
I successfully cloned the Git repository
這篇是詳細介紹Git的,中間有一部分是怎麼去搭建,你可以看下
『柒』 怎樣在linux 上搭建git +apache伺服器
1:伺服器端創建用戶(git)
# sudo adsergit
2:客戶端生成公鑰,並
創建公鑰:ssh-keygen,
在客戶端的用戶目錄下查看生成的公鑰和私鑰對
#cd ~/.ssh
#ls
id_dsa id_dsa.pub
公鑰所在的目錄:windows在」C:/User/username/.ssh」目錄下,linux在」~/.ssh」,~代表用戶目錄
3:伺服器git用戶下添加各個用戶公鑰,並配置ssh服務
將各個用戶的公鑰文件追加在伺服器git用戶的authorized_keys文件中
$ cat id_rsa.john.pub >> ~/.ssh/authorized_keys
$ cat id_rsa.josie.pub >> ~/.ssh/authorized_keys
$ cat id_rsa.jessica.pub >> ~/.ssh/authorized_keys
修改.ssh和authorized_keys的許可權).忘記下面的話,會每次輸入密碼,(ps,被這個坑了好久)
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
4,在git用戶下創建git庫
cd gitDIR
mkdir project.git
cd project.git
git init –bare
5,客戶端使用
提交自己的庫
mkdir project
cd project
git init
vi first.txt
git remote add origin gitserver/gitDIR/project.git
git push origin master
克隆:git clonegit@gitserver/gitDIR/project.git
6,限制開發者登陸
默認情況下,能夠連接git伺服器用戶也可以通過ssh直接登陸伺服器,那麼伺服器將會存在被多用戶登入的風險,限制的方法是:
Vi /etc/passwd
git:x:1000:1000::/home/git:/bin/sh
該行修改後的樣子如下:
git:x:1000:1000::/home/git:/bin/git-shell
『捌』 如何在伺服器上搭建git伺服器
安裝步驟此處略去。
END
安裝CopSSH
安裝步驟此處略去。
END
修改配置
修改CopSSH配置文件C:\Program Files\ICW\etc\sshd_config,確保如下行為非注釋行,且設置為「no」:
END
生成用戶帳號
1
在伺服器上生成Windows用戶,取消用戶下次登錄時須更改密碼,設置密碼永不過期:
2
將該用戶隸屬於GitUser組(如尚未生成改組,則先生成改組):
END
激活用戶
在Windows啟動程序組中,運行如下程序(C:\Program Files\ICW\bin\ copsshcp.exe):
進入COPSSH Control Panel應用對話框,正常情況下服務應該為正在運行(圖標為綠色,如為紅色,則可嘗試點選該按鈕,啟動該服務):
選擇Users頁面:
點選Add按鈕,出現如下導航對話框:
選擇Forward按鈕,出現如下頁面,選擇欲激活的用戶對應的域名及用戶名:
選擇Forward按鈕,進入如下頁面,選擇Linux shell and Sftp,所有選項選中:
選擇Forward按鈕,進入確認頁面,選擇Apply:
回到如下頁面,選擇Apply後,關閉。
『玖』 linux搭建git伺服器後怎麼使用
linux搭建git伺服器後怎麼使用GitHub就是一個免費託管開源代碼的遠程倉庫。但是對於某些視源代碼如生命的商業公司來說,既不想公開源代碼,又捨不得給GitHub交保護費,那就只能自己搭建一台Git伺服器作為私有倉庫使用。linux搭建git伺服器後怎麼使用