月度归档:2017年12月

CentOS7 Lsyncd 文件实时同步(替代Rsync和Inotify)

Lsyncd结合了inotify + rsync,Lsyncd监视本地目录树事件监视器接口(inotify或fsevents)。它聚合和组合事件几秒钟,然后生成一个(或多个)进程(es)来同步更改。

部署环境

# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 

# uname -a                
Linux filesync-20.203.localdomain 3.10.0-693.11.1.el7.x86_64 #1 SMP Mon Dec 4 23:52:40 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
    
# rsync --version   
rsync  version 3.0.9  protocol version 30
Copyright (C) 1996-2011 by Andrew Tridgell, Wayne Davison, and others.
Web site: http://rsync.samba.org/
Capabilities:
    64-bit files, 64-bit inums, 64-bit timestamps, 64-bit long ints,
    socketpairs, hardlinks, symlinks, IPv6, batchfiles, inplace,
    append, ACLs, xattrs, iconv, symtimes

rsync comes with ABSOLUTELY NO WARRANTY.  This is free software, and you
are welcome to redistribute it under certain conditions.  See the GNU
General Public Licence for details.
    
# lsyncd --version         
Version: 2.2.2

  安装部署 lsyncd

部署机器

Server-A  192.168.20.203   [主文件服务器,  读写]
Server-B  192.168.20.204   [备份文件服务器,只读]

密钥登录

Server-A服务器上操作

#生成密钥文件
ssh-keygen -t rsa
#将公钥拷贝到B
ssh-copy-id username@192.168.20.204
#测试
ssh username@192.168.20.204

安装 lsyncd

yum -y install lsyncd

配置文件

settings {
    logfile    = "/tmp/lsyncd.log",
    statusFile = "/tmp/lsyncd.status",
    insist = true,
    statusInterval = 10
}
sync {
    default.rsyncssh,
    source="/data",
    host="username@192.168.20.204",
    targetdir="/data",
    rsync = {
        archive = true,
        compress = false,
        whole_file = false,
        _extra = {"--bwlimit=40960"}
    },
    ssh = {
        port = 22
    }
}

测试

lsyncd -nodaemon /etc/lsyncd.conf

后台启动 lsyncd

systemctl start lsyncd
systemctl enable lsyncd

系统优化

echo -e "\nfs.inotify.max_user_watches = 8192000" >> /etc/sysctl.conf 
sysctl -p

参考文档

CentOS6 LVM 管理

CentOS6 LVM 管理

添加磁盘到LVM

fdisk /dev/vdb
n

t # 磁盘id设置为 8e ,Linux LVM


 umount /data
 fdisk /dev/vdb
 vgdisplay 
 d
 vgextend VolGroup /dev/vdb1 
 vgdisplay 
 lvextend -L +490G /dev/VolGroup/lv_root 
 lvdisplay 
 resize2fs /dev/VolGroup/lv_root 
 df 
 df -h
 vi /etc/fstab 

参考文档