{"id":104068,"date":"2024-09-15T22:53:07","date_gmt":"2024-09-15T14:53:07","guid":{"rendered":"https:\/\/lrxjmw.cn\/?p=104068"},"modified":"2024-09-15T22:53:07","modified_gmt":"2024-09-15T14:53:07","slug":"lsyncd-linux-server","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/lsyncd-linux-server.html","title":{"rendered":"\u5927\u795e\u6559\u4f60\uff1aLsyncd\u590d\u5236\u5e76\u5b9e\u65f6\u540c\u6b65\u5230\u8fdc\u7a0b\u670d\u52a1\u5668"},"content":{"rendered":"
Lsyncd\u76d1\u89c6\u672c\u5730\u76ee\u5f55\u6811\u4e8b\u4ef6\u76d1\u89c6\u5668\u63a5\u53e3(inotify\u6216fsevents)\u3002\u5b83\u805a\u5408\u5e76\u5c06\u4e8b\u4ef6\u7ec4\u5408\u5728\u4e00\u8d77\u51e0\u79d2\u949f\uff0c\u7136\u540e\u751f\u6210\u4e00\u4e2a(\u6216\u591a\u4e2a)\u8fdb\u7a0b\u6765\u540c\u6b65\u8fd9\u4e9b\u66f4\u6539\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u7531rsync\u5b9e\u73b0\u540c\u6b65\u3002\u56e0\u6b64\uff0cLsyncd\u662f\u4e00\u79cd\u8f7b\u91cf\u7ea7\u7684\u5b9e\u65f6\u955c\u50cf\u89e3\u51b3\u65b9\u6848\uff0c\u76f8\u5bf9\u5bb9\u6613\u5b89\u88c5\uff0c\u4e0d\u9700\u8981\u65b0\u7684\u6587\u4ef6\u7cfb\u7edf\u6216\u5757\u8bbe\u5907\uff0c\u4e5f\u4e0d\u4f1a\u59a8\u788d\u672c\u5730\u6587\u4ef6\u7cfb\u7edf\u7684\u6027\u80fd\u3002<\/p>\n
Rsync+ssh\u662f\u4e00\u79cd\u9ad8\u7ea7\u64cd\u4f5c\u914d\u7f6e\uff0c\u5b83\u4f7f\u7528ssh\u6765\u6267\u884c\u6587\u4ef6\u548c\u76ee\u5f55\u76f4\u63a5\u5728\u76ee\u6807\u4e0a\u79fb\u52a8\uff0c\u800c\u4e0d\u662f\u5728\u7ebf\u8def\u4e0a\u91cd\u65b0\u4f20\u8f93\u79fb\u52a8\u76ee\u6807\u3002\u7ec6\u7c92\u5ea6\u7684\u5b9a\u5236\u53ef\u4ee5\u901a\u8fc7\u914d\u7f6e\u6587\u4ef6\u5b9e\u73b0\u3002\u81ea\u5b9a\u4e49\u52a8\u4f5cconfigs\u751a\u81f3\u53ef\u4ee5\u4ece\u5934\u7f16\u5199\uff0c\u4eceshell\u811a\u672c\u5230Lua\u8bed\u8a00\u7f16\u5199\u7684\u4ee3\u7801\u3002\u8fd9\u79cd\u65b9\u6cd5\u7b80\u5355\uff0c\u5f3a\u5927\uff0c\u7075\u6d3b\u7684\u914d\u7f6e\u53ef\u4ee5\u88ab\u89e3\u51b3\u3002<\/p>\n
Lsyncd 2.2.2\u8981\u6c42\u5728\u6240\u6709\u6e90\u548c\u76ee\u6807\u673a\u5668\u4e0arsync >= 3.1\u3002<\/p>\n
\u7cfb\u7edf\u73af\u5883\uff1a<\/p>\n
RenwoleServer\uff1a10.28.204.65 \u670d\u52a1\u7aef<\/p>\n
RenwoleClient\uff1a10.28.204.66 \u5ba2\u6237\u7aef<\/p>\n
OS\uff1aCentOS Linux release 7.4.1708 (Core) x64<\/p>\n
\r\n \u8bf7\u53c2\u9605\uff1a\u300aCentOS7 Configuring Rsync Server\u300b<\/a>\u3002\r\n<\/pre>\n\u5b89\u88c5\u6269\u5c55\u4f9d\u8d56\u5305<\/strong><\/span><\/div>\n\r\n$ yum install -y gcc gcc-c++ lua lua-devel cmake libxml2 libxml2-devel\r\n<\/pre>\n\u6e90\u4ee3\u7801\u7f16\u8bd1\u5b89\u88c5lsyncd<\/strong><\/span><\/div>\n\r\n$ wget https:\/\/github.com\/axkibe\/lsyncd\/archive\/release-2.2.2.tar.gz\r\n$ tar xvf release-2.2.2.tar.gz\r\n$ cd lsyncd-release-2.2.2\r\n$ cmake -DCMAKE_INSTALL_PREFIX=\/usr\/local\/lsyncd\r\n$ make && make install\r\n$ ln -s \/usr\/local\/lsyncd\/bin\/lsyncd \/usr\/bin\/lsyncd\r\n\r\n\u5b89\u88c5\u8fc7\u7a0b\u53ef\u80fd\u62a5\u9519\uff1a\r\n\r\n-- Configuring incomplete, errors occurred!\r\n<\/pre>\n\u5b89\u88c5lua-devel\u5373\u53ef\u3002<\/p>\n
\u8bbe\u7f6e\u65e0\u5bc6\u7801SSH\u767b\u5f55<\/strong><\/span><\/div>\n\u56e0\u4e3a\u8fd9\u91cc\u4f7f\u7528rsyncssh\u8fdb\u884c\u540c\u6b65\uff0c\u6240\u4ee5\u8fd8\u9700\u8981\u914d\u7f6eroot\u8d26\u53f7\u65e0\u5bc6\u7801ssh\u767b\u5f55\u3002\u8be6\u7ec6\u914d\u7f6e\u8bf7\u53c2\u9605\uff1a<\/p>\n
\u300a\u5982\u4f55\u5728Linux\u4e2d\u8bbe\u7f6eSSH\u65e0\u5bc6\u7801\u767b\u5f55\u300b<\/p>\n
\u914d\u7f6elsyncd<\/strong><\/span><\/div>\n\u4ee5\u4e0b\u662f\u4e09\u79cd\u5e38\u7528\u914d\u7f6e\u6848\u4f8b<\/p>\n
1.\u8fdc\u7a0b\u540c\u6b65rsyncssh\u6a21\u5f0f\u914d\u7f6e\u65b9\u6848\uff1a<\/p>\n
\r\n$ vim \/etc\/lsyncd.conf\r\n\r\nsettings {\r\n logfile = \"\/var\/log\/lsyncd.log\", --\u65e5\u5fd7\u8def\u5f84\r\n statusFile = \"\/var\/log\/lsyncd.status\", --\u72b6\u6001\u6587\u4ef6\r\n pidfile = \"\/var\/run\/lsyncd.pid\", --pid\u6587\u4ef6\u8def\u5f84\r\n statusInterval = 1, --\u72b6\u6001\u6587\u4ef6\u5199\u5165\u6700\u77ed\u65f6\u95f4\r\n nodaemon = false, --daemon\u8fd0\u884c\r\n maxProcesses = 1, --\u6700\u5927\u8fdb\u7a0b\r\n maxDelays = 1, --\u6700\u5927\u5ef6\u8fdf\r\n}\r\nsync {\r\n default.rsyncssh, --\u9ed8\u8ba4rsync+ssh,rsync\u7248\u672c\u9700\u8981\u5347\u7ea73\u4ee5\u4e0a\u7248\u672c\r\n source = \"\/apps\/www\/renwoleblog\/\", --\u6e90\u76ee\u5f55\r\n delete = true, --\u4fdd\u6301\u5b8c\u5168\u540c\u6b65 \r\n host = \"root@10.28.204.66\", \r\n targetdir = \"\/apps\/www\/renwoleblog\/bak\/\", --\u76ee\u6807\u76ee\u5f55\r\n exclude={ \r\n \".txt\" --\u9700\u6392\u9664\u7684\u6587\u4ef6\r\n },\r\nrsync = {\r\n binary = \"\/usr\/bin\/rsync\", --\u9700\u5148\u5b89\u88c5\u597drsync\r\n archive = true, --\u5f52\u6863\r\n compress = false, --\u538b\u7f29\r\n owner = true, --\u5c5e\u4e3b\r\n perms = true, --\u6743\u9650\r\n whole_file = false\r\n },\r\nssh = {\r\n port = 22\r\n }\r\n}\r\n<\/pre>\n2.\u672c\u5730\u76ee\u5f55\u540c\u6b65\u914d\u7f6e\u65b9\u6848\uff1a<\/p>\n
\r\nsync {\r\n default.rsync,\r\n source = \"\/apps\/www\/renwoleblog\/\",\r\n target = \"\/apps\/www\/renwoleblog\/bak\/\",\r\n}\r\n<\/pre>\n3.\u8fdc\u7a0b\u540c\u6b65rsync-daemon\u6a21\u5f0f\u914d\u7f6e\u65b9\u6848<\/p>\n
\r\nsync {\r\n default.rsync,\r\n source = \"\/apps\/www\/renwoleblog\/\",\r\n target = \"renwole@10.28.204.65::renwolecom\",\r\n delete=\"true\",\r\n exclude = { \".bak*\" },\r\n delay = 30,\r\n init = false,\r\n rsync = {\r\n binary = \"\/usr\/bin\/rsync\",\r\n archive = true,\r\n compress = true,\r\n verbose = true,\r\n perms = true,\r\n password_file = \"\/etc\/rsync.password\",\r\n _extra = {\"--bwlimit=200\"}\r\n }\r\n}\r\n<\/pre>\n\u91cd\u70b9\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n
\r\n-- # \u6ce8\u91ca\u7b26\r\nsettings # \u662f\u5168\u5c40\u914d\u7f6e\r\nsync # \u5b9a\u4e49\u540c\u6b65\u53c2\u6570\r\nrsync # \u5b9a\u4e49\u540c\u6b65\u6587\u4ef6\u53c2\u6570\r\nssh # \u5b9a\u4e49\u670d\u52a1\u5668\u8fdc\u7a0b\u7aef\u53e3\r\n<\/pre>\nlsyncd\u914d\u7f6e\u6587\u4ef6\u5141\u8bb8\u591a\u4e2async\u4e92\u4e0d\u5f71\u54cd\u3002<\/p>\n
\u8bf4\u660e\uff1a\u5982\u679c\u662f\u4e00\u5bf9\u591a\uff0c\u8bf7\u53c2\u9605\u672c\u5730\u540c\u6b65\uff0c\u4fee\u6539\u76ee\u6807\u76ee\u5f55\u5373\u53ef\u3002<\/p>\n
\u521b\u5efasystemctl\u7cfb\u7edf\u5355\u5143\u6587\u4ef6<\/strong><\/span><\/div>\n\u4e3a\u4e86\u5b9e\u73b0systemctl\u8fdb\u884c\u7ba1\u7406\uff0c\u8bf7\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\u4ee5\u53ca\u811a\u672c\u542f\u52a8\u6587\u4ef6\uff0c\u547d\u4ee4\u5982\u4e0b\uff1a<\/p>\n
\r\n$ vim \/etc\/sysconfig\/lsyncd\r\n\r\n\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1a\r\n\r\nLSYNCD_OPTIONS=\"\/etc\/lsyncd.conf\"\r\n\r\n\u521b\u5efa\u542f\u52a8\u6587\u4ef6\uff1a\r\n\r\n$ vim \/usr\/lib\/systemd\/system\/lsyncd.service\r\n\r\n\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff1a\r\n\r\n[Unit]\r\nDescription=Live Syncing (Mirror) Daemon\r\nAfter=network.target\r\n\r\n[Service]\r\nType=simple\r\nEnvironmentFile=-\/etc\/sysconfig\/lsyncd\r\nExecStart=\/usr\/local\/lsyncd\/bin\/lsyncd -nodaemon $LSYNCD_OPTIONS\r\n\r\n[Install]\r\nWantedBy=multi-user.target\r\n<\/pre>\n\u542f\u52a8lsyncd\u5e76\u52a0\u5165\u5f00\u673a\u81ea\u542f\u52a8<\/strong><\/span><\/div>\n\r\n$ systemctl start lsyncd\r\n$ systemctl enable lsyncd\r\n\r\n\u63a5\u4e0b\u6765\u4f60\u5c31\u53ef\u4ee5\u5f80\u6e90\u670d\u52a1\u5668\/apps\/www\/renwoleblog\/\u5185\u4e0a\u4f20\u4efb\u610f\u6587\u4ef6\uff0c\u5b8c\u6210\u540e\u7acb\u523b\u5c31\u4f1a\u540c\u6b65\u5230\u5ba2\u6237\u7aef 10.28.204.66 \/apps\/www\/renwoleblog\/bak\/\u76ee\u5f55\u5185\uff0c\u4e5f\u53ef\u4ee5\u67e5\u770b\u670d\u52a1\u7aef\u7684lsyncd\u65e5\u5fd7\u6587\u4ef6\u5206\u6790\u662f\u5426\u540c\u6b65\u6210\u529f\u3002\u4f8b\u5982\uff1a\r\n\r\n[root@RenwoleServer ~] $ cat \/var\/log\/lsyncd.log\r\n\r\n...\r\nFri Dec 22 01:19:22 2017 Normal: Calling rsync with filter-list of new\/modified files\/dirs\r\n\/PCHunter_renwole.com.tar.gz\r\n\/\r\nFri Dec 22 01:19:24 2017 Normal: Finished (list): 0\r\nFri Dec 22 01:19:32 2017 Normal: Calling rsync with filter-list of new\/modified files\/dirs\r\n\/PCHunter_renwole.com.tar.gz\r\n\/\r\nFri Dec 22 01:19:34 2017 Normal: Finished (list): 0\r\nFri Dec 22 01:19:34 2017 Normal: Calling rsync with filter-list of new\/modified files\/dirs\r\n\/PCHunter_renwole.com.tar.gz\r\n\/\r\nFri Dec 22 01:19:36 2017 Normal: Finished (list): 0\r\n<\/pre>\n\u65e5\u5fd7\u5185\u5bb9\u663e\u793aPCHunter_renwole.com.rar\u6587\u4ef6\u6210\u529f\u540c\u6b65\u3002<\/p>\n
\u53e6\u5916lsyncd\u662f\u57fa\u4e8einotify + rsync\u7684\u5f00\u6e90\u540c\u6b65\u8f6f\u4ef6\uff0c\u76f8\u5bf9\u4e8e\u5176\u4ed6\u540c\u6b65\u8f6f\u4ef6\u66f4\u52a0\u5b89\u5168\u53ef\u9760\uff0c\u5360\u7528\u8d44\u6e90\u66f4\u5c11\uff0c\u4f46\u914d\u7f6e\u7565\u9ebb\u70e6\u3002<\/p>\n
lsyncd \u8fd8\u652f\u6301\u5f53\u76d1\u63a7\u5230\u67d0\u4e2a\u6307\u5b9a\u4e8b\u4ef6\u65f6\u5c31\u6267\u884c\u4ec0\u4e48\u6837\u7684\u547d\u4ee4\uff0c\u7531\u4e8e\u662f\u901a\u8fc7\u65f6\u95f4\u5ef6\u8fdf\u548c\u7d2f\u8ba1\u4e8b\u4ef6\u547d\u4e2d\u6b21\u6570\u6765\u89e6\u53d1\u540c\u6b65\uff0c\u5728\u8bbe\u8ba1\u4e0a\u8981\u4f18\u4e8einotify\uff0c\u53e6\u5916\u4ed6\u7684\u540c\u6b65\u901f\u5ea6\u5b8c\u5168\u53d6\u51b3\u4e8e\u4f60\u7684\u7f51\u7edc\u8d28\u91cf\u3002<\/p>\n
\n\u539f\u6587\u6765\u81ea\uff1ahttps:\/\/renwole.com\/archives\/1001<\/a><\/p>\n