天天记事 443 / 2022-03-07 18:48:41
一、CentOS安装subversion及配置方法
1. 安装subversion
#遇到其它问题,可百度找答案,如:CentOS无法安装/更新subversion,可能需要更改yum的配置
这把操作过程遇到的解决方法也一同放这里(仅记录一些必要命令)
#备份原有东西,如需要用下面脚本,可去除注释
#cd /opt/yum.repos.d/
#sudo mkdir backup
#sudo mv *repo backup/
#sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-8.repo
#sudo sed -i -e "s|mirrors.cloud.aliyuncs.com|mirrors.aiyun.com|g" /etc/yum.repos.d/CentOS-*
#sudo -i -e "s|releasever|releasever-stream|g" /etc/yum.repos.d/CentOS-*
#sudo yum clean all
#sudo yum makecache
sudo yum -y install subversion
2. 创建版本库(多个版本库,sources、softs和docs)
mkdir /opt/svndir
svnadmin create /opt/svndir/sources
svnadmin create /opt/svndir/softs
svnadmin create /opt/svndir/docs
3. 配置统一管理账户(创建三个svn账号:user1、user2和user3,密码都是1234567890,保存到passwd.txt文件中)
echo [users]>passwd.txt
echo user1=1234567890>>passwd.txt
echo user2=1234567890>>passwd.txt
echo user3=1234567890>>passwd.txt
4. 为账户分配资源权限(权限统一配置到authz.txt文件中)
echo [sources:/]>authz.txt
echo user1=rw>>authz.txt
echo [softs:/]>>authz.txt
echo user1=rw>>authz.txt
echo user2=r>>authz.txt
echo user3=r>>authz.txt
echo [docs:/]>>authz.txt
echo user1=rw>>authz.txt
echo user3=rw>>authz.txt
#authz.txt生成的内容如下
[sources:/]
user1=rw
[softs:/]
user1=rw
user2=r
user3=r
[doc:/]
user1=rw
user3=rw
5. 将账户和授权绑定到版本库
编辑如下位置的svnserve.conf文件
/opt/svndir/sources/conf/svnserve.conf
/opt/svndir/softs/conf/svnserve.conf
/opt/svndir/docs/conf/svnserve.conf
统一修改为如下内容
[general]
anon-access=none
auth-access=write
password-db=/opt/svndir/passwd.txt
authz-db=/opt/svndir/authz.txt
realm=welcome
[sasl]
操作方法:
echo [general]>/opt/svndir/sources/conf/svnserve.conf
echo anon-access=none>>/opt/svndir/sources/conf/svnserve.conf
echo auth-access=write>>/opt/svndir/sources/conf/svnserve.conf
echo password-db=/opt/svndir/passwd.txt>>/opt/svndir/sources/conf/svnserve.conf
echo authz-db=/opt/svndir/authz.txt>>/opt/svndir/sources/conf/svnserve.conf
echo realm=welcome to sources>>/opt/svndir/sources/conf/svnserve.conf
echo [sasl]>>/opt/svndir/sources/conf/svnserve.conf
echo [general]>/opt/svndir/softs/conf/svnserve.conf
echo anon-access=none>>/opt/svndir/softs/conf/svnserve.conf
echo auth-access=write>>/opt/svndir/softs/conf/svnserve.conf
echo password-db=/opt/svndir/passwd.txt>>/opt/svndir/softs/conf/svnserve.conf
echo authz-db=/opt/svndir/authz.txt>>/opt/svndir/softs/conf/svnserve.conf
echo realm=welcome to softs>>/opt/svndir/softs/conf/svnserve.conf
echo [sasl]>>/opt/svndir/softs/conf/svnserve.conf
echo [general]>/opt/svndir/docs/conf/svnserve.conf
echo anon-access=none>>/opt/svndir/docs/conf/svnserve.conf
echo auth-access=write>>/opt/svndir/docs/conf/svnserve.conf
echo password-db=/opt/svndir/passwd.txt>>/opt/svndir/docs/conf/svnserve.conf
echo authz-db=/opt/svndir/authz.txt>>/opt/svndir/docs/conf/svnserve.conf
echo realm=welcome to docs>>/opt/svndir/docs/conf/svnserve.conf
echo [sasl]>>/opt/svndir/docs/conf/svnserve.conf
6. 启动svn服务
svnserve -d -r /opt/svndir --listen-port 8900 --log-file svn.log
7. 查看进程是否启动
ps -Al|grep svnserve
或
netstat -anop|grep svnserve
或
telnet 127.0.0.1 8900
8. 测试服务
网络服务测试,停止防火墙
systemctl stop firewalld.service
访问svn
svn://192.168.100.203:8900/sources
svn://192.168.100.203:8900/softs
svn://192.168.100.203:8900/docs
再启动防火墙
systemctl start firewalld.service
#通常安全操作方法,将svn端口加入防火墙白名单
将svn服务端口加入防火墙白名单
firewall-cmd --zone=public --add-port=8900/tcp --permanent
#如果弄错了,也可以从防火墙移出去
#firewall-cmd --zone=public --remove-port=8900/tcp --permanent
重启防火墙
systemctl restart firewalld.service
#再次访问
svn://192.168.100.203:8900/sources
svn://192.168.100.203:8900/softs
svn://192.168.100.203:8900/docs
二、安装httpd及配置
1. 安装httpd
sudo yum -y install httpd
2. 启动服务
systemctl start httpd
3. 访问测试,httpd默认启用80端口
http://127.0.0.1/
4. 停止掉服务修改默认配置
systemctl stop httpd
4. 修改配置
vim /etc/httpd/conf/httpd.conf
[端口]
找到下面这一行配置
Listen 80
将后面80修改为其它端口,如8089
[工作目录]
找到下面这一行配置
DocumentRoot "/var/www/html"
将后面目录修改为自己的目录:
DocumentRoot "/opt/www/html"
(注意:如果没有的话,创建一个:
mkdir -p /opt/www/html && echo welcome>/opt/www/html/index.html
)
[配置目录权限及其它限制特性]
<Directory "/opt/www/html">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
5. 启动httpd并测试访问
http://localhost:8089/
(注意,默认情况下,可能你需要关闭CentOS-8的SELinux,这样才能修改端口!
vim /etc/selinux/config
将里面SELINUX修改为下面这样
SELINUX=disabled
保存,重启Linux)
三、整合svn和httpd
1. 为httpd安装WebDav支持(把svnserve和httpd都停止掉
systemctl stop httpd.service
killall svnserve
)
sudo yum install -y httpd mod_dav_svn
2. 设置账号文件
需要注意的是,这里的账号密码和svnserve的账号密码文件不一样,需要加密,同时文件格式也不一样
我们可以通过下面命令来配置上面用到的账号
#创建密码文件并写入账号密码(密码是加密的)
touch /opt/svndir/htpasswd.txt
htpasswd -b /opt/svndir/htpasswd.txt user1 1234567890
htpasswd -b /opt/svndir/htpasswd.txt user2 1234567890
htpasswd -b /opt/svndir/htpasswd.txt user3 1234567890
3. 配置svn虚拟路径,注意,我这里使用的是多个仓库,所以使用SVNParentPath属性配置仓库跟路径,另外,授权文件AuthUserFile指向上面密码文件,最后,授权文件和svn配置的保持一致。
<Location /svn/>
DAV svn
SVNListParentPath off
SVNParentPath /opt/svndir
AuthType Basic
AuthName "Subversion repositories"
AuthUserFile /opt/svndir/htpasswd.txt
AuthzSVNAccessFile /opt/svndir/authz.txt
Require valid-user
AllowOverride All
</Location>
4. 授权目录访问权限
sudo chown -R apache:apache /opt/svndir/sources
sudo chown -R apache:apache /opt/svndir/softs
sudo chown -R apache:apache /opt/svndir/docs
5. 开启http服务的防火墙端口
firewall-cmd --zone=public --add-port=8089/tcp --permanent
6. 启动httpd服务,注意了,这里将svn服务整合到了httpd,不用再启动svnserve服务。
systemctl start httpd.service
7. 访问资源
http://192.168.100.203:8089/svn/sources/
#通过上面authz.txt配置可知,仅user1具有读写权限,其它用户无权限
http://192.168.100.203:8089/svn/softs/
#通过上面authz.txt配置可知,user1具有读写权限,user2和user3只有只读权限
http://192.168.100.203:8089/svn/docs/
#通过上面authz.txt配置可知,user1具有读写权限,user3有读写权限,user2无权限
8. 停止httpd服务
systemctl stop httpd.service
到此,在CentOS下面搭建http协议下的svn环境结束。
需要注意的是,http协议交互文件是不安全的,一般建议在httpd基础上结合SSL一起来做,所以需要申请个数字证书,可通过阿里云、腾讯云或百度云去申请个免费的用。
四、Ubuntu安装 apache + svn,直接上命令:
sudo apt install subversion apache2 libapache2-svn
执行上面命令时,可能出现找不见libapache2-svn提示,此时换下面的
sudo apt install subversion apache2 libapache2-mod-svn
配置方法同CentOS
启停apache2的方法一样,仅是服务名称不一样,如下:
#停止服务
systemctl stop apache2
#启动服务
systemctl start apache2