您的位置:首頁>正文

如何在CentOS7中安裝Subversion 1.9.7

因為專案需要在CentOS 7.4環境下搭建一個SVN伺服器, 但是CentOS裡自帶的subversion版本只到1.7.14

與Subversion官網8月10日發佈的SVN 1.8.19, SVN 1.9.7相去甚遠, 會嚴重影響SVN用戶端的使用, 因此我們需要卸載掉自帶的Subversion, 使用yum方式重新安裝Subversion最新版本

我們執行命令

yum remove subversion*yum clean all

直接卸載subversion和相關庫包

但是當我們使用yum命令再安裝subversion時, 發現CentOS自帶源的Subversion版本仍然是1.7.14

說明從CentOS自帶源安裝Subversion最新版本此路不通, 我們需要另行添加Repo源

參考https://tecadmin.net/install-subversion-1-8-on-centos-rhel/#一文, 我們在

/etc/yum.repos.d目錄下添加subversion.repo檔, 內容如下

[Subversion]name=Wandisco SVN Repobaseurl=http://opensource.wandisco.com/centos/$releasever/svn-1.9/RPMS/$basearch/enabled=1gpgcheck=0

由於我們這裡安裝的是SVN1.9, 在repo檔裡配置的是svn-1.9, 如果要安裝SVN1.8, 可以改為svn-1.8

執行yum install -y subversion命令安裝Subversion

下列步驟參考了https://www.cnblogs.com/fuyuanming/p/6123395.html一文,

有部分有所修改

1)創建運行SVN伺服器所需的用戶svn

groupadd svnuseradd -g svn svn

這裡之所以要創建svn用戶啟動SVN伺服器, 而不使用root用戶啟動SVN伺服器, 是因為如果使用root用戶啟動SVN伺服器, 通過SVN用戶端使用非root帳戶訪問SVN伺服器時, 會出現

"xxxxxxxx db/txn-current-lock:permission denied"錯誤。

將svn用戶加入sudoers用戶中

2)執行rpm -ql subversion命令瞭解SVN安裝的位置

3)創建SVN版本庫資料夾

mkdir -p /opt/svnRepos

切換到svn用戶, 為svn用戶添加這個資料夾的存取權限

sudo chmod -R o+rw /opt/svnRepos

4)創建SVN版本庫

svnadmin create /opt/svnRepos

執行命令後/opt/svnRepos資料夾下新增了一些資料夾

5)添加使用者密碼和存取權限

進入conf目錄, 可以看到以下檔

authz文件是許可權控制檔

passwd是帳號密碼檔

svnserve.conf是SVN服務設定檔

修改passwd檔, 在[users]段添加使用者svnuser1和訪問密碼

修改authz檔, 在檔最後為svnuser1使用者添加svn根目錄存取權限

這裡[/]表示是svn根目錄, svnuser1=rw說明svnuser1使用者對根目錄有讀寫許可權。 如果要限制某些用戶對某些資料夾的

讀寫許可權, 這裡的[/]可以改為具體的資料夾目錄, 再添加具體的用戶許可權, 這裡不再贅述。

6) 修改svn設定檔

修改svnserve.conf檔

打開以下幾項的注釋(圖中以白色字體標注)

anon-access = read #匿名使用者可讀

auth-access = write #授權使用者可寫

password-db = passwd #使用哪個檔作為帳號檔

authz-db = authz #使用哪個檔作為許可權檔

realm = /opt/svnRepos # 認證空間名, 版本庫所在目錄

7)啟動SVN伺服器

執行以下命令

svnserve -d -r /opt/svnRepos --config-file=/opt/svnRepos/conf/svnserve.conf

這條指令的參數-d表示以守護進程形式運行Svn伺服器,

-r表示Svn伺服器的根目錄, 後接SVN的根目錄。

--config-file是Svn伺服器啟動所引用的設定檔, 後接設定檔路徑。

svnserve指令的更多參數可以參考此文

https://linux.die.net/man/8/svnserve

啟動後可以查看到svnserve進程已經啟動

8)在防火牆上開放SVN伺服器埠

SVN伺服器默認埠是3690, 如果要修改默認埠, 可以在運行svnserve命令時添加--listen-port參數, 後接需要指定的埠號。

執行以下命令在CentOS7系統防火牆上開放SVN伺服器埠

firewall-cmd --permanent --add-port=3690/tcpsystemctl restart firewalld.service

在用戶端安裝Tortoise SVN 1.9.7,安裝完成後新建一個資料夾, 在資料夾中右擊, 在彈出右鍵功能表中選擇[Repo-brower]功能表, 在彈出的位址對話方塊中輸入SVN://IP(我們這裡是SVN://192.168.56.102),再在驗證對話方塊中輸入用戶名rick和密碼, 即可以訪問SVN根目錄,我們使用svnuser1用戶登錄SVN,如下圖所示

我們使用svnuser1使用者在根目錄下新建trunk,tags和branches三個資料夾

9)將SVN伺服器設置為開機啟動服務

網上有相關檔通過修改/etc/rc.local檔設置SVN伺服器開機啟動,這種做法在CentOS 7環境下已經過時,我們使用CentOS 7正常添加服務的方式。

我們切換到/usr/lib/systemd/system目錄下,創建名為svnserver.service的檔,添加以下內容

[Unit]Description=SVN Server service After=network.target[Service]Type=forkingExecStart= /usr/bin/svnserve -d -r /opt/svnRepos --config-file=/opt/svnRepos/conf/svnserve.confExecStop= /home/svn/stopSVN.shUser=svnRestart=on-abort[Install]WantedBy=multi-user.target

這裡啟動SVN伺服器直接使用命令,我試過寫一個.sh檔替換,但啟動後出現code=exited,status=203/EXEC錯誤,改用現在這種形式。

stopSVN.sh是用於關閉SVN服務的指令檔,內容如下:

#!/bin/sh#查找是否有svnserve對應的進程,有的話關閉進程ps -ef|grep svnserve |grep -v grepif [ $? -ne 0 ]thenecho "the svn server does not start"elsekillall -9 sh svnservefi#####

保存svnserver.service檔後,執行以下命令

systemctl daemon-reloadsystemctl enable svnserver.servicesystemctl start svnserver.service

如果shell視窗沒有出現錯誤資訊,表示啟動已成功,我們可以執行以下命令檢查啟動狀態

systemctl status svnserver.service

運行以下命令停止服務

systemctl stop svnserver.service

我們這時再運行systemctl stop svnserver.service,可以看到服務已經被停掉

至此SVN伺服器在Linux伺服器安裝成功,再次啟動CentOS系統後SVN伺服器會開機啟動。

補充一點,CentOS自帶的SELinux默認是Enforcing,處於打開狀態,對於自啟動的SVN服務,會導致用戶端訪問SVN伺服器時出現Permisson Denied的錯誤,我們需要手動關閉它,修改/etc/selinux/config檔

# This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - No SELinux policy is loaded.SELINUX=disabled# SELINUXTYPE= can take one of three two values:# targeted - Targeted processes are protected,# minimum - Modification of targeted policy. Only selected processes are protected.# mls - Multi Level Security protection.SELINUXTYPE=targeted

把SELINUX從enforcing改為disabled,重啟系統,SVN服務自啟動後,從用戶端訪問不再出現Permssion Denied錯誤。

網上有相關檔通過修改/etc/rc.local檔設置SVN伺服器開機啟動,這種做法在CentOS 7環境下已經過時,我們使用CentOS 7正常添加服務的方式。

我們切換到/usr/lib/systemd/system目錄下,創建名為svnserver.service的檔,添加以下內容

[Unit]Description=SVN Server service After=network.target[Service]Type=forkingExecStart= /usr/bin/svnserve -d -r /opt/svnRepos --config-file=/opt/svnRepos/conf/svnserve.confExecStop= /home/svn/stopSVN.shUser=svnRestart=on-abort[Install]WantedBy=multi-user.target

這裡啟動SVN伺服器直接使用命令,我試過寫一個.sh檔替換,但啟動後出現code=exited,status=203/EXEC錯誤,改用現在這種形式。

stopSVN.sh是用於關閉SVN服務的指令檔,內容如下:

#!/bin/sh#查找是否有svnserve對應的進程,有的話關閉進程ps -ef|grep svnserve |grep -v grepif [ $? -ne 0 ]thenecho "the svn server does not start"elsekillall -9 sh svnservefi#####

保存svnserver.service檔後,執行以下命令

systemctl daemon-reloadsystemctl enable svnserver.servicesystemctl start svnserver.service

如果shell視窗沒有出現錯誤資訊,表示啟動已成功,我們可以執行以下命令檢查啟動狀態

systemctl status svnserver.service

運行以下命令停止服務

systemctl stop svnserver.service

我們這時再運行systemctl stop svnserver.service,可以看到服務已經被停掉

至此SVN伺服器在Linux伺服器安裝成功,再次啟動CentOS系統後SVN伺服器會開機啟動。

補充一點,CentOS自帶的SELinux默認是Enforcing,處於打開狀態,對於自啟動的SVN服務,會導致用戶端訪問SVN伺服器時出現Permisson Denied的錯誤,我們需要手動關閉它,修改/etc/selinux/config檔

# This file controls the state of SELinux on the system.# SELINUX= can take one of these three values:# enforcing - SELinux security policy is enforced.# permissive - SELinux prints warnings instead of enforcing.# disabled - No SELinux policy is loaded.SELINUX=disabled# SELINUXTYPE= can take one of three two values:# targeted - Targeted processes are protected,# minimum - Modification of targeted policy. Only selected processes are protected.# mls - Multi Level Security protection.SELINUXTYPE=targeted

把SELINUX從enforcing改為disabled,重啟系統,SVN服務自啟動後,從用戶端訪問不再出現Permssion Denied錯誤。

同類文章
Next Article
喜欢就按个赞吧!!!
点击关闭提示