1. 程式人生 > >CentOS 7 安裝SVN並整合HTTP訪問

CentOS 7 安裝SVN並整合HTTP訪問

yunwei admin all 訪問 included efi 公網 apach acc

#!/bin/bash
## -------------------------------------------------
## 安裝svn並整合http訪問
## -------------------------------------------------


echo -e "\033[1;36m安裝apache\033[0m"
cd /data/software
yum install expat expat-devel
wget http://mirrors.hust.edu.cn/apache/apr/apr-1.6.2.tar.gz
wget http://mirrors.hust.edu.cn/apache/apr/apr-util-1.6.0.tar.gz
wget http://mirrors.shuosc.org/apache/httpd/httpd-2.4.27.tar.gz
tar xvf apr-1.6.2.tar.gz
tar xvf apr-util-1.6.0.tar.gz
tar xvf httpd-2.4.27.tar.gz
/bin/cp -rf apr-1.6.2 httpd-2.4.27/srclib/apr
/bin/cp -rf apr-util-1.6.0 httpd-2.4.27/srclib/apr-util
cd httpd-2.4.27
./configure --prefix=/opt/apache --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支持
make
make install

echo -e "\033[1;36m安裝subversion\033[0m"
cd /data/software
wget http://www.sqlite.org/2017/sqlite-amalgamation-3200100.zip
wget http://mirrors.shuosc.org/apache/subversion/subversion-1.9.7.tar.gz
tar xvf subversion-1.9.7.tar.gz
unzip sqlite-amalgamation-3200100.zip
/bin/cp -rf sqlite-amalgamation-3200100 subversion-1.9.7/sqlite-amalgamation
cd subversion-1.9.7
./configure --prefix=/opt/subversion --with-apxs=/opt/apache/bin/apxs --with-apr=/opt/apache/bin/apr-1-config --with-apr-util=/opt/apache/bin/apu-1-config
make
make install
/bin/cp -raf subversion/mod_authz_svn/.libs/mod_authz_svn.so /opt/apache/modules/
/bin/cp -raf subversion/mod_dav_svn/.libs/mod_dav_svn.so /opt/apache/modules/

echo -e "\033[1;36m整合apache和subversion\033[0m"
sed -i ‘[email protected] rewrite_module modules/[email protected] rewrite_module modules/mod_rewrite.so\nLoadModule dav_svn_module modules/mod_dav_svn.so\nLoadModule authz_svn_module modules/[email protected]‘ /opt/apache/conf/httpd.conf
cat >> /opt/apache/conf/httpd.conf << EOF

# Subversion default settings
Include conf/extra/httpd-svn.conf
EOF

cat > /opt/apache/conf/extra/httpd-svn.conf << EOF
<Location /leishen>
DAV svn
SVNListParentPath On
SVNParentPath /data/subversion
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /opt/subversion/conf/passwdfile
AuthzSVNAccessFile /opt/subversion/conf/accessfile
Require valid-user
</Location>
EOF

mkdir -p /opt/subversion/conf

##創建賬戶配置文件,因為是第一次創建,passwdfile文件原本不存在所以需要加-c參數,日後需要在passwdfile中追加第二個用戶,去掉-c參數即可
echo -e "\033[1;36m創建第一個用戶\nUSER:jinps\nPASS:jinsppasswd\033[0m"
/opt/apache/bin/htpasswd -bc /opt/subversion/conf/passwdfile jinsp jinsppasswd

echo -e "\033[1;36m創建權限樹配置文件\033[0m"
cat > /opt/subversion/conf/accessfile << EOF
[groups]
manager = yunfy
ops = jinsp,bxjg

[yunwei:/]
@manager = rw
@ops = rw
* =

[yunwei:/H05]
@manager = rw
@ops = rw
* =
EOF

echo -e "\033[1;36m新增SVN倉庫\033[0m"
mkdir -p /data/subversion
cd /data/subversion
/opt/subversion/bin/svnadmin create yunwei

echo -e "\033[1;36m啟動apache\033[0m"
/opt/apache/bin/apachectl restart

echo -e "\033[1;36m測試使用http訪問svn\033[0m"
echo -e "\033[1;32mhttp://本機公網IP/leishen/yunwei/H05\033[0m"

CentOS 7 安裝SVN並整合HTTP訪問