架設 共享 存取 Git Server

How to create git server for sharing without painness

作者: 七味粉 |
文章2013-04-15
141 分享
59
    如果你使用Load balance 來實作網頁的分流,你可能會有2台以上的伺服器。我們常常會遇到修改一份程式碼,就要很笨的複製好幾份更新到伺服器,這邊利用 git 來自動更新網頁。修改一份程式碼 (client) 向 其餘的電腦(server)做 git push的動作,達到一台修改,全部更新。
  1. 安裝 git

  2. 
    
    [shell]yum install git
    [shell]yum install gitk [tell]gitk (以圖表顯示版本)[/tell]

  3. Server 端設定

  4. 
    
    [shell]mkdir /home/git/your_website
    [shell]useradd git [com]新增 git 帳號[/com]
    [shell]cd /home/git/your_website
    [shell]git init -- bare
    [com]單純 repository,無法新增檔案,只做repository的功能。[/com]

  5. Client 端設定

  6. 
    
    [shell]useradd git [tell]新增 git 帳號[/tell]
    [shell]cd /home/git [tell]切換到 git 目錄 [/tell]
    [shell]git clone git@server_ip:/home/git/your_website
    [com]在 server 端 修改的網站內容複製到 client 端[/com]
    [shell]vim test.php [tell]測試,我們新增一個檔案。[/tell]
    [shell]git commit -m 'this is a test file.'
    [shell]git push [tell]將檔案更新至 server 端[/tell]

  7. 檢查狀態

  8. 
    
    [shell]git pull [com]看 server 端有沒有新的資料[/com]
    [shell]git status [com]查詢 git 狀況[/com]

  9. 注意事項

  10. 
    
    1.chown -R git:git /home/git/your_website
    #更改檔案目錄擁有者及群組為git
    2.git config receive.denyCurrentBranch ignore
    #發生錯誤,忽略server端的master

  11. push.script

  12. 
    
    [shell]vim push.script
    [vim]cd /home/git/your_website[/vim]
    [vim]git push[/vim]

  13. 排程

  14. 
    
    [shell]crontab -e
    */1 * * * * /var/www/html/pull.script
    [tell]每分鐘去抓看看網站有沒有更新的資料[/tell]

貼心小提醒
1.您目前未登入,若於此狀態進行文章收藏,紀錄可能無法長期保留。
2.建議登入後進行收藏,好文會幫你保存著,隨時要看也不怕找不到唷~

KiKiNote持續為您提供最優質的資訊內容,謝謝您!
不再顯示此視窗

複製成功