Linux下如何配置svn的https访问
这篇文章主要介绍Linux下如何配置svn的https访问,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完!
Apache Subversion 通常被缩写成 SVN,是一个开放源代码的版本控制系统,Subversion 在 2000 年由 CollabNet Inc 开发,现在发展成为 Apache 软件基金会的一个项目,同样是一个丰富的开发者和用户社区的一部分。 SVN相对于的RCS、CVS,采用了分支管理系统,它的设计目标就是取代CVS。互联网上免费的版本控制服务多基于Subversion。
[root@localhost~]#yuminstall-ysubversion2.可以使用命令查看svn是否安装成功
[root@localhost~]#svn使用“svnhelp”得到用法。[root@localhost~]#svnhelp[root@localhost~]#svn--version[root@localhost~]#svnadminhelp...3.创建svn服务器的仓库
先创建目录(这里目录可以随意,我为了方便自己管理就起了 /wfq)
[root@localhost/]#mkdir/wfq/svn/project
然后创建仓库,仓库目录指定为刚才创建的目录
[root@localhost/]#svnadmincreate/wfq/svn/project
因为我们创建文件夹时使用root权限创建的所以我们需要修改组权限,防止因为权限不够而svn操作失败
[root@localhost/]#chown-Rapache:apache/wfq/svn/project
进入到该目录中就会发现生成了很多文件,文件中svn中最主要的配置就在conf目录中
[root@localhost/]#cd/wfq/svn/project/[root@localhostproject]#ll总用量8drwxr-xr-x.2rootroot541月1902:12confdrwxr-sr-x.6rootroot2331月1902:12db-r--r--r--.1rootroot21月1902:12formatdrwxr-xr-x.2rootroot2311月1902:12hooksdrwxr-xr-x.2rootroot411月1902:12locks-rw-r--r--.1rootroot2291月1902:12README.txt[root@localhostproject]#cdconf/[root@localhostconf]#ll总用量12-rw-r--r--.1rootroot10801月1902:12authz-rw-r--r--.1rootroot3091月1902:12passwd-rw-r--r--.1rootroot30901月1902:12svnserve.conf
conf–|
–| authz —svn的权限配置
–| passwd —svn的密码配置(注意:因为我们要使用httpd 所以这里的密码验证文件不是密码文件所以不可以用)
–| svnserve.conf —svn的基本配置文件
4.SVN指定库启动与关闭1.命令方式启动(有缺陷)
关闭svn
[root@localhostssl]#ps-ef|grepsvnserveroot14381019:06?00:00:00/usr/bin/svnserve--daemon--pid-file=/run/svnserve/svnserve.pid-r/wfq/svnroot14931137019:23pts/000:00:00grep--color=autosvnserve[root@localhostssl]#kill-91438
启动指定目录
[root@localhostssl]#svnserve-d-r/wfq/svn/[root@localhostssl]#ps-ef|grepsvnserveroot15091019:24?00:00:00svnserve-d-r/wfq/svn/root15111137019:24pts/000:00:00grep--color=autosvnserve[root@localhostssl]#systemctlrestarthttpd
这种方式有点缺点就是不能 使用下面这几个命令来控制svn服务
[root@localhostssl]#systemctlstartsvnserve[root@localhostssl]#systemctlrestartsvnserve[root@localhostssl]#systemctlstopsvnserve[root@localhostssl]#systemctlstatussvnserve
2.修改默认的启动目录
将OPTIONS=”-r /wfq/svn”变量修改未上面创建的根目录
[root@localhostssl]#vi/etc/sysconfig/svnserve#OPTIONSisusedtopasscommand-lineargumentstosvnserve.##Specifytherepositorylocationin-rparameter:OPTIONS="-r/wfq/svn"
重启
[root@localhostssl]#systemctlrestartsvnserve[root@localhostssl]#systemctlrestarthttpd创建 apache环境支持http svn连接1.使用yum源下载httpd和mod_dav_svn两个模块
httpd模块 是Apache超文本传输协议(HTTP)服务器的主程序。被设计为一个独立运行的后台进程,它会建立一个处理请求的子进程或线程的池。
mod_dav_svn 配置指令 模块 是通过 Apache HTTP 服务器提供 Subversion 版本库服务的配置说明。
[root@localhostproject]#yuminstall-yhttpdmod_dav_svn2.创建用户和密码文件,并且配置svn权限
创建密码文件 htpasswd 命令中 最后面的是用户名,然后输入密码回车,再次确认密码回车就会创建好文件
如果要追加用户的话就使用 -m 命令 去掉c命令否则会覆盖了
使用命令查看后则会发现已创建该用户
[root@localhost/]#htpasswd-cm/wfq/svn/project/conf/http-authbugwfqNewpassword:Re-typenewpassword:Addingpasswordforuserbugwfq[root@localhost/]#vi/wfq/svn/project/conf/http-authbugwfq:$apr1$0FjoVFII$Zb4G0C8/r3ooQKPmcJHCi/~~~
进入到 conf/authz 文件中配置权限详细配置方式请参考 配置详解
[root@localhost/]#vi/wfq/svn/project/conf/authz###Thisfileisanexampleauthorizationfileforsvnserve.###Itsformatisidenticaltothatofmod_authz_svnauthorization###files.###Asshownbeloweachsectiondefinesauthorizationsforthepathand###(optional)repositoryspecifiedbythesectionname.###Theauthorizationsfollow.Anauthorizationlinecanreferto:###-asingleuser,###-agroupofusersdefinedinaspecial[groups]section,###-analiasdefinedinaspecial[aliases]section,###-allauthenticatedusers,usingthe'$authenticated'token,###-onlyanonymoususers,usingthe'$anonymous'token,###-anyone,usingthe'*'wildcard.######Amatchcanbeinvertedbyprefixingtherulewith'~'.Rulescan###grantread('r')access,read-write('rw')access,ornoaccess###('').[aliases]#joe=/C=XZ/ST=Dessert/L=SnakeCity/O=SnakeOil,Ltd./OU=ResearchInstitute/CN=JoeAverage[groups]#harry_and_sally=harry,sally#harry_sally_and_joe=harry,sally,&joeadmin=bugwfq#配置用户组admin组内成员admin=zs,ls,ww#[/foo/bar]#harry=rw#&joe=r#*=[/]@admin=rw#所属组权限配置r读w写#[repository:/baz/fuz]"/wfq/svn/project/conf/authz"37L,1113Cwritten3.配置svnserve.conf 文件
去掉 下面几个配置前面的#号
[root@localhost/]#vi/wfq/svn/project/conf/svnserve.conf###Thisfilecontrolstheconfigurationofthesvnservedaemon,ifyou###useittoallowaccesstothisrepository.(Ifyouonlyallow###accessthroughhttp:and/orfile:URLs,thenthisfileis###irrelevant.)###Visithttp://subversion.apache.org/formoreinformation.[general]###Theanon-accessandauth-accessoptionscontrolaccesstothe###repositoryforunauthenticated(a.k.a.anonymous)usersand###authenticatedusers,respectively.###Validvaluesare"write","read",and"none".###Settingthevalueto"none"prohibitsbothreadingandwriting;###"read"allowsread-onlyaccess,and"write"allowscomplete###read/writeaccesstotherepository.###Thesamplesettingsbelowarethedefaultsandspecifythatanonymous###usershaveread-onlyaccesstotherepository,whileauthenticated###usershavereadandwriteaccesstotherepository.anon-access=readauth-access=write###Thepassword-dboptioncontrolsthelocationofthepassword###databasefile.Unlessyouspecifyapathstartingwitha/,###thefile'slocationisrelativetothedirectorycontaining###thisconfigurationfile.###IfSASLisenabled(seebelow),thisfilewillNOTbeused.###Uncommentthelinebelowtousethedefaultpasswordfile.password-db=http-auth###Theauthz-dboptioncontrolsthelocationoftheauthorization###rulesforpath-basedaccesscontrol.Unlessyouspecifyapath###startingwitha/,thefile'slocationisrelativetothethe###directorycontainingthisfile.Ifyoudon'tspecifyan###authz-db,nopath-basedaccesscontrolisdone.###Uncommentthelinebelowtousethedefaultauthorizationfile.authz-db=authz###Thisoptionspecifiestheauthenticationrealmoftherepository.###Iftworepositorieshavethesameauthenticationrealm,theyshould###havethesamepassworddatabase,andviceversa.Thedefaultrealm"/wfq/svn/project/conf/svnserve.conf"61L,3085Cwritten4.配置httpd.conf配置文件
服务目录:/etc/httpd/ 主配置文件:/etc/httpd/conf/httpd.conf
SVNParentPath /wfq/svn ##为根project 的上级目录 AuthUserFile /wfq/svn/project/conf/httppasswd ##密码文件位置 AuthzSVNAccessFile /wfq/svn/project/conf/authz ##权限配置
[root@localhost/]#vi/etc/httpd/conf/httpd.conf...ServerNamelocahost:80DAVsvnSVNListParentPathonSVNParentPath/wfq/svnAuthTypeBasicAuthName"Subversionrepositories"AuthUserFile/wfq/svn/project/conf/httppasswdAuthzSVNAccessFile/wfq/svn/project/conf/authzRequirevalid-userSVNAutoversioningonModMimeUsePathInfoon...[root@localhost/]#5.修改svn目录下文件的属主和属组
[root@localhost/]#cd/wfq/svn/[root@localhostsvn]#chown-Rapache.project/[root@localhostsvn]#ll总用量0drwxr-xr-x.6apacheapache861月1902:12project[root@localhostsvn]#llproject/总用量8drwxr-xr-x.2apacheapache711月1903:21confdrwxr-sr-x.6apacheapache2331月1902:12db-r--r--r--.1apacheapache21月1902:12formatdrwxr-xr-x.2apacheapache2311月1902:12hooksdrwxr-xr-x.2apacheapache411月1902:12locks-rw-r--r--.1apacheapache2291月1902:12README.txt[root@localhostsvn]#
重启httpd
[root@localhostsvn]#systemctlrestarthttpdJobforhttpd.servicefailedbecausethecontrolprocessexitedwitherrorcode.See"systemctlstatushttpd.service"and"journalctl-xe"fordetails.
查看启动失败原因
[root@localhostsvn]#systemctlstatushttpd●httpd.service-TheApacheHTTPServerLoaded:loaded(/usr/lib/systemd/system/httpd.service;disabled;vendorpreset:disabled)Active:failed(Result:exit-code)since六2019-01-1903:57:46CST;1min30sagoDocs:man:httpd(8)man:apachectl(8)Process:1952ExecStop=/bin/kill-WINCH${MAINPID}(code=exited,status=1/FAILURE)Process:1951ExecStart=/usr/sbin/httpd$OPTIONS-DFOREGROUND(code=exited,status=0/SUCCESS)MainPID:1951(code=exited,status=0/SUCCESS)1月1903:57:46localhost.localdomainsystemd[1]:StartingTheApacheHTTPServer...1月1903:57:46localhost.localdomainhttpd[1951]:httpd(pid1600)alreadyrunning1月1903:57:46localhost.localdomainkill[1952]:kill:cannotfindprocess""1月1903:57:46localhost.localdomainsystemd[1]:httpd.service:controlprocessexited,code=exitedstatus=11月1903:57:46localhost.localdomainsystemd[1]:FailedtostartTheApacheHTTPServer.1月1903:57:46localhost.localdomainsystemd[1]:Unithttpd.serviceenteredfailedstate.1月1903:57:46localhost.localdomainsystemd[1]:httpd.servicefailed.
查看日志
[root@localhostsvn]#vi/var/log/httpd/error_log[SatJan1902:40:38.9374892019][core:notice][pid1599]SELinuxpolicyenabled;httpdrunningascontextunconfined_u:unconfined_r:unconfined_t:s0-s0:c0.c1023[SatJan1902:40:38.9384392019][suexec:notice][pid1599]AH01232:suEXECmechanismenabled(wrapper:/usr/sbin/suexec)[SatJan1902:40:38.9544482019][auth_digest:notice][pid1600]AH01757:generatingsecretfordigestauthentication...[SatJan1902:40:38.9652692019][lbmethod_heartbeat:notice][pid1600]AH02282:Noslotmemfrommod_heartmonitor[SatJan1902:40:38.9929312019][mpm_prefork:notice][pid1600]AH00163:Apache/2.4.6(CentOS)SVN/1.7.14configured--resumingnormaloperations[SatJan1902:40:38.9929702019][core:notice][pid1600]AH00094:Commandline:'httpd'
原来是本地80端口忘开了,这里为了方便直接关闭防火墙
[root@localhost/]#systemctlstopfirewalld.service[root@localhost/]#systemctldisablefirewalld.service
然后接着重启发现虽然成功了,但是访问的时候报了500
Theserverencounteredaninternalerrorormisconfigurationandwasunabletocompleteyourrequest.Pleasecontacttheserveradministratoratroot@localhosttoinformthemofthetimethiserroroccurred,andtheactionsyouperformedjustbeforethiserror.
然后我查看了下错误日志
[SatJan1904:42:55.7495052019][authn_file:error][pid2207](13)Permissiondenied:[client192.168.4.208:10890]AH01620:Couldnotopenpasswordfile:/wfq/svn/project/conf/httppasswd[SunJan2003:43:02.9369282019][mpm_prefork:notice][pid2202]AH00171:Gracefulrestartrequested,doingrestart
发现是新装的系统SELinux未关闭,授权没有生效。
有两种处理方案:
1.永久关闭selinux并重启系统
[root@localhost~]#vi/etc/selinux/config
将SELINUX=enforcing修改为SELINUX=disabled
重启系统reboot命令 应用相关设置
参考文章:linux 关闭selinux
2.命令方式直接修改SVN目录的权限配置
chcon-R-h-thttpd_sys_content_t/wfq/svn/project
然后访问地址http://ip/svn/project 输入设置的账号和密码 看到该界面就说明访问成功了
升级为https访问1.SSL环境搭建SSL数字证书
1.下载openssl与mod_ssl模块
[root@localhost~]#yuminstall-yopensslmod_ssl
2.生成key和证书
[root@localhost~]#mkdir/etc/httpd/conf/ssl/[root@localhost~]#cd/etc/httpd/conf/ssl/[root@localhostssl]#ll总用量0[root@localhostssl]#opensslgenrsa-des3-outserver.key1024GeneratingRSAprivatekey,1024bitlongmodulus............++++++...............++++++eis65537(0x10001)Enterpassphraseforserver.key:Verifying-Enterpassphraseforserver.key:生成csr[root@localhostssl]#opensslreq-new-keyserver.key>server.csrEnterpassphraseforserver.key:Youareabouttobeaskedtoenterinformationthatwillbeincorporatedintoyourcertificaterequest.WhatyouareabouttoenteriswhatiscalledaDistinguishedNameoraDN.TherearequiteafewfieldsbutyoucanleavesomeblankForsomefieldstherewillbeadefaultvalue,Ifyouenter'.',thefieldwillbeleftblank.-----CountryName(2lettercode)[XX]:CN#国家名称(2个字母代码)StateorProvinceName(fullname)[]:gd#省份LocalityName(eg,city)[DefaultCity]:sz#城市OrganizationName(eg,company)[DefaultCompanyLtd]:xx#公司名称OrganizationalUnitName(eg,section)[]:xx#公司部门CommonName(eg,yournameoryourserver'shostname)[]:bugwfq#主机名EmailAddress[]:bugwfq@163.com#邮件地址Pleaseenterthefollowing'extra'attributestobesentwithyourcertificaterequestAchallengepassword[]:123456#密码Anoptionalcompanyname[]:bugwfq#可选的公司名称...#生成证书[root@localhostssl]#opensslreq-x509-days2048-keyserver.key-inserver.csr>server.crtEnterpassphraseforserver.key:[root@localhostssl]#ll总用量12-rw-r--r--1rootroot9971月2123:27server.crt-rw-r--r--1rootroot7291月2123:26server.csr-rw-r--r--1rootroot9631月2123:22server.key
如果使用的阿里云服务器,并且有域名则找到对应的域名管理,开启ssl证书然后下载apache 对应的证书
会生成以下几个文件
将这些文件放到 /etc/httpd/conf/ssl 目录下
2.配置SSL环境\1. 打开/etc/httpd/conf/httpd.conf 配置文件配置以下信息
[root@localhost/]#vi/etc//httpd/conf/httpd.conf...#Loadconfigfilesinthe"/etc/httpd/conf.d"directory,ifany....LoadModulessl_modulemodules/mod_ssl.soMutexdefaultssl-cacheSSLRandomSeedstartupbuiltinSSLSessionCachenoneSSLCertificateFileconf/ssl/server.crtSSLCertificateKeyFileconf/ssl/server.key#SSLCertificateChainFileconf/ssl/X_X_X_chain.crt#如果是openssl生产的可以不配,如果是正规机构配置的可以放上去...DAVsvn...ModMimeUsePathInfoonSSLRequireSSL#配置该行,
2.重启httpd
[root@localhost/]#systemctlrestarthttpd
然后访问对应的地址 https://xxx.xxx.xxx.xxx/svn/project
因为我使用openssl 生成得,所以虽然证书可以了,但是只适用于开发环境,上面还会出现证书不安全的提示
(需要在电脑上手动安装证书 在这里就不提了)
如果我们从专门得证书机构申请证书就不会出现提示(下面这个是我自己阿里云申请配置的)
因为默认是http请求
所以我们要把http请求重定向到https的请求方式
1.修改配置文件
打开/etc/httpd/conf/httpd.conf 配置文件配置以下信息
1).添加mod_rewrite.so模块
...LoadModulessl_modulemodules/mod_ssl.s我添加在了这一行下面LoadModulerewrite_modulemodules/mod_rewrite.so...
2.配置重定向规则
...我配置在了标签上方RewriteEngineonRewriteCond%{SERVER_PORT}!^443$RewriteRule^.*$https://%{SERVER_NAME}%{REQUEST_URI}[L,R]...
3.重启httpd
[root@localhostssl]#systemctlrestarthttpd
搞定
有时候可能回遇到不同情况要多看日志或启动信息去解决,配置文件的配置可能每个电脑上配置的方式会有所差异
在配置的时候尽量多摸索,多查询网上其他资料。
在这里附上我用到的一些命令
svnserve-d-r/路径#指定目录启动其中-d表示守护进程-r表示在后台执行/路径为svn的安装目录ps-ef|grepsvnserve#这里是采取linux杀死进程的方式关闭SVNkill-9pid#杀死进程,此4967为进程号systemctlstart服务名#启动服务httpd/svnserve/........systemctlstop服务名#关闭服务httpd/svnserve/........systemctlrestart服务名#重启服务httpd/svnserve/........systemctlstatus服务名#服务的状态查看可以查询错误
以上是“Linux下如何配置svn的https访问”这篇文章的所有内容,感谢各位的阅读!希望分享的内容对大家有帮助,更多相关知识,欢迎关注亿速云行业资讯频道!
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。