本文實例為大家分享了CentOS6.9快速安裝配置svn的具體代碼,供大家參考,具體內容如下
環境介紹:
操作系統:CentOS release 6.9 (Final)
192.168.65.130 (svn服務器)
192.168.65.129 (svn客戶端)
一、svn安裝檢查(在兩臺上都執行)
if [ ! -f /usr/bin/svn ]; then yum -y install subversion >/dev/null echo "svn has been installed." >/dev/null /usr/bin/svn --version|head -1|awk -F" " '{print $3}'fi
二、創建版本庫文件夾(僅在130上操作)
mkdir -p /data/svn/sinsvn#創建版本庫svnadmin create /data/svn/sinsvnmkdir -p /data/www/sinsvn
三、主要操作
#導入所需管理的項目到版本庫repository中svn import /data/www/sinsvn/ file:///data/svn/sinsvn -m "svn first test"#檢查是否導入成功svn list --verbose file:///data/svn/sinsvn#修改版本庫的配置文件# vim /data/svn/sinsvn/conf/svnserve.confcat >/data/svn/sinsvn/conf/svnserve.conf <<"EOF"[general]anon-access = noneauth-access = writepassword-db = /data/svn/passwdauthz-db = /data/svn/authzrealm =sinsvnEOFcp /data/svn/sinsvn/conf/passwd /data/svncp /data/svn/sinsvn/conf/authz /data/svn#修改允許訪問版本庫的用戶文件# vim /data/svn/passwdcat >/data/svn/passwd <<"EOF"[users]harry = harrysin = sinEOF# vim /data/svn/authzcat >/data/svn/authz <<"EOF"[groups]myteam = harry,sin[/]harry = rw[sinsvn:/]@myteam = rw[secsvn:/www]@myteam =rsin= rw[sincms:/]sin= rwharry=EOF# 啟動 svn 服務svnserve -d -r /data/svn/# 查看ps -ef|grep svnserve|grep -v 'grep'netstat -anltp|grep 3690
四、測試
# 測試,在另外一臺機器上操作(129),目的是效果更為明顯些# 1、mkdir -p /data/wwwmkdir -p /data/wwwcd /data/www/# 2、svn co 代碼svn co svn://192.168.65.130/sinsvn --username=harry --password=harry# 3、添加branches,tags,trunk目錄cd sinsvn/mkdir branchesmkdir tagsmkdir trunksvn add branches trunk tagssvn ci -m 'create branches trunk tags dir'# 4、在trunk中添加測試文件,并提交到版本庫cd trunktouch index.phpmkdir classtouch class/conn.phpsvn add index.php svn add class/......svn ci -m 'test file'svn delete index.php class class/ index.phpsvn ci -m 'delete files'mkdir webgamesvn add webgame/svn ci -m 'add webgame dir'# 追加操作cd webgamecp /tmp/VMwareTools-10.2.0-7259539.tar.gz .cp /tmp/yum.log .svn add *svn ci -m 'add VMwareTools yum.log for test'############### 這里假設130的機器上有個web項目mkdir -p /data/webdircd /data/webdirsvn co svn://192.168.65.130/sinsvn/trunk/webgame --username=harry --password=harry# 追加操作cd /data/webdir/webgame/svn update ll # 可以查看到更新后的結果
五、腳本定制更新
# 定時更新腳本(針對整個目錄自動更新的腳本,被動模式)cat >/root/svnauto_update.sh<<"EOF"cd /data/webdir/webgame/svn update &>>/tmp/svnauto_update.logEOFchmod +x /root/svnauto_update.shchmod +x /etc/crontab/etc/init.d/crond restart# 添加至crontab計劃任務中cat >>/var/spool/cron/root<<"EOF"# svnauto_update.sh * 09-23 * * * /bin/sh /root/svnauto_update.shEOF# 自動更新腳本(針對版本號觸發式更新)#svn 目錄:/data/svn/sinsvn#站點目錄:/data/webdir/webgame#實現:#1.找到svn項目的hooks目錄,這里是/data/svn/sinsvn/hooks。目錄中默認會幾個對應操作的鉤子模板,我們需要創建一個post-commit的文件。find /data/svn/sinsvn/ -name hooks#2.新建post-commit,內容如下cat >/data/svn/sinsvn/hooks/post-commit<<"EOF"#!/bin/bashREPOS="$1"REV="$2"export LANG=zh_CN.UTF-8echo "Code Deployed at "$1" Committed revision "$2" ; `date "+%Y-%m-%d %H:%M:%S"`" >> /tmp/post-commit.log/usr/bin/svn update --username harry --password harry /data/webdir/webgame >> /tmp/post-commit.logEOFchmod +x /data/svn/sinsvn/hooks/post-commit
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答
圖片精選