CentOS通过nginx转发http支持访问SVN
这里写自定义目录标题
需要三大服务组件:
1、SVN服务
2、httpd服务
3、nginx服务
第一步,安装、配置三大服务组件:
1.1安装,svn:
#yum install subversion
1.2新建一个目录用于存储SVN目录
#mkdir /svn
1.3新建一个测试仓库
# svnadmin create /svn/test/
# ll /svn/test/
drwxr-xr-x. 2 root root 4096 Jul 28 18:12 conf
drwxr-sr-x. 6 root root 4096 Jul 28 18:12 db
-r--r--r--. 1 root root 2 Jul 28 18:12 format
drwxr-xr-x. 2 root root 4096 Jul 28 18:12 hooks
drwxr-xr-x. 2 root root 4096 Jul 28 18:12 locks
-rw-r--r--. 1 root root 229 Jul 28 18:12 README.txt
以下关于目录的说明:
hooks目录:放置hook脚步文件的目录
locks目录:用来放置subversion的db锁文件和db_logs锁文件的目录,用来追踪存取文件库的客户端
format目录:是一个文本文件,里边只放了一个整数,表示当前文件库配置的版本号
conf目录:是这个仓库配置文件(仓库用户访问账户,权限)
1.4配置SVN服务的配置文件
svnserve.conf 主要配置文件
authz 权限管理配置
passwd 账号密码配置
svnserver.conf:
cd /svn/test/conf/
# vi svnserve.conf
### This file controls the configuration of the svnserve daemon, if you
### use it to allow access to this repository. (If you only allow
### access through http: and/or file: URLs, then this file is
### irrelevant.)
### Visit http://subversion.tigris.org/ for more information.
[general]
### These options control access to the repository for unauthenticated
### and authenticated users. Valid values are "write", "read",
### and "none". The sample settings below are the defaults.
anon-access = read ##注意前边不要有空格,要顶齐( #控制非鉴权用户访问版本库的权限)
auth-access = write ##注意前边不要有空格,要顶齐( #控制鉴权用户访问版本库的权限)
### The password-db option controls the location of the password
### database file. Unless you specify a path starting with a /,
### the file's location is relative to the directory containing
### this configuration file.
### If SASL is enabled (see below), this file will NOT be used.
### Uncomment the line below to use the default password file.
password-db = passwd ##注意前边不要有空格,要顶齐( #指定用户名口令文件名)
### The authz-db option controls the location of the authorization
### rules for path-based access control. Unless you specify a path
### starting with a /, the file's location is relative to the the
### directory containing this file. If you don't specify an
### authz-db, no path-based access control is done.
### Uncomment the line below to use the default authorization file.
authz-db = authz ##(#指定权限配置文件名)
### This option specifies the authentication realm of the repository.
### If two repositories have the same authentication realm, they should
### have the same password database, and vice versa. The default realm
### is repository's uuid.
realm = /svn/test/ ##这个是提示信息(#指定版本库的认证域,即在登录时提示的认证域名称,并且作为凭证缓存的关键字)
[sasl]
### This option specifies whether you want to use the Cyrus SASL
### library for authentication. Default is false.
### This section will be ignored if svnserve is not built with Cyrus
### SASL support; to check, run 'svnserve --version' and look for a line
### reading 'Cyrus SASL authentication is available.'
# use-sasl = true
### These options specify the desired strength of the security layer
### that you want SASL to provide. 0 means no encryption, 1 means
### integrity-checking only, values larger than 1 are correlated
### to the effective key length for encryption (e.g. 128 means 128-bit
### encryption). The values below are the defaults.
# min-encryption = 0
# max-encryption = 256
1.5,配置访问用户及密码
修改配置添加账号密码,以账号=密码的格式配置,=号两边尽量不要存在空格
# vi passwd
### This file is an example password file for svnserve.
### Its format is similar to that of svnserve.conf. As shown in the
### example below it contains one section labelled [users].
### The name and password for each user follow, one account per line.
[users]
# harry=harryssecret
# sally=sallyssecret
lqb=lqb123456
test1=123456
test2=654321
authz 权限管理配置
权限管理分为组管理和目录权限管理
用户组配置:组名=账号,账号… 多账号之间以,号分割
//创建svn组和组用户的权限
[groups]
//创建一个组,并制定两个用户
admin = root,yang
//制定根目录下的权限
[/]
//first组用户权限为读写
@admin = rw
//其他用户只有读权限
* = r
//保存退出
[groups]
admin=admin,lqb #admin 用户组只有一个admin账号
test=test1,test2 #test用户组有test1和test2二个账号
# 设置所有仓库的权限
[/] #仓库根目录
@admin=rw #admin用户组有读写权限
@test=r #test用户组有只读权限
zw=rw #zw用户有读写权限
*= #其他用户无权限
# 设置test1仓库的权限
[test1:/]
@admin=rw
@test=rw
# 设置test2仓库的权限
[test2:/]
@admin=rw
@test=rw
启动SVN
单仓库可以直接以仓库目录启动
svnserve -dr /svn/test --listen-port 5690 # -d : 守护进程 -r : svn数据根目录 --listen-port 自定义端口
多仓库启动上层svn目录
svnserve -dr /home/svn # -d : 守护进程 -r : svn数据根目录
访问地址分别为:
svn://ip/test1
svn://ip/test2
查看svn服务
ps -aux|grep svnserve #默认端口为:3690
停止SVN服务
# ps 查出svnserve进程id,再kill掉,或只启动一个svn仓库时可用pkill
pkill svnserve
设置开机自启动
systemctl enable svnserve.service
2、安装 httpd和apahce的svn模块:
#yum install httpd
#yum install -y httpd mod_dav_svn
检查Apache,mod_dav_svn是否安装成功
安装成功后,会有mod_dav_svn.so和mod_authz_svn.so两个文件。
# httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built: Nov 16 2020 16:18:20
# find / -name mod_dav_svn.so
/usr/lib64/httpd/modules/mod_dav_svn.so
# find / -name mod_authz_svn.so
/usr/lib64/httpd/modules/mod_authz_svn.so
增加配置文件/etc/httpd/conf.d/subversion.conf
#vi /etc/httpd/conf.d/subversion.conf
LoadModule dav_svn_module modules/mod_dav_svn.so
LoadModule authz_svn_module modules/mod_authz_svn.so
# vi /etc/httpd/conf.d/w_svn_9001.conf
Listen 2365 #设置一个端口服务,NG会跳转到这个端口
<Location /svn>
DAV svn
SVNParentPath /svn/test/ # 仓库路径
AuthType Basic
AuthName "svn repos"
AuthUserFile /svn/test/passwdfile # 指定HTTP访问SVN的密码文件(HTTP访问SVN的账号密码 通过htpasswd 添加到这个文件)
AuthzSVNAccessFile /svn/test/auth # 指定HTTP访问SVN的权限文件
Satisfy Any
Require valid-user
</Location>
创建http登陆SVN用户文件passwd(subversion.conf中AuthUserFile指定的文件 ),
#htpasswd /svn/test/passwdfile lqb
New password: 123456
Re-type new password: 123456
Adding password for user lqb
# cat /svn/test/passwdfile
lqb:$apr1$gQ3qKK9Q$ZYFb.DVPf4vLGzTsU3L0f1
http登陆SVN的权限文件直接复制svn仓库中的权限文件就可以,没有特殊需要不需要重新配置
#cp /svn/test/conf/authz /svn/test/auth
配置apache对SVN库目录权限
#chown -R apache:apache /svn/test/
#ll /opt/svn
-rwxr--r-- 1 root root 1127 Jul 16 21:04 authz
-rw-r--r-- 1 root root 43 Jul 16 21:02 passwd
drwxrwxrwx 6 apache apache 4096 Jul 18 04:33 test
重启httpd服务
#systemctl restart httpd
或者:
#/etc/init.d/httpd restart
常用http服务命令
httpd -v #查看已经安装的httpd的版本
rpm -qa | grep httpd #查看是否已经安装了httpd
ps -ef | grep httpd #查看httpd的进程
service httpd status #查看httpd的运行状态
service httpd stop #停止httpd
service httpd start #启动httpd
service httpd start #重新启动httpd
3、安装nginx
3.1下载
#wget http://nginx.org/download/nginx-1.9.9.tar.gz
3.2解压
#tar -zxvf nginx-1.9.9.tar.gz
3.3编译
#./configure ##(需要更多功能可以在这个命令后添加需要的模块)
#make
3.4安装
#make install
3.5配置(切换到/usr/local/nginx安装目录)
#pwd
/usr/local/nginx/conf
#vi nginx.conf
server {
listen 80;
server_name svn.xxxxx.com;
#防XSS攻击
add_header X-Xss-Protection 1;
#nginx强制使用https访问(http跳转到https)
#rewrite ^(.*) https://$server_name$1 permanent;
location /{
proxy_redirect off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:2365/;
proxy_read_timeout 150; # 秒
}
access_log logs/potal_tomcat_8881_access.log;
}
3.6检查配置、启动服务
## pwd
/usr/local/nginx/sbin
#./nging -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
#./nginx -s reload
到此,可以在浏览器上通过HTTP使用域名去访问SVN
直接使用IP+端口不需要用NG转发
更多推荐

所有评论(0)