rsync + crond ==定時數據同步centos
sersync(inotify) + rsync ==實時數據同步,利用rsync實現安全
##應用場景服務器
..1 主備服務器之間同步數據定時 ==配合crond sersync inotify等實現ui
..1 安裝spa
centos6.5已經安裝了rsync3d
rpm -qa | grep rsyncorm
若是沒有,用下面兩種方式之一安裝server
yum install rsyncblog
rpm -ivh rsyn.xxxxxxxxx.rpm ==這個要本身去尋找一下rpm的安裝包,推薦直接使用yum的安裝方式ip
..2 配置
..2.1三個配置文件,這幾個文件都須要手動建立
touche /etc/rsyncd.d/rsyncd.conf ==主配置文件
touche /etc/rsyncd.d/rsyncd.secrets ==用戶名和密碼配置文件
touche /etc/rsyncd.d/rsyncd.motd ==客戶端登陸的提示信息
chmod 600 touche /etc/rsyncd.d/rsyncd.secrets ==密碼文件要注意權限的安全性
..2.1.1 /etc/rsyncd.d/rsyncd.conf
# Distributed under the terms of the GNU General Public License v2
# Minimal configuration file for rsync daemon
# See rsync(1) and rsyncd.conf(5) man pages for help
# This line is required by the /etc/init.d/rsyncd script
pid file = /var/run/rsyncd.pid
port = 873
address = 192.168.202.100
#uid = nobody
#gid = nobody
uid = rsyncd #軟件使用哪個用戶操做本地的文件
gid = rsyncd
use chroot = no
read only = no #能夠讀寫的意思
#limit access to private LANs
hosts allow=192.168.202.0/255.255.255.0 10.0.1.0/255.255.255.0
hosts deny=*
max connections = 5
motd file = /etc/rsyncd.d/rsyncd.motd
#This will give you a separate log file
#log file = /var/log/rsync.log
#This will log every file transferred - up to 85,000+ per user, per sync
#transfer logging = yes
log format = %t %a %m %f %b
syslog facility = local3
timeout = 300
##下面是兩個模塊module,客戶端來訪問的時候是使用中括號中的模塊兒名
[100data1] ##模塊名
path = /backup/data1 ##真實的路徑
list=yes ##是否容許list
ignore errors
auth users = root
secrets file = /etc/rsyncd.d/rsyncd.secrets
comment = This is 100 server data1
exclude = ##list的時候會顯示
[100data2]
path = /backup/data2
list=yes
ignore errors
auth users = root
secrets file = /etc/rsyncd.d/rsyncd.secrets
comment = This is 100 server data2
exclude =
..2.1.二、 /etc/rsyncd.d/rsyncd.secrets
服務端的密碼文件,能夠寫多個用戶,這裏的
..2.1.3 /etc/rsyncd.d/motd 客戶端使用的時候的提示文本
..2.2啓動
/usr/bin/rsync --daemon --config=/etc/rsyncd.d/rsyncd.conf
以daemon方式運行起來,端口就是配置文件裏面的873
..2.3 新建目錄,用戶同步數據的目錄,從配置文件中看出目錄是 /backup/data1 /backup/data2
mkdir –p /backup/data1
mkdir –p /backup/data2
chown –R rsyncd /backup/data1 ==讓配文件的用戶對此文件有讀寫的權限
chown –R rsyncd /backup/data2 ====讓配文件的用戶對此文件有讀寫的權限
..1 安裝
centos6.5已經安裝了rsync
rpm -qa | grep rsync
若是沒有,用下面兩種方式之一安裝
yum install rsync
rpm -ivh rsyn.xxxxxxxxx.rpm
..2 配置 和 創建目錄文件
touch /etc/rsyncd.d/rsyncd.secrets 在裏面寫入密碼
chmod 600 /etc/rsyncd.d/rsyncd.secrets ==這個是爲了安全
mkdir –p /backup/data1
mkdir –p /backup/data2
..3 鏈接服務器端使用
..3.0 man rsync
..3.1 list
rsync --list-only rsync://root@192.168.202.100 這個不須要密碼,直接就看見了
..3.2 上傳
rsync -avzp –password file=/etc/rsyncd.d/rsyncd.secrets /backup/data2/ rsync://root@192.168.202.100:/100data2
..3.3 下載
rsync -avzp --password-file=/etc/rsyncd.d/rsyncd.secrets rsync://root@192.168.202.100:/100data2 .