=================同步接收服务器配置=================
安装软件
rsync,xinetd
**********************修改/etc/rsyncd.conf文件内容为**********************
/etc/rsyncd: configuration file for rsync daemon mode
See rsyncd.conf man page for more options.
configuration example:
uid = root
gid = root
use chroot = yes
hosts allow = 172.30.0.0/24[开放远程IP,可配置一台远程服务器IP]
hosts deny = *
max connections = 4
strict modes = yes
port = 873
pid file = /var/run/rsyncd.pid
lock file = /var/run/rsync.lock
log file = /opt/dev/logs/rsyncd.log
log format = %t %a %m %f %b
motd file =/opt/dev/rsyncd.motd
timeout = 300
read only = no
write only = no
exclude = lost+found/
transfer logging = yes
timeout = 900
ignore nonreadable = yes
dont compress = *.gz *.tgz *.zip *.z *.Z *.rpm *.deb *.bz2
[www]
path = /opt/www
auth users = root
list = yes
secrets file = /opt/dev/conf/rsyncd.secrets
comment = www rsync files
[ftp]
path = /home/ftp
comment = ftp export area
**********************新建/opt/dev/conf/rsyncd.secrets文件**********************
内容为用户名密码,详情如下:
root:toltech
执行chmod 600 /opt/dev/conf/rsyncd.secrets,使用文件可读取
**********************新建/opt/dev/conf/rsyncd.motd文件**********************
内容为rsync提示,详情如下:
+++++++++++++++++++++++++++
David Camp +
+++++++++++++++++++++++++++
这里可自定义提示信息
**********************创建/etc/xinetd.d/rsync文件,并添加如下内容**********************
default: off
description: The rsync server is a good addition to an ftp server, as it \
allows crc checksumming etc.
service rsync
{
disable = no
flags = IPv6
socket_type = stream
wait = no
user = root
server = /usr/bin/rsync
server_args = --daemon
log_on_failure += USERID
}
**********************启动同步应用服务**********************
service xinetd start
=================同步发起服务器配置=================
安装软件
rsync,inotify-tools
**********************新建/opt/dev/conf/rsyncd.secrets文件**********************
内容为目标服务器rsync用户密码,详情如下:
toltech
执行chmod 600 /opt/dev/conf/rsyncd.secrets,使用文件可读取
**********************文件同步测试命令**********************
rsync -avz --delete --password-file=/opt/dev/conf/rsyncd.secrets /opt/www/ root@172.24.1.17::www
**********************修改linux配置文件**********************
[root@localhost opt]# vi /etc/selinux/config
SELINUX=disabled
[root@localhost openssh-7.2p1]# setenforce 0
**********************新建/opt/dev/scripts/inotify_rsync文件,文件内容为同步命令脚本,详情如下**********************
-------------单服务器文件同步-------------
!/bin/bash
hosts=172.30.0.175
src=/opt/www/
dest=www
user=root
/opt/servers/inotify-tools/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src
| while read files
do
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/opt/dev/conf/rsyncd.secrets $src $user@$hosts::$dest
echo "${files} was rsynced" >>/opt/dev/logs/rsync_%y-%m-%d.log 2>&1
done
-------------多服务器文件同步-------------
!/bin/bash
hosts=("172.30.0.171" "172.30.0.173")
src=/opt/www/
dest=www
user=root
/opt/servers/inotify-tools/bin/inotifywait -mrq --timefmt '%d/%m/%y %H:%M' --format '%T %w%f%e' -e modify,delete,create,attrib $src
| while read files
do
for hostip in ${hosts[@]}
do
/usr/bin/rsync -vzrtopg --delete --progress --password-file=/opt/dev/conf/rsyncd.secrets $src $user@$hostip::$dest
echo "${files} was rsynced" >>/opt/dev/logs/rsync_$hostip.log 2>&1
done
done
**********************后台执行同步命令**********************
nohup sh inotify_rsync &
rsync -avz --delete --password-file=/opt/dev/conf/rsyncd.secrets /opt/www/ root@172.30.0.173::www