Centos7搭建SVN服务(多个仓库)并利用svn 钩子(hooks)自动部署仓库代码到指定web目录

  • 内容
  • 评论
  • 相关

1、下载安装 subversion
yum -y install subversion
测试安装是否成功
svnserve --version

1.png2.png

2、创建 svn 版本库,初始化相关配置文件

[root@iZ2zegxpw7sisogrymd96zZ server]# mkdir -p    www/server/svnserver/svnrepos/web1
[root@iZ2zegxpw7sisogrymd96zZ server]# mkdir -p    www/server/svnserver/svnrepos/web2
[root@iZ2zegxpw7sisogrymd96zZ server]# svnadmin create   www/server/svnserver/svnrepos/web1
[root@iZ2zegxpw7sisogrymd96zZ server]# svnadmin create   www/server/svnserver/svnrepos/web2

进入web1仓库目录下的conf文件夹,将其中的authz与passwd文件复制到svnrepos目录

[root@iZ2zegxpw7sisogrymd96zZ conf]# cp authz  ../../
[root@iZ2zegxpw7sisogrymd96zZ conf]# cp passwd  ../../



然后修改web1/conf下的svnserve.conf文件,将其中的passwd文件制定与authz文件制定进行修改,其他配置按正常单svn配置。(web2仓库同样设置一遍)

[general]
anon-access = read
auth-access = write
password-db =../../passwd      //根据实际情况写路径,我这里是拿到了www/server/svnserver/svnrepos目录
authz-db =../../authz               //根据实际情况写路径,我这里是拿到了www/server/svnserver/svnrepos目录
realm = My First Repository
[sasl]

解释:
anon-access = none:表示禁止匿名用户访问。
auth-access = write:表示授权用户拥有读写权限。
password-db = passswd:指定用户名口令文件,即 passwd 文件。
authz-db = authz:指定权限配置文件,即 authz 文件。


编辑svn用户配置文件,我这里的是www/server/svnserver/svnrepos/passwd文件

[users]

#用户名=密码
wl=905507
wl1=9055071


编辑svn权限控制配置文件我这里的是www/server/svnserver/svnrepos/authz文件

[aliases]
[groups]
#用户组名=用户名
admin=wl,wl1
[/]
#表示用户组admin对根目录有读写的权限,r为读,w为写
@admin=rw

到此配置结束,web1仓库和web2仓库公用www/server/svnserver/svnrepos/下面的限控制配置文件(authz)和用户配置文件passwd 

3.启动svn服务
svnserve -d --listen-port 3389 -r   /www/server/svnserver/svnrepos/

监听3389端口,这里我改过默认端口3690 ,-r指定目录,我的两个仓库web1和web2在 /www/server/svnserver/svnrepos/这个目录下面。

在window上用svn客户端就可以检出了,如下图填写

10.png


4.实现一个仓库对应一个web站点,通过windos客户端提交代码到仓库以后利用svn的钩子 hooks自动把代码同步到指定的web站点,然后通过域名打开直接访问。

新建web站点,建立成功之后我的web1目录是:/www/wwwroot/web1.php5.wlphp.com

新建web站点,建立成功之后我的web2目录是:/www/wwwroot/web2.php5.wlphp.com

找到每个仓库的钩子配置文件做修改

/www/server/svnserver/svnrepos/web1/hooks

/www/server/svnserver/svnrepos/web1/hooks

把web1/hooks目录下的post-commit.tmpl拷贝下重命名

cp  post-commit.tmpl  post-commit

vim  post-commit

然后修改里面内容如下,里面其他内容保留,最底部可能有一个发送邮件的脚本,可以注释掉他。


WEB=/www/wwwroot/web2.php5.wlphp.com   //定制web目录
cd $WEB && /usr/bin/svn update --username  wl  --password 905507 --no-auth-cache   进入web目录然后执行svn的update ,指定svn用户名密码


给该脚本增加执行权限

chmod +x   post-commit

然后我们到web1的web站点目录首次执行下checkout,后面就不需要了。


svn  checkout   svn://101.200.88.170:3389/web1   ./            // 这里需要注意 最后的 ./ 参数要有否则会出来一个二级目录


首次checkout,需要输入root的密码,然后验证svn的账号密码,保存密码输入yes即可

Authentication realm: <svn://101.200.88.170:3389> My First Repository
Password for 'root': 
Authentication realm: <svn://101.200.88.170:3389> My First Repository
Username: wl
Password for 'wl': 
-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:
   <svn://101.200.88.170:3389> My First Repository
can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.
You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Please type 'yes' or 'no': yes
Checked out revision 0.

然后通过windows客户端首次checkout版本库web1,提交代码测试下我们的成果吧。
web2的操作流程和web1一样。

12.png13.png






本文标签:

版权声明:若无特殊注明,本文皆为《菜鸟站长》原创,转载请保留文章出处。

本文链接:Centos7搭建SVN服务(多个仓库)并利用svn 钩子(hooks)自动部署仓库代码到指定web目录 - http://wlphp.com/?post=220

发表评论

电子邮件地址不会被公开。 必填项已用*标注