Shell脚本搭建高效数据镜像备份Rsync服务

本文发布时间: 2019-Mar-22
在我们的日常运维中,会经常遇到搭建rsync服务的需求,如:网站文件的同步(镜像或备份),patch的更新,各种异机备份等容灾备份等等。如果把rsync服务的搭建写成脚本,那么就可以在执行脚本之后,有了基本的服务框架,只需针对具体的细节、安全要求做进一步改善,就OK,从而提高我们的工作效率。很多Linux系统,像RHEL和CentOS默认安装的是rsync 2.x版本的,而我推荐使用3.x版本,因为3.x在同步算法上有改进,更加有效率。rsync官网:http://rsync.samba.org/1)下载最新稳定版本rsync-3.0.8[root@server ~]# cd tools[root@server tools]# wget -c http://rsync.samba.org/ftp/rsync/src/rsync-3.0.8.tar.gz2)编译安装rsync-3.0.8[root@server tools]# tar xf rsync-3.0.8.tar.gz[root@server tools]# cd rsync-3.0.8[root@server rsync-3.0.8]# ./configure && make3)编译安装后,会在rsync-3.0.8/目录中生成rsync二进制文件,把它拷贝到/usr/local/bin/下:[root@server rsync-3.0.8]# \cp rsync /usr/local/binPS:服务端和客户端都要进行以上的安装操作,如果客户端和服务端都是一种类型的操作系统,可以编译安装一次,然后把rsync二进制命令分发到其他服务器的/usr/local/bin/下即可。4)在服务端编辑Rsync服务搭建脚本(rsync_server_set.sh)[root@server ]# cd shells/[root@server shells]# vi rsync_server_set.sh#!/bin/bash## Script Name: rsync_server_set.sh# Description: set rsync service quickly.# +------------------ client side e.g. ------------------+# $rsync -avz /root/admin/xxx.txt $address::mystation# $rsync -avz $address::xxx_client/ /home/# +------------------------------------------------------+# Author: 300second - 51cto.com# Date: 2012-10-18# rsync=/usr/local/bin/rsyncconf_file=/etc/rsyncd.confport=873address=192.168.1.41hosts_allow=192.168.1.0/24rsync_dir='[mystation]path = /home/admin/'date=`date +%F" "%T`cat > $conf_file <<EOFpid file = /var/run/rsyncd.pidport = $portaddress = $addressuid = rootgid = rootuse chroot = noread only = nohosts allow = $hosts_allow#hosts deny = *$rsync_dirEOF$rsync --daemon --config=$conf_filecat >>/etc/rc.local <<EOF# rsync daemon $date$rsync --daemon --config=$conf_fileEOFexit 05)在服务端直接运行该脚本就搭建好了Rsync服务[root@server shells]# chmod 755 rsync_server_set.sh[root@server shells]# ./rsync_server_set.sh本文出自 “300second的运维小站” 博客


(以上内容不代表本站观点。)
---------------------------------
本网站以及域名有仲裁协议。
本網站以及域名有仲裁協議。

2024-Mar-04 02:11pm
栏目列表