目录

1.1应用介绍

1.2一些考虑

一、安装Svn服务器端

1.安装subversion

2.检查安装情况

3.尝试启动svn

4.创建一个版本库

5.备份原始配置文件

6.查看修改配置文件svnserve.conf

7.重新启动svn服务

二.下面开始搭建Open×××

1.下载软件包

2.安装过程

3.初始化服务端设置

4.拷贝密钥文件

5.编辑配置文件

6.然后在服务器上启动***

7.检查启动状态

8.客户端软件

9.执行自动代码更新的脚本

1.1应用介绍

涉及软件

Open×××+Svn+Rsync+Crontab

应用场景:

亚马逊云服务器

开源软件应用:

开源软件

应用

Open×××

运维远程维护,svn代码更新上传等

Svn

网站程序代码版本管理

Rsync+Cron

网站代码的自动更新

1.2一些考虑:

1)服务器不对外开放多余端口,仅开放Open×××ssh端口

[root@LAMP ~]# nmap 54.250.xxx.xx

PORT     STATE  SERVICE

8090/tcp closed unknown

8093/tcp closed unknown

因为亚马逊的登录是基于密钥认证的,所以ssh端口并没有禁止,以防止那天open***挂了,登录不上。

2svn服务器设置

为了保证svn服务器的安全,所以svn并不对公网开放,iptables上没有允许从外网连接svn服务器,只有通过***才能进行更新,也算是保证一点安全

3)没有用svn钩子的原因

我尝试测试了一上午,一个在本地测试很好的钩子到服务器上就没法用了,但是因为要用,所以就先协调了代码更新的时间,指定代码更新的时间,然后使用rsync+crontab的方法,进行自动更新,先实现功能。

如果有朋友解决过类似的问题,也欢迎交流。

系统环境

[root@ip-10-0-0-139 ~]# uname -a

Linux ip-10-0-0-139 3.4.37-40.44.amzn1.x86_64 #1 SMP Thu Mar 21 01:17:08 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux

软件版本

Svnsubversion-1.7.9-1.28.amzn1.x86_64

Open×××open***-2.0.9.tar.gz

一、安装Svn服务器端

1.因为svn属于我们内部使用,所以不存在什么并发,直接yum

[root@ip-10-0-0-227 ~]# yum install subversion -y

2.检查安装情况

[root@ip-10-0-0-227 ~]# rpm -qa |grep subversion

subversion-1.7.9-1.28.amzn1.x86_64

subversion-libs-1.7.9-1.28.amzn1.x86_64

3.尝试启动svn

[root@ip-10-0-0-227 tool]# svnserve -d -r --listen-port 8090 /application/svnserver/

-d:以daemon守护进程的方式启动

-r:指定项目的根目录

--listen-port:指定svn服务的端口,默认为了3690

[root@ip-10-0-0-227 tool]# ps -ef |grep svn

root     26757     1  0 Jun03 ?        00:00:00 svnserve --listen-port 8090 -d -r /application/svndata/

4.创建一个版本库

[root@ip-10-0-0-227 tool]# svnadmin create /application/svnserver/webpro

[root@ip-10-0-0-227 tool]# tree /application/svnserver/webpro/ -L 1

/application/svnserver/webpro/

├── conf

├── db

├── format

├── hooks

├── locks

└── README.txt

5.备份原始配置文件

[root@ip-10-0-0-227 tool]# cd  /application/svnserver/webpro/conf/

[root@ip-10-0-0-227 conf]# for i in `ls`;do cp $i $i.$(date +%F);done

[root@ip-10-0-0-227 conf]# ll

total 24

-rw-r--r-- 1 root root 1080 Jun  4 14:45 authz

-rw-r--r-- 1 root root 1080 Jun  4 14:47 authz.2013-06-04

-rw-r--r-- 1 root root  309 Jun  4 14:45 passwd

-rw-r--r-- 1 root root  309 Jun  4 14:47 passwd.2013-06-04

-rw-r--r-- 1 root root 3090 Jun  4 14:45 svnserve.conf

-rw-r--r-- 1 root root 3090 Jun  4 14:47 svnserve.conf.2013-06-04

6.查看修改配置文件svnserve.conf

[root@ip-10-0-0-227 conf]# egrep -v "^###|^$"  svnserve.conf

[general]

# anon-access = read

# auth-access = write

# password-db = passwd

# authz-db = authz

# realm = My First Repository

# force-username-case = none

[sasl]

# use-sasl = true

# min-encryption = 0

# max-encryption = 256

Svn的配置文件,分为2部分:

[general]常用的配置选项

[sasl]SASL认证

SASL认证介绍:

subversion1.5以上的版本默认装了sasl认证,解决svnserve密码文件passwd是明文的问题,生成一个sasl认证的密码文件sasldb

我这里svn因为不对外网提供服务,所以也没有使用SASL去加密

修改的地方

1.anon-access = none 如果使用默认的read,则匿名用户也可以读取数据,此选项建议设置为none,如果不开启此选项,可能导致win客户端下查看svn日志出现1970-1-1的日期问题

2.auth-access = write 允许用户写入

3.password-db = passwd 存放用户密码的文件的位置

4. authz-db = authz存放用户权限的设置

权限注意:

这里使用root用户将 passwdauthz这个两个文件的权限设置700.chmod 700 passwd authz

Passwd文件的设置

[root@ip-10-0-0-227 conf]# cat passwd

SVNweb = QYL102

Authz文件的设置

[root@ip-10-0-0-227 conf]# cat  authz

[groups]

web_sa = zjSVNweb

设置用户属于某个组,这里我们可以将不同的用户分别属于不同的组,然后做不同的权限设置

[webpro:/]

@web_sa = rw

Webpro这个版本库,进行权限设置ett_sa这个组的用户具有可写权限

7.重新启动svn服务

[root@ip-10-0-0-227 conf]# ps -ef |grep svn

root     26757     1  0 Jun03 ?        00:00:00 svnserve --listen-port 8090 -d -r /application/svnserver/

root     29658 29513  0 15:10 pts/0    00:00:00 grep svn

[root@ip-10-0-0-227 conf]# kill - 9 26757

[root@ip-10-0-0-227 conf]# svnserve --listen-port 8090 -d -r /application/svnserver/

到此svn服务已经基本设置完成。

二.下面开始搭建Open×××

1.下载软件包

[root@ip-10-0-0-227 tool]# wget http://www.oberhumer.com/opensource/lzo/download/lzo-2.02.t                                                                                      ar.gz

[root@ip-10-0-0-227 tool]# wget http://down1.chinaunix.net/distfiles/open***-2.0.9.tar.gz

[root@ip-10-0-0-227 tool]# ll

-rw-r--r--  1 root root 599387 Oct 17  2005 lzo-2.02.tar.gz

-rw-r--r--  1 root root 669076 May 13  2008 open***-2.0.9.tar.gz

Lzo是一个压缩模块,在open***进行数据传输的过程压缩数据,可以减少open***在传输过程中的带宽

2.安装过程

在安装open***的时候需要openssl包的支持

[root@ip-10-0-0-227 tool]#yum install openssl* -y

[root@ip-10-0-0-227 tool]#tar zxf lzo-2.02.tar.gz

[root@ip-10-0-0-227 tool]#cd lzo-2.02  

[root@ip-10-0-0-227 lzo-2.02]#./configure            

[root@ip-10-0-0-227 lzo-2.02]#make

[root@ip-10-0-0-227 lzo-2.02]#make install

[root@ip-10-0-0-227 lzo-2.02]#cd ..  

[root@ip-10-0-0-227 tool]# tar zxf open***-2.0.9

[root@ip-10-0-0-227 tool]# cd open***-2.0.9

[root@ip-10-0-0-227 open***-2.0.9]#

./configure --with-lzo-headers=/usr/local/include/ --with-lzo-lib=/usr/local/lib

[root@ip-10-0-0-227 open***-2.0.9]#make

[root@ip-10-0-0-227 open***-2.0.9]#make install

3.初始化服务端设置

[root@ip-10-0-0-227 2.0]# tail -6  vars

# Don't leave any of these fields blank.

export KEY_COUNTRY="CN"

export KEY_PROVINCE="CA"

export KEY_CITY="yiwu"

export KEY_ORG="zhejiang"

export KEY_EMAIL="fun@163.com"

设置一些基本的信息:国家CN、城市、组织、邮箱等

当做ca证书的时候,会读取这里面的文件,我们需要修改成我们自己的

修改完成后,使用source或者 点 进行加载

[root@ip-10-0-0-227 2.0]# source vars

NOTE: If you run ./clean-all, I will be doing a rm -rf on /home/tool/open***-2.0.9/easy-rsa/2.0/keys

[root@ip-10-0-0-227 2.0]# ./clean-all

[root@ip-10-0-0-227 2.0]# ll keys/

total 4

-rw-r--r-- 1 root root 0 Jun  4 16:02 index.txt

-rw-r--r-- 1 root root 3 Jun  4 16:02 serial

[root@ip-10-0-0-227 2.0]# date

Tue Jun  4 16:02:34 UTC 2013

[root@ip-10-0-0-227 2.0]# ./build-ca

Generating a 1024 bit RSA private key

.....++++++

..............................++++++

writing new private key to 'ca.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [CA]:

Locality Name (eg, city) [yiwu]:

Organization Name (eg, company) [zhejiang]:

Organizational Unit Name (eg, section) []:

Common Name (eg, your name or your server's hostname) [zhejiang CA]:

Email Address [fun@163.com]:

[root@ip-10-0-0-227 2.0]# ll keys/

total 12

-rw-r--r-- 1 root root 1180 Jun  4 16:02 ca.crt

-rw------- 1 root root  916 Jun  4 16:02 ca.key

-rw-r--r-- 1 root root    0 Jun  4 16:02 index.txt

-rw-r--r-- 1 root root    3 Jun  4 16:02 serial

生成服务端的key

[root@ip-10-0-0-227 2.0]# ./build-key-server server

Generating a 1024 bit RSA private key

...........................................................++++++

........++++++

writing new private key to 'server.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [CA]:

Locality Name (eg, city) [yiwu]:

Organization Name (eg, company) [zhejiang]:

Organizational Unit Name (eg, section) []:

Common Name (eg, your name or your server's hostname) [server]:

Email Address [fun@163.com]:

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

Using configuration from /home/tool/open***-2.0.9/easy-rsa/2.0/openssl.cnf

Check that the request matches the signature

Signature ok

The Subject's Distinguished Name is as follows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'CA'

localityName          :PRINTABLE:'yiwu'

organizationName      :PRINTABLE:'zhejiang'

commonName            :PRINTABLE:'server'

emailAddress          :IA5STRING:'fun@163.com'

Certificate is to be certified until Jun  2 16:05:52 2023 GMT (3650 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

[root@ip-10-0-0-227 2.0]# ll keys/ -t

total 40

-rw-r--r-- 1 root root 3800 Jun  4 16:05 01.pem

-rw-r--r-- 1 root root   97 Jun  4 16:05 index.txt

-rw-r--r-- 1 root root   21 Jun  4 16:05 index.txt.attr

-rw-r--r-- 1 root root    3 Jun  4 16:05 serial

-rw-r--r-- 1 root root 3800 Jun  4 16:05 server.crt

-rw-r--r-- 1 root root  660 Jun  4 16:05 server.csr

-rw------- 1 root root  916 Jun  4 16:05 server.key

-rw-r--r-- 1 root root 1180 Jun  4 16:02 ca.crt

-rw------- 1 root root  916 Jun  4 16:02 ca.key

-rw-r--r-- 1 root root    0 Jun  4 16:02 index.txt.old

-rw-r--r-- 1 root root    3 Jun  4 16:02 serial.old

生成客户端key

[root@ip-10-0-0-227 2.0]# ./build-key fun

Generating a 1024 bit RSA private key

..........................++++++

.++++++

writing new private key to 'fun.key'

-----

You are about to be asked to enter information that will be incorporated

into your certificate request.

What you are about to enter is what is called a Distinguished Name or a DN.

There are quite a few fields but you can leave some blank

For some fields there will be a default value,

If you enter '.', the field will be left blank.

-----

Country Name (2 letter code) [CN]:

State or Province Name (full name) [CA]:

Locality Name (eg, city) [yiwu]:

Organization Name (eg, company) [zhejiang]:

Organizational Unit Name (eg, section) []:

Common Name (eg, your name or your server's hostname) [fun]:

Email Address [fun@163.com]:

Please enter the following 'extra' attributes

to be sent with your certificate request

A challenge password []:

An optional company name []:

Using configuration from /home/tool/open***-2.0.9/easy-rsa/2.0/openssl.cnf

Check that the request matches the signature

Signature ok

The Subject's Distinguished Name is as follows

countryName           :PRINTABLE:'CN'

stateOrProvinceName   :PRINTABLE:'CA'

localityName          :PRINTABLE:'yiwu'

organizationName      :PRINTABLE:'zhejiang'

commonName            :PRINTABLE:'fun'

emailAddress          :IA5STRING:'fun@163.com'

Certificate is to be certified until Jun  2 16:07:20 2023 GMT (3650 days)

Sign the certificate? [y/n]:y

1 out of 1 certificate requests certified, commit? [y/n]y

Write out database with 1 new entries

Data Base Updated

[root@ip-10-0-0-227 2.0]# ll keys/ -t

total 64

-rw-r--r-- 1 root root 3671 Jun  4 16:07 02.pem

-rw-r--r-- 1 root root 3671 Jun  4 16:07 fun.crt

-rw-r--r-- 1 root root  191 Jun  4 16:07 index.txt

-rw-r--r-- 1 root root   21 Jun  4 16:07 index.txt.attr

-rw-r--r-- 1 root root    3 Jun  4 16:07 serial

-rw-r--r-- 1 root root  655 Jun  4 16:07 fun.csr

-rw------- 1 root root  916 Jun  4 16:07 fun.key

-rw-r--r-- 1 root root 3800 Jun  4 16:05 01.pem

-rw-r--r-- 1 root root   21 Jun  4 16:05 index.txt.attr.old

-rw-r--r-- 1 root root   97 Jun  4 16:05 index.txt.old

-rw-r--r-- 1 root root    3 Jun  4 16:05 serial.old

-rw-r--r-- 1 root root 3800 Jun  4 16:05 server.crt

-rw-r--r-- 1 root root  660 Jun  4 16:05 server.csr

-rw------- 1 root root  916 Jun  4 16:05 server.key

-rw-r--r-- 1 root root 1180 Jun  4 16:02 ca.crt

-rw------- 1 root root  916 Jun  4 16:02 ca.key

[root@ip-10-0-0-227 2.0]# ./build-dh

Generating DH parameters, 1024 bit long safe prime, generator 2

This is going to take a long time

需要注意的是:

不管是生成的服务端的serverkey,还是客户端的key,我们都要注意我们执行的命令是否是真的执行完成,并且成功了,在我搭建open***启动和认证的时候,发现一些错误莫名奇妙的,后来才发现,原来某些key在生成的过程中,可能是由于我的错误,导致key的大小为0,从而导致认证不正确与服务启动不了。

4.拷贝密钥文件

[root@ip-10-0-0-227 2.0]# mkdir /etc/***

[root@ip-10-0-0-227 2.0]# cp -a keys /etc/***/

[root@ip-10-0-0-227 2.0]# tree /etc/***/

/etc/***/

└── keys

   ├── 01.pem

   ├── 02.pem

   ├── ca.crt

   ├── ca.key

   ├── dh1024.pem

   ├── fun.crt

   ├── fun.csr

   ├── fun.key

   ├── index.txt

   ├── index.txt.attr

   ├── index.txt.attr.old

   ├── index.txt.old

   ├── serial

   ├── serial.old

   ├── server.crt

   ├── server.csr

   └── server.key

5.编辑配置文件

[root@ip-10-0-0-227 2.0]# cat /etc/***/fum.conf

port 8091

#open***的监听端口

proto tcp

#协议为tcp

dev tun

#模式为路由模式,可选为tap跟tun

#一下几个为对应密钥或者ca的文件位置,建议使用绝对路径

ca /etc/***/keys/ca.crt

cert /etc/***/keys/server.crt

key /etc/***/keys/server.key

dh /etc/***/keys/dh1024.pem

server 10.8.0.0 255.255.255.0

#*** server动态分配给*** client的地址池

ifconfig-pool-persist ipp.txt

#设置open*** 记录Client 曾经使用过的IP地址

keepalive 10 120

#10ping一次,120秒未接受到包,即认为客户端断线

comp-lzo

#压缩功能

persist-key

#***重启后,不会需要重新认证客户端私钥

persist-tun

#设置***自动连接状态

status open***-status.log

#客户端连接的状态等信息

verb 3

#帮助提供一些调试信息,不应设置过大,否则可能给系统带来一些额外的性能损失

duplicate-cn

#允许一份密钥认证,同时多人登录

push "route 10.8.0.0 255.255.255.0"

#*** server的内网网段

client-to-client

#允许客户端之间互联

log /var/log/open***.log

#日志,如果有什么问题,从日志里往往能得到一些信息

#下面三行则主要是配置×××用的,在我们的一台专用***服务器上进行的配置

push "redirect-gateway def1 bypass-dhcp dypass-dns"  ×××服务器当作自己的网关

push "dhcp-option DNS 8.8.8.8"指定DNS

push "dhcp-option DNS 8.8.4.4"

6.然后在服务器上启动***

[root@ip-10-0-0-227 2.0]# /usr/local/sbin/open*** --config /etc/***/fum.conf &

7.检查启动状态

[root@ip-10-0-0-227 2.0]# ps -ef |grep ***

root     26529     1  0 Jun03 ?        00:00:16 /usr/local/sbin/open*** --config /etc/open***/fum.conf

root     29901 29513  0 16:34 pts/0    00:00:00 grep ***

[root@ip-10-0-0-227 2.0]# netstat -anptu|grep ***

tcp        0      0 0.0.0.0:8091                0.0.0.0:*                   LISTEN      26529/open***

8.配置防火墙

[root@ip-10-0-0-227 ~]# iptables -t nat -A POSTROUTING -o eth0 -s 10.8.0.0/24 -j MASQUERADE

这里我们要将***网段即10.8.0.0的数据全部,改成源地址是服务器外网的地址,即SNAT

-j MASQUERADE的作用:从服务器的网卡上,自动获取当前ip地址来做NAT

-s 10.8.0.0 即源地址是***地址的全部从,服务器的网卡出去

客户端

下载客户端需要的证书文件

几个常用的密钥文件介绍

ca.crt               服务端和客户端都要有,作用CA认证

ca.key key        标识机器的一个加密文件

dh1024.pem      算法文件

server.crt          服务端的认证

server.key         服务端的密钥

fun.crt              客户端的认证

fun.key       客户端的密钥

客户端需要的文件:ca.crt fun.csr fun.crt fun.key 外加一份 客户端的配置文件

这里给出客户端的配置文件

client

dev tun

proto tcp

remote 54.xxx  8090 #服务器的IP地址与端口

resolv-retry infinite

nobind

persist-key

persist-tun

#认证文件

ca ca.crt

cert fun.crt

key fun.key

comp-lzo

verb 3

redirect-gateway def1

#下面这一行配置就是使用open***分配的网关,也是×××的时候用的

8.客户端软件:

XP下适用

http://open***.se/files/install_packages/open***-2.0.9-gui-1.0.3-install.exe

如果是win7 64则可能会出现需要驱动验证签名,可能需要下面的版本

http://***tech.googlecode.com/files/open***-2.1.1-gui-1.0.3-install-cn-64bit.zip

配置文件的位置:C:\Program Files\Open×××\config\

配置方法:在该目录下新建一个文件夹,把从服务器上下载的认证文件放到里面,然后编辑一个txt记事本,加入上面的配置文件,然后重命名为:文件名.o*** 即可

然后单击右下角的连接

连接后的图标样式为

命令行查看

打开www.ip138.com

9.关于钩子的问题

因为与那边的服务器,存在时差的问题,这边提交,但钩子却没办法执行,郁闷了半天,最后没办法只有写脚本了

9.执行自动代码更新的脚本

#!/bin/sh

SVN=/usr/bin/svn

CMD=/bin/tar

date=`/bin/date +%F`

$SVN update --username zjSV --password QYL1 /data/websvn

if [ $? -eq 0 ]

then

     cd /data/website/

     $CMD zcf funm-$date.tar.gz ./funm

     /usr/bin/rsync -az --delete /data/websvn/ /tmp/test

fi

定时任务

# webpro update on every day 0:00

0 0 * * * /bin/sh /home/script/svn.sh >/dev/null 2>&1

制度安排:

开发每天上午把代码更新到web服务器上,然后在上午十一点,美国时间晚12小时,大约接近凌晨的时候,进行网站程序代码的更新