{"id":40,"date":"2015-09-26T03:21:00","date_gmt":"2015-09-26T03:21:00","guid":{"rendered":"http:\/\/nby.me\/?p=156"},"modified":"2017-03-26T18:18:09","modified_gmt":"2017-03-26T10:18:09","slug":"156","status":"publish","type":"post","link":"https:\/\/nby.me\/?p=40","title":{"rendered":"CentOS7 \u670d\u52a1\u5668\u6587\u4ef6\u53cc\u5411\u540c\u6b65\u65b9\u6848"},"content":{"rendered":"<p>\u4e3b\u8981\u53c2\u8003\u4e86<a href=\"http:\/\/maxsum.me\/archives\/65\/\">http:\/\/maxsum.me\/archives\/65\/<\/a>\u8fd9\u7bc7\u6587\u7ae0<br \/>\n\u611f\u8c22\u8fd9\u7bc7\u6587\u7ae0\u7684\u4f5c\u8005<br \/>\n\u53e6\u5916\u8fd8\u9700\u8981\u611f\u8c22\u540c\u4e8b\u4eae\u54e5 \u89e3\u7b54\u4e86\u6211\u5f88\u591a\u7684\u95ee\u9898 \u8fd9\u4e2a\u811a\u672c\u4e5f\u662f\u5728\u4eae\u54e5\u6307\u70b9\u4e0b\u5b8c\u6210\u7684<br \/>\n\u4f17\u6240\u5468\u77e5\uff0c\u7531\u4e8eCentOS7\u6539\u4e86\u5f88\u591a\u4e1c\u897f\uff0c\u6709\u8bb8\u591a\u4e1c\u897f\u66f4\u86cb\u75bc\u4e86\u3002\u3002\u3002<br \/>\n\u627e\u4e86\u5f88\u591a\u6587\u4ef6\u540c\u6b65\u7684\u65b9\u6848\uff0c\u6700\u7ec8\u786e\u5b9a\u4f7f\u7528\u4e86Unison+inotify-tools\u3002<br \/>\nUnison\u662f\u4e00\u5957\u53cc\u5411\u540c\u6b65\u8f6f\u4ef6\uff0c\u53ef\u4ee5\u5b9e\u73b0\u8de8\u5e73\u53f0\u7684\u53cc\u5411\u540c\u6b65\uff0c\u4f46\u662f\u4e0d\u5e26\u6587\u4ef6\u4fee\u6539\u68c0\u6d4b\u3002<br \/>\ninotify \u662f Linux \u81ea\u5e26\u7684\u4e00\u5957\u76d1\u63a7\u6587\u4ef6\u53d8\u5316\u7684\u5de5\u5177\uff0c\u914d\u5408 Unison \u4f7f\u7528\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5b9e\u65f6\u540c\u6b65\u3002<br \/>\n\u4e0d\u591a\u5570\u55e6\uff0c\u6211\u5c31\u76f4\u63a5\u7ed9\u81ea\u52a8\u5316\u90e8\u7f72\u811a\u672c\u4e86\u3002<!--more--><\/p>\n<h1>!\/bin\/bash<\/h1>\n<p>rpm -Uvh <a href=\"https:\/\/mirror.webtatic.com\/yum\/el7\/epel-release.rpm\">https:\/\/mirror.webtatic.com\/yum\/el7\/epel-release.rpm<\/a><br \/>\nrpm -Uvh <a href=\"https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm\">https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm<\/a><br \/>\nrpm -Uvh <a href=\"http:\/\/pkgs.repoforge.org\/rpmforge-release\/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm\">http:\/\/pkgs.repoforge.org\/rpmforge-release\/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm<\/a><br \/>\nrpm &#8211;import \/etc\/pki\/rpm-gpg\/RPM-GPG-KEY-EPEL-7<\/p>\n<h1>\u5b89\u88c5EPEL\u6e90<\/h1>\n<p>yum repolist<br \/>\nyum update -y<\/p>\n<h1>\u66f4\u65b0\u8f6f\u4ef6<\/h1>\n<p>yum groupinstall &#8220;Development Tools&#8221; &#8220;Development Libraries&#8221; -y<\/p>\n<h1>\u5b89\u88c5\u5f00\u53d1\u5de5\u5177\u548c\u5e93<\/h1>\n<p>yum install ocaml ctags-etags yum install glibc-static glib* inotify-tools -y<\/p>\n<h1>\u5b89\u88c5\u7f16\u8bd1Unison\u9700\u8981\u7684\u8f6f\u4ef6\u548cinotify-tools\u6587\u4ef6\u53d8\u5316\u76d1\u63a7<\/h1>\n<p>wget <a href=\"http:\/\/www.seas.upenn.edu\/~bcpierce\/unison\/\/download\/releases\/stable\/unison-2.48.3.tar.gz\">http:\/\/www.seas.upenn.edu\/~bcpierce\/unison\/\/download\/releases\/stable\/unison-2.48.3.tar.gz<\/a><br \/>\ntar xf unison-2.48.3.tar.gz<br \/>\ncd unison-2.48.3<br \/>\nmake UISTYLE=text THREADS=true STATIC=true<br \/>\ncp unison \/usr\/local\/bin\/<\/p>\n<h1>\u7f16\u8bd1\u4f1a\u51fa\u9519\u4f46\u662funison\u80fd\u8fd0\u884c\u5c31OK<\/h1>\n<p>mkdir ~\/.unison<br \/>\ncat \/dev\/null; then<\/p>\n<pre><code>timestamp=\\$(date \"+%s\");<\/code><\/pre>\n<p>else<\/p>\n<pre><code>if [ \\$((\\$(date \"+%s\") - \\$timestamp)) -gt \\$mininterval ]; then\r\n  timestamp=\\$(date \"+%s\");\r\n  {\r\n    #\u9632\u6b62\u5927\u91cf unison \u540c\u65f6\u8fd0\u884c\r\n    if ps -e | grep unison &gt; \/dev\/null; then return; fi\r\n    unison;\r\n  }&amp;\r\nelse if [ \\$((\\$(date \"+%s\") - \\$timestamp)) -gt 0 ]; then\r\n  timestamp=\\$((\\$(date \"+%s\") + \\$mininterval));\r\n  {\r\n    sleep \\$mininterval;\r\n    #\u9632\u6b62\u5927\u91cf unison \u540c\u65f6\u8fd0\u884c\r\n    if ps -e | grep unison &gt; \/dev\/null; then return; fi\r\n    unison;\r\n  }&amp;\r\nfi fi<\/code><\/pre>\n<p>fi<br \/>\ndone<br \/>\nEOF<\/p>\n<p>echo &#8220;<em>\/5 <\/em> * touch \/home\/sync&#8221; &gt;&gt; \/var\/spool\/cron\/root #home\u76ee\u5f55\u6539\u6210\u4f60\u8981\u540c\u6b65\u7684\u76ee\u5f55<br \/>\nsystemctl enable crond.service<br \/>\nsystemctl start crond.service<br \/>\nsystemctl restart crond.service<\/p>\n<h1>\u4e3a\u4ec0\u4e48\u8981\u7528cron\u5462~\u56e0\u4e3a\u3002\u3002\u3002\u5982\u679c\u8fd9\u4e2a\u64cd\u4f5c\uff08\u5bf9\u6587\u4ef6\u7684\u65b0\u589e\u4fee\u6539\uff09 inotify\u5c31\u4e0d\u4f1a\u63a2\u6d4b\u522b\u6587\u4ef6\u3001\u6587\u4ef6\u5939\u7684\u4fee\u6539\u548c\u5220\u9664 Orz<\/h1>\n<p>\u628a\u4ee5\u4e0a\u6587\u4ef6\u4fdd\u5b58\u6210sync.sh\u6587\u4ef6<br \/>\n\u7136\u540e\u52a0\u6267\u884c\u6743\u9650<\/p>\n<p>\u4e0a\u9762\u90a3\u4e2a\u6267\u884c\u5b8c\u6bd5\u4f60\u8fd8\u9700\u8981SSH \u4fe1\u4efb<\/p>\n<p>\u8fd9\u91cc\u9700\u8981\u53cc\u673a\u4e4b\u95f4\u4e92\u76f8\u65e0\u9700\u5bc6\u7801\u767b\u5f55\u5bf9\u65b9\u7684 SSH\u3002\u4e0b\u9762\u8fd9\u6bb5\u63a8\u8350\u5728 root \u4e0b\u6267\u884c\uff0c\u56e0\u4e3a unison \u540c\u6b65\u5fc5\u987b\u8981\u6709\u5bf9\u76ee\u5f55\u7684\u8bfb\u5199\u6743\u9650\uff0c\u5982\u679c\u4f60\u8981\u540c\u6b65\u7684\u76ee\u5f55\u53ea\u6709\u4e00\u4e2a\u7528\u6237\u7684\u6587\u4ef6\uff08\u6bd4\u5982\u90fd\u662f\u5c5e\u4e8e www \u7684\uff09\uff0c\u4e5f\u53ef\u4ee5\u4e0d\u7528 root\u3002\u4e24\u53f0\u673a\u5404\u81ea\u6267\u884cw<\/p>\n<p>\/\/\u751f\u6210 SSH key<br \/>\nssh-keygen<br \/>\n\/\/\u590d\u5236\u5230\u53e6\u4e00\u670d\u52a1\u5668\u76ee\u5f55<br \/>\nssh-copy-id -i .ssh\/id_rsa.pub root@[\u53e6\u4e00\u670d\u52a1\u5668\u7684 IP]<\/p>\n<p>\u53e6\u5916 \u6211\u5efa\u8bae\u6bcf\u6b21\u5f00\u673a\u65b0\u5efa\u4e00\u4e2ascreen\u5728\u540e\u53f0\u8dd1\u8fd9\u4e2async.sh\u3002\u3002\u3002<br \/>\n\u5199\u5230\u542f\u52a8\u6587\u4ef6\u7684\u8bdd\u4f1a\u51fa\u95ee\u9898\u7684\u3002\u3002\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e3b\u8981\u53c2\u8003\u4e86http:\/\/maxsum.me\/archives\/65\/\u8fd9\u7bc7\u6587\u7ae0 \u611f\u8c22\u8fd9\u7bc7\u6587\u7ae0\u7684\u4f5c\u8005 \u53e6\u5916\u8fd8\u9700\u8981\u611f &hellip; <a href=\"https:\/\/nby.me\/?p=40\" class=\"more-link\">\u95b1\u8b80\u5168\u6587 <span class=\"screen-reader-text\">CentOS7 \u670d\u52a1\u5668\u6587\u4ef6\u53cc\u5411\u540c\u6b65\u65b9\u6848<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,1],"tags":[6,5,8,7],"_links":{"self":[{"href":"https:\/\/nby.me\/index.php?rest_route=\/wp\/v2\/posts\/40"}],"collection":[{"href":"https:\/\/nby.me\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nby.me\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nby.me\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nby.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=40"}],"version-history":[{"count":1,"href":"https:\/\/nby.me\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions"}],"predecessor-version":[{"id":59,"href":"https:\/\/nby.me\/index.php?rest_route=\/wp\/v2\/posts\/40\/revisions\/59"}],"wp:attachment":[{"href":"https:\/\/nby.me\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=40"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nby.me\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=40"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nby.me\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=40"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}