部署Svnmanager+Apache解決SVN易用安全性問題
Subversion作為目前最流行的版本控制軟體,得到了廣泛的應用。但是單獨直接使用Subversion的話,在安全性和易用性上都存在問題,比如:明文密碼和賬號與許可權樹的管理等方面。因此,目前來說,可以通過SVNManager來解決易用性問題(圖形化介面),結合Apache來解決安全性問題(賬號的加密以及對SSL傳輸的支援)。
下面,是我基於LAMP環境下對Subversion+SVNManager結合的原始碼部署過程,由於是原始碼安裝與配置,因此可以支援所有的Linux平臺,希望能對大家有所幫助。
1.安裝配置apache
[[email protected] tools]# wget
[[email protected] tools]# tar xjvf httpd-2.2.22.tar.bz2
[[email protected] tools]# cd httpd-2.2.22
[[email protected] httpd-2.2.22]# ./configure --prefix=/opt/apache2 --enable-so --enable-dav --enable-dav-fs --enable-maintainer-mode --with-included-apr --enable-rewrite --enable-ssl --enable-proxy --enable-proxy-http
--enable-so 開啟動態庫支援,svn要求apache必須啟用so --enable-dav --enable-dav-fs 是支援svn認證使用的 --enable-maintainer-mode 開啟除錯模式 --with-included-apr 使用內建的apr --enable-rewrite 開啟rewrite --enable-ssl 開啟SSL --enable-proxy 開啟proxy支援 --enable-proxy-http 開啟proxy http支援 |
[[email protected] httpd-2.2.22]# useradd -M apache
修改apache配置檔案,讓它以使用者apache身份執行
[[email protected] httpd-2.2.22]# vi /opt/apache2/conf/httpd.conf
User apache Group apache |
[[email protected] httpd-2.2.22]# cd ..
[[email protected] tools]# wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz
[[email protected] tools]# tar xf cmake-2.8.4.tar.gz
[[email protected] tools]# cd cmake-2.8.4
[[email protected] cmake-2.8.4]# ./configure
[[email protected] cmake-2.8.4]# make;make install
[[email protected] httpd-2.2.22]# cd ..
[[email protected] tools]# wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.3-m3.tar.gz
[[email protected] tools]# tar xf mysql-5.5.3-m3.tar.gz
[[email protected] tools]# cd mysql-5.5.3-m3
[[email protected] mysql-5.5.3-m3]# cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql \
-DSYSCONFDIR=/opt/mysql/etc \
-DMYSQL_DATADIR=/opt/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
-DMYSQL_USER=mysql \
-DEXTRA_CHARSETS=all \
-DWITH_READLINE=1 \
-DWITH_SSL=system \
-DWITH_EMBEDDED_SERVER=1 \
-DENABLED_LOCAL_INFILE=1 \
-DWITH_INNOBASE_STORAGE_ENGINE=1
[[email protected] mysql-5.5.3-m3]# make && make install
建立mysql普通使用者
[[email protected] mysql-5.5.3-m3]# useradd -M mysql
以mysql使用者身份建立預設庫
[[email protected] mysql-5.5.3-m3]# /opt/mysql/bin/mysql_install_db --user=mysql
讓mysql啟動,並在後臺執行
[[email protected] mysql-5.5.3-m3]# /opt/mysql/bin/mysqld_safe &
為mysql的root使用者設定一個密碼,如123456(請根據具體情況進行設定)
[[email protected] mysql-5.5.3-m3]# /opt/mysql/bin/mysqladmin -u root password '123456'
3.安裝配置php
[[email protected] mysql-5.5.3-m3]# cd ..
[[email protected] tools]# wget http://cn2.php.net/get/php-5.3.18.tar.gz/from/this/mirror
[[email protected] tools]# tar xf php-5.3.18.tar.gz
[[email protected] tools]# cd php-5.3.18
[[email protected] php-5.3.18]# ./configure --prefix=/opt/php --with-apxs2=/opt/apache2/bin/apxs --with-mysql=/opt/mysql --enable-mbstring
--with-apxs2 支援apache --with-mysql 支援mysql --enable-mbstring 支援mbstring庫,svnmanager所需 |
建立php.ini配置檔案
[[email protected] php-5.3.18]# cp php.ini-development /opt/php/etc/php.ini
使apache支援php
[[email protected] php-5.3.18]# vi /opt/apache2/conf/httpd.conf
#檢查是否存在以下一行內容 LoadModule php5_module modules/libphp5.so #新增index.php支援 <IfModule dir_module> DirectoryIndex index.php index.html </IfModule> <IfModule mime_module> AddType application/x-compress .Z AddType application/x-gzip .gz .tgz AddType application/x-httpd-php .php AddType application/x-httpd-php-source .phps </IfModule> |
[[email protected] php-5.3.18]# /opt/apache2/bin/apachectl restart
4.安裝配置subversion
[[email protected] php-5.3.18]# cd ..
[[email protected] tools]# wget http://subversion.tigris.org/downloads/subversion-1.6.13.tar.bz2
[[email protected] tools]# wget http://subversion.tigris.org/downloads/subversion-deps-1.6.13.tar.bz2
subversion-deps-1.6.13.tar.bz2是subversion的依賴包,解壓後會自動放在先解壓的subversion-1.6.13目錄中
[[email protected] tools]# tar jxvf subversion-1.6.13.tar.bz2
[[email protected] tools]# tar jxvf subversion-deps-1.6.13.tar.bz2
[[email protected] tools]# cd subversion-1.6.13
[[email protected] subversion-1.6.13]# ./configure --prefix=/opt/subversion --with-apxs=/opt/apache2/bin/apxs --with-apr=/opt/apache2/bin/apr-1-config --with-apr-util=/opt/apache2/bin/apu-1-config
[[email protected] subversion-1.6.13]# make
編譯時出現如下錯誤:
+--------------------------------------+
/usr/bin/ld: cannot find -lexpat
collect2: ld returned 1 exit status
make: *** [subversion/svn/svn] Error 1
+--------------------------------------+
說明缺少expat及expat-devel包,安裝expat及expat-devel包即可解決
[[email protected] subversion-1.6.13]# yum -y install expat expat-devel
安裝完expat及expat-devel包,再重新編譯安裝
[[email protected] subversion-1.6.13]# make
[[email protected] subversion-1.6.13]# make install
編輯apache配置檔案使其與subversion相融合
[[email protected] subversion-1.6.13]# vi /opt/apache2/conf/httpd.conf
檢查是否存在這兩行,並確保在/opt/apache2/modules目錄下存在mod_dav_svn.so和mod_authz_svn.so這兩個檔案 LoadModule dav_svn_module modules/mod_dav_svn.so LoadModule authz_svn_module modules/mod_authz_svn.so 新增以下兩行 # Subversion default settings Include conf/extra/httpd-svn.conf |
[[email protected] subversion-1.6.13]# cd /opt/apache2/conf/extra/
[[email protected] extra]# vi httpd-svn.conf
<Location /svn> DAV svn SVNListParentPath On SVNParentPath /data/svn_repo AuthType Basic AuthName "Subversion Repository" AuthUserFile /opt/subversion/conf/svn_passwdfile AuthzSVNAccessFile /opt/subversion/conf/svn_accessfile Require valid-user </Location> |
[[email protected] extra]# cd /opt/subversion
[[email protected] subversion]# mkdir conf
建立賬戶配置檔案,回車後會提示輸入密碼兩次,因為是第一次建立,svn_passwdfile檔案原本不存在所以需要加-c引數,之後就不再需要了
[[email protected] subversion]# /opt/apache2/bin/htpasswd -c /opt/subversion/conf/svn_passwdfile jack
建立許可權樹配置檔案
[[email protected] subversion]# vi /opt/subversion/conf/svn_accessfile
[groups] g_manager = jack g_coder = tom g_hr = mary g_vip = jack,tom,mary [project1:/] [project1:/code] [project1:/code/source] [project1:/hr] [project1:/temp] |
[[email protected] subversion]# mkdir -p /data/svn_repo
建立測試倉庫project1
[[email protected] subversion]# /opt/subversion/bin/svnadmin create /data/svn_repo/project1
修改倉庫許可權
[[email protected] subversion]# chown -R apache:apache /data/svn_repo
重新啟動apache
[[email protected] subversion]# /opt/apache2/bin/apachectl restart
測試能否正常訪問
瀏覽器輸入:http://192.168.1.59/svn/project1/,輸入之前建立的jack使用者和密碼
5.安裝VersionControl_SVN
[[email protected] subversion]# /opt/php/bin/pear install VersionControl_SVN-0.3.4
注:安裝過程為線上安裝,需要連線網際網路。
出現以下資訊則表明安裝成功
+------------------------------------------------------------------------------+
downloading VersionControl_SVN-0.3.4.tar ...
Starting to download VersionControl_SVN-0.3.4.tar (Unknown size)
.............................................................done: 446,464 bytes
downloading XML_Parser-1.3.4.tar ...
Starting to download XML_Parser-1.3.4.tar (Unknown size)
...done: 90,624 bytes
install ok: channel://pear.php.net/XML_Parser-1.3.4
install ok: channel://pear.php.net/VersionControl_SVN-0.3.4
+------------------------------------------------------------------------------+
檢查是否安裝成功
[[email protected] subversion]# /opt/php/bin/pear list
出現以下資訊則表明安裝成功
+------------------------------------------------------------------------------+
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.7 stable
Console_Getopt 1.3.0 stable
PEAR 1.9.4 stable
Structures_Graph 1.0.4 stable
VersionControl_SVN 0.3.4 alpha
XML_Parser 1.3.4 stable
XML_Util 1.2.1 stable
+------------------------------------------------------------------------------+
6.安裝配置svnmanager
[[email protected] tools]# wget http://downloads.sourceforge.net/project/svnmanager/svnmanager/1.08/svnmanager-1.08.tar.gz
[[email protected] tools]# tar xzvf svnmanager-1.08.tar.gz
將解壓出來的svnmanager程式目錄複製到apache的站點根目錄
[[email protected] tools]# cp -rp svnmanager-1.08 /opt/apache2/htdocs/svnman
建立並編輯svnmanager的配置檔案
[[email protected] tools]# cd /opt/apache2/htdocs/svnman/
[[email protected] svnman]# cp config.php.linux config.php
[[email protected] svnman]# vi config.php
$lang = "en_US.UTF-8";
//Shell command's //Subversion locations $svn_trash_loc = ""; $svnserve_user_file=""; $smtp_server = "smtp.mailserver.net"; $dsn = "mysql://svnmanager:[email protected]/svnmanager"; //注意將mysqli修改為mysql $admin_name = "admin"; |
[[email protected] svnman]# cd /home/tools
[[email protected] tools]#
wget http://download.pear.php.net/package/VersionControl_SVN-0.3.4.tgz
[[email protected] tools]# tar xzvf VersionControl_SVN-0.3.4.tgz
[[email protected] tools]# mv VersionControl_SVN-0.3.4 /opt/apache2/htdocs/svnman/VersionControl
修改許可權
[[email protected] tools]# chown -R apache:apache /opt/apache2/htdocs/
[[email protected] tools]# chown -R apache:apache /opt/subversion/
7.建立svnmanager資料庫
[[email protected] tools]# /opt/mysql/bin/mysql -u root -p123456
mysql>create database svnmanager;
mysql>grant all privileges on svnmanager.* to 'svnmanager'@'localhost' identified by '123456';
mysql>flush privileges;
mysql>quit;
8.訪問svnmanager
在瀏覽器中輸入:http://192.168.1.59/svnman/
第一次訪問會出現以下資訊
+------------------------------------------------------------------------------+
All tables are missing.
Creating requried tables...
Please reload page!
+------------------------------------------------------------------------------+
重新重新整理頁面,會出現以下登陸畫面。
預設login賬號密碼均為admin,登陸後建立一個新的管理員賬號svnmanager後,admin賬戶就會被自動遮蔽掉了;之後再次使用新賬號svnmanager登入就會出現管理svn的諸多選項,如:建立版本庫、設定賬戶、設定許可權、匯入匯出等比較實用的功能。
轉載於:https://blog.51cto.com/300second/1065758