一、準備工作
環境準備:服務器一臺:192.168.1.116
subversion-1.6.1.tar.gz
subversion-deps-1.6.1.tar.gz
包下載地址:4ajb
將安裝包上傳到服務器:
安裝依賴包:
yum install gcc openssl openssl-devel expat -y
二、安裝
解壓兩個源碼包
tar xzvf subversion-1.6.1.tar.gz
tar xzvf subversion-deps-1.6.1.tar.gz
cd subversion-1.6.0
./configure --prefix=/usr/local/svn/
若出現以下錯誤忽略
configure: WARNING: we have configured without BDB filesystem support
make -j4
make install
安裝成功
進入SVN目錄
cd /usr/local/svn && ls
bin build-1 include lib share
查看SVN版本
[root@postfix svn]# bin/svnserve --version
svnserve,版本 1.6.0 (r36650)
編譯於 Apr 7 2020,13:28:05
版權所有 (C) 2000-2009 CollabNet。
Subversion 是開放源代碼軟件,請參閱 http://subversion.tigris.org/ 站點。
此產品包含由 CollabNet(http://www.Collab.Net/) 開發的軟件。
下列版本庫後端(FS) 模塊可用:
* fs_fs : 模塊與文本文件(FSFS)版本庫一起工作。
將SVN添加到環境變量中: export PATH="$PATH:/usr/local/svn/bin"
vim /etc/profile
export PATH="$PATH:/usr/local/svn/bin"
刷新權限
source /etc/profile
三、建立一個測試倉庫
mkdir -p /data/svn/svntest
svnadmin create /data/svn/svntest/
修改配置文件
cd /data/svn/svntest/conf
vim svnserver.conf
#將下面語句去掉註銷並修改, 保存退出
anon-access = none # 使非授權用戶無法訪問
auth-access = write # 使授權用戶有寫權限
password-db = passwd
authz-db = authz # 訪問控制文件
vim psswd
#新增test用戶,密碼test
[users]
# harry = harryssecret
# sally = sallyssecret
test = test
vim authz
指定SVN用戶擁有的目錄權限
[/]
test = rw
* =
運行SVN, 如果3690端口被佔用, 後面可以加上 --listen-port 3391
svnserve -d -r /data/svn
[root@postfix conf]# svnserve -d -r /data/svn/
[root@postfix conf]# lsof -i:3690
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
svnserve 79507 root 3u IPv4 62570 0t0 TCP *:svn (LISTEN)
四、Windows安裝TortoiseSVN
地址: https://tortoisesvn.net/downloads.html
選擇適合自己的版本,樓主選擇的是1.10.5-64
本地安裝TortoiseSVN軟件,選擇對應的安裝目錄,
右擊SVN檢出, 輸入版本庫URL,點擊確定
輸入之前的設置賬戶和密碼
五、 SVN鉤子(hooks)自動部署代碼到web目錄
切換到SVN中hooks目錄
/data/svn/svntest/hooks
cp post-commit.tmpl post-commit
修改文件,添加內容
#!/bin/sh
export LANG=en_US.UTF-8
/usr/local/svn/bin/svn update /usr/local/nginx/html --username test --password test
# POST-COMMIT HOOK
給post-commit 加上執行權限
chmod +x post-commit
svn checkout svn://192.168.1.116/svntest /usr/share/nginx/html --username=test --password=test
[root@postfix html]# svn checkout svn://192.168.1.116/svntest /usr/share/nginx/html --username=test --password=test
-----------------------------------------------------------------------
注意! 你的密碼,對於認證域:
<svn://192.168.1.116:3690> 2ef4f42c-7893-11ea-95fa-a9ab807487e3
只能明文保存在磁盤上! 如果可能的話,請考慮配置你的系統,讓 Subversion
可以保存加密後的密碼。請參閱文檔以獲得詳細信息。
你可以通過在“/root/.subversion/servers”中設置選項“store-plaintext-passwords”爲“yes”或“no”,
來避免再次出現此警告。
-----------------------------------------------------------------------
保存未加密的密碼(yes/no)?y
請輸入 'yes' 或 'no': yes
取出版本 0。
在同步的目錄新建一個ddd.txt的文件,然後寫入內容
右鍵點擊提交(SVN Commit)可能會報下面圖片錯誤
在post-commit的配置中註釋掉這一行,然後再次右鍵提交
服務器進入 /usr/local/nginx/html 也就是前面post-commit的配置