實驗架構圖以下:
php
2.實驗環境需求(3臺主機便可,1臺服務器安裝svn加rsync,1臺web服務器,1臺客戶端機器)html
node2 192.168.21.233 centos 6.6 x64 svn(subversion) + rsync
node
node5 192.168.21.222 centos 6.6 x64 LAMP(Linux+Apache+MySQL+php)mysql
各軟件的做用:svn用來作版本控制的,由於在公司內部上線一個項目時,在多人開發的狀況下,都會通過多人修改,此時項目源碼的管理就變得很是重要了,在RHEL系列下有這樣一款軟件svn(subversion)linux
Subversion is a concurrent version control system which enables one or more users to collaborate in developing and maintaining a hierarchy of files and directories while keeping a history of all changes. Subversion only stores the differences between versions,instead of every complete file. Subversion is intended to be a compelling replacement for CVS.nginx
Subversion是一個併發版本控制系統,使一個或多個用戶協做開發和維護一個文件和目錄的層次結構,同時保持全部更改的歷史。Subversion存儲版本之間的差別,而不是每個完整的文件。Subversion肯定爲強迫替換CVS。web
百度百科對CVS的解釋:CVS(Concurrent Versions System)版本控制系統是一種GNU軟件包,主要用於在多人開發環境下源碼的維護。sql
rsync是用來將編寫好的源碼同步到遠程的web服務器上。shell
軟件包都經過yum方式來安裝 yum install package_name
vim
[root@node5 ~]# rpm -q httpd
httpd-2.2.15-39.el6.centos.x86_64
[root@node5 ~]# rpm -q mysql-server
mysql-server-5.1.73-3.el6_5.x86_64
[root@node5 ~]# rpm -q php
php-5.3.3-40.el6_6.x86_64
[root@node2 ~]# rpm -q subversion
subversion-1.6.11-12.el6_6.x86_64
[root@node2 ~]# rpm -q rsync
rsync-3.0.6-12.el6.x86_64
3.配置環境
[root@node2 ~]# rpm -ql subversion
...
/etc/rc.d/init.d/svnserve 服務啓動腳本
...
/usr/bin/svn 會經常使用到的命令
/usr/bin/svnadmin
...
/usr/share/man/man5/svnserve.conf.5.gz 配置文件手冊
....
客戶端訪問服務器時有三種方式:svnserve訪問、svnserve和ssh訪問、Apache間接訪問,這裏以svnserve方式來說解。
svnadmin - Subversion repository administration too subversion的版本管理工具l
SYNOPSIS 命令格式
svnadmin command /path/to/repos [options] [args]
。。。。。。
Run ‘svnadmin help’ to access the built-in tool documentation. 經過svnadmin查看工具的使用
NAME
svn - Subversion command line client tool subversion的命令行客戶端工具
SYNOPSIS 命令格式
svn command [options] [args]
。。。。。
Run ‘svn help’ to access the built-in tool documentation. 查看命令的文檔
[root@node2 ~]# svnadmin help
general usage: svnadmin SUBCOMMAND REPOS_PATH [ARGS & OPTIONS ...]
Type 'svnadmin help <subcommand>' for help on a specific subcommand.
Type 'svnadmin --version' to see the program version and FS modules.
Available subcommands: svnadmin help subcommand查看子命令的使用,好比:svnadmin help create
crashtest
create 建立一個新的版本庫
deltify
dump
help (?, h)
。。。
[root@node2 ~]# mkdir /svn/project [root@node2 ~]# svnadmin create /svn/project 建立一個新的版本庫 [root@node2 ~]# ls -l /svn/project total 24 drwxr-xr-x 2 root root 4096 May 15 08:39 conf drwxr-sr-x 6 root root 4096 May 15 08:39 db -r--r--r-- 1 root root 2 May 15 08:39 format drwxr-xr-x 2 root root 4096 May 15 08:39 hooks drwxr-xr-x 2 root root 4096 May 15 08:39 locks -rw-r--r-- 1 root root 229 May 15 08:39 README.txt [root@node2 ~]# ls /usr/local/nginx-1.4.7/auto/ cc feature headers install modules os summary define have include lib nohave sources types endianness have_headers init make options stubs unix [root@node2 ~]# du -sh /usr/local/nginx-1.4.7/auto/ 436K /usr/local/nginx-1.4.7/auto/ 導入源碼到版本庫中,這裏使用nginx的部分源碼來舉例,使用import子命令 -m [--message] ARG : specify log message ARG 至關於說明性的子串 [root@node2 ~]# svn import /usr/local/nginx-1.4.7/auto/ file:///svn/project/ -m "Initialization of a project" Adding /usr/local/nginx-1.4.7/auto/nohave Adding /usr/local/nginx-1.4.7/auto/os Adding /usr/local/nginx-1.4.7/auto/os/linux Adding /usr/local/nginx-1.4.7/auto/os/win32 ....... Adding /usr/local/nginx-1.4.7/auto/make Adding /usr/local/nginx-1.4.7/auto/have_headers Committed revision 1. [root@node2 ~]# svn list file:///svn/project/ 列出版本庫中有哪些文件 cc/ define endianness feature have have_headers headers include init install lib/ make modules nohave options os/ sources stubs summary types/ unix [root@node2 ~]# ls /svn/project/conf/ authz passwd svnserve.conf 客戶端在訪問版本庫服務器時,服務器會根據版本庫目錄下conf/svnserve.conf文件中的定義對用戶進行訪問控制 [root@node2 ~]# vim /svn/project/conf/svnserve.conf 查看man svnserve.conf有配置文件的詳細說明 。。。。 作以下修改 [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 = none #設置匿名帳號訪問權限,這裏爲none無權限 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 = My First Repository #設置版本庫域,若是兩個版本庫的認證域相同,他們將使用相同的密碼數據 [root@node2 ~]# vim /svn/project/conf/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 keepalived = keepalived #用戶名 = 密碼 haproxy = haproxy [root@node2 ~]# vim /svn/project/conf/authz 。。。 添加以下內容 [groups] # harry_and_sally = harry,sally # harry_sally_and_joe = harry,sally,&joe operator = keepalived,haproxy #指定一個operator組包括了剛纔的兩個用戶 [/] #設置版本庫的根路徑 @operator = rw #指定組對版本庫的訪問權限爲讀寫 * = r #其餘用戶的權限,權限能夠設置爲 只讀 'r' 讀寫'rw' 無'' 。。。 [root@node2 ~]# ls /svn/project/ conf db format hooks locks README.txt [root@node2 ~]# ls /svn/project/hooks/ post-commit.tmpl post-unlock.tmpl pre-revprop-change.tmpl post-lock.tmpl pre-commit.tmpl pre-unlock.tmpl post-revprop-change.tmpl pre-lock.tmpl start-commit.tmpl 在hooks目錄下,能夠提供一個post-commit的可執行的shell腳本,每當結束對版本庫的編輯時,執行commit一下 ,即會調用對應版本庫中hooks目錄下commit腳本執行,這裏由於結合rsync來作同步,恰好可使用到,等會後 面提供腳本的使用內容。
啓動svnserve服務
能夠用svnserve命令來啓動,使用-d選項說明以守護進程方式運行svnserve,-r PATH 爲版本庫指定一個虛擬
路徑,默認svn會將服務器上全部的版本庫都共享給用戶,使用-r僅發佈個別版本給用戶,svnserve -d -r /svn/project也可使用service start svnserve啓動svnserve,svnserve默認是監聽在tcp的3690端口
客戶端訪問
svn命令
[root@node2 ~]# svn help
usage: svn <subcommand> [options] [args]
。。。
Available subcommands: 這裏()括號中的能夠說是簡寫
add #添加文件
blame (praise, annotate, ann)
cat #查看文件的內容
changelist (cl) #查看改變的列表
checkout (co) #從服務器版本庫中複製一份副本到本地
cleanup
commit (ci) #將本地工做副本修改後的內容發佈到版本中
copy (cp)
delete (del, remove, rm) #刪除文件、目錄
diff (di) #對比兩個版本之間的差異
export
help (?, h)
import #導入一個源碼庫到版本庫中
info
list (ls) #列出版本庫中的文件
lock
log
merge
mergeinfo
mkdir
其餘的子命令使用到均可以查看幫助手冊的,svn help subcommand
[root@node2 ~]# svn checkout file:///svn/project nginx_source
A nginx_source/nohave
A nginx_source/os
A nginx_source/os/linux
A nginx_source/os/win32
A nginx_source/os/darwin
A nginx_source/os/conf
A nginx_source/os/freebsd
A nginx_source/os/solaris
A nginx_source/unix
。。。
[root@node2 ~]# vim /svn/project/hooks/post-commit 這裏經過post-commit腳本
#!/bin/bash
REPOS="$1" #版本庫的絕對路徑
REV="$2" #對應更新到的版本號
DIR="/root/nginx_source"
export LC_ALL=en_US.UTF-8
export LANG=zh_CN.UTF-8
CURDATE=`/bin/date`
#用來記錄日誌
echo "Code Deployed by at $CURDATE,$REPOS,$REV" >> /root/nginx_change.log
#當版本庫發生改變時,把更新寫入到副本當中
/usr/bin/svn update $DIR --username keepalived --password keepalived --no-auth-cache 2>1 /root/nginx_update.log
#使用rsync同步項目到web服務器上
/usr/bin/rsync -r -e ssh --stats --progress $DIR root@192.168.21.222:/var/www/html
這裏rsync同步時須要輸入遠程主機的密碼,因此咱們能夠經過密鑰來進行認證,
[root@node2 ~]#ssh-keygen -t rsa -P ''
[root@node2 ~]#ssh-copy-id -i .ssh/id_rsa.pub root@192.168.21.222
在windows上面操做時,須要安裝一個軟件TortoiseSVN,這裏提供一個下載路徑是英文版的http://pan.baidu.com/s/1ntoU1jN ,下載後安裝,安裝好後,在桌面上右擊時選擇(SVN檢出或者SVN Checkout)
接下來就能夠打開文件進行操做了,咱們修改cc目錄下的gcc文件,在第5行添加了(hello Eventyone)和第33行添加了(Hello world!),在cc目錄下的owc文件中第10行到第15行的內容
# maximize speed
CFLAGS="$CFLAGS -ot"
# reorder instructions for best pipeline usage
CFLAGS="$CFLAGS -op"
# inline intrinsic functions
CFLAGS="$CFLAGS -oi" 都刪除了
然後在project文件夾上右擊,選擇SVN Commit。。。進行commit操做
[root@node2 ~]# svn cat file:///svn/project/cc/gcc | head -5 發現已經更新了
# Copyright (C) Igor Sysoev
# Copyright (C) Nginx, Inc.
hello Eventyone
[root@node2 ~]# svn cat file:///svn/project/cc/gcc | head -35 | tail -5 兩個文件都更新成功
. auto/feature
Hello world£?
CC_TEST_FLAGS=
[root@node5 ~]# ls /var/www/html/ 這裏遠程也已經把文件同步過來了
nginx_source
[root@node5 ~]# ls /var/www/html/nginx_source/
cc feature headers install modules os summary
define have include lib nohave sources types
endianness have_headers init make options stubs unix
下面經過新增幾個文件,查看一下效果,在project目錄下新建了兩個.txt的文件zabbixtxt、openstack.txt,並在openstack.txt文件添加了以下內容:
Migrating to the cloud
Hello,Openstack
ok,如今進行commit操做
[root@node2 ~]# svn list file:///svn/project cc/ define endianness feature have have_headers headers include init install lib/ make modules nohave openstatck.txt.txt options os/ sources stubs summary types/ unix zabbix.txt.txt [root@node2 ~]# svn cat file:///svn/project/openstatck.txt.txt Migrating to the cloud Hello£?Openstack[root@node2 ~]# [root@node5 ~]# ls /var/www/html/nginx_source/ cc feature headers install modules options stubs unix define have include lib nohave os summary zabbix.txt.txt endianness have_headers init make openstatck.txt.txt sources types [root@node5 ~]# cat /var/www/html/nginx_source/openstatck.txt.txt Migrating to the cloud Hello£?Openstack[root@node5 ~]# 發現一切都ok,就介紹到此
有興趣能夠本身好好研究研究,有什麼錯誤系統你們能夠指正,謝謝閱讀