22.1 代码管理平台介绍

22.1 代码管理平台介绍

版本控制,记录若干文件内容变化,以便未来查阅特定版本修订状况
版本管理工具发展简史,cvs svn  git 参考http://luckypoem14.github.io/test/2012/04/24/scm-history/
svn全称subversion,是一个开源版本控制系统,始于2000年
git是linux创始人linus发起的,2005年发布,最初目的是更好管理linux内核代码
git和svn不一样在于git不须要依赖服务端就能够工做,即git是分布式的
关于git和svn的比较你们参考http://blog.lishiming.net/?p=305
github是基于git的在线web页面代码托管平台,能够选择付费服务
gitlab能够认为是一个开源的github,二者没有直接关系html

简单来讲:
git 是一种版本控制系统,是一个命令,是一种工具
gitlib 是用于实现git功能的开发库
github 是一个基于git实现的在线代码仓库,包含一个网站界面,向互联网开放
gitlab 是一个基于git实现的在线代码仓库软件,你能够用gitlab本身搭建一个相似于github同样的系统,通常用于在企业、学校等内部网络搭建git私服linux

22.2 安装svn

yum install -y subversion
 建立版本库 
 mkdir -p /data/svnroot/myproject
 svnadmin create /data/svnroot/myproject
 cd !$/conf #authz为权限配置文件,passwd为密码文件
 vim authz//配置文件改成以下
[groups]
admins = aming,user1
[/]
@admins = rw
*= r
[myproject:/]
user1 = rw
 vim passwd//加入以下内容
[users]
aming = aming_!(*$123
user1 = user1_^^^123
user2 = user2-***123
 vim svnserver.conf//更改或增长以下内容
[general]
anon-access = none
auth-access = write
password-db = passwd
authz-db = authz
realm = /data/svnroot/myproject
svnserve -d -r /data/svnroot //这样就启动了
[root@Dasoncheng ~]# yum install -y subversion
[root@Dasoncheng ~]# mkdir -p /data/svnroot/project1  ##建立文件夹
[root@Dasoncheng ~]# svnadmin create /data/svnroot/project1  
##初始化文件夹,里面会生成配置文件;(我试着没有建立文件夹 直接初始化自动生成了文件夹)
[root@Dasoncheng ~]# ll !$
ll /data/svnroot/project1
total 8
drwxr-xr-x 2 root root  54 Oct 23 20:46 conf
drwxr-sr-x 6 root root 233 Oct 23 20:46 db
-r--r--r-- 1 root root   2 Oct 23 20:46 format
drwxr-xr-x 2 root root 231 Oct 23 20:46 hooks
drwxr-xr-x 2 root root  41 Oct 23 20:46 locks
-rw-r--r-- 1 root root 229 Oct 23 20:46 README.txt
[root@Dasoncheng ~]# cd !$/conf
cd /data/svnroot/project1/conf
[root@Dasoncheng conf]# ll  ##咱们须要对conf文件夹里面进行修改
total 12
-rw-r--r-- 1 root root 1080 Oct 23 20:46 authz   ##这个是权限配置文件;
-rw-r--r-- 1 root root  309 Oct 23 20:46 passwd  ##这个是密码文件;
-rw-r--r-- 1 root root 3090 Oct 23 20:46 svnserve.conf  ##这个是服务启动的配置文件;
[root@Dasoncheng conf]# vim authz
[groups]  ##组=成员1,成员2
admins = aming,user1
[/]  ##这个"/"表明/data/svnroot/project1 这个文件夹;下面就是对其权限控制
@admins = rw  ##admins组成员 具备读写权限;
* = r  ##非admins具备读权限;
[project1:/]  ##这个"[nameofproject:/]"表明的是项目名,针对不一样项目的权限控制;
user1 = rw  ##use1对项目project1具备读写权限;
[root@Dasoncheng conf]# vim passwd  ##密码配置文件;
[users]
aming = p@ssw0rd  ##格式:username = password
user1 = p@ssw0rd1
[root@Dasoncheng conf]# vim svnserve.conf
[general]
anon-access = none   ##表明未受权用户,无任何权限
auth-access = write  ##受权用户 可写权限;
password-db = passwd  ##用户密码文件;
authz-db = authz  ##权限控制文件;
realm = /data/svnroot/myproject  ##表示对哪一个项目生效;
[root@Dasoncheng conf]# svnserve -d -r /data/svnroot/  ##-d以deamon后台启动,-r指svn目录;
[root@Dasoncheng conf]# ps aux |grep svn
root       4447  0.0  0.0 162204   652 ?        Ss   21:06   0:00 svnserve -d -r /data/svnroot/
root       4449  0.0  0.0 112664   968 pts/1    S+   21:06   0:00 grep --color=auto svn
[root@Dasoncheng conf]# netstat -lntp 
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
tcp        0      0 0.0.0.0:3690            0.0.0.0:*               LISTEN      4447/svnserve

22.3 客户端上使用svn(linux)

yum install -y  subversion
 svn checkout svn://192.168.133.130/myproject --username=aming
 cd myproject ; ls -la
 cp /etc/fstab .
 svn add .  //添加到版本控制中心
 svn commit -m “add file” //把文件上传到服务器
 svn delete filename  //在本地删除
 svn commit -m “delete filename” //在服务器上删除
 svn update //把当前目录下的文件都更新到最新版
 svn log //查看变动日志

安装好了,那么 咱们用60.12用户aming来作测试(上传):git

[root@localhost ~]# cd /home/
[root@localhost home]# mkdir svntest  ##建立文件夹给svn用;
[root@localhost home]# cd svntest/
[root@localhost svntest]# yum install -y subversion
[root@localhost svntest]# svn checkout svn://192.168.60.11/project1 --username=aming  
##svn检出项目project1,使用aming登陆;
Authentication realm: <svn://192.168.60.11:3690> /data/svnroot/project1
Password for 'aming':   ##输入aming密码;

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:  
##警告:你的密码对于验证域来讲
   <svn://192.168.60.11:3690> /data/svnroot/project1

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes   ##是否不加密保存密码;
Checked out revision 0.
[root@localhost svntest]# ll  
total 0
drwxr-xr-x 3 root root 18 Oct 23 21:45 project1
[root@localhost svntest]# cd project1/
[root@localhost project1]# ls -la
total 0
drwxr-xr-x 3 root root 18 Oct 23 21:45 .
drwxr-xr-x 3 root root 22 Oct 23 21:45 ..
drwxr-xr-x 4 root root 75 Oct 23 21:45 .svn
[root@localhost project1]# cp /etc/fstab .  ##拷贝fstab文件到当前目录下;
[root@localhost project1]# ll
total 4
-rw-r--r-- 1 root root 501 Oct 23 21:46 fstab
[root@localhost project1]# svn add ./fstab    ##添加fstab到版本控制中心;
A         fstab
[root@localhost project1]# svn commit -m "add fstab"  ##上传文件到服务器;
Adding         fstab
Transmitting file data .
Committed revision 1.

换60.11机器,使用user1登陆 同步svn:github

[root@Dasoncheng ~]# cd /home/
[root@Dasoncheng home]# mkdir svntest
[root@Dasoncheng home]# cd svntest/
[root@Dasoncheng svntest]# svn checkout svn://192.168.60.11/project1 --username=user1
Store password unencrypted (yes/no)? yes
A    project1/fstab
Checked out revision 1.
[root@Dasoncheng svntest]# ll
total 0
drwxr-xr-x 3 root root 31 Oct 23 21:58 project1
[root@Dasoncheng svntest]# cd project1/
[root@Dasoncheng project1]# ll
total 4
-rw-r--r-- 1 root root 501 Oct 23 21:58 fstab
[root@Dasoncheng project1]# svn delete fstab 
D         fstab
[root@Dasoncheng project1]# svn commit -m "delete fstab"
Deleting       fstab

Committed revision 2.
##60.12同步后查看
[root@localhost project1]# svn update
Updating '.':
D    fstab
Updated to revision 2.
[root@localhost project1]# ll  ##文件已经删除;
total 0
[root@localhost project1]# svn log
------------------------------------------------------------------------
r2 | user1 | 2017-10-23 22:06:17 +0800 (Mon, 23 Oct 2017) | 1 line

delete fstab
------------------------------------------------------------------------
r1 | aming | 2017-10-23 21:47:26 +0800 (Mon, 23 Oct 2017) | 1 line

add fstab
------------------------------------------------------------------------
##接下来是作更新(同步编辑的文件):
[root@localhost project1]# vim 1.txt
[root@localhost project1]# svn add 1.txt 
A         1.txt
[root@localhost project1]# svn commit -m "add 1.txt"
Adding         1.txt
Transmitting file data .
Committed revision 3.
[root@localhost project1]# echo 'hello world' >> 1.txt
[root@localhost project1]# svn commit -m "ch 1.txt"  ##这个就是更新1.txt文件
[root@localhost project1]# svn update  ##同步服务器文件;
Updating '.':
At revision 4.
[root@localhost project1]# svn log  ##查看日志;
------------------------------------------------------------------------
r4 | aming | 2017-10-23 22:09:40 +0800 (Mon, 23 Oct 2017) | 1 line

ch 1.txt
------------------------------------------------------------------------
r3 | aming | 2017-10-23 22:08:08 +0800 (Mon, 23 Oct 2017) | 1 line

add 1.txt
------------------------------------------------------------------------
r2 | user1 | 2017-10-23 22:06:17 +0800 (Mon, 23 Oct 2017) | 1 line

delete fstab
------------------------------------------------------------------------
r1 | aming | 2017-10-23 21:47:26 +0800 (Mon, 23 Oct 2017) | 1 line

add fstab
------------------------------------------------------------------------

聊聊:关于未加密保存密码的文件!web

[root@localhost svn.simple]# cd /root/.subversion/auth/svn.simple
[root@localhost svn.simple]# ll
total 4
-rw-r--r-- 1 root root 153 Oct 23 21:45 5e6bd6c8885f754dad23a6cb50fc2792
[root@localhost svn.simple]# cat 5e6bd6c8885f754dad23a6cb50fc2792 
K 8
passtype
V 6
simple
K 8
password
V 8
p@ssw0rd
K 15
svn:realmstring
V 49
<svn://192.168.60.11:3690> /data/svnroot/project1
K 8
username
V 5
aming
END
##这里面就保存了用户名和密码;

咱们删掉这个文件试试:vim

[root@localhost svn.simple]# rm -f 5e6bd6c8885f754dad23a6cb50fc2792 
[root@localhost svn.simple]# cd /home/svntest/project1
[root@localhost project1]# svn update  ##同步的时候;
Updating '.':
Authentication realm: <svn://192.168.60.11:3690> /data/svnroot/project1
Password for 'root':   ##这里提示输入root密码,这确定是不行的啥 咱们回车
Authentication realm: <svn://192.168.60.11:3690> /data/svnroot/project1
Username: aming  ##输入用户名 ok 再密码;
Password for 'aming': 

-----------------------------------------------------------------------
ATTENTION!  Your password for authentication realm:

   <svn://192.168.60.11:3690> /data/svnroot/project1

can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.

You can avoid future appearances of this warning by setting the value
of the 'store-plaintext-passwords' option to either 'yes' or 'no' in
'/root/.subversion/servers'.
-----------------------------------------------------------------------
Store password unencrypted (yes/no)? yes
At revision 5.

22.4 客户端上使用svn(windows)

安装过程略过:
mark
建立文件夹提供svn服务; mark
右键,checkout(会弹出用户名密码界面输入);
mark
验证完成以后,就是这个界面!
mark
能够看到,已经和服务器同步了;
建立文件,并同步:
mark
mark
mark
mark
mark 提交完成以后,咱们去其余客户端同步看看;windows

[root@Dasoncheng ~]# cd /home/svntest/
[root@Dasoncheng svntest]# cd project1/
[root@Dasoncheng project1]# ll
total 4
-rw-r--r-- 1 root root 70 Oct 23 22:10 1.txt
[root@Dasoncheng project1]# svn update
Updating '.':
A    2.txt
Updated to revision 6.
[root@Dasoncheng project1]# ll
total 8
-rw-r--r-- 1 root root 70 Oct 23 22:10 1.txt
-rw-r--r-- 1 root root 41 Oct 24 08:37 2.txt
[root@Dasoncheng project1]# cat 2.txt 
aaaaaaaaaaaaaaaaaaaaaaaa
bbbbbbbbbbbbbbb[root@Dasoncheng project1]#

删除1.txt,Windows同步查看:服务器

[root@Dasoncheng project1]# svn delete 1.txt 
D         1.txt
[root@Dasoncheng project1]# svn commit -m "delete 1.txt"
Deleting       1.txt

Committed revision 7.

mark
mark