Centos6.5環境下安裝SVN 整合Apache+SSL,centos6.5svn
弄了兩天,終於在伺服器上初步搭建起來了SVN(版本1.8)。
伺服器系統:Centos6.5 64位,搭建過程中全部採用源碼編譯安裝(configure/make/make install),推薦大家使用編譯安裝。
源碼安裝需要先安裝gcc 來進行編譯,如果沒有編譯環境就 yum -y install gcc 安裝一下。
下載的源碼都是最新的,沒辦法,有些軟體的源碼舊版本真的很難找,乾脆就用當前最新的了。
個人習慣把軟體都裝在 /usr/local/ 源碼下載放到/usr/local/src/ 以下沒有特殊指明均如此
按照步驟如下:
su root 直接root許可權下操作
一、安裝Apr, Apr-util
cd /usr/local/src wget -c http://mirror.bit.edu.cn/apache//apr/apr-1.5.1.tar.gz tar -zxvf apr-1.5.1.tar.gz chown -R root:root apr-1.5.1 cd apr-1.5.1 ./configure --prefix=/usr/local/apr make && make install
接下來,
wget -c http://mirrors.cnnic.cn/apache//apr/apr-util-1.5.4.tar.gz tar -zxvf apr-util-1.5.4.tar.gz chown -R root:root apr-util-1.5.4 cd apr-util-1.5.4
./configure --prefix=/usr/local/apu --with-apr=/usr/local/apr/
make && make install
好啦,驗證一下吧
./apr/bin/apr-1-config --version 1.5.1 ./apu/bin/apu-1-config --version 1.5.4
二、安裝 openssl
wget -c http://www.openssl.org/source/openssl-1.0.1k.tar.gz
tar -zxvf openssl-1.0.1k.tar.gz
cd openssl-1.0.1k.tar.gz
./config --prefix=/usr/local/openssl -fPIC no-gost no-shared no-zlib
make && make install
三、安裝apache httpd server
wget -c http://mirrors.cnnic.cn/apache//httpd/httpd-2.4.10.tar.gz
tar -zxvf httpd-2.4.10.tar.gz
cd httpd-2.4.10
安裝httpd 其依賴比較多,有些參數可能是舊版本使用的 可以先 ./configure --help 查看一下
有很多從網上查看的編譯方法如下,可能會發生錯誤: configure: error: pcre-config for libpcre not found.
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apu/
--enable-so --enable-dav --enable-maintainer-mode --enable-rewrite
--enable-ssl --with-ssl=/usr/local/openssl
所以還得安裝 pcre (Regex函數庫)
直接到官網下載 我這裡下載的版本是8.36
tar -zxvf pcre-8.36.tar.gz
cd pcre-8.36
mv pcre-8.36 /usr/local/pcre 直接拷到/usr/local
./configure (編譯使用gcc+,沒有就安裝一下yum -y install gcc-c++)
make && make install
安裝好了,就重新編譯 httpd 就OK了
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apu/
--enable-so --enable-dav --enable-maintainer-mode --enable-rewrite
--enable-ssl --with-ssl=/usr/local/openssl --with-pcre=/usr/local/pcre/pcre-config
然後就開始 make, make install(前面安裝openssl時如果不加上-fPIC 這裡可能就會出錯)。
有些人在這一步可能會出現問題:
exports.c:1653: error: redefinition of 'ap_hack_apr_version_string' exports.c:1022: error: previous definition of 'ap_hack_apr_version_string' was here
這個是./server/exports.c 這個檔案中 出現很多 兩個相同的常量 從apr apu included進來的 都是相同的,我選擇了一個笨方法 把多出來的常量刪掉再make install,其實 ./configure中有個參數 --with-included-apr 加上編譯就OK了。
安裝完畢,嘗試啟動 /usr/local/apache/bin/apachectl -k start
開啟瀏覽器 輸入 http://127.0.0.1
頁面顯示 : It works!
四、安裝Zlib
wget -c http://zlib.net/zlib-1.2.8.tar.gztar -zxvf zlib-1.2.8.tar.gzchown -R root:root zlib-1.2.8mv zlib-1.2.8 zlibmv zlib /usr/local/cd /usr/local/zlib./configuremake && make install
五、安裝Sqlite
wget -c http://www.sqlite.org/2014/sqlite-autoconf-3080704.tar.gztar -zxvf sqlite.autoconf-3080704.tar.gzchown -R root:root sqlite.autoconf-3080704.tar.gzmv sqlite.autoconf-3080704 sqlitemv sqlite /usr/localcd /usr/local/sqlite./configuremake && make install
六、安裝Subversion1.8
wget -c http://mirrors.hust.edu.cn/apache/subversion/subversion-1.8.11.tar.gztar -zxvf subversion-1.8.11.tar.gz
cd subversion-1.8.11mkdir -p ./sqlite-amalgamation (在這裡 把剛剛安裝好的sqlite中的sqlite3.c檔案拷貝到這)
cp /usr/local/sqlite/sqlite3.c ./sqlite-amalgamation/
./configure --prefix=/usr/local/subversion --with-apxs=/usr/local/apache/bin/apxs --with-apr=/usr/local/apr/
--with-apr-util=/usr/local/apu/ --with-zlib --enable-maintainer-mode
make && make instal
好啦,來驗證一下吧
/usr/local/subversion/bin/svnserve --version
svnserve, version 1.8.11 (r1643975)
compiled Jan 12 2015, 18:58:04 on x86_64-unknown-linux-gnu
.
.
.
看一下 /usr/local/subversion/libexec/ 目錄下是否存在
mod_authz_svn.so
mod_dav_svn.so
七、Subversion 和 Apache整合
(1)配置Subversion
建立SVN版本庫
mkdir -p /opt/svn/data/repos
/usr/local/subversion/bin/svnadmin create /opt/svn/data/repos
cd /usr/local/data
apache預設情況下存取權限是 daemon,所以相應地,
chown -R daemon /opt/svn/data/repos
接下來,產生存取控制檔案
apache提供了產生工具,可以直接使用htpasswd命令產生
/usr/local/apache/bin/htpasswd -c /opt/svn/data/repos/conf/passwd admin (-c 建立檔案)
/usr/local/apache/bin/htpasswd /opt/svn/data/repos/conf/passwd username
使用者建立完,接下來編輯一下authz (/opt/svn/data/repos/conf/authz) 裡面也 有相應的模板例子
[groups] (表示群組)
boss=admin //組名=使用者,使用者,使用者……(逗號分隔)
boys=username
……
[repos:/]
@boss=rw
@boys=r
*=
具體怎麼配置就自己去查閱資料啦。r 讀 w 寫
(2)配置Apache
cd /usr/local/apache/
把subversion中的兩個檔案拷貝到./modules/
cp /usr/local/subversion/libexec/mod_authz_svn.so ./modules/
cp /usr/local/subversion/libexec/mod_dav_svn.so ./modules
接下來,編輯httpd.conf
vi ./conf/httpd.conf
首先在LoadModules的末端,加上
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
然後在配置末尾加上
<Location /repos>
DAV svn
SVNParentPath /opt/svn/data/ #SVN倉庫的父目錄
SVNListParentPath On
SVNAutoversioning On
SVNReposName "repos"
AuthzSVNAccessFile /opt/svn/data/repos/conf/authz #前面產生的存取控制檔案
AuthType Basic
AuthName "hello,welcome to my repos!"
AuthUserFile /opt/svn/data/repos/conf/passwd #使用者檔案
Require valid-user
</Location>
到此整合完啦,重啟一下apache
./bin/apachectl -k restart
可以用瀏覽器開啟 輸入 http://127.0.0.1/repos 提示輸入帳號 密碼 進入。
八、配置Https
(1)首先要產生認證私密金鑰
cd /usr/local/apache/conf/ #直接在conf目錄下存放
/usr/local/openssl/bin/openssl genrsa 1024 > server.key
輸出提示:
Generating RSA private key, 1024 bit long modulus
.....++++++
........++++++
e is 65537 (0x10001)
這樣就產生好了 server.key 這個檔案在conf中
(2)對憑證進行填寫必要資訊
/usr/local/openssl/bin/openssl req -new -key server.key > server.csr
You are about to be asked to enter information that will be incorporatedinto your certificate request.What you are about to enter is what is called a Distinguished Name or a DN.There are quite a few fields but you can leave some blankFor some fields there will be a default value,If you enter '.', the field will be left blank.-----Country Name (2 letter code) [AU]:CNState or Province Name (full name) [Some-State]:GuangdongLocality Name (eg, city) []:ShenzhenOrganization Name (eg, company) [Internet Widgits Pty Ltd]:xxxxxOrganizational Unit Name (eg, section) []:Common Name (e.g. server FQDN or YOUR name) []:xxxxxxxEmail Address []:xxxxxxxPlease enter the following 'extra' attributesto be sent with your certificate requestA challenge password []:xxxxxxxAn optional company name []:xxxxxxx
填好資訊,產生server.csr
(3)產生認證
/usr/local/openssl/bin/openssl req -x509 -days 1024 -key server.key -in server.csr > server.crt # -days 表示有效期間
(4)編輯設定檔httpd.conf httpd-ssl.conf
vi httpd.conf 將 #Include conf/extra/httpd-ssl.conf前面的‘#’ 去掉
Include conf/extra/httpd-ssl.conf
vi ./extra/httpd-ssl.conf
加上
SSLCertificateFile "/usr/local/apache/conf/server.crt"
SSLCertificateKeyFile "/usr/local/apache/conf/server.key"
(5)強制要求通過https訪問 /repos
在httpd.conf中<Location /repos> SSLRequireSSL . . . . .</Location
(6)
重啟Apache,搞定。