lsync

 

=================================================================================

 

【lsync】

 

详细说明:

https://www.cnblogs.com/zxci/p/6243574.html

 

 安装: 

 yum install lsyncd

 

一、lrsync+ssh+shell模式 (root用户)

 

1. 先做双机互信

 

====================ssh互信==========================

方式一:

root:

1.制作公钥:

源机器上生成公钥

#ssh-keygen

2.拷贝公钥到目标机器

ssh-copy-id -i  ~/.ssh/id_rsa.pub "-p 11223 root@103.35.117.196"

 

方式二:

root:

做双机信任

把 cat /root/.ssh/id_rsa.pub 的内容

拷贝到 目标端的

/root/.ssh/authorized_keys   

到节点

mkdir /root/.ssh

cd  /root/.ssh

/root/.ssh/authorized_keys

chmod 700  -R /root

chmod 644 /root/.ssh/*

 

关闭限制root登陆

vim /etc/ssh/sshd_config

#PermitRootLogin no

 

-------------------------

 

普通用户互信

那就注意: 权限和目录都是普通目录的

mkdir /home/bwttomcat/.ssh

传公钥

chmod 700 -R /home/bwttomcat

chown -R bwttomcat:bwttomcat /home/bwttomcat/.ssh

chmod 644 /home/bwttomcat/.ssh/*

 

 

=========================================================

===================server安装配置===================

=========================================================

 

#yum -y install lsyncd

 

vim /etc/lsyncd.conf

settings {

    logfile = "/var/log/lsyncd/lsyncd.log",

    statusFile = "/var/log/lsyncd/lsyncd.status",

    inotifyMode  = "CloseWrite or Modify",

    maxProcesses = 16,

}

 

sync {

    default.rsync,

    source    = "/home/nativeapp",

    target    = "root@103.35.117.196:/home/nativeapp",

    delete    = false,

    delay     = 5,

    -- init   = true,

    rsync     = {

        binary   = "/usr/bin/rsync",

        archive  = true,

        compress = false,

        rsh = "/usr/bin/ssh -p 11223 -o StrictHostKeyChecking=no"

    }

}

 

 

 

 

二、lrsync+rsync模式 (rsync用户)

 

 

 

=========================================================

===================server安装配置===================

=========================================================

#yum -y install lsyncd

 

 

useradd rsync -s /sbin/nologin -M

 

 

vim /etc/lsyncd.conf

settings {

    logfile      = "/var/log/lsyncd.log",

    statusFile   = "/var/log/lsyncd.status",

    inotifyMode  = "CloseWrite or Modify",

    maxProcesses = 16,

}

 


sync{

    default.rsync,

    source = "/usr/local/nginx/conf/http_facadehost_acg/",

    target = "rsync_backup@35.201.186.54::http_facadehost_acg/",

    delete = false,

    rsync = {

        binary = "/usr/bin/rsync",

        archive = true,

        compress = true,

        verbose  = true,

        password_file = "/etc/rsync.password",

        _extra    = {"--bwlimit=20000"},

    }

}

sync{

    default.rsync,

    source = "/home/dataacg/",

    target = "rsync_backup@35.201.186.54::dataacg/",

    delete = false,

    rsync = {

        binary = "/usr/bin/rsync",

        archive = true,

        compress = true,

        verbose  = true,

        password_file = "/etc/rsync.password",

        _extra    = {"--bwlimit=20000"},

    }

}

 

 

创建密码文件:

vim /etc/rsync.pass
10vqpPXw


chmod 400 /etc/rsync.pass

 

重启:

/etc/init.d/lsyncd restart && tailf /var/log/lsyncd/lsyncd.log

centos7: lsyncd -nodaemon /etc/lsyncd.conf (先查看报错) systemctl start lsyncd.service
&& tailf /var/log/lsyncd/lsyncd.log

 

=========================================================

===================cilent安装配置===================

=========================================================

 

1.系统自带的rsync

 

注意:

同步的目录必须存在

hosts allow = 144.48.220.63/29  配置必须加好

 客户端要开放873给服务端访问

firewall-cmd --zone=public --add-port=873/tcp  --permanent
firewall-cmd --permanent --add-rich-rule="rule family="ipv4" source address="192.168.142.166" port protocol="tcp" port="
873" accept"
firewall
-cmd --reload
firewall
-cmd --list-all

 

 

 

vim  /etc/rsyncd.conf

#Rsync server

uid = root

gid = root

use chroot = no

max connections = 4000

timeout = 600

pid file =/var/run/rsyncd.pid

lock file =/var/run/rsync.lock

log file = /var/log/rsyncd.log

ignore errors

read only = false

list = false

hosts allow = 144.48.220.63/29

hosts allow = 144.48.220.57/29

hosts deny = 0.0.0.0/32

auth users = rsync_backup

secrets file =/etc/rsync.password

################################################

[http_facadehost_bwt]

comment = http_facadehost_bwt

path = /usr/local/nginx/conf/http_facadehost_bwt/

##############################################

[databwt]

comment = databwt

path = /home/databwt/

exclude = nginx

############################################

[http_facadehost_bwt_source]

comment = http_facadehost_bwt_source

path = /usr/local/nginx/conf/http_facadehost_bwt_source/

##############################################

[databwt_source]

comment = databwt_source

path = /home/databwt_source/

exclude = nginx

###########################################

 

 

2.创建passwd  

vim /etc/rsync.password

rsync_backup:10vqpPXw

 

3.授权

chmod 700 /etc/rsync.password

 

 

4.启动

 rsync --daemon

 ps -fe|grep rsync

 
查看日志传输是否正常:

  tailf /var/log/rsyncd.log

 

 

5.监控rsync

cat /etc/crontab

# rsync status check

* * * * * /bin/bash /home/scripts/rsync_monitor.sh

 

 

cat /home/scripts/rsync_monitor.sh

#!/bin/bash

#Desc: rsync process monitor script.

#Auth: jeck

#Date: 2017-4-2

 

ip=$(/sbin/ifconfig | grep -A3 -w "HWaddr" | grep "inet addr" | head -1 | cut -f 2 -d ":" | cut -f 1 -d " "|sed -n 1p)

date=$(/bin/date +"%Y-%m-%d %H:%M:%S")

rsync_status=$(/bin/ps -ef | grep "rsync --daemon" | grep -v grep | wc -l)

 

if [ $rsync_status -lt 1 ]; then

    echo "${date} ${ip} rsync process is stopped, restarting..." &>> /tmp/rsync_monitor.out

    /usr/bin/rsync --daemon

    echo "${date} ${ip} rsync process is running." &>> /tmp/rsync_monitor.out

else

    echo "${date} ${ip} rsync process is running." &>> /tmp/rsync_monitor.out

fi

 

 

 

====================================================================================

问题1:

执行命令:/etc/init.d/lsyncd status

显示:lsyncd 已死,但 pid 文件仍存

于是查看日志文件:cat /var/log/lsyncd/lsyncd.log

日志里显示:

Error: Terminating since out of inotify watches.
Consider increasing /proc/sys/fs/inotify/max_user_watches

 

其中 max_user_watches 是一个文件,里面有一个数字值,表示每个inotify实例可监听的最大上限数量。

这问题明显就是文件增多,导致无法监控更多的文件,把里面的那个值改大点就可以了

修改方法1:echo 10008192 > /proc/sys/fs/inotify/max_user_watches(修改后,Linux系统重启inotify配置max_user_watches无效被恢复默认值8192)

修改方法2:vim /etc/sysctl.conf 

注意添加的内容:

fs.inotify.max_user_watches=99999999(你想设置的值,此方法修改后重启linux,max_user_watches值不会恢复默认值8192

重新启动 lsyncd :service lsyncd restart

查看 lsyncd 状态 :/etc/init.d/lsyncd status

显示:lsyncd (pid  9943) 正在运行...

问题解决。

 

posted @ 2020-09-30 14:27  扶我起来写代码  阅读(856)  评论(0)    收藏  举报