基于ssl的SVN版本控制和复制

 

一、 服务器安装配置
1.环境搭建
yum install –y openssl      //安装openssl
安装软件会在/etc/pki/目录下安装ssl服务所需要的文件
生成根证书
cd /etc/pki/tls/misc/
./CA –newca   
回车创建新文件,输入加密密码(本密码最后一步给自己签名时候要用),并填写证书信息:
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:Henan
Locality Name (eg, city) []:Zhengzhou
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Orgtec
Organizational Unit Name (eg, section) []:Orgtec
Common Name (eg, YOUR name) []:svn.orgtec.cn
Email Address []:[email protected]
Common Name填入主机全称是比较好的选择。这个名称必须与通过浏览器访问您网站的URL完全相同,否则用户会发现您服务器证书的通用名与站点的名字不匹配,用户就会怀疑您的证书的真实性。服务器证书和客户证书的Common Name应该和CA一致。
本命令会在/etc/pki/CA/目录中生成cacert.pem(根证书)和/etc/pki/CA/private/目录中生成cakey.pem(根证书私钥)
这样就建好了一个CA服务器,有了一个根证书的私钥cakey.pem和根证书cacert.pem现在就可以用cacert.pem给服务器证书或者客户端证书签名
 
服务器证书
a) 生成服务器私钥
openssl genrsa -des3 -out server.key 1024
输入加密密码,用128位rsa算法生成密钥,得到server.key文件。
b) 生成服务器证书请求(CSR)
openssl req -new -key server.key -out server.csr
CSR(Certificate Signing Request)是一个证书签名请求,在申请证书之前,首先要在WEB服务器上生成CSR,并将其提交给CA认证中心,CA才能给您签发SSL服务器证书。可以这样认为,CSR就是一个在您服务器上生成的证书。CSR主要包括以下内容:
Country Name (2 letter code) [AU]:CN
State or Province Name (full name) [Some-State]:Henan
Locality Name (eg, city) []:Zhengzhou
Organization Name (eg, company) [Internet Widgits Pty Ltd]:Orgtec
Organizational Unit Name (eg, section) []:Orgtec
Common Name (eg, YOUR name) []:use.orgtec.cn
Email Address []:[email protected]
Please enter the following ‘extra’ attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
Common Name填入主机名和CA一致。
本步骤生成的证书文件统一放在/etc/pki/tls/目录下面
使用openssl提供的CA脚本给生成的服务器证书签名
mv server.csr newreq.pem
/etc/pki/tls/misc/CA -sign
mv newcert.pem server.crt
 
签名证书后,可通过如下命令可查看服务器证书的内容:
openssl x509 -noout -text -in server.crt
可通过如下命令验证服务器证书:
openssl verify -CAfile ca.crt server.crt
 
3. 客户证书
客户证书是可选的。如果有客户证书,就是双向认证HTTPS,否则就是单向认证HTTPS。
a) 生成客户私钥
openssl genrsa -des3 -out client.key 1024
b) 生成客户证书签名请求
openssl req -new -key client.key -out client.csr
c) 生成客户证书(使用CA证书签名)
openssl ca -in client.csr -out client.crt
d) 证书转换成浏览器认识的格式
openssl pkcs12 -export -clcerts -in client.crt -inkey client.key -out client.pfx
 
安装apache
yum install –y zlib-devel openssl-devel
#tar -zxvf httpd-2.2.9.tar.gz
#cd httpd-2.2.9/srclib/apr
#./configure –with-prefix=/usr/local/apr && make && make install
#cd ../apr-util/
#./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr && make &&make install
#cd ../..
#./configure  --prefix=/usr/local/apache2  --enable-dav  --enable-dav-fs  --enable-so --enable-ssl  --enable-mods-shared=all –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util
#make
#make install
 
安装neon
yum install –y libxml2-devel
不需要支持http协议可以略掉安装,后面两台服务同步更新时候需要http协议支持
tar zxvf neon-0.29.6.tar.gz
cd neon-0.29.6
./configure --prefix=/usr/local/neon( --enable-shared ) --with-ssl --with-libs=/usr/lib/:/usr/lib/openssl:/usr/include/openssl
make && make install
 
安装sqlite-autoconf
tar –zxv –f sqlite-autoconf-3071300.tar.gz
cd sqlite-autoconf
./configure –prefix=/usr/local/sqlite && make && make install
cd ..
 
安装subversion
# tar zxvf subversion-1.7.6.tar.gz
# cd subversion-1.7.6
# ./configure --prefix=/usr/local/subversion --with-apxs=/usr/local/apache2/bin/apxs --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-neon=/usr/local/neon/ --with-ssl –with-sqlite=/usr/local/sqlite
make && makeinstall
svnadmin --version
 
创建一个 Subversion 版本库:
# 创建文件夹
$ mkdir -p /svn/repos
# 运行创建版本库的命令,指定数据存储为 FSFS,如果要指定为 Berkeley DB,则将 fsfs 替换为 bdb
$ svnadmin create --fs-type fsfs /svn/repos
查看生成的版本库结构:
$ ls -l /svn/repos
创建项目临时目录,建议目录结构如下:
mkdir -p /svn/tmp/project_exam/trunk
mkdir -p /svn/tmp/project_exam/tags
mkdir -p /svn/tmp/project_exam/branches
然后将项目文件复制到trunk下,如果是从CVS转移过来的项目,用下面命令清理目录
#find projectname/ -name CVS -exec rm -rf {} \;
 
导入source
[root@localhost /etc/svn/tmp/project_exam/trunk/exam_online] # /usr/local/subverion/bin/svn import -m "initial import" /svn/tmp/ file:///svn/repos/
-m 后面跟的是操作注释 /svn/tmp是项目文件位置 file:///svn/repos是创建的软件仓库
检查是否倒入成功
#svn list --verbose file:/// svn/repos/
如果成功你看到到你倒入的项目列表
 
9, 给仓库授权
#chown -R apache.apache /svn/repos   
#chown –R apache.apache /usr/local/apache2/htdocs
注意:repos的所有者和apache的所有者必须是 apache用户
要不然,做apache和版本库无法同步
10,用Apache管理用户权限:
首先需要创建一个用户文件
htpasswd /svn/passwordfile username
如果 passwordfile 不存在,可以加上 -c 选项让 htpasswd 新建一个。创建好的文件内容是用户名加上密码的 MD5 密文。
接下来修改 httpd.conf,在 Location 标签中加入如下内容:
先修改版本库的权限:
User daemon
Group daemon
//把上述内容改成:
User apache
Group apache
整合apache svn:
<Location /repos>
Dav svn
SVNPath /svn/repos
AuthType Basic
AuthName "svn repos"
AuthUserFile  /svn/passwordfile
# AuthzSVNAccessFile /svn/repos/conf/authz
require valid-user
SSLRequireSSL
</Location>
启动apache 使用https://localhost/repos访问
启用Include conf/extra/httpd-ssl.conf
配置文件的内容:
SSLSessionCache None (或者默认)
SSLMutex default   (或者默认)
注释掉DocumentRoot (或者改为/svn/repos需要在主配置文件里面开放权限) 和ServerName
修改SSLCertificateFile   和 SSLCertificateKeyFile指向服务器证书和密钥
其他不要改
 
二、 利用svn 进行版本库和web根目录同步更新
#cp /svn/repos/hooks/post-commit.tmpl /svn/repos/hooks/post-commit
#vim /svn/repos/hooks/post-commit
注释掉所有代码 添加/usr/local/subversion/bin/svn update /usr/local/apache2/htdocs
#chmod +x /svn/repos/hooks/post-commit
以后任何客户端更新代码后 代码即被同步到web根目录下
三 、利用svnsync同步两个svn版本库
#mkdir /svn/repos2
#svnadmin create –fs-type fsfs /svn/respos2
#chown -R apache.apache /svn/repos2
#chmod 770 /svn/repos2
#chmod -R g+w /svn/repos2
apache配置文件中添加相应的内容
#cp /svn/repos2/hooks/pre_revprop_change.tmpl /svn/repos2/hooks/pre_revprop_change
#注释掉所有的行,添加exit 0
初始化正确后会显示Copied properties for revision 0
 
如果需要同步更新
编辑post-commit 添加svnsync sync --non-interactive http://192.168.2.128/repos --sync-username test --sync-password testqwertyu --source-username test --source-password testqwertyu     同时要注意权限 -sync-username和password为对方主机svn的用户密码
本测试两个版本库在同一个服务器如果不在同一服务器可以用URL来进行地址替换 注意:subversion编译时候要添加neno 增加
如果两个版本库要进行双向同步更新   则在另外一台服务器上进行相同的脚步配置即可
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章