rsync、gitlab、svn安装和使用

rsync、gitlab、svn安装和使用

1.rsync简介

rsync是linux系统下的数据镜像备份工具。使用快速增量备份工具Remote Sync可以远程同步,支持本地复制,或者与其他SSH、rsync主机同步。

2.rsync特性

rsync支持很多特性:

可以镜像保存整个目录树和文件系统
可以很容易做到保持原来文件的权限、时间、软硬链接等等
无须特殊权限即可安装
快速:第一次同步时rsync会复制全部内容,但在下一次只传输修改过的文件。rsync在传输数据的过程中可以实行压缩及解压缩操作,因此可以使用更少的带宽
安全:可以使用scp、ssh等方式来传输文件,当然也可以通过直接的socket连接
支持匿名传输,以方便进行网站镜像
3.rsync的ssh认证协议
rsync命令来同步系统文件之前要先登录remote主机认证,认证过程中用到的协议有2种:

ssh协议
rsync协议

rsync server`端不用启动`rsync``daemon`进程,只要获取`remote host`的用户名和密码就可以直接`rsync`同步文件
`rsync server`端因为不用启动`daemon`进程,所以也不用配置文件`/etc/rsyncd.conf

ssh认证协议跟scp的原理是一样的,如果在同步过程中不想输入密码就用ssh-keygen -t rsa打通通道

//这种方式默认是省略了 -e ssh 的,与下面等价:
rsync -avz /SRC -e ssh root@172.16.12.129:/DEST 
    -a  //文件宿主变化,时间戳不变
    -z  //压缩数据传输
 
//当遇到要修改端口的时候,我们可以:
rsync -avz /SRC -e "ssh -p2222" root@172.16.12.129:/DEST  
//修改了ssh 协议的端口,默认是22

4.rsync命令

//Rsync的命令格式常用的有以下三种:

 rsync [OPTION]... SRC DEST
    rsync [OPTION]... SRC [USER@]HOST:DEST
    rsync [OPTION]... [USER@]HOST:SRC DEST
  
//对应于以上三种命令格式,rsync有三种不同的工作模式:
1)拷贝本地文件。当SRC和DES路径信息都不包含有单个冒号":"分隔符时就启动这种工作模式。如:
[root@localhost ~]# ls
anaconda-ks.cfg  nfs.sh
[root@localhost ~]# rsync -a nfs.sh a.sh
[root@localhost ~]# ll
total 12
-rw-------. 1 root root 1453 Jun 13 19:27 anaconda-ks.cfg
-rwxr-xr-x  1 root root 1041 Aug  8 18:14 a.sh
-rwxr-xr-x  1 root root 1041 Aug  8 18:14 nfs.sh
[root@localhost ~]# ll -i
total 12
33574978 -rw-------. 1 root root 1453 Jun 13 19:27 anaconda-ks.cfg
33574979 -rwxr-xr-x  1 root root 1041 Aug  8 18:14 a.sh
33574990 -rwxr-xr-x  1 root root 1041 Aug  8 18:14 nfs.sh

2)使用一个远程shell程序(如rsh、ssh)来实现将本地机器的内容拷贝到远程机器。当DST路径地址包 \
含单个冒号":"分隔符时启动该模式。如:
[root@localhost ~]# rsync -avz nfs.sh root@172.16.12.129:/root/b.sh
sending incremental file list
nfs.sh

sent 643 bytes  received 35 bytes  1,356.00 bytes/sec
total size is 1,041  speedup is 1.54
[root@localhost ~]# ssh root@172.16.12.129 'ls -l /root'
total 8
-rw-------. 1 root root 1454 Aug  6 04:39 anaconda-ks.cfg
-rwxr-xr-x  1 root root 1041 Aug  8  2018 b.sh

3)使用一个远程shell程序(如rsh、ssh)来实现将远程机器的内容拷贝到本地机器。当SRC地址路径 \
包含单个冒号":"分隔符时启动该模式。如:
[root@localhost ~]# ls
anaconda-ks.cfg  a.sh  nfs.sh
[root@localhost ~]# rsync -avz root@172.16.12.129:/etc/yum.repos.d /root/
receiving incremental file list
yum.repos.d/
yum.repos.d/163.repo
yum.repos.d/redhat.repo

sent 66 bytes  received 918 bytes  1,968.00 bytes/sec
total size is 1,820  speedup is 1.85
[root@localhost ~]# ls
anaconda-ks.cfg  a.sh  nfs.sh  yum.repos.d
[root@localhost ~]# ls yum.repos.d/
163.repo  redhat.repo



//rsync常用选项:
    -a, --archive       //归档
    -v, --verbose       //啰嗦模式
    -q, --quiet         //静默模式
    -r, --recursive     //递归
    -p, --perms         //保持原有的权限属性
    -z, --compress      //在传输时压缩,节省带宽,加快传输速度
    --delete            //在源服务器上做的删除操作也会在目标服务器上同步

5.rsync+inotify

rsync与传统的cp、tar备份方式相比,rsync具有安全性高、备份迅速、支持增量备份等优点,通过rsync可以解决对实时性要求不高的数据备份需求,例如定期的备份文件服务器数据到远端服务器,对本地磁盘定期做数据镜像等。
随着应用系统规模的不断扩大,对数据的安全性和可靠性也提出的更好的要求,rsync在高端业务系统中也逐渐暴露出了很多不足,首先,rsync同步数据时,需要扫描所有文件后进行比对,进行差量传输。如果文件数量达到了百万甚至千万量级,扫描所有文件将是非常耗时的。而且正在发生变化的往往是其中很少的一部分,这是非常低效的方式。其次,rsync不能实时的去监测、同步数据,虽然它可以通过linux守护进程的方式进行触发同步,但是两次触发动作一定会有时间差,这样就导致了服务端和客户端数据可能出现不一致,无法在应用故障时完全的恢复数据。基于以上原因,rsync+inotify组合出现了!

Inotify是一种强大的、细粒度的、异步的文件系统事件监控机制,linux内核从2.6.13起,加入了Inotify支持,通过Inotify可以监控文件系统中添加、删除,修改、移动等各种细微事件,利用这个内核接口,第三方软件就可以监控文件系统下文件的各种变化情况,而inotify-tools就是这样的一个第三方软件。
在前面有讲到,rsync可以实现触发式的文件同步,但是通过crontab守护进程方式进行触发,同步的数据和实际数据会有差异,而inotify可以监控文件系统的各种变化,当文件有任何变动时,就触发rsync同步,这样刚好解决了同步数据的实时性问题。

把源服务器上/etc目录实时同步到目标服务器的/tmp/下
在目标服务器上做一下操作

//关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]# getenforce
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/sysconfig/selinux
//安装rsync服务端软件
[root@localhost ~]#  yum -y install rsync  rsync-daemon
上次元数据过期检查:23:10:53 前,执行于 2021年10月10日 星期日 23时32分12秒。
软件包 rsync-3.1.3-11.el8.x86_64 已安装。
依赖关系解决。
设置rsyncd.conf配置文件
[root@localhost ~]# cat /etc/rsyncd.conf 
log file = /var/log/rsyncd.log   
pidfile = /var/run/rsyncd.pid     
lock file = /var/run/rsync.lock   
secrets file = /etc/rsync.pass    

[etc_from_client]     
path = /tmp/        
comment = sync etc from client
uid = root        
gid = root        
port = 873        
ignore errors     
read only = no    
list = no     
max connections = 200     
timeout = 600     
auth users = admin       
hosts allow = 192.168.197.131
//创建用户认证文件
[root@localhost ~]# echo 'admin:123456' > /etc/rsync.pass
[root@localhost ~]# cat /etc/rsync.pass
admin:123456
//设置用户权限
[root@localhost ~]# chmod 600 /etc/rsync*
[root@localhost ~]# ll /etc/rsync*
-rw-------. 1 root root 885 1011 22:52 /etc/rsyncd.conf
-rw-------. 1 root root  13 1011 22:54 /etc/rsync.pass
//启动rsync服务并设置开机自启动
[root@localhost ~]# systemctl start rsyncd
[root@localhost ~]# systemctl enable rsyncd
Created symlink /etc/systemd/system/multi-user.target.wants/rsyncd.service → /usr/lib/systemd/system/rsyncd.service.
[root@localhost ~]# ss -antl
State    Recv-Q   Send-Q      Local Address:Port       Peer Address:Port   Process   
LISTEN   0        5                 0.0.0.0:873             0.0.0.0:*                
LISTEN   0        128               0.0.0.0:111             0.0.0.0:*                
LISTEN   0        32          192.168.122.1:53              0.0.0.0:*                
LISTEN   0        128               0.0.0.0:22              0.0.0.0:*                
LISTEN   0        5               127.0.0.1:631             0.0.0.0:*                
LISTEN   0        5                    [::]:873                [::]:*                
LISTEN   0        80                      *:3306                  *:*                
LISTEN   0        128                  [::]:111                [::]:*                
LISTEN   0        128                  [::]:22                 [::]:*                
LISTEN   0        5                   [::1]:631                [::]:*  

在源服务器上做以下操作:

//关闭防火墙和selinux
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld     
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@localhost ~]#  getenforce 0
Enforcing
[root@localhost ~]# setenforce 0
[root@localhost ~]# sed -ri 's/^(SELINUX=).*/\1disabled/g' /etc/sysconfig/selinux
[root@localhost ~]# cd /etc/yum.repos.d/
[root@localhost yum.repos.d]# wget http://mirrors.163.com/.help/CentOS7-Base-163.repo
--2021-10-11 23:02:41--  http://mirrors.163.com/.help/CentOS7-Base-163.repo
正在解析主机 mirrors.163.com (mirrors.163.com)... 59.111.0.251
正在连接 mirrors.163.com (mirrors.163.com)|59.111.0.251|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:1572 (1.5K) [application/octet-stream]
正在保存至: “CentOS7-Base-163.repo”

CentOS7-Base-163.repo 100%[======================>]   1.54K  --.-KB/s  用时 0s      

2021-10-11 23:02:41 (56.7 MB/s) - 已保存 “CentOS7-Base-163.repo” [1572/1572])

[root@localhost yum.repos.d]# cd 
[root@localhost ~]# sed -i 's/\$releasever/7/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost ~]# sed -i 's/^enabled=.*/enabled=1/g' /etc/yum.repos.d/CentOS7-Base-163.repo
[root@localhost ~]# yum -y install epel-release
[root@localhost ~]# yum -y install rsync
Extra Packages for Enterprise Linux 7 - x86_64       2.5 MB/s |  17 MB     00:06    
上次元数据过期检查:0:00:04 前,执行于 2021年10月11日 星期一 23时04分34秒。
软件包 rsync-3.1.3-11.el8.x86_64 已安装。
依赖关系解决。
无需任何处理。
//创建认证密码文件
[root@localhost ~]# echo '123456' > /etc/rsync.pass
[root@localhost ~]# cat /etc/rsync.pass
123456
[root@localhost ~]# chmod 600 /etc/rsync.pass
//创建测试目录
[root@localhost ~]# mkdir -pv /root/etc/test
mkdir: 已创建目录 '/root/etc'
mkdir: 已创建目录 '/root/etc/test'
[root@localhost ~]# rsync -avH --port 873 --progress --delete /root/etc/ admin@192.168.197.128::etc_from_client --password-file=/etc/rsync.pass
sending incremental file list
deleting vmware-root_924-2722763428/
deleting vmware-root_903-3979774182/
deleting tracker-extract-files.1000/
deleting tracker-extract-files.0/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-rtkit-daemon.service-g7Bco8/tmp/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-rtkit-daemon.service-g7Bco8/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-mariadb.service-kKwmzS/tmp/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-mariadb.service-kKwmzS/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-geoclue.service-drC8Zv/tmp/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-geoclue.service-drC8Zv/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-fwupd.service-leCjdT/tmp/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-fwupd.service-leCjdT/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-colord.service-zoT1xA/tmp/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-colord.service-zoT1xA/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-chronyd.service-2OVAlF/tmp/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-chronyd.service-2OVAlF/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-ModemManager.service-AWAetc/tmp/
deleting systemd-private-ab9f8f7ff4744405af6888ae91fe702b-ModemManager.service-AWAetc/
deleting .local/share/ibus-typing-booster/data/
deleting .local/share/ibus-typing-booster/
deleting .local/share/
deleting .local/
deleting .font-unix/
deleting .esd-975/
deleting .esd-1000/socket
deleting .esd-1000/
deleting .esd-0/socket
deleting .esd-0/
deleting .XIM-unix/
deleting .X11-unix/X1024
deleting .X11-unix/X0
deleting .X11-unix/
deleting .Test-unix/
deleting .ICE-unix/2153
deleting .ICE-unix/1492
deleting .ICE-unix/
deleting sensitive-info.log
deleting program.log
deleting packaging.log
deleting ks-script-sjvqx3ij
deleting dbus.log
deleting anaconda.log
deleting .viminfo
deleting .X1024-lock
deleting .X0-lock
./
test/

sent 77 bytes  received 1,722 bytes  719.60 bytes/sec
total size is 0  speedup is 0.00
//安装inotify-tools工具,实时触发rsync进行同步
[root@localhost ~]#  yum -y install make gcc gcc-c++ inotify-tools
上次元数据过期检查:0:05:14 前,执行于 2021年10月11日 星期一 23时04分34秒。
软件包 make-1:4.2.1-10.el8.x86_64 已安装。
软件包 gcc-8.4.1-1.el8.x86_64 已安装。
软件包 gcc-c++-8.4.1-1.el8.x86_64 已安装。
依赖关系解决。
[root@localhost ~]# mkdir /scripts
[root@localhost ~]# touch /scripts/inotify.sh
[root@localhost ~]# chmod 755 /scripts/inotify.sh 
[root@localhost ~]# cat /scripts/inotify.sh 
host=192.168.197.128      
src=/etc        
des=etc_from_client  
password=/etc/rsync.pass
inotifywait=/usr/bin/inotifywait

$inotifywait -mrq --timefmt '%Y%m%d %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src \ 
        | while read files;do
    rsync -avzP --delete  --timeout=100 --password-file=${password} $src $user@$host::$des
        echo "${files} was rsynced" >>/tmp/rsync.log 2>&1
done
//启动
[root@localhost ~]# nohup bash /scripts/inotify.sh >/dev/null 2>&1&
[5] 1729334
[4]   已完成               nohup bash /scripts/inotify.sh > /dev/null 2>&1
//在源服务器上生成一个新文件
[root@localhost ~]# ls /etc/yum.repos.d/
CentOS-Stream-AppStream.repo
CentOS-Stream-BaseOS.repo
[root@localhost ~]# echo 'hello world' >  /etc/yum.repos.d/test
//查看inotify生成的日志
[root@localhost ~]# tail /tmp/rsync.log
//设置脚本开机自动启动
[root@localhost ~]# chmod +x /etc/rc.d/rc.local
[root@localhost ~]# ll /etc/rc.d/rc.local
-rwxr-xr-x 1 root root 473 Aug 10 23:23 /etc/rc.d/rc.local
[root@localhost ~]# echo 'nohup /bin/bash /scripts/inotify.sh' >> /etc/rc.d/rc.local
[root@localhost ~]# tail /etc/rc.d/rc.local
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local
nohup /bin/bash /scripts/inotify.sh
[root@localhost tmp]# ls /etc/yum.repos.d
CentOS-Stream-AppStream.repo
CentOS-Stream-BaseOS.repo

gitlab

1.版本控制介绍

版本控制是指对软件开发过程中各种程序代码、配置文件及说明文档等文件变更的管理,是软件配置管理的核心思想之一。

版本控制最主要的功能就是追踪文件的变更。它将什么时候、什么人更改了文件的什么内容等信息忠实地了记录下来。每一次文件的改变,文件的版本号都将增加。除了记录版本变更外,版本控制的另一个重要功能是并行开发。软件开发往往是多人协同作业,版本控制可以有效地解决版本的同步以及不同开发者之间的开发通信问题,提高协同开发的效率。并行开发中最常见的不同版本软件的错误(Bug)修正问题也可以通过版本控制中分支与合并的方法有效地解决。
具体来说,在每一项开发任务中,都需要首先设定开发基线,确定各个配置项的开发初始版本,在开发过程中,开发人员基于开发基线的版本,开发出所需的目标版本。当发生需求变更时,通过对变更的评估,确定变更的影响范围,对被影响的配置项的版本进行修改,根据变更的性质使配置项的版本树继续延伸或产生新的分支,形成新的目标版本,而对于不受变更影响的配置项则不应发产生变动。同时,应能够将变更所产生的对版本的影响进行记录和跟踪。必要时还可以回退到以前的版本。例如当开发需求或需求变更被取消时,就需要有能力将版本回退到开发基线版本。在曾经出现过的季度升级包拆包和重新组包的过程中,其实就是将部分配置项的版本回退到开发基线,将对应不同需求的不同分支重新组合归并,形成新的升级包版本。
版本控制是软件配置管理的核心功能。所有置于配置库中的元素都应自动予以版本的标识,并保证版本命名的唯一性。版本在生成过程中,自动依照设定的使用模型自动分支、演进。除了系统自动记录的版本信息以外,为了配合软件开发流程的各个阶段。还需要定义、收集一些元数据来记录版本的辅助信息和规范开发流程,并为今后对软件过程的度量做好准备。当然如果选用的工具支持,这些辅助数据将能直接统计出过程数据,从而方便软件过程改进活动的进行。对于配置库中的各个基线控制项,应该根据其基线的位置和状态来设置相应的访问权限。一般来说,对于基线版本之前的各个版本都应处于被锁定的状态,如需要对它们进行变更,则应按照变更控制的流程来进行操作。

常用的版本控制工具:

gitlab
subversion

2.gitlab部署

[root@localhost ~]# yum -y install epel-release
上次元数据过期检查:0:23:24 前,执行于 2021年10月11日 星期一 23时04分34秒。
软件包 epel-release-7-11.noarch 已安装。
依赖关系解决。
=====================================================================================
 软件包                   架构               版本             仓库              大小
=====================================================================================
升级:
[root@localhost ~]# yum -y install git curl openssh-server openssh-clients postfix cronie policycoreutils-python-utils

Extra Packages for Enterprise Linux 7 - x86_64       3.7 MB/s |  17 MB     00:04    
上次元数据过期检查:0:00:02 前,执行于 2021年10月11日 星期一 23时28分31秒。
软件包 curl-7.61.1-17.el8.x86_64 已安装。
软件包 openssh-server-8.0p1-5.el8.x86_64 已安装。
[root@localhost ~]# systemctl restart postfix
[root@localhost ~]# systemctl enable postfix
Created symlink /etc/systemd/system/multi-user.target.wants/postfix.service → /usr/lib/systemd/system/postfix.service.
[root@localhost ~]# wget https://mirrors.tuna.tsinghua.edu.cn/gitlab-ce/yum/el8/gitlab-ce-14.3.2-ce.0.el8.x86_64.rpm
正在保存至: “gitlab-ce-14.3.2-ce.0.el8.x86_64.rpm”

gitlab-ce-14.3.2-ce.0 100%[======================>] 917.02M  10.7MB/s  用时 90s     

2021-10-11 23:31:44 (10.2 MB/s) - 已保存 “gitlab-ce-14.3.2-ce.0.el8.x86_64.rpm” [961561901/961561901])
[root@localhost ~]# rpm -ivh gitlab-ce-14.3.2-ce.0.el8.x86_64.rpm 
警告:gitlab-ce-14.3.2-ce.0.el8.x86_64.rpm: 头V4 RSA/SHA256 Signature, 密钥 ID f27eab47: NOKEY
Verifying...                          ################################# [100%]
准备中...                          ################################# [100%]
正在升级/安装...
   1:gitlab-ce-14.3.2-ce.0.el8        #############################     ( 87%)
[root@localhost ~]# vim /etc/gitlab/gitlab.rb   
external_url 'http://192.168.197.131'
//重启
[root@localhost ~]# gitlab-ctl reconfigure+

# svn安装

1.下载

下载地址: https://tortoisesvn.net/downloads.html

进入界面安装
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
请添加图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值