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

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

1、下载安装 subversion

yum -y install subversion

测试安装是否成功

svnserve --version

0.png

1.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客户端就可以检出了,如下图填写


2.png

2.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一样。


3.png

3.png

4.png

相关文章
|
18天前
|
Java Linux Shell
linux自动部署jar包,注册系统服务(基于Centos7)
linux自动部署jar包,注册系统服务(基于Centos7)
138 0
|
18天前
|
安全 算法 Linux
CentOS7下部署长亭科技雷池Web应用防火墙(WAF)开源社区版
CentOS7下部署长亭科技雷池Web应用防火墙(WAF)开源社区版
579 0
|
18天前
|
缓存
详解CentOS8更换yum源后出现同步仓库缓存失败的问题
详解CentOS8更换yum源后出现同步仓库缓存失败的问题
166 0
|
18天前
|
Java Shell Linux
解决 centos下执行sh文件报错“/bin/bash^M: 坏的解释器:没有那个文件或目录” 问题
解决 centos下执行sh文件报错“/bin/bash^M: 坏的解释器:没有那个文件或目录” 问题
113 0
|
7月前
|
Linux 应用服务中间件 nginx
CentOS7搭建yum源仓库(阿里源)
CentOS7搭建yum源仓库(阿里源)
1218 0
|
18天前
|
Linux
Centos7.4升级7.9失败,救援:/boot目录下文件丢失error: file ‘/initramfs-3.10.0-957.el7.x86_64.img‘ not found
以上步骤应该可以帮助你解决问题。如果问题仍然存在,可能需要更深入的排查。
47 1
|
18天前
SVN 如何将分支代码合并回主干
SVN 如何将分支代码合并回主干
16 0
|
6月前
|
Linux
centos之--目录权限配置
CentOS中,可以使用chmod命令来设置文件夹的权限
186 0
|
18天前
|
自然语言处理 Shell 网络安全
Liunx服务器搭建SVN服务,并通过钩子实现代码自动部署
Liunx服务器搭建SVN服务,并通过钩子实现代码自动部署
39 3
|
18天前
|
安全 Linux 网络安全
百度搜索:蓝易云【公网访问的Linux CentOS本地Web站点搭建指南】
请注意,将Web站点放在公网上可能涉及安全风险,建议您确保Web应用程序的安全性,并根据需要进行必要的防护措施,如防火墙设置、使用HTTPS等,以保障您的服务器和数据的安全。
127 0

热门文章

最新文章