1、SVN
SVN属于集中式的版本控制系统,都有一个单一的集中管理的服务器,保存所有文件的修订版本,而协同工作的人们都通过客户端连到这台服务器,取出最新的文件或者提交更新。
1.1、SVN的特点概括起来主要由以下几条:
1)每个版本库有唯一的URL(官方地址),每个用户都从这个地址获取代码和数据;
2)获取代码的更新,也只能连接到这个唯一的版本库,同步以取得最新数据;
3)提交必须有网络连接(非本地版本库);
4)提交需要授权,如果没有写权限,提交会失败;
5)提交并非每次都能够成功。如果有其他人先于你提交,会提示”改动基于过时的版本,先更新再提交”… 诸如此类;
6)冲突解决是一个提交速度的竞赛:手快者,先提交,平安无事;手慢者,后提交,可能遇到麻烦的冲突解决。
好处:每个人都可以一定程度上看到项目中的其他人正在做些什么。而管理员也可以轻松掌控每个开发者的权限。
缺点:中央服务器的单点故障。
若是宕机一小时,那么在这一小时内,谁都无法提交更新、还原、对比等,也就无法协同工作。如果中央服务器的磁盘发生故障,并且没做过备份或者备份得不够及时的话,还会有丢失数据的风险。最坏的情况是彻底丢失整个项目的所有历史更改记录,被客户端提取出来的某些快照数据除外,但这样的话依然是个问题,你不能保证所有的数据都已经有人提取出来。
简单来说,SVN原理上只关心文件内容的具体差异。每次记录有哪些文件作了更新,以及都更新了哪些行的什么内容。
1.2、SVN的搭建和使用
注意版本库所在的目录为:/data/svn
1.检查已安装版本
rpm -qa subversion
卸载旧版本SVN
yum remove subversion
2、修改源
CentOS6.6 默认yum源安装的subversion版本为1.6.11,所以先要创建SVN的yum源。
2.1、创建一个yum repo文件
vi /etc/yum.repos.d/wandisco-svn.repo
2.2、添加如下内容
[WandiscoSVN]name=Wandisco SVN Repo#注意:$releasever为linux系统版本baseurl=http://opensource.wandisco.com/centos/$releasever/svn-1.9/RPMS/$basearch/enabled=1gpgcheck=0
2.3、清楚源缓存
yum clean all
2.4、查看SVN源的版本
yum list | grep subversion | grep 1.9
3、安装SVN
yum install -y subversion
4、验证安装
svnserve --version
5、创建版本库
mkdir -p /data/svn/svnadmin create /data/svn/data-center
6、配置用户及密码
密码的生成可以使用如下命令
htpasswd /data/svn/data-center/conf/passwd username
vi /data/svn/data-center/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]user1=k0YpEdfYFQJaUK86QgC
7、配置权限控制
vi /data/svn/data-center/conf/authz
参考如下内容:
[groups]data-center_m = user1,user2data-center_g = user1,user2data-center_zps_g = user1,user2data-center_op_g = user1,user2data-center_dw_g = user1,user2data-center_dev_g = user1,user2data-center_prd_g = user1,user2data-center_back = user1,user2data-center_it = user1,user2[data-center:/]@data-center_m= rw[data-center:/管理]@data-center_m= rw[data-center:/ZPS]@data-center_zps_g= rw[data-center:/部门日常事务]@data-center_m= rw@data-center_g= rw[data-center:/运营分析组]@data-center_m= rw@data-center_op_g= rw[data-center:/数据仓库组]@data-center_m= rw@data-center_dw_g= rw@data-center_prd_g= rw[data-center:/数据仓库组/01文档/04详细设计]@data-center_op_g=r[data-center:/应用开发组]@data-center_m= rw@data-center_dev_g= rw@data-center_dw_g= r[data-center:/产品设计组]@data-center_m= rw@data-center_dev_g= rw@data-center_prd_g= rw[data-center:/项目中心]@data-center_m= rw@data-center_dev_g= rw@data-center_prd_g= rw@data-center_dw_g= rw@data-center_op_g= rw[data-center:/IT组]@data-center_m= rw@data-center_it= rw
8、服务配置
vi /data/svn/data-center/conf/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 = noneauth-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 = /data/svn/data-center[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
9、启动SVN
svnserve -d -r /data/svn
10、注意:
1、可能涉及到防火墙设置
subversion默认端口 为3690有开启3690端口的命令,在终端输入以下命令:1>iptables -I INPUT -i eth0 -p tcp --dport 3690 -j ACCEPT2>iptables -I OUTPUT -o eth0 -p tcp --sport 3690 -j ACCEPT然后保存:etc/rc.d/init.d/iptables save在看看是否已经有了360端口的开放权限:/etc/init.d/iptables status
3、SVN日志文件显示时间为1970-01-01 No data
在SVN服务器上打开svnserve.conf文件,将其中名为anon-access的一项设置为 anon-access = none。
2、Git
Git属于分布式的版本控制系统,实际上,Git 更像是把变化的文件作快照后,记录在一个微型的文件系统中。每次提交更新时,它会纵览一遍所有文件的指纹信息并对文件作一快照,然后保存一个指向这次快照的索引。为提高性能,若文件没有变化,Git 不会再次保存,而只对上次保存的快照作一连接。Git还支持离线提交更新,等到了有网络的时候再上传到远程的镜像仓库。
2.1、Git的特点概括起来主要由以下几条:
1)Git中每个克隆(clone)的版本库都是平等的。你可以从任何一个版本库的克隆来创建属于你自己的版本库,同时你的版本库也可以作为源提供给他人,只要你愿意。
2)Git的每一次提取操作,实际上都是一次对代码仓库的完整备份。
3)提交完全在本地完成,无须别人给你授权,你的版本库你作主,并且提交总是会成功。
4)甚至基于旧版本的改动也可以成功提交,提交会基于旧的版本创建一个新的分支。
5)Git的提交不会被打断,直到你的工作完全满意了,PUSH给他人或者他人PULL你的版本库,合并会发生在PULL和PUSH过程中,不能自动解决的冲突会提示您手工完成。
6)冲突解决不再像是SVN一样的提交竞赛,而是在需要的时候才进行合并和冲突解决。
2.2、Git的搭建和配置:
本文搭建的gitlab是基于yum的方式进行安装的,具体的安装步骤如下:
1、配置yum源
vim /etc/yum.repos.d/gitlab-ce.repo
2、复制如下内容并保存
注意baseurl的配置是centos7的地址
[gitlab-ce]name=gitlab-cebaseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el7/Repo_gpgcheck=0Enabled=1Gpgkey=https://packages.gitlab.com/gpg.ke如果是centos6的,baseurl修改为[gitlab-ce]name=gitlab-cebaseurl=https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el6/Repo_gpgcheck=0Enabled=1Gpgkey=https://packages.gitlab.com/gpg.ke
3、更新本地yum缓存
sudo yum makecache
4、yum安装gitlab,此处安装版本是11.9.8
sudo yum intall gitlab-ce #自动安装最新版sudo yum install gitlab-ce-11.9.8 #安装指定版本,此处为10.2.2#注意安装的过程中可能会报:#这个问题简单总结了一下!#GPG key retrieval failed: [Errno 14] PYCURL ERROR 7 - "couldn't connect to host"#简单的翻译:GPG密钥检索失败:[14] PYCURL errno的错误 - “无法连接到主机”#可以使用如下命令进行跳过sudo yum install gitlab-ce-11.9.8 --nogpgcheck ####跳过校验
5、更改配置
vim /etc/gitlab/gitlab.rb
参考如下内容:
找到 external_url 'http://000.00.00.00:8081'修改成你的地址,此处为http://192.168.1.157:82找到 unicorn['port'] = 8091修改其他端口,可能9090被其他的进程占用了。注意:这个/etc/gitlab/gitlab.rb很多端口都需要检查下是否有被占用。
6、对GitLab进行编译
gitlab-ctl reconfigure
7、清除缓存
gitlab-rake cache:clear RAILS_ENV=production
8、启动gitlab服务,以及关闭防火墙等操作
sudo gitlab-ctl start # 启动所有 gitlab 组件;并加入开机启动项里面:/etc/rc.localsudo gitlab-ctl stop # 停止所有 gitlab 组件;sudo gitlab-ctl restart # 重启所有 gitlab 组件;sudo gitlab-ctl status # 查看服务状态;sudo gitlab-ctl tail # 查看日志;#关闭防火墙:service iptables stop ###centos6关闭防火墙systemctl stop firewalld.service ###centos7关闭防火墙
9、访问gitlab
http://192.168.1.157:82gitlab默认的root账号,首次进入需要修改root密码
10、全局配置
git config --global user.email "user1@xxx.com"git config --global user.name "张三"
