ubuntu+apache+subversion+LDAP:ubuntu+svn+apache配置_Rocket MAN的博客-CSDN博客
window + apache + subversion :https://blog.csdn.net/qq_41566366/article/details/114101392
目录
故障一:Failed to start The Apache HTTP Server.
故障二:httpd (pid xxx) already running
故障四:svn:E175013 禁止访问‘xxx’ & error.log 显示 /svn/authz permissions denied
故障五:服务器发送了意外的返回值(405 Method Not Allowed)
故障七:could not begin a transaction
故障一:执行报错:svn: E175002: 服务器发送了意外的返回值(500 Internal Server Error)
故障二:svn: E175002: 方法 OPTIONS 失败于 “http://xxx/xxx/xxx”
服务器环境 centos 7
[root@Server-CentOS7 ~]# uname -a
Linux Server-CentOS7 3.10.0-1062.el7.x86_64 #1 SMP Wed Aug 7 18:08:02 UTC 2019 x86_64 x86_64 x86_64 GNU/Linux
软件安装
安装subversion
yum -y install subversion # -y 默认yes
报错:[Errno 14] HTTP Error 416 - Requested Range Not Satisfiable 正在尝试其它镜像。
再次执行上面的命令,成功!
查看svn版本
svn --version
svn,版本 1.7.14 (r1542130)
编译于 Sep 30 2020,17:44:04
安装apache
yum -y install httpd # -y 默认yes
httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 16 2020 16:18:20
安装mod_dav_svn
yum -y install mod_dav_svn
安装mod_ldap
用于ldap验证,ldap验证的配置,文章最后
yum install mod_ldap -y
可以看到在 /etc/httpd/modules中新增了mod_authnz_ladp.so 和 mod_ldap.so两个文件
创建版本库
用root身份创建版本库,授权给apache
sudo mkdir /svn
cd /svn
sudo svnadmin create repoTest1
sudo chown -R apache:apache repoTest1
创建passwd账号文件
sudo mkdir /etc/svn
sudo htpasswd -cm /etc/svn/passwd user01
sudo chown root:apache /etc/svn/passwd
sudo chmod 640 /etc/svn/passwd
创建authz权限文件
sudo cp /svn/repoTest1/conf/authz /svn/authz
sudo vi /svn/authz
配置authz文件
[groups]
# harry_and_sally = harry,sally
# harry_sally_and_joe = harry,sally,&joe
admin=user001
[/]
@admin=rw
[repoTest1:/]
@admin=rw
配置apache,账号密码访问
配置10-subversion.conf文件
在apache中配置svn版本库
sudo vim /etc/httpd/conf.modules.d/10-subversion.conf
<Location /svn>
DAV svn
SVNParentPath /svnSVNListParentPath on # on 配合 authz中权限配置,可以访问根目录/svn,否则最高只能访问到版本库.
AuthName "SVN Repos"
AuthType Basic
AuthUserFile /etc/svn/passwd
AuthzSVNAccessFile /svn/authz
Require valid-user
</Location>
故障一:Failed to start The Apache HTTP Server.
检查apache状态
sudo systemctl status httpd.service -l --no-pager
(该--no-pager
标志会将整个日志输出到您的屏幕,而无需调用less
仅一次显示一个内容屏幕的工具。需要注意的是,如果使用该命令输出不一定代表着apache启动失败,因为他显示的历史消息。如果运行 sudo systemctl restart httpd.service成功后再执行上面的命令,apache 的状态就会更新为成功的状态)
这个时候报错:Failed to start The Apache HTTP Server.
当然你也可以使用下面的命令,它可以排查出apache的问题
sudo apachectl configtest
Output
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::c485:ac87:7cd7:1e98. Set the 'ServerName' directive globally to suppress this message
Syntax OK
解决方法:设置全局servername
sudo vim /etc/httpd/conf/httpd.conf
在末尾添加
ServerName 127.0.0.1
再次执行apache检查程序输出 Syntax OK,说明apache配置没什么问题了
sudo apachectl configtest
output
Syntax OK
故障二:httpd (pid xxx) already running
再次检查apache状态,报错端口已存在,我们来处理端口问题
sudo systemctl status httpd.service -l --no-pager
查看使用pid 7055 的是哪个进程,多次kill杀掉该pid
netstat -antup|grep 7055
kill -9 7055
彻底杀掉后再次执行下面的命令还是会说pid被占用,这个原因上面已经说了,是由于该命令记录的是历史信息
sudo systemctl status httpd.service -l --no-pager
重启httpd即可
sudo systemctl restart httpd.service
故障三:浏览器访问显示无法访问此网站
win 浏览器访问地址 IP:port/svn/repoTest1
打开http服务端口并重启防火墙
sudo firewall-cmd --zone=public --permanent --add-service=http
sudo firewall-cmd --reload
再次访问浏览器
故障四:svn:E175013 禁止访问‘xxx’ & error.log 显示 /svn/authz permissions denied
似乎浏览器上弹出了校验账号密码的框就说明没有问题了,事情没有那么简单
在服务器端输入:
svn info --username user01 http://localhost/svn/repoTest1
查看httpd日志
tail -6 /etc/httpd/logs/error_log
有人说这是因为selinux,需要引用下面的selinux规则
chcon -R -t httpd_sys_content_t /svn/repoTest1
chcon -R -t httpd_sys_rw_content_t /svn/repoTest1
重启服务器
systemctl restart httpd.service
systemctl enable httpd.service
再次在服务器端访问,提示/svn/authz Permission denied ,我把/svn 和 /svn/authz 权限设置成了777还是不行,可以确定不是目录权限的问题
svn info --username user01 http://localhost/svn/repoTest1
于是一不做二不休,把上面修改selinux的目录更改为根目录/svn 并重启
chcon -R -t httpd_sys_content_t /svn
chcon -R -t httpd_sys_rw_content_t /svn
systemctl restart httpd.service
systemctl enable httpd.service
再次在服务器端访问,奇怪了,这一次成功了
访问浏览器:
故障五:服务器发送了意外的返回值(405 Method Not Allowed)
这个错误是在使用svn info访问版本库根目录的时候错处的
上面已经说过,svn中你既可以设置每个库一个单独的authz和passwd,也可以设置所有库共用相同的authz和passwd来统一管理,仅仅是配置文件/etc/httpd/conf.modules.d/10-subversion.conf 中,使用SVNPath还是SVNParentPath 。
如果我们采用第二种方式,配置文件中的SVNListParentPath on 将可以让我们访问版本库上一层目录,这样可以很方便的在小乌龟repo reporitory 中切换不同版本库查看。上面我们已经增加了这个配置。
在小乌龟和浏览器中我们可以顺利访问根目录:
不过如果通过服务器中的命令行svn来访问,就会出错 服务器发送了意外的返回值(405 Method Not Allowed)
error.log中
这里我没有深究是什么原因,只要能在tortoisesvn中访问就可以了
故障六:使用小乌龟tortoisesvn卡住
这个问题整整折磨了我两个月之久,表现形式为:
1、浏览器访问正常
2、同样两个端口指向同一地址的svn版本库,有的人A端口正常B卡住,有的人B端口正常A卡住,有的AB都会卡住,或者时访问提示The Server sent an improper HTTP response.
我一度陷入了崩溃,甚至一度怀疑是客户端和服务器版本不对应或者小乌龟软件自身的故障(因为同样的地址我用smartsvn就没有这种情况)造成的问题,所以把大量时间浪费在找软件自身的问题上,心酸啊。
而且这个问题网上答案寥寥无几,国外很多大神说着可能与网路环境或者安全软件将小乌龟批量流量识别为Dos攻击后屏蔽有关,为此我甚至动用了windos debug工具debView查看小乌龟进程,甚至让运维关闭了安全软件,都没有找到完美的答案。
最后怎么解决的呢?我们公司处于安全考虑,每个客户端都会安装加密系统,不知道为什么,这个加密系统会对tortoisesvn发出的请求进行拦截,所以每次tortoisesvn发出请求,都会被莫名其妙的卡住,而且关还关不掉,必须在任务管理器中才能关闭。在此之前运维从没想过这方面的问题,后来他们找到厂商才解决了的。
故障七:could not begin a transaction
这个还是selinux的问题
getsebool -a | grep httpd_unified
httpd_unified --> off
设置为on
setsebool -P httpd_unified on
chcon -R -t httpd_sys_content_rw_t /svn
如果设置了还是报错could not begin a transaction,查看一下目录权限是否是apache权限
配置Apache,LADP代替账号密码访问
文章开头,我们已经下载了 mod_ldap ,那么现在我们来修改配置文件,配置用LDAP方式代替账号密码的方式
配置10-subversion.conf文件
sudo vim /etc/httpd/conf.modules.d/10-subversion.conf
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
LoadModule dontdothat_module modules/mod_dontdothat.so
<Location /svn>
DAV svn
SVNParentPath /svn
SVNListParentPath on
AuthName "SVN Repos"
AuthType Basic
AuthzSVNAccessFile /svn/authz
# Use passwd
#AuthUserFile /etc/svn/passwd
#Require valid-user
Use LDAP auth against an active directory
AuthBasicProvider ldap
AuthLDAPBindDN "CN=ldap,OU=developer,DC=your_domain,DC=edu"
AuthLDAPBindPassword your_password
AuthLDAPURL ldap://IP:389/OU=developer,DC=your_domain,DC=edu?sAMAccountName?sub?(objectClass=*) NONE
Require ldap-attribute objectClass=user
</Location>
重启:
sudo systemctl restart httpd.service
故障一:执行报错:svn: E175002: 服务器发送了意外的返回值(500 Internal Server Error)
svn info --username F20G001588 http://localhost/svn/repoTest1
看了外网stackExchange的说法,原因还是因为selinux,selinux有很多关于httpd进程的配置项,可以找到完整列表
getsebool -a | grep httpd
可以看到httpd_can_connect_ladp处于关闭状态,执行下面公式开始该项
setsebool -P httpd_can_connect_ldap on
故障二:svn: E175002: 方法 OPTIONS 失败于 “http://xxx/xxx/xxx”
再次执行svn info 报错:svn: E175002: 方法 OPTIONS 失败于 “http://localhost/svn/repoTest1”
svn info --username F20G001588 http://localhost/svn/repoTest1
重启服务器,发现报错了
systemctl restart httpd.service
原来是在解决前面出现的问题的时候我在/etc/httpd/conf.modules.d/10-subversion.conf 中增加了 LDAPVerifyServerCert Off ,去除掉再次重启,接着用LDAP方式访问,成功!
限制用户使用svn命令
任何可以登录shell的用户都有权限使用svn,这样会给系统造成很大的隐患,我们需要限制只有root用户/sudo权限/apache组这三类可以使用svn
ll -a /usr/bin | grep svn
-rwxr-xr-x. 1 root root 238024 10月 1 2020 svn
-rwxr-xr-x. 1 root root 69016 10月 1 2020 svnadmin
-rwxr-xr-x. 1 root root 36168 10月 1 2020 svndumpfilter
-rwxr-xr-x. 1 root root 69064 10月 1 2020 svnlook
-rwxr-xr-x. 1 root root 52776 10月 1 2020 svnrdump
-rwxr-xr-x. 1 root root 85960 10月 1 2020 svnserve
-rwxr-xr-x. 1 root root 52832 10月 1 2020 svnsync
-rwxr-xr-x. 1 root root 15512 10月 1 2020 svnversion
sudo chmod 750 /usr/bin/svn*
#sudo chown root:apache /usr/bin/svn*
sudo systemctl restart httpd.service
说明一:关于权限需要说明几点
1、svn的权限只分‘r’和‘w’,和linux目录不一样,没有‘x’执行权限,r代表读,w代表写、修改、删除权限;
2、如果需要设置默认全员权限,可以使用‘*=‘,例如*=代表全员无读写权限,*=r 代表全员可读,*=rw代表全员可读写。如下,代表根目录全员不可读写
[/]
*=
3、权限可以追加,例如实现全仅管理员可读写,其他人无权读写
[/]
*=
@admin=rw
4、权限可以继承
例如admin组成员在根目录中已经有rw权限,那么在下面的子目录中,如果没有特别说明,都是有rw权限的。在子目录中要有权限,不管是r还是rw,在上一层的父目录中也一定要有r权限。关于这块的详细说明,请看Apache与Svn的整合及apache的账号权限设置 最后一段
需要特别注意的是使用‘*=’(所有人禁止读写),“*=r”(所有人只读) ,"*=rw"(所有人读写权限)时,他所在的目录将重置该目录的权限,使得本目录及以下权限无法继承上级目录权限。
如下:代表admin对repo1拥有读写权限,但是D2任何人都没有权限
[/]
*=
@admin=r
[repo1:/]
@admin=rw
[repo2:/]
*=
How to Setup an Apache Subversion (SVN) Server on CentOS 7:How to Setup an Apache Subversion (SVN) Server on CentOS 7 - Vultr.com
Install and Configure Apache Subversion (SVN) on CentOS 7 : Install Apache Subversion (SVN) on RHEL 8 / Rocky Linux 8
svn: E175002: 服务器发送了意外的返回值(500 Internal Server Error)解决方法: linux - apache got internal error when access ldap module - Super User