Lsyncd For CentOS配置步骤
CentOS 6 配置lsyncd实现应用目录自动同步备份
官方Reference: https://axkibe.github.io/lsyncd
#首先关掉SElinux
#临时关闭:setenforce 0
#永久关闭: vim /etc/selinux/config 设置为disabled
#lsync需要调用rsync,故需要在客户端和服务端分别安装rsync软件包
1.
#rpm -ivh http://dl.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
注:如果遇到URL地址无法解析的情况,需检查配置的DNS Server地址
cat >>/etc/resolv.conf <<EOF nameserver 114.114.114.114 nameserver 8.8.8.8 EOF
2.
#yum –y install lsyncd
3.修改/etc/lsyncd.conf配置文件,内容如下:
-- User configuration file for lsyncd. -- Simple example for default rsync, but executing moves through on the target. -- For more examples, see /usr/share/doc/lsyncd*/examples/ --sync{default.rsyncssh,source="/var/www/html", host="localhost", targetdir="/tmp/htmlcopy/"} settings { logfile ="/var/log/lsyncd.log", statusFile ="/var/log/lsyncd.status", inotifyMode = "CloseWrite", maxProcesses = 10, } sync { default.rsync, source = "/var/mg", target = "root@10.1.1.40:/var/mg", maxDelays = 5, delay = 20, excludeFrom = "/root/lsyncd_exclude.lst", rsync = { binary = "/usr/bin/rsync", archive = true, compress = false, bwlimit = 5000, -- rsh = "/usr/bin/ssh -p 6622 -o StrictHostKeyChecking=no" –如果ssh非默认端口,需添加此行,同时注意语法问题 } }
4.在客户端上创建lsyncd_exclude.lst并指定exclude的目录
#touch /root/lsyncd_exclude.lst #echo "mglogs" > /root/lsyncd_exclude.lst
5.在客户端上生成SSH密钥对并将公钥CP到备份服务器
#ssh-keygen –t rsa #scp /root/.ssh/id_rsa.pub {备份服务器IP}:/root/.ssh/authorized_keys
6.在备份服务器上创建目录
#mkdir –p /var/mg
7.启动lsyncd进程
#/etc/init.d/lsyncd start #ps –ef|grep lsyncd 确认进程已启动
8.添加开机自启动
#chkconfig rsyncd on