svn是Subversion的简称,是一个开放源代码的版本控制系统。
一、下载安装Subversion必要的源码文件
- Apache
wget http://mirrors.shu.edu.cn/apache/httpd/httpd-2.4.32.tar.gz
- Subversion
wget http://mirrors.hust.edu.cn/apache/subversion/subversion-1.9.7.tar.gz
- apr源码包
wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.3.tar.gz
- apr-util源码包
wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.6.1.tar.gz
- serf源码包
wget http://mirrors.shu.edu.cn/apache/serf/serf-1.3.9.tar.bz2
- scons源码包
wget https://sourceforge.net/projects/scons/files/scons/2.5.1/scons-2.5.1.tar.gz
- openssl源码包
wget https://www.openssl.org/source/openssl-1.1.1-pre4.tar.gz
- sqlite-amalgamation源码包
wget http://www.sqlite.org/2018/sqlite-autoconf-3230000.tar.gz
二、安装必要依赖
1、yum -y install zlib zlib-devel openssl openssl-devel python*
三、安装apr
tar xvf apr-1.6.3.tar.gz cd apr-1.6.3 mkdir /usr/local/apr ./configure --prefix=/usr/local/apr make && make install
四、安装apr-util
tar xvf apr-util-1.6.1.tar.gz cd apr-util-1.6.1 mkdir /usr/local/apr-util ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr make && make install
五、安装scons
tar xvf scons-2.5.1.tar.gz cd scons-2.5.1 mkdir /usr/local/scons python setup.py install --prefix=/usr/local/scons
六、安装serf
tar xvf serf-1.3.9.tar.bz2 cd serf-1.3.9 mkdir /usr/local/serf /usr/local/scons PREFIX=/usr/local/serf APR=/usr/local/apr APU=/usr/local/apr-util /usr/local/scons install cp /usr/local/serf/lib/libserf-1.so* /usr/local/lib/
七、安装openssl
tar xvf openssl-1.1.1-pre4.tar.gz cd openssl-1.1.1-pre4 ./config --prefix=/usr/local/opensll-1.1.1 make && make install
八、安装sqlite
tar xvf sqlite-autoconf-3230000.tar.gz cd sqlite-autoconf-3230000 ./configure --prefix=/usr/local/sqlite mkdir /usr/local/sqlite make -j `grep processor /proc/cpuinfo | wc -l` && make install
九、安装httpd
useradd -r -d /app/website -s /sbin/nologin apache //app/website 表示网站的默认路径 ,如果不指定的话,默认是/var/www/html tar xvf httpd-2.4.32.tar.gz cd httpd-2.4.32 ./configure --prefix=/usr/local/httpd-2.4.32 --enable-so --enable-ssl --enable-cgi --enable-rewrite --with-zlib --with-pcre --enable-modules=most --enable-mpms-shared=all --with-mpm=prefork --with-openssl=/usr/local/opensll-1.1.1 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util vim /usr/local/httpd-2.4.32/conf/httpd.conf //修改默认用户及主页 User apache Group apache LoadModule dav_module modules/mod_dav.so //取消此行注释
十、安装Subversion
tar -xvf subversion-1.9.7.tar.gz cd subversion-1.9.7 ./configure --prefix=/usr/local/subversion-1.9.7 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-zlib=/usr/local/zlib --with-serf=/usr/local/serf/ --enable-mod-activation --with-apache-libexecdir=/usr/local/httpd-2.4.32/modules/ make -j `grep processor /proc/cpuinfo | wc -l` && make install //根据CPU核心自动安排多线程编译 echo "export PATH=/usr/local/subversion-1.9.7/bin:$PATH" >> /etc/profile source /etc/profile svn help
如果出现如下信息
svn: error while loading shared libraries: libserf-1.so.1: cannot open shared object file: No such file or director
cd /etc/ld.so.conf.d/ vi user-libs.conf 把我们拷贝serf的文件的目录加上 /usr/local/serf/lib ldconfig
十一、创建svn仓库
mkdir -p /data/repos svnadmin create /data/repos cd /data/repos
十二、目录结构
总用量 24 drwxr-xr-x. 2 root root 4096 4月 3 17:59 conf drwxr-sr-x. 6 root root 4096 4月 3 17:32 db -r--r--r--. 1 root root 2 4月 3 17:32 format drwxr-xr-x. 2 root root 4096 4月 3 17:32 hooks drwxr-xr-x. 2 root root 4096 4月 3 17:32 locks -rw-r--r--. 1 root root 229 4月 3 17:32 README.txt
十三、启动关闭svn服务
一台机器可以启动多个svn服务,需修改不同端口号。
svnserve -d -r /data/repos --listen-port 3690 ps -ef|grep svn netstat -ln|grep 3690 killall svnserve
十四、设置svn服务开机启动
方法一:
修改/etc/rc.d/rc.local文件,添加如下命令
/usr/local/subversion-1.9.7/svn/bin/svnserve -d -r /data/repos --listen-port 3690
方法二:
在/etc/init.d/目录下创建svn文件并设置权限755,代码如下
#!/bin/bash # centos下可以用如下命令管理svn: service svn start(restart/stop) SVN_HOME=/data/repos if [ ! -f "/usr/local/subversion-1.9.7/svn/bin/svnserve" ] then echo "svnserver startup: cannot start" exit fi case "$1" in start) echo "Starting svnserve..." /usr/local/subversion-1.9.7/svn/bin/svnserve -d --listen-port 3690 -r $SVN_HOME echo "Finished!" ;; stop) echo "Stoping svnserve..." killall svnserve echo "Finished!" ;; restart) $0 stop $0 start ;; *) echo "Usage: svn { start | stop | restart } " exit 1 esac
十五、实现svn代码仓库与web线上同步
svn代码仓库目录/data/repos/www1
web线上目录/data/wwwroot/www1
1、首先checkout一份
svn co svn://192.168.1.254/www1 /data/wwwroot/www1
2、修改目录权限
cd /data/repos/www1/hooks cp post-commit.tmpl post-commit vi post-commit
3、建立同步脚本
cd /data/repos/www1/hooks cp post-commit.tmpl post-commit vi post-commit
添加如下代码
export.UTF-8 SVN=/usr/local/subversion-1.9.7/svn/bin WEB=/data/wwwroot/www1 $SVN update $WEB --username test --password 123456 chown -R 766 $WEB
chmod 755 post-commit
原文地址:http://blog.51cto.com/liuhuiliang/2096497