{"id":57,"date":"2015-07-05T13:40:19","date_gmt":"2015-07-05T05:40:19","guid":{"rendered":"http:\/\/cn.hostease.com\/xueyuan\/?p=57"},"modified":"2015-11-10T14:21:56","modified_gmt":"2015-11-10T06:21:56","slug":"rsyncinotify-%e5%ae%9e%e7%8e%b0%e6%95%b0%e6%8d%ae%e5%ae%9e%e6%97%b6%e5%90%8c%e6%ad%a5","status":"publish","type":"post","link":"https:\/\/cn.hostease.com\/xueyuan\/uncategorized\/rsyncinotify-%e5%ae%9e%e7%8e%b0%e6%95%b0%e6%8d%ae%e5%ae%9e%e6%97%b6%e5%90%8c%e6%ad%a5\/","title":{"rendered":"rsync+inotify \u5b9e\u73b0\u6570\u636e\u5b9e\u65f6\u540c\u6b65"},"content":{"rendered":"<p>rsync\u53ef\u4ee5\u5b9e\u73b0\u89e6\u53d1\u5f0f\u7684\u6587\u4ef6\u540c\u6b65\uff0c\u4f46\u662f\u901a\u8fc7crontab\u5b88\u62a4\u8fdb\u7a0b\u65b9\u5f0f\u8fdb\u884c\u89e6\u53d1\uff0c\u540c\u6b65\u7684\u6570\u636e\u548c\u5b9e\u9645\u6570\u636e\u4f1a\u6709\u5dee\u5f02\uff0c\u800cinotify\u53ef\u4ee5\u76d1\u63a7\u6587\u4ef6\u7cfb\u7edf\u7684\u5404\u79cd\u53d8\u5316\uff0c\u5f53\u6587\u4ef6\u6709\u4efb\u4f55\u53d8\u52a8\u65f6\uff0c\u5c31\u89e6\u53d1rsync\u540c\u6b65\uff0c\u8fd9\u6837\u521a\u597d\u89e3\u51b3\u4e86\u540c\u6b65\u6570\u636e\u7684\u5b9e\u65f6\u6027\u95ee\u9898\u3002<\/p>\n<p><strong>\u4e00\u3001\u57fa\u672c\u73af\u5883<\/strong><\/p>\n<p>\u7cfb\u7edf\uff1aCentOS\u00a02.6.32-220.el6.x86_64<br \/>\n\u8f6f\u4ef6\u5305\u7248\u672c\uff1arsync-3.0.6-12.el6.x86_64<br \/>\ninotify-tools-3.14<br \/>\n\u4e0b\u8f7d\u94fe\u63a5\uff1ahttps:\/\/github.com\/downloads\/rvoicilas\/inotify-tools\/inotify-tools-3.14.tar.gz<\/p>\n<p>\u670d\u52a1\u7aef\uff08server\uff09\uff1a172.16.32.204<br \/>\n\u5ba2\u670d\u7aef\uff08client1\uff09\uff1a172.16.32.205<br \/>\n\uff08client2\uff09\uff1a172.16.32.206<\/p>\n<p><strong>\u4e8c\u3001\u5ba2\u6237\u7aef\u914d\u7f6e\uff08172.16.32.205\u3001172.163.32.206\uff09<\/strong><\/p>\n<p><strong>1. client1 172.16.32.205\u914d\u7f6e<\/strong><\/p>\n<p>\u5b89\u88c5rsync<br \/>\n<strong>#yum install -y rsync xinetd<\/strong><\/p>\n<p>\u5728\/etc\/\u76ee\u5f55\u4e0b\u5efa\u7acbrsyncd.conf\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u7f16\u8f91<br \/>\n<strong>#vim \/etc\/rsyncd.conf\u00a0<\/strong><\/p>\n<p>uid = nobody<br \/>\ngid = nobody<br \/>\nuse chroot = no<br \/>\nmax connections = 10<br \/>\nstrict modes = yes<br \/>\npid file = \/var\/run\/rsyncd.pid<br \/>\nlock file = \/var\/run\/rsync.lock<br \/>\nlog file = \/var\/log\/rsyncd.log<br \/>\n[lixuan]<br \/>\npath = \/data\/lixuan\/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u672c\u5730\u81ea\u5b9a\u4e49\u8def\u5f84<br \/>\ncomment = client file<br \/>\nignore errors<br \/>\nread only = no<br \/>\nwrite only = no<br \/>\nhosts allow = 172.16.32.204 \u00a0 \u00a0 \u00a0\u00a0#\u670d\u52a1\u7aefIP\u5730\u5740<br \/>\nhosts deny = *<br \/>\nlist = false<br \/>\nuid = root<br \/>\ngid = root<br \/>\nauth users = root<br \/>\nsecrets file = \/etc\/client1.pass \u00a0 \u00a0 #\u81ea\u52a8\u540c\u6b65\u5bc6\u7801\u6587\u4ef6<\/p>\n<p>\u65b0\u5efa\/etc\/client1.pass \u00a0\u6587\u4ef6<br \/>\n<strong>#echo &#8220;root:123456&#8221; &gt;&gt;\/etc\/client1.pass<\/strong><br \/>\n<strong> #chmod 600 \/etc\/client1.pass<\/strong><\/p>\n<p>\u542f\u52a8rsync\u670d\u52a1<br \/>\n<strong>#\/etc\/init.d\/xinetd start<\/strong><\/p>\n<p><strong>2<\/strong><strong>. client2 172.16.32.206\u914d\u7f6e<\/strong><\/p>\n<p>\u5b89\u88c5rsync<br \/>\n<strong>#yum install -y rsync xinetd<\/strong><\/p>\n<p>\u5728\/etc\/\u76ee\u5f55\u4e0b\u5efa\u7acbrsyncd.conf\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u7f16\u8f91<br \/>\n<strong>#vim \/etc\/rsyncd.conf\u00a0<\/strong><\/p>\n<p>uid = nobody<br \/>\ngid = nobody<br \/>\nuse chroot = no<br \/>\nmax connections = 10<br \/>\nstrict modes = yes<br \/>\npid file = \/var\/run\/rsyncd.pid<br \/>\nlock file = \/var\/run\/rsync.lock<br \/>\nlog file = \/var\/log\/rsyncd.log<br \/>\n[lixuan]<br \/>\npath = \/data\/lixuan\/ \u00a0 \u00a0 \u00a0 \u00a0 \u00a0#\u672c\u5730\u81ea\u5b9a\u4e49\u8def\u5f84<br \/>\ncomment = client file<br \/>\nignore errors<br \/>\nread only = no<br \/>\nwrite only = no<br \/>\nhosts allow = 172.16.32.204 \u00a0 \u00a0\u00a0\u00a0#\u670d\u52a1\u7aefIP\u5730\u5740<br \/>\nhosts deny = *<br \/>\nlist = false<br \/>\nuid = root<br \/>\ngid = root<br \/>\nauth users = root<br \/>\nsecrets file = \/etc\/client2.pass \u00a0 \u00a0 #\u81ea\u52a8\u540c\u6b65\u5bc6\u7801\u6587\u4ef6<\/p>\n<p>\u4fdd\u5b58\u9000\u51fa\uff01<\/p>\n<p>\u65b0\u5efa\/etc\/client2.pass \u00a0\u6587\u4ef6<br \/>\n<strong>#echo &#8220;root:123456&#8221; &gt;&gt;\/etc\/client2.pass<br \/>\nchmod 600 \/etc\/client2.pass<\/strong><\/p>\n<p>\u542f\u52a8rsync\u670d\u52a1<br \/>\n<strong>#\/etc\/init.d\/xinetd start<\/strong><\/p>\n<p><strong>\u4e09\u3001\u670d\u52a1\u7aef\u914d\u7f6e\uff08172.16.32.204\uff09<\/strong><\/p>\n<p><strong>1.\u5b89\u88c5rsync\u00a0<\/strong><br \/>\n<strong><br \/>\n#yum install -y rsync xinetd<\/strong><\/p>\n<p>\u5728\/etc\/\u76ee\u5f55\u4e0b\u5efa\u7acbrsyncd.conf\u914d\u7f6e\u6587\u4ef6\u8fdb\u884c\u7f16\u8f91<br \/>\n<strong>#vim \/etc\/rsyncd.conf\u00a0<\/strong><\/p>\n<p>uid = root<br \/>\ngid = root<br \/>\nuse chroot = no<br \/>\nmax connections = 100<br \/>\nlog file = \/var\/log\/rsyncd.log<br \/>\npid file = \/var\/run\/rsyncd.pid<br \/>\nlock file = \/var\/run\/rsync.lock<br \/>\nsecrets file = \/etc\/server.pass<br \/>\n[lixuan]<br \/>\npath = \/data\/lixuan\/<br \/>\nauth users = root<br \/>\nlist = no<br \/>\nread only = no<br \/>\nsecrets file = \/etc\/servers.pass<br \/>\ncomment = server\u00a0directory<\/p>\n<p>\u4fdd\u5b58\u9000\u51fa\uff01<\/p>\n<p>\u65b0\u5efa\/etc\/server.pass \u00a0\u6587\u4ef6<br \/>\n<strong>#echo &#8220;root:123456&#8221; &gt;&gt;\/etc\/server.pass<br \/>\n#chmod 600 \/etc\/server.pass<\/strong><\/p>\n<p>\u542f\u52a8rsync\u670d\u52a1<br \/>\n<strong>#\/etc\/init.d\/xinetd start<\/strong><\/p>\n<p><strong>2. \u5b89\u88c5inotify<\/strong><\/p>\n<p>\u9a8c\u8bc1\u5185\u6838\u662f\u5426\u652f\u6301inotify<br \/>\n<strong>#<\/strong><strong>uname -r<\/strong><br \/>\n2.6.32-220.el6.x86_64<\/p>\n<p><strong>#<\/strong><strong>ll \/proc\/sys\/fs\/inotify<\/strong><br \/>\ntotal 0<br \/>\n-rw-r&#8211;r&#8211; 1 root root 0 Jun 11 10:15 max_queued_events \u00a0 \u00a0#\u8868\u793a\u8c03\u7528inotify_init\u65f6\u5206\u914d\u7ed9inotify instance\u4e2d\u53ef\u6392\u961f\u7684event\u7684\u6570\u76ee\u7684\u6700\u5927\u503c<br \/>\n-rw-r&#8211;r&#8211; 1 root root 0 Jun 11 10:15 max_user_instances \u00a0 \u00a0 #\u8868\u793a\u6bcf\u4e00\u4e2areal user ID\u53ef\u521b\u5efa\u7684inotify instatnces\u7684\u6570\u91cf\u4e0a\u9650<br \/>\n-rw-r&#8211;r&#8211; 1 root root 0 Jun 11 10:15 max_user_watches \u00a0 \u00a0 \u00a0#\u8868\u793a\u6bcf\u4e2ainotify instatnces\u53ef\u76d1\u63a7\u7684\u6700\u5927\u76ee\u5f55\u6570\u91cf<\/p>\n<div><\/div>\n<p>\u914d\u7f6e\u670d\u52a1\u7aef\u5185\u5bb9\u53d1\u5e03\u811a\u672c<br \/>\n<strong>#vim \/data\/sh\/inotifyrsync.sh<\/strong><\/p>\n<p>#!\/bin\/bash<br \/>\nclient1=172.16.32.205<br \/>\nclient2=172.16.32.206<br \/>\nsrc=\/data\/lixuan\/<br \/>\ndst=lixuan<br \/>\nuser=root<\/p>\n<p>\/usr\/local\/bin\/inotifywait -mrq &#8211;timefmt &#8216;%d\/%m\/%y %H:%M&#8217; &#8211;format &#8216;%T %w%f%e&#8217; -e close_write,modify,delete,create,attrib $src | while read files<br \/>\ndo<br \/>\n\/usr\/bin\/rsync -vzrtopg &#8211;delete &#8211;progress &#8211;password-file=\/etc\/client.pass $src $user@$client1::$dst<br \/>\n\/usr\/bin\/rsync -vzrtopg &#8211;delete &#8211;progress &#8211;password-file=\/etc\/client.pass $src $user@$client2::$dst<br \/>\necho &#8220;${files} was rsynced&#8221; &gt;&gt;\/tmp\/rsync.log 2&gt;&amp;1<br \/>\ndone<\/p>\n<p>\u4fdd\u5b58\u9000\u51fa\uff01<\/p>\n<p>\u65b0\u5efa\/etc\/client.pass \u00a0\u6587\u4ef6<br \/>\n<strong>#echo &#8220;123456&#8221; &gt;&gt;\/etc\/client.pass<br \/>\n#chmod 600 \/etc\/client.pass<\/strong><\/p>\n<p>\u8d4b\u4e88\u811a\u672c\u6267\u884c\u6743\u9650<br \/>\n<strong>#chmod 755 \/data\/sh\/<\/strong><strong>inotifyrsync.sh<\/strong><\/p>\n<p>\u540e\u53f0\u6267\u884c\u811a\u672c<br \/>\n<strong>#sh \/data\/sh\/<\/strong><strong>inotifyrsync.sh &amp;<\/strong><\/p>\n<p>\u5c06\u6b64\u811a\u672c\u52a0\u5165\u5f00\u673a\u81ea\u542f\u52a8\u6587\u4ef6\u4e2d<br \/>\n<strong>#echo &#8220;\/data\/sh\/inotifyrsync.sh &amp;&#8221; \u00a0&gt;&gt;\u00a0<\/strong><strong>\/etc\/rc.local<\/strong><\/p>\n<p><strong>\u56db\u3001\u6d4b\u8bd5rsync+inotify\u6570\u636e\u5b9e\u65f6\u540c\u6b65<\/strong><\/p>\n<p>\u5728\u670d\u52a1\u7aef\uff08172.16.32.204\uff09\u7684\/data\/lixuan\/\u76ee\u5f55\u4e2d\u6dfb\u52a0\u5220\u9664\u76ee\u5f55\u6216\u6587\u4ef6\uff0c\u7136\u540e\u8fdb\u5165\u5ba2\u6237\u7aef\uff08172.16.32.205\u3001172.16.32.206\uff09\u7684\/data\/lixuan\/\u76ee\u5f55\u4e2d\u67e5\u770b\u662f\u5426\u548c\u670d\u52a1\u7aef\u6570\u636e\u5b9e\u65f6\u4fdd\u6301\u4e00\u81f4\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>rsync\u53ef\u4ee5\u5b9e\u73b0\u89e6\u53d1\u5f0f\u7684\u6587\u4ef6\u540c\u6b65\uff0c\u4f46\u662f\u901a\u8fc7crontab\u5b88\u62a4\u8fdb\u7a0b\u65b9\u5f0f\u8fdb\u884c\u89e6\u53d1\uff0c\u540c\u6b65\u7684\u6570\u636e\u548c\u5b9e\u9645\u6570\u636e\u4f1a\u6709\u5dee\u5f02\uff0c &#8230; <a title=\"rsync+inotify \u5b9e\u73b0\u6570\u636e\u5b9e\u65f6\u540c\u6b65\" class=\"read-more\" href=\"https:\/\/cn.hostease.com\/xueyuan\/uncategorized\/rsyncinotify-%e5%ae%9e%e7%8e%b0%e6%95%b0%e6%8d%ae%e5%ae%9e%e6%97%b6%e5%90%8c%e6%ad%a5\/\" aria-label=\"\u9605\u8bfb rsync+inotify \u5b9e\u73b0\u6570\u636e\u5b9e\u65f6\u540c\u6b65\">\u9605\u8bfb\u66f4\u591a<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[1],"tags":[94,38,93,95],"class_list":["post-57","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-inotify","tag-linux","tag-rsync","tag-95"],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack-related-posts":[],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/57","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/comments?post=57"}],"version-history":[{"count":1,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/57\/revisions"}],"predecessor-version":[{"id":58,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/posts\/57\/revisions\/58"}],"wp:attachment":[{"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/media?parent=57"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/categories?post=57"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cn.hostease.com\/xueyuan\/wp-json\/wp\/v2\/tags?post=57"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}