服务器:192.168.80.12
一、部署搭建SVN
1、安装SVN服务
yum install subversion -y
svnserve --version //查版本
svnserve,版本 1.7.14 (r1542130)
编译于 Apr 11 2018,02:40:28
......
2、为PHP程序员创建仓库目录repo
mkdir -p /opt/svn/repo //创建目录
svnadmin create /opt/svn/repo/ //创建新仓库
3、调整SVN参数
vi /opt/svn/repo/conf/svnserve.conf //调整SVN参数
[general] //总体配置
anon-access = none //匿名用户没有任何权限
auth-access = write //认证用户具有写权限
password-db = /opt/svn/repo/conf/passwd //用户的密码文件
authz-db = /opt/svn/repo/conf/authz //用户信息文件
.....
4、启动SVN服务
svnserve -d -r /opt/svn/repo/ //启动SVN服务,关闭通过kill PID
netstat -ntap | grep svnserve
tcp 0 0 0.0.0.0:3690 0.0.0.0:* LISTEN 3585/svnserve
kill pid号 //停止服务
vi /etc/sysconfig/svnserve
OPTIONS="-r /opt/svn/repo/ " #将这行的路径改为仓库的路径
systemctl start svnserve
systemctl stop svnserve
//关闭防火墙和安全功能
systemctl stop firewalld.service
setenforce 0
5、为PHP程序员jack建立账户,配置仓库具有读写权限,并将账户信息及仓库目录信息反馈给PHP程序员
cd /opt/svn/repo
vi conf/passwd //创建账户密码文件,一定要顶格写
[users]
jack = 123123 //格式:用户名 = 用户密码
tom = 123123
vi conf/authz //创建权限文件
[/]
jack = r
tom = r
[/webphp]
jack = rw //运维工程师账户具有读权限,用于部署,*表示其他人
* =
[/webpa]
tom = r
* =
mkdir webphp
mkdir webpa
svn import -m -F webphp file:///opt/svn/repo/webphp "初始化目录"
提交后的版本为 1
svn import -m -F webphp file:///opt/svn/repo/webpa
提交后的版本为 2
在windows上用 tortoise登录 svn://192.168.80.12
Linux上:
PHP程序员将代码导入webphp项目中。
通过SVN服务器的sysadmin账户部署代码至nginx服务器及PHP服务器,注意nginx和PHP服务器配置的服务目录分别是/usr/local/nginx/html/webphp和/var/www/html/webphp
nginx服务器
yum install -y svn
cd /usr/local/nginx/html/webphp
svn co svn://192.168.80.12/webphp //根据提示先输root密码再使用账户jack登录,即可部署代码
php服务器一样部署
二、使用http访问svn
yum install -y httpd mod_dav_svn
htpasswd -cm /opt/svn/repo/conf/http-passwd jack
输入密码2次
htpasswd -m /opt/svn/repo/conf/http-passwd tom //去掉c,否则会覆盖
输入密码2次
vi /opt/svn/repo/conf/svnserve.conf
general] //总体配置
anon-access = none //匿名用户没有任何权限
auth-access = write //认证用户具有写权限
password-db = / opt/svn/repo/conf/http-passwd //用户的密码文件
authz-db = /opt/svn/repo/conf/authz //用户信息文件
cd /opt/svn/repo
vi conf/authz
[/]
jack = r
tom = r
[/webphp]
* =
jack = rw
[/webpa]
tom = rw
* =
vi /etc/httpd/conf/httpd.conf
末尾添加
<Location /svn>
DAV svn
SVNListParentPath on
SVNParentPath /opt/svn //repo的上一级目录
AuthType Basic
AuthName "Subversion repositories"
AuthUserFile / opt/svn/repo/conf/http-passwd //htpasswd密码文件路径
AuthzSVNAccessFile /opt/svn/repo/conf/authz //用户信息文件路径
Require valid-user
SVNAutoversioning on
ModMimeUsePathInfo on
</Location>
chown -R apache:apache /opt/svn
systemctl restart httpd
用浏览器登录: http://192.168.80.12/svn/repo,填写用户名和密码,进去后看到该用户有权限访问的文件夹,即成功。之后可以用tortoise登录
三、升级https访问
yum install -y openssl mod_ssl
1、生成key和证书
mkdir /etc/httpd/conf/ssl/
cd /etc/httpd/conf/ssl/
openssl genrsa -des3 -out server.key 1024
随便输入一个新密码
openssl req -new -key server.key > server.csr
输入刚才设的密码
生成证书
req -x509 -days 2048 -key server.key -in server.csr > server.crt
输入设的密码
vi /etc/httpd/conf/httpd.conf
...
# Load config files in the "/etc/httpd/conf.d" directory, if any.
...
LoadModule ssl_module modules/mod_ssl.so
Mutex default ssl-cache
SSLRandomSeed startup builtin
SSLSessionCache none
SSLCertificateFile conf/ssl/server.crt
SSLCertificateKeyFile conf/ssl/server.key
#SSLCertificateChainFile conf/ssl/X_X_X_chain.crt #如果是openssl 生产的可以不配,如果是正规机构配置的可以放上去
...
<Location /svn>
DAV svn
...
ModMimeUsePathInfo on
SSLRequireSSL #配置该行,
</Location>
systemctl restart httpd
然后访问对应的地址 https://192.168.80.12/svn/repo
2、设置http重定向到https 因为默认是http请求
#添加mod_rewrite.so模块
vi /etc/httpd/conf/httpd.conf
LoadModule ssl_module modules/mod_ssl.so 我添加在了这一行下面
LoadModule rewrite_module modules/mod_rewrite.so
#配置重定向规则
我配置在了<Location /svn> 标签上方
RewriteEngine on
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
<Location /svn>
systemctl restart httpd
登录:192.168.80.12/svn/repo