- 如果你使用Load balance 來實作網頁的分流,你可能會有2台以上的伺服器。我們常常會遇到修改一份程式碼,就要很笨的複製好幾份更新到伺服器,這邊利用 git 來自動更新網頁。修改一份程式碼 (client) 向 其餘的電腦(server)做 git push的動作,達到一台修改,全部更新。
- 安裝 git
- Server 端設定
- Client 端設定
- 檢查狀態
- 注意事項
- push.script
- 排程
[shell]yum install git
[shell]yum install gitk [tell]gitk (以圖表顯示版本)[/tell]
[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]
[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]
[shell]git pull [com]看 server 端有沒有新的資料[/com]
[shell]git status [com]查詢 git 狀況[/com]
1.chown -R git:git /home/git/your_website
#更改檔案目錄擁有者及群組為git
2.git config receive.denyCurrentBranch ignore
#發生錯誤,忽略server端的master
[shell]vim push.script
[vim]cd /home/git/your_website[/vim]
[vim]git push[/vim]
[shell]crontab -e
*/1 * * * * /var/www/html/pull.script
[tell]每分鐘去抓看看網站有沒有更新的資料[/tell]