1.rsync同步簡介
2.配置rsync備份源
3.rsync命令基本用法
4.rsync備份操作示例
5.rsync+inotify結(jié)合使用成都創(chuàng)新互聯(lián)公司專注于景洪企業(yè)網(wǎng)站建設(shè),響應(yīng)式網(wǎng)站建設(shè),電子商務(wù)商城網(wǎng)站建設(shè)。景洪網(wǎng)站建設(shè)公司,為景洪等地區(qū)提供建站服務(wù)。全流程定制網(wǎng)站建設(shè),專業(yè)設(shè)計,全程項目跟蹤,成都創(chuàng)新互聯(lián)公司專業(yè)和態(tài)度為您提供的服務(wù)
1.Remote Sync,遠程同步
2.支持本地復(fù)制,或者與其他SSH、rsync主機同步
3.官方網(wǎng)站: http://rsync.samba.org
CentOS 7-4作為同步源:192.168.18.148
CentOS 7-5作為客戶機:192.168.18.145
[root@localhost ~]# hostnamectl set-hostname rsyncd
[root@localhost ~]# su
[root@rsyncd ~]# rpm -q rsync
rsync-3.0.9-18.el7.x86_64
[root@rsyncd ~]# vim /etc/rsyncd.conf
uid = nobody
gid = nobody
use chroot = yes
pid file = /var/run/rsyncd.pid
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
#以上內(nèi)容去掉注釋
address = 192.168.18.148 #本機IP地址
port 873 #開端口
log file = /var/rsyncd.log #指定日志文件
hosts allow = 192.168.18.0/24 #允許網(wǎng)段訪問
#在pid下行添加以上內(nèi)容
[wwwroot]
path = /var/www/html
comment = www.kgc.com
read only = yes
auth users = backuper
secrets file = /etc/rsyncd_users.db
#在dont下一行插入以上內(nèi)容:共享模塊
#修改完成后按Esc退出插入模式,輸入:wq保存退出
#添加密碼文件
[root@rsyncd ~]# vim /etc/rsyncd_users.db
backuper:abc123 #需要和共享模塊中的auth_users名稱一致
#添加完成后按Esc退出插入模式,輸入:wq保存退出
[root@rsyncd ~]# chmod 600 /etc/rsyncd_users.db
[root@rsyncd ~]# rsync --daemon
[root@rsyncd ~]# netstat -ntap | grep rsync
tcp 0 0 192.168.18.148:873 0.0.0.0:* LISTEN 6150/rsync
#此時873端口開啟
[root@rsyncd ~]# systemctl stop firewalld.service
[root@rsyncd ~]# setenforce 0
[root@rsyncd ~]# yum install httpd -y
[root@rsyncd html]# cd ..
[root@rsyncd www]# chmod 777 html/
[root@rsyncd www]# ls -l
總用量 0
drwxr-xr-x. 2 root root 6 8月 8 19:42 cgi-bin
drwxrwxrwx. 2 root root 24 12月 16 08:41 html
[root@localhost ~]# hostnamectl set-hostname client
[root@localhost ~]# su
[root@client ~]# systemctl stop firewalld.service
[root@client ~]# setenforce 0
[root@client ~]# rpm -q rsync
rsync-3.0.9-18.el7.x86_64
[root@client ~]# yum install httpd -y
[root@client ~]# cd /var/www/html/
#此時文件中是空的沒有文件的
[root@client html]# cd ..
[root@client www]# chmod 777 html/
[root@client www]# ls -l
總用量 0
drwxr-xr-x. 2 root root 6 8月 8 19:42 cgi-bin
drwxrwxrwx. 2 root root 6 8月 8 19:42 html
#同步方法一:
[root@client www]# rsync -avz backuper@192.168.18.148::wwwroot /var/www/html/
Password: #此時輸入密碼abc123,敲回車
receiving incremental file list
./
index.html
sent 83 bytes received 172 bytes 12.44 bytes/sec
total size is 17 speedup is 0.07
[root@client www]# cd html/
[root@client html]# ls #此時index.html文件被同步
index.html
[root@client html]# cat index.html
this is test web
#同步方法二:
[root@client www]# rsync -avz rsync://backuper@192.168.18.148::wwwroot /var/www/html/
Password: #此時輸入密碼abc123,敲回車
receiving incremental file list
./
index.html
sent 83 bytes received 172 bytes 12.44 bytes/sec
total size is 17 speedup is 0.07
[root@client www]# cd html/
[root@client html]# ls #此時index.html文件被同步
index.html
[root@client html]# cat index.html
this is test web
[root@client html]# vim /etc/server.pass
abc123
#寫入密碼信息后按Esc退出插入模式,輸入:wq保存退出
[root@client html]# chmod 600 /etc/server.pass
[root@client html]# rsync -avz --delete --password-file=/etc/server.pass backuper@192.168.18.148::wwwroot /var/www/html/ #用此條命令可以直接進入
receiving incremental file list
./
index.html
sent 83 bytes received 172 bytes 510.00 bytes/sec
total size is 17 speedup is 0.07
[root@client html]# ls
index.html
[root@client html]# cat index.html
this is test web
#后面就可以在crontab -e中添加計劃任務(wù)了
1.執(zhí)行備份的時間固定,延遲明顯、實時性差
2.當(dāng)同步源長期不變化時,密集的定期任務(wù)是不必要的
1.一旦同步源出現(xiàn)變化,立即啟動備份
2.只要同步源無變化,則不執(zhí)行備份
1.從版本2.6.13開始提供
2.可以監(jiān)控文件系統(tǒng)的變動情況,并作出通知響應(yīng)
3.輔助軟件: inotify-tools
[root@rsyncd www]# vim /etc/rsyncd.conf
read only = no #關(guān)閉只讀功能
#修改完成后按Esc退出插入模式,輸入:wq保存退出
執(zhí)行腳本
[root@rsyncd ~]# netstat -ntap | grep rsync
tcp 0 0 192.168.18.148:873 0.0.0.0:* LISTEN 2768/rsync
[root@rsyncd ~]# kill -9 2768 #殺死該進程
[root@rsyncd ~]# rsync --daemon #啟動rsync
[root@rsyncd ~]# failed to create pid file /var/run/rsyncd.pid: File exists
#提示有pid文件存在
[root@rsyncd ~]# cd /var/run/
[root@rsyncd run]# ls
abrt dhclient-ens33.pid lock radvd syslogd.pid
alsactl.pid dmeventd-client log rpcbind systemd
atd.pid dmeventd-server lsm rpcbind.sock tmpfiles.d
auditd.pid faillock lvm rsyncd.pid tuned
avahi-daemon firewalld lvmetad.pid samba udev
certmonger gdm mdadm sepermit udisks2
chrony gssproxy.pid media setrans user
chronyd.pid gssproxy.sock mount setroubleshoot utmp
console httpd named sm-notify.pid vmware
crond.pid initramfs netreport spice-vdagentd xtables.lock
cron.reboot ksmtune.pid NetworkManager sshd.pid
cups libvirt plymouth sudo
dbus libvirtd.pid ppp sysconfig
[root@rsyncd run]# cat rsyncd.pid
2768
[root@rsyncd run]# rm -rf rsyncd.pid #刪除此pid文件
[root@rsyncd run]# rsync --daemon #再次啟動
[root@rsyncd run]# netstat -ntap | grep rsync #此時會生成新的pid號
tcp 0 0 192.168.18.148:873 0.0.0.0:* LISTEN 5416/rsync
[root@rsyncd run]# cat rsyncd.pid
5416
#此時正常運轉(zhuǎn)rsync
[root@client opt]# ./inotify.sh
#此時監(jiān)控開啟
[root@client html]# echo "this is test" > test.txt
[root@rsyncd run]# cd /var/www/html/
[root@rsyncd html]# ls
index.html test.txt
[root@rsyncd html]# cat test.txt
this is test
另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。
本文題目:rsync遠程同步(定期同步,實時同步實戰(zhàn)!)-創(chuàng)新互聯(lián)
當(dāng)前路徑:http://jinyejixie.com/article8/jseop.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供搜索引擎優(yōu)化、網(wǎng)站設(shè)計公司、網(wǎng)站維護、定制開發(fā)、手機網(wǎng)站建設(shè)、定制網(wǎng)站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容