CentOS下安装svn,添加新用户,重启svn服务
系统环境:CentOS6.9
安装方式:yum install
安装软件:系统自动下载SVN软件
1、检查是否安装了低版本的SVN
[root@localhost /]# rpm -qa subversion
2、卸载旧的SVN
[root@localhost modules]# yum remove subversion
安装SVN
[root@localhost modules]# yum install httpd httpd-devel subversion mod_dav_svn mod_auth_mysql
确认已安装了svn模块
[root@localhost /]# cd /etc/httpd/modules
[root@localhost modules]# ls | grep svn
检验已经安装的SVN版本信息
[root@localhost modules]# svnserve --version
代码库创建
SVN软件安装完成后还需要建立SVN库
[root@localhost modules]# mkdir -p /home/svn/svnrepos
[root@localhost modules]# svnadmin create /home/svn/svnrepos/test1
执行上面的命令后,自动建立test1库,查看/home/svn/svnrepos/test1, 文件夹发现包含了conf, db,format,hooks, locks, README.txt等文件,说明一个SVN库已经建立。
配置代码库
进入上面生成的文件夹conf下,进行配置
[root@localhost modules]# cd /home/svn/svnrepos/test1/conf
用户密码passwd、权限控制authz配置及服务svnserve.conf配置这几个都不用讲了很简单
配置防火墙端口
[root@localhost conf]# vi /etc/sysconfig/iptables
添加以下内容:
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3690 -j ACCEPT
保存后重启防火墙
[root@localhost conf]# service iptables restart
或是关闭防火墙 :service iptables stop
启动SVN
svnserve -d -r /home/svn/svnrepos
查看SVN进程
[root@localhost conf]# ps aux|grep svnserve
停止重启SVN
[root@localhost password]# killall svnserve //停止
或kill -9 进程id
[root@localhost password]# svnserve -d -r /home/svn/svnrepos // 启动
测试
SVN服务已经启动,使用客户端测试连接。
客户端连接地址:svn://ip/库名(注意是svn)
输入用户名和密码
8.强制用户提交SVN输入日志信息:
cd /home/svn/svnrepos/test1/hooks
vim pre-commit
#!/bin/sh
REPOS="$1"
TXN="$2"
SVNLOOK=/usr/bin/svnlook
#根据SVN安装目录而定(find / -name svnlook)
LOGMSG=`$SVNLOOK log -t "$TXN" "$REPOS" | grep "[a-zA-Z0-9]" | wc -c`
if [ "$LOGMSG" -lt 4 ];
#至少4个字符
then
echo "Log message can't be empty! you must input more than 4 chars as comment!." 1>&2
exit 1
fi
chmod 755 pre-commit
如果需要更多svn版本库访问,只需要创建相应的版本库目录,配置参考第四、五步!
svnadmin create /opt/svn/test3
svnadmin create /opt/svn/test4
...
...
...
svnadmin create /opt/svn/test100
Apache及多版本库管理:
在/home/svn下建立目录svnconf,
#cd svnconf
#touch passwd authz
执行htpasswd /home/svn/svnconf/passwd 用户
输入及确认密码
#vi authz 编辑权限,直接写就行
这个yum安装和编译安装不一样,会自动生成/etc/httpd/conf.d/subversion.conf关于svn的配置文件,里面的两个认证模块是开启的
在其下面添加配置文件
<Location /svn> #svn在访问的时候用到,http://ip/svn
DAV svn
SVNParentPath /home/svn/svnrepos #多版本库时的共同目录
SVNListParentPath on
AuthType Basic
AuthName "Subversion repository"
AuthUserFile /home/svn/svnconf/passwd
Require valid-user
AuthzSVNAccessFile /home/svn/svnconf/authz
</Location>
不关闭selinux会导致web无法访问密码文件,关闭selinux要重启服务器
客户端或是浏览器访问http://ip/库名就可以了
关于连接win服务器AD域用户认证
先在win服务器域控users下建立svn连接数据用户svnadmin
然后上面的内部认证的配置文件~/conf.d/subversion.conf改为:
<Location />
DAV svn
SVNParentPath /home/svn/svnrepos
SVNListParentPath On
AuthzLDAPAuthoritative off
AuthType Basic
AuthName "Authorization Realm"
AuthzSVNAccessFile /home/svn/svnconf/authz
AuthBasicProvider ldap
AuthLDAPBindDN "CN=svnadmin,CN=Users,DC=***,DC=com"
AuthLDAPBindPassword "****"
AuthLDAPURL "ldap://10.1.1.*:389/DC=***,DC=com?sAMAccountName?sub?(objectClass=*)"
Require valid-user
</Location>