Centos 6.5上Apache + PAM + SVN服务安装配置(使用本地系统用户认证)

类别:原创 服务器 php

本文参考html


svn 基础搭建 参考 http://jedy82.blog.51cto.com/425872/1395834linux

http://blog.csdn.net/sxhong/article/details/9176881    
svn 操做命令 参考 http://blog.csdn.net/gexiaobaohelloworld/article/details/7752862apache

本地用户访问权限配置参考:http://f2blog.ssorc.tw/rewrite.php/read-309.htmlvim


第一:说明,软件说明,和安装的目的
架设基于linux下的SVN服务器,进行版本控制,并使用本地系统用户名和密码进行登录认证。 服务器


第二:本例操做环境
所使用的系统环境为 Centos 6.5 64位操做系统 ide

[root@tian ~]# uname -a    
Linux tian.test.com 2.6.32-431.11.2.el6.x86_64 #1 SMP Tue Mar 25 19:59:55 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux    
[root@tian ~]# hostname    
tian.test.com    
[root@tian ~]# more /etc/redhat-release    
CentOS release 6.5 (Final)    
[root@tian ~]# svn


第三:服务器安装和基本配置
1.  安装必须的软件包

mod_dav_svn    
subversion    
httpd 测试

[root@tian ~]# yum install mod_dav_svn subversion httpd -y  
[root@tian ~]# httpd -v    
Server version: Apache/2.2.15 (Unix)    
Server built:   Apr  3 2014 23:56:16    
[root@tian ~]#    
[root@tian ~]# svnserve --version    
svnserve, version 1.6.11 (r934486)    
  compiled Mar  6 2014, 10:49:10 ui

后面省略

[root@tian ~]#


2.建立svn仓库
有了SVN软件后还须要创建SVN库,创建两个示例库test1 test2    
[root@tian ~]# mkdir /svndata    
[root@tian ~]# svnadmin  create /svndata/test1/    
执行上面的命令后,自动创建多个文件, 分别是conf, db, format, hooks, locks, README.txt    
[root@tian ~]# ls /svndata/test1/    
conf  db  format  hooks  locks  README.txt    
[root@tian ~]# svnadmin  create /svndata/test2    
[root@tian ~]#    
[root@tian ~]# cat /etc/httpd/conf/httpd.conf | grep apache | grep -v "#"    
User apache    
Group apache    
[root@tian ~]#    
[root@tian ~]# grep apache /etc/passwd    
apache:x:48:48:Apache:/var/www:/sbin/nologin    
[root@tian ~]#    
[root@tian ~]# chown apache -R /svndata
[root@tian ~]# chmod -R 700  /svndata   
[root@tian ~]# ll /svndata/    
total 8    
drwx------ 6 apache root 4096 Apr 16 10:14 test1    
drwx------ 6 apache root 4096 Apr 16 10:32 test2

 


3.配置apache
[root@tian ~]# vi /etc/httpd/conf/httpd.conf    
\\修改ServerName,不然启动apache会报错 修改后以下    
[root@tian ~]# cat /etc/httpd/conf/httpd.conf | egrep ServerName |egrep -v "^#|^$"    
ServerName localhost 


4.查看svn的apache模块
[root@tian ~]# ll /etc/httpd/modules/mod_* | grep svn    
-rwxr-xr-x 1 root root  13456 Mar  6 18:52 /etc/httpd/modules/mod_authz_svn.so    
-rwxr-xr-x 1 root root 153472 Mar  6 18:52 /etc/httpd/modules/mod_dav_svn.so    
[root@tian ~]#


5.简单配置svn
[root@tian ~]# vim /etc/httpd/conf.d/subversion.conf    
[root@tian ~]# cat /etc/httpd/conf.d/subversion.conf |egrep -v "^#|^$"    
subversion.conf的详细内容(去掉注释后):

LoadModule dav_svn_module     modules/mod_dav_svn.so  
LoadModule authz_svn_module   modules/mod_authz_svn.so    
<Location /svn/test1>    
  DAV svn    
  SVNPath /svndata/test1    
</Location>    
<Location /svn/test2>    
  DAV svn    
  SVNPath /svndata/test2    
</Location>    
[root@tian ~]#


6.启动httpd服务
[root@tian ~]# service httpd restart    
Stopping httpd:                                            [FAILED]    
Starting httpd:                                            [  OK  ]    
[root@tian ~]#

 

7.开机启动httpd服务

[root@tian ~]# chkconfig httpd on

 

这个配置的内容是最基本,没有指定认证方式,因此是能够匿名访问的,在访问时使用的路径是:http://host/svn/test1  及 http://host/svn/test2


第四:进阶配置(使用http方式认证)
1.设置密码文件
[root@tian ~]# htpasswd -cm /etc/svn-passwd-file-test1  tian    
New password:    
Re-type new password:    
Adding password for user tian    
[root@tian ~]# more /etc/svn-passwd-file-test1  
tian:$apr1$Np79jiyx$TAATTmBzK5DM8zP2hJJsm/    
[root@tian ~]#


2.设置权限文件
[root@tian ~]# cat >> /etc/svn-authz-file-test1 <<EOF    
[/]    
tian=rw    
EOF    
[root@tian ~]# more /etc/svn-authz-file-test1    
[/]    
tian=rw    
[root@tian ~]#    
[root@tian ~]# cp /etc/svn-passwd-file-test1 /etc/svn-passwd-file-test2    
[root@tian ~]# cp /etc/svn-authz-file-test1 /etc/svn-authz-file-test2    
[root@tian ~]#


3.修改配置文件
[root@tian ~]# vim /etc/httpd/conf.d/subversion.conf    
subversion.conf的详细内容:    
[root@tian ~]# cat /etc/httpd/conf.d/subversion.conf |egrep -v "^#|^$"    
LoadModule dav_svn_module     modules/mod_dav_svn.so    
LoadModule authz_svn_module   modules/mod_authz_svn.so    
<Location /svn/test1>    
  DAV svn    
  SVNPath /svndata/test1    
     AuthType Basic    
     AuthName "Authorization Realm"    
     AuthzSVNAccessFile /etc/svn-authz-file-test1          \\ 权限认证文件    
     AuthUserFile /etc/svn-passwd-file-test1               \\ 密码文件    
     Require valid-user    
</Location>    
<Location /svn/test2>    
  DAV svn    
  SVNPath /svndata/test2    
     AuthType Basic    
     AuthName "Authorization Realm"    
     AuthzSVNAccessFile /etc/svn-authz-file-test2           \\ 权限认证文件    
     AuthUserFile /etc/svn-passwd-file-test2                \\ 密码文件    
     Require valid-user    
</Location>    
[root@tian ~]#


4.重启服务
[root@tian ~]# service  httpd restart    
Stopping httpd:                                            [  OK  ]    
Starting httpd:                                            [  OK  ]    
[root@tian ~]#

这个配置的内容是中指定了认证方式,在访问时使用的路径是:http://host/svn/test1http://host/svn/test2
输入用户名和密码能够登陆表示成功!


5.测试
[root@tian ~]# svn co --username tian --password 123456 http://127.0.0.1/svn/test1 svn/test1    
Checked out revision 0.    
[root@tian ~]# ls svn/test1/    
[root@tian ~]# touch  svn/test1/aa    
[root@tian ~]# touch  svn/test1/bb    
[root@tian ~]# svn add svn/test1/aa svn/test1/bb    
A         svn/test1/aa    
A         svn/test1/bb    
[root@tian ~]# svn ci -m "test"  svn/test1/aa svn/test1/bb    
Adding         svn/test1/aa    
Adding         svn/test1/bb    
Transmitting file data ..    
Committed revision 1.    
[root@tian ~]#    
[root@tian ~]# ls svn/test1/                              
aa  bb    
[root@tian ~]# svn update svn/test1/    
At revision 1.    
[root@tian ~]#


第五:进阶配置(使用pam认证,使用本地系统用户)

1.安装pam模块    

[root@tian ~]# ls /etc/httpd/modules/mod_auth_pam.so    
ls: cannot access /etc/httpd/modules/mod_auth_pam.so : No such file or directory    
[root@tian ~]# ls /etc/httpd/modules/mod_auth_sys_group.so    
ls: cannot access /etc/httpd/modules/mod_auth_sys_group.so: No such file or directory    
[root@tian ~]#
[root@tian ~]# rpm -ivh http://mirrors.ustc.edu.cn/fedora/epel/6/x86_64/epel-release-6-8.noarch.rpm          \\ 安装epel的yum源,此源中提供 mod_auth_pam模块
[root@tian ~]#
[root@tian ~]# yum install -y mod_auth_pam    
[root@tian ~]#    
[root@tian ~]# ls /etc/httpd/modules/mod_auth_pam.so    
/etc/httpd/modules/mod_auth_pam.so    
[root@tian ~]# ls /etc/httpd/modules/mod_auth_sys_group.so    
/etc/httpd/modules/mod_auth_sys_group.so    
[root@tian ~]#


2.检查默认的pam配置
[root@tian ~]# more /etc/httpd/conf.d/auth_pam.conf    
LoadModule auth_pam_module modules/mod_auth_pam.so    
LoadModule auth_sys_group_module modules/mod_auth_sys_group.so    
[root@tian ~]# more /etc/pam.d/httpd    
#%PAM-1.0    
auth       include      password-auth    
account    include      password-auth    
# Comment out the previous account line and uncomment the following line if    
# you wish to allow logins that don't have a system account    
#account    required     pam_permit.so    
[root@tian ~]#


3.新建测试用户和svn用户组,并进行相关配置

新建能够访问svn的用户组,这里是svn (gid 504),并只有svn组里的用户才能访问svn资源,注意必定要将运行httpd的用户加入到此组中,不然,httpd程序没法读取 /etc/shadow 文件,形成svn不能成功认证  
[root@tian ~]# groupadd svn    
[root@tian ~]# grep svn /etc/group    
svn:x:504:    
[root@tian ~]# useradd test    
[root@tian ~]# passwd test    
Changing password for user test.    
New password:    
BAD PASSWORD: it is based on a dictionary word    
Retype new password:    
passwd: all authentication tokens updated successfully.    
[root@tian ~]#    
[root@tian ~]# usermod -a -G svn test    
[root@tian ~]# cat /etc/httpd/conf/httpd.conf | grep apache | grep -v "#"    
User apache    
Group apache    
[root@tian ~]#    
[root@tian ~]# usermod -a -G svn apache    
[root@tian ~]# grep svn /etc/group    
svn:x:504:test,apache    
[root@tian ~]# chgrp svn /etc/shadow    
[root@tian ~]# ll /etc/shadow    
-r--r----- 1 root svn 938 Apr 16 11:57 /etc/shadow    
[root@tian ~]#


4.设置权限文件
[root@tian ~]# cat >> /etc/svn-authz-file-test1 <<EOF    
[/]    
test=rw    
EOF    
[root@tian ~]#  more /etc/svn-authz-file-test1    
[/]    
tian=rw    
[/]    
test=rw    
[root@tian ~]#


5.修改配置文件,使用本地系统用户
说明:此处咱们对两个svn资源分别使用两种验证方式:    
test1,使用本地系统用户验证(用户必须属于svn用户组)    
test2,使用svn的密码文件进行验证,用户不是本地系统用户

[root@tian ~]# cat /etc/httpd/conf.d/subversion.conf |egrep -v "^#|^$"  
LoadModule dav_svn_module     modules/mod_dav_svn.so    
LoadModule authz_svn_module   modules/mod_authz_svn.so    
<Location /svn/test1>    
  DAV svn    
  SVNPath /svndata/test1    
     AuthType Basic    
     AuthName "Authorization Realm"    
     AuthUserFile /etc/svn-passwd-file-test1                       \\仍使用 svn-passwd-file-test1 文件控制访问权限    
     Require group svn                                             \\只有属于本地用户组svn中的用户才能访问    
</Location>

<Location /svn/test2>  
  DAV svn    
  SVNPath /svndata/test2    
     AuthType Basic    
     AuthName "Authorization Realm"    
     AuthzSVNAccessFile /etc/svn-authz-file-test2    
     AuthUserFile /etc/svn-passwd-file-test2      \\ 使用此处指定文件中的用户名和密码进行验证    
     Require valid-user    
</Location>    
[root@tian ~]#


6.重启服务
[root@tian ~]# service  httpd restart    
Stopping httpd:                                            [  OK  ]    
Starting httpd:                                            [  OK  ]    


[root@tian ~]#

7.测试
test1 使用本地系统用户组svn中的用户进行验证    
test2 使用密码文件进行认证

[root@tian ~]# svn co --username test --password test123 http://127.0.0.1/svn/test1 svn/test1    
Checked out revision 1.    
[root@tian ~]# svn update svn/test1/    
At revision 1.    
[root@tian ~]# svn co --username tian --password 123456 http://127.0.0.1/svn/test2 svn/test2    
Checked out revision 0.    
[root@tian ~]# svn update svn/test2    
At revision 0.    
[root@tian ~]#    
[root@tian ~]# ls svn/test1    
aa  bb    
[root@tian ~]# ls svn/test2    
[root@tian ~]#


第六:补充 更多信息

   1. 在上面的配置中经过SVNPath指定了一个代码仓库。可是在实际应用,每每是有多个仓库存放不一样的项目代码,这时能够将SVNPath改成:

       SVNParentPath  /svndata  
       但此时的不足是,因各仓库的权限控制使用的是一个权限控制文件,因此各仓库的权限保持的彻底一致    
   2.当有多个项目时 ,实际上是建议设置多个目录,分别进行权限控制,以下    
  <Location /svn/test1>    
  DAV svn    
  SVNPath /svndata/test1/    
     AuthType Basic    
     AuthName "Authorization Realm"    
     AuthzSVNAccessFile /etc/svn-authz-file-test1      
     AuthUserFile /etc/svn-passwd-file-test1          
     Require valid-user    
  </Location>    
  <Location /svn/test2>    
  DAV svn    
  SVNPath /svndata/test2/    
     AuthType Basic    
     AuthName "Authorization Realm"    
     AuthzSVNAccessFile /etc/svn-authz-file-test2      
     AuthUserFile /etc/svn-passwd-file-test2          
     Require valid-user    
  </Location>

   3. 使用htpasswd添加用户时,认证文件svn-auth-file不存在时,使用:

       htpasswd -cm /etc/svn-auth-file-test2 tester01

       会建立一个的文件,而且添加tester01用户。而此后再增长用户,使用:

       htpasswd /etc/svn-auth-filetest2 tester02

   4. 新增长代码库后,必定修改文件夹权限,否者客户端会获得Permission Denied的提示。

   5. 每次修改过配置文件之后,都要从新启动httpd服务。  
   6. svn中指定用户使用访问的方法    
     Require group svn           \\ 只有属于本地用户组svn中的用户才能访问    
     Require user test           \\ 只有test用户才能访问    
   7. 必须注意,若是使用本地系统用户进行验证,必定要确保运行httpd的用户能读取/etc/shadow中的内容    
   8. 不管使用那种认证方式,权限控制均可以使用 AuthzSVNAccessFile 参数指定的文件来进行控制


至此 全部配置完成

相关文章
相关标签/搜索