数据实时同步lsyncd指定用户运行主备模式
A和B两台服务器,A的ip为192.168.0.2,B的ip为192.168.0.3,A为主,B为备,A同步/home/web目录到B的/home/bak目录
以下是A上主的配置文件
settings {
logfile = "/var/log/lsyncd/lsyncd.log",
statusFile = "/var/log/lsyncd/lsyncd.status",
inotifyMode = "CloseWrite",
maxProcesses = 10,
}
sync {
default.rsync,
source = "/home/web",
target = "[email protected]::backup",
delete= true,
exclude = { ".*" },
delay = 1,
rsync = {
binary = "/usr/bin/rsync",
archive = true,
compress = true,
verbose = true,
password_file = "/etc/rsync.password",
_extra = {"--bwlimit=200"}
}
}
创建密码文件
echo "123258" >/etc/rsync.password
chmod 600 /etc/rsync.password
在B的备上操作
uid = rsync
gid = rsync
port = 873
fake super = yes
use chroot = no
max connections = 200
timeout = 300
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 = 192.168.0.0/24
auth users = rsync_backup
secrets file = /etc/rsync.password
[backup]
comment = "bak dir"
path = /home/bak
创建用户,创建目录,创建密码文件,给权
useradd rsync -M -s /sbin/nologin
echo "rsync_backup:123258" >/etc/rsync.password
chmod 600 /etc/rsync.password
mkdir -p /home/bak
chown rsync.rsync /backup -R
在主上输入以下命令同步
rsync -avz /etc/passwd [email protected]::backup --password-file=/etc/rsync.password
测试后发现已经同步
版权申明
本文系作者 @天边的云 原创发布在Loshub站点。未经许可,禁止转载。
暂无评论数据