環境:
CentOS5.8 x64 ,開發包組已安裝,iptables,selinux已經關閉
一.安裝配置apache
1.1 下載編譯安裝apache
tar xvf httpd-2.2.22.tar.bz2
cd httpd-2.2.22
./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
make && make install
1.2 配置apache
添加apache 用戶
useradd -r apache
以apache身份運行httpd
sed -i 's@User daemon@User apache@g' /opt/apache2/conf/httpd.conf
sed -i 's@Group daemon@Group apache@g' /opt/apache2/conf/httpd.conf
1.3 為了方便將apache命令加入PATH,並將apache庫導出
echo 'export PATH=$PATH:/opt/apache2/bin' > /etc/profile.d/httpd.sh
. /etc/profile.d/httpd.sh
echo '/opt/apache2/lib' > /etc/ld.so.conf.d/apache.conf
導出
ldconfig
rm -rf httpd-2.2.22
二.安裝MySQL
2.1安裝cmake
tar xvf cmake-2.8.4.tar.gz
cd cmake-2.8.4
./configure
make && make install
cd ..
rm -rf cmake-2.8.4
2.2 安裝mysql
tar xf mysql-5.5.28.tar.gz
cd mysql-5.5.28
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
make && make install
cd ..
rm -Rf mysql-5.5.28
配置文件與啟動腳本
cd /opt/mysql
cp support-files/my-huge.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
2.3 以mysql用戶運行mysql,修改PATH並導出庫
useradd -r mysql
chown -R mysql:root .
./scripts/mysql_install_db --user=mysql --datadir=data/
echo 'export PATH=$PATH:/opt/mysql/bin' > /etc/profile.d/mysql.sh
./etc/profile.d/mysql.sh
echo '/opt/mysql/lib' > /etc/ld.so.conf.d/mysql.conf
ldconfig
啟動mysql
service mysqld start
三.安裝php
3.1 安裝php,安裝它是因為svnmanager需要
cd /root/svn
tar xvf php-5.3.18.tar.gz
cd php-5.3.18
./configure --prefix=/opt/php \
--with-apxs2=/opt/apache2/bin/apxs \
--with-mysql=/opt/mysql \
--enable-mbstring
make && make install
cp php.ini-production /etc/php.ini
cd ..
rm -Rf php-5.3.18
添加apache的php支持
sed -i '/AddType application\/x-gzip .gz .tgz/a\
AddType application/x-httpd-php .php' /opt/apache2/conf/httpd.conf
sed -i 's@DirectoryIndex index.html@DirectoryIndex index.php index.html@g' /opt/apache2/conf/httpd.conf
啟動apache測試
rm -f /opt/apache2/htdocs/index.html
echo '<?php
phpinfo()
?>' > /opt/apache2/htdocs/index.php
apachectl start
訪問http://$IP/測試apache,php,mysql是否部署下確
四.安裝subversion
4.1 解壓安裝subversion
tar xf subversion-1.6.13.tar.bz2
tar xf subversion-deps-1.6.13.tar.bz2
cd 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
make && make install
echo 'export PATH=$PATH:/opt/subversion/bin' > /etc/profile.d/svn.sh
. /etc/profile.d/svn.sh
cd ..
rm -rf subversion-1.6.13
4.2 讓apache與svn結合
sed -i '/httpd-default.conf/a\
Include conf/extra/httpd-svn.conf' /opt/apache2/conf/httpd.conf
echo '
<Location /svn>
DAV svn
SVNListParentPath On
SVNParentPath /opt/svn_repos
AuthType Basic
AuthName "Subversion Repository"
AuthUserFile /opt/subversion/conf/passwdfile
AuthzSVNAccessFile /opt/subversion/conf/accessfile
Require valid-user
</Location> ' > /opt/apache2/conf/extra/httpd-svn.conf
4.3 創建提到的文件
mkdir /opt/subversion/conf
touch /opt/subversion/conf/passwdfile
touch /opt/subversion/conf/accessfile
mkdir /opt/svn_repos
4.4 創建一個repo,添加一個測試賬戶,配置權限,測試
svnadmin create /opt/svn_repos/test/ ##創建一個repo
chown -R apache:apache /opt/subversion/ ##我們通過apache來管理svn的
chown -R apache:apache /opt/svn_repos/
Linux/1727.html' target='_blank'>htpasswd -bm /opt/subversion/conf/passwdfile test "admin"
echo '
[test:/]
* = r
test = rw ' > /opt/subversion/conf/accessfile ##access文件是權限控制文件
4.5 重啟apache測試
apachectl restart
訪問http://$IP/svn/test
輸入賬號,密碼
如果看到test - Revision 0: / 證明沒問題,繼續
五.安裝svnmanager,以圖形化的方式管理svn
5.1 安裝VersionControl_SVN,svnmanager需要它
/opt/php/bin/pear install VersionControl_SVN-0.3.4
出現ok,等代表成功
5.2 安裝svnmanager
tar xf svnmanager-1.08.tar.gz
mv svnmanager-1.08 /opt/apache2/htdocs/svnman
5.3 修改配置文件
cp /opt/apache2/htdocs/svnman/config.php.linux /opt/apache2/htdocs/svnman/config.php
vim /opt/apache2/htdocs/svnman/config.php
$htpassword_cmd = "/opt/apache2/bin/htpasswd"; ##意思很明顯
$svn_cmd = "/opt/subversion/bin/svn";
$svnadmin_cmd = "/opt/subversion/bin/svnadmin";
//Subversion locations
$svn_config_dir = "/opt/subversion/conf";
$svn_repos_loc = "/opt/svn_repos";
$svn_passwd_file = "/opt/subversion/conf/passwdfile";
$svn_access_file = "/opt/subversion/conf/accessfile";
$dsn = "mysql://svnmanager:admin@localhost/svnmanager"; ##mysql,去掉i
$admin_name = "admin"; ##初始的賬號密碼
$admin_temp_password = "admin";
5.4 創建
數據庫
mysql> create database svnmanager;
mysql> grant all on svnmanager.* to 'svnmanager'@'localhost' identified by 'admin';
mysql> flush privileges;
5.5 將VersionControl_SVN拷到svnmanager中
tar xvf VersionControl_SVN-0.3.4.tgz
mv VersionControl_SVN-0.3.4 /opt/apache2/htdocs/svnman/VersionControl
chown -R apache:apache /opt/apache2
5.6 訪問測試
http://$IP/svnman
初始賬號:admin
初始密碼:admin
建立新的管理賬號後舊的就停用了
svnmanager用法見http://wenku.baidu.com/view/4d95d0303968011ca30091a2.html
建立庫,與用戶後測試。到此svn服務器構建完畢
六.配置svn雙機同步
原來有svn服務器,現在做一個鏡像服務器,當原來的服務器down掉後可以代替它
源服務器:192.168.17.140
鏡像服務器:192.168.17.139
實例同步的為源服器為crm的項目到鏡像服務器
6.1 在鏡像服務器上建立一新庫crm,與具有讀寫權限的用戶
用svnmanager來建,svnadmin create 的話svnmanager中看不到
這個就不寫了,假設源上是http://192.168.17.140/svn/crm,鏡像的為http://192.168.17.139/svn/crm,用戶為:laoguang,密碼為:admin 對兩個項目都可讀可寫
6.2 修改鏡像服務下項目hook目錄下的腳本並啟用
cp /opt/svn_repos/crm/hooks/pre-revprop-change.tmpl /opt/svn_repos/crm/hooks/pre-revprop-change
vim /opt/svn_repos/crm/hooks/pre-revprop-change
把最後的exit 1改為exit 0 即可
6.3 鏡像服務器執行初始化
svnsync init file:///opt/svn_repos/crm/ http://192.168.17.140/svn/crm/
輸入具有讀寫賬號密碼,root的好像寫的不對也沒事
比如,我在192.168.17.140的一個賬號laoguang 密碼 admin
出現Copied properties for revision 0. 代表正確
6.4 開始同步源服務器上的數據
svnsync sync file:///opt/svn_repos/crm/
---------------------------
Store password unencrypted (yes/no)? yes
Transmitting file data ..............................
Committed revision 1.
Copied properties for revision 1.
Transmitting file data .
Committed revision 2.
Copied properties for revision 2.
Transmitting file data .
Committed revision 3.
Copied properties for revision 3.
-----------------------------
代表同步成功
6.5 配置當源版本改變時自動同步
下面開始在源服器上操作
cp /opt/svn_repos/qingdao/hooks/post-commit.tmpl /opt/svn_repos/qingdao/hooks/post-commit
chmod 755 /opt/svn_repos/qingdao/hooks/post-commit
刪除未注釋的內容
在最下面寫上
/opt/subversion/bin/svnsync sync --non-interactive http://192.168.17.139/svn/crm/ --username laoguang --password admin
升級源svn版本,測試鏡像上同步了沒。
七.配置svn 禁止普能用記刪除文件
7.1修改源上的鉤子腳本
cp /opt/svn_repos/qingdao/hooks/pre-commit.tmpl /opt/svn_repos/qingdao/hooks/pre-commit
chmod +x /opt/svn_repos/qingdao/hooks/pre-commit
vim /opt/svn_repos/qingdao/hooks/pre-commit
REPOS="$1" ##庫位置
TXN="$2" ##版本
SVNLOOK=/opt/subversion/bin/svnlook ##svnlook的位置
SCMLIST="admin" ##允許刪除的用記
C_USER=`$SVNLOOK info -t $TXN $REPOS | sed -n "1p"` ##執行commit的用戶
if [ -z `echo $SCMLIST | grep $C_USER` ];then ## 如果commit的用戶沒在允許的裡面
echo `$SVNLOOK changed -t $TXN $REPOS` > /opt/svn_repos/qingdao/commit_log ##將操作寫入日志
if cat /opt/svn_repos/qingdao/commit_log|cut -d" " -f1|uniq -u|grep "^D";then ##如果日志開頭包含D(D代表刪除)
echo "You do not have permisson to delete a file" > /dev/stderr ##提示錯誤
rm -rf /opt/svn_repos/qingdao/commit_log ##刪除文件
exit 1 ##錯誤退出
fi
fi
exit 0
轉自:http://laoguang.blog.51cto.com/6013350/1139645