{"id":6396,"date":"2016-10-18T10:59:32","date_gmt":"2016-10-18T02:59:32","guid":{"rendered":"http:\/\/rmohan.com\/?p=6396"},"modified":"2016-10-19T18:33:01","modified_gmt":"2016-10-19T10:33:01","slug":"lsyncd-on-centos-7-rhel-7","status":"publish","type":"post","link":"https:\/\/mohan.sg\/?p=6396","title":{"rendered":"Lsyncd on CentOS 7 &#038; RHEL 7"},"content":{"rendered":"<p>Lsyncd stands for \u201cLive Syncing Daemon\u201c, as the name suggest lsyncd is used to sync or replicate files &amp; directories locally and remotely after a specific time of interval. It uses Rsync &amp; ssh in the backend.<\/p>\n<p>Lsyncd works on Master and Slave architecture where it monitors the directory on the master server, if any changes or modification are done then lsyncd will replicate the same on its slave servers after specific interval of time.<\/p>\n<p>In this article we will discuss how to install and use lsyncd on CentOS 7 &amp; RHEL 7.<\/p>\n<p>Scenario : Suppose want to sync the folder \u201c\/var\/www\/html\u201d from Master server to Slave server<\/p>\n<p>Master clusterserver1 IP = 192.168.1.20<br \/>\nSlave clusterserver2 IP = 192.168.1.21<br \/>\nDirectory to be Sync = \/var\/www\/html<br \/>\nFirst Enable Key based authentication between Master and Slave Server.<\/p>\n<p>Login to Master server &amp; generate the public and Private keys using ssh-keygen command.<br \/>\n[root@clusterserver1 html]# ssh-keygen<br \/>\nGenerating public\/private rsa key pair.<br \/>\nEnter file in which to save the key (\/root\/.ssh\/id_rsa):<br \/>\nCreated directory &#8216;\/root\/.ssh&#8217;.<br \/>\nEnter passphrase (empty for no passphrase):<br \/>\nEnter same passphrase again:<br \/>\nYour identification has been saved in \/root\/.ssh\/id_rsa.<br \/>\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub.<br \/>\nThe key fingerprint is:<br \/>\na6:6e:8f:e8:2b:62:0c:a7:25:1f:c3:2b:74:eb:5a:33 root@clusterserver1.rmohan.com<br \/>\nThe key&#8217;s randomart image is:<br \/>\n+&#8211;[ RSA 2048]&#8212;-+<br \/>\n| |<br \/>\n| |<br \/>\n| |<br \/>\n| |<br \/>\n| . S |<br \/>\n|o.*. o |<br \/>\n|+*.E. . |<br \/>\n|+o=.oo.. |<br \/>\n|.+o++oo.. |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n[root@clusterserver1 html]#<br \/>\nssh-copy-id -i \/root\/.ssh\/id_rsa.pub root@192.168.1.21<\/p>\n<p>root@clusterserver1 html]# ssh-keygen<br \/>\nGenerating public\/private rsa key pair.<br \/>\nEnter file in which to save the key (\/root\/.ssh\/id_rsa):<br \/>\nCreated directory &#8216;\/root\/.ssh&#8217;.<br \/>\nEnter passphrase (empty for no passphrase):<br \/>\nEnter same passphrase again:<br \/>\nYour identification has been saved in \/root\/.ssh\/id_rsa.<br \/>\nYour public key has been saved in \/root\/.ssh\/id_rsa.pub.<br \/>\nThe key fingerprint is:<br \/>\na6:6e:8f:e8:2b:62:0c:a7:25:1f:c3:2b:74:eb:5a:33 root@clusterserver1.rmohan.com<br \/>\nThe key&#8217;s randomart image is:<br \/>\n+&#8211;[ RSA 2048]&#8212;-+<br \/>\n| |<br \/>\n| |<br \/>\n| |<br \/>\n| |<br \/>\n| . S |<br \/>\n|o.*. o |<br \/>\n|+*.E. . |<br \/>\n|+o=.oo.. |<br \/>\n|.+o++oo.. |<br \/>\n+&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;+<br \/>\n[root@clusterserver1 html]# ssh-copy-id -i \/root\/.ssh\/id_rsa.pub root@192.168.1.21<br \/>\nThe authenticity of host &#8216;192.168.1.21 (192.168.1.21)&#8217; can&#8217;t be established.<br \/>\nECDSA key fingerprint is 43:25:9c:32:53:18:33:a9:25:f7:cd:bb:b0:64:80:fd.<br \/>\nAre you sure you want to continue connecting (yes\/no)? yes<br \/>\n\/usr\/bin\/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed<br \/>\n\/usr\/bin\/ssh-copy-id: INFO: 1 key(s) remain to be installed &#8212; if you are prompted now it is to install the new keys<br \/>\nroot@192.168.1.21&#8217;s password:<\/p>\n<p>Number of key(s) added: 1<\/p>\n<p>Now try logging into the machine, with: &#8220;ssh &#8216;root@192.168.1.21&#8242;&#8221;<br \/>\nand check to make sure that only the key(s) you wanted were added.<\/p>\n<p>[root@clusterserver1 html]# ssh 192.168.1.21<br \/>\nLast login: Sun Jul 10 16:26:31 2016 from 192.168.1.1<br \/>\n[root@clusterserver2 ~]# logout<br \/>\nConnection to 192.168.1.21 closed.<br \/>\n[root@clusterserver1 html]#<br \/>\n[root@clusterserver1 html]# rpm -iUvh http:\/\/dl.fedoraproject.org\/pub\/epel\/7\/x86_64\/e\/epel-release-7-8.noarch.rpm<br \/>\nRetrieving http:\/\/dl.fedoraproject.org\/pub\/epel\/7\/x86_64\/e\/epel-release-7-8.noarch.rpm<br \/>\nPreparing&#8230; ################################# [100%]<br \/>\npackage epel-release-7-8.noarch is already installed<br \/>\n[root@clusterserver1 html]#<\/p>\n<p>[root@clusterserver1 html]# yum install lsyncd<\/p>\n<p>[root@clusterserver1 html]# cp \/usr\/share\/doc\/lsyncd-2.1.5\/examples\/lrsync.lua \/etc\/lsyncd.conf<br \/>\ncp: overwrite \u2018\/etc\/lsyncd.conf\u2019? y<br \/>\n[root@clusterserver1 html]#<br \/>\n[root@clusterserver1 html]# cat \/etc\/lsyncd.conf<br \/>\n&#8212;-<br \/>\n&#8212; User configuration file for lsyncd.<br \/>\n&#8212;<br \/>\n&#8212; Simple example for default rsync.<br \/>\n&#8212;<br \/>\nsettings = {<br \/>\nlogfile = &#8220;\/var\/log\/lsyncd.log&#8221;,<br \/>\nstatusFile = &#8220;\/var\/log\/lsyncd.stat&#8221;,<br \/>\nstatusInterval = 2,<br \/>\n}<br \/>\nsync{<br \/>\ndefault.rsync,<br \/>\nsource=&#8221;\/var\/www\/html&#8221;,<br \/>\ntarget=&#8221;192.168.1.21:\/var\/www\/html&#8221;,<br \/>\nrsync={rsh =&#8221;\/usr\/bin\/ssh -l root -i \/root\/.ssh\/id_rsa&#8221;,}<br \/>\n}<br \/>\n[root@clusterserver1 html]#<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Lsyncd stands for \u201cLive Syncing Daemon\u201c, as the name suggest lsyncd is used to sync or replicate files &amp; directories locally and remotely after a specific time of interval. It uses Rsync &amp; ssh in the backend.<\/p>\n<p>Lsyncd works on Master and Slave architecture where it monitors the directory on the master server, if any [&#8230;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[73],"tags":[],"_links":{"self":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6396"}],"collection":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=6396"}],"version-history":[{"count":1,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6396\/revisions"}],"predecessor-version":[{"id":6397,"href":"https:\/\/mohan.sg\/index.php?rest_route=\/wp\/v2\/posts\/6396\/revisions\/6397"}],"wp:attachment":[{"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=6396"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=6396"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mohan.sg\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=6396"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}