Service side:
First, install rsync, and then edit the configuration file, if not, you can manually create
Rsync, xinetd (Rsync is better than 3.0, the algorithm is better and faster. XINETD Monitoring and Management rsync service)
/etc/rsyncd.conf
UID = www
GID = www
Use chroot = no
Max connections = 200
Timeout = 600
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsyncd.log
[web]
Path =/var/www/html/
Ignore errors
Read Only = no
List = no
Hosts allow = 192.168.72.0/24
Auth users = rsync
Secrets file =/etc/rsyncd.password
Edit the/etc/xinetd.d/rsync configuration (if you can not manually write it yourself)
Cat/etc/xinetd.d/rsync
Service rsync
{
Disable = No
Socket_type = stream
Wait= No
User= root
Server= /usr/bin/rsync
Server_args=--daemon
Log_on_failure+ = USERID
}
Change Yes to No
Useradd-r rsync (user specified in the configuration file, if not, manually add a system user)
Systemctl Restart Xinetd.service
To see if the port is started (default 873)
lsof-i:873
COMMAND PID USER FD TYPE DEVICE size/off NODE NAME
xinetd 6830 root 5u IPv6 53674 0t0 TCP *:rsync (LISTEN)
Second, modify the permissions
Chown-r www:/var/www/html/www.rsync-server.com/
LL-DH www.rsync-server.com/
Drwxr-xr-x. 2 www. www. 06:42 www.rsync-server.com/
Create a user authentication file (manually created yourself)
echo "Rsync:password" >/etc/rsyncd.password
Modify authentication file permissions for security reasons
chmod 600/etc/rsyncd.password
Client:
Here only needs the password, does not need the user, lest wants to synchronize, also must carry on the manual interaction, the permission is equal to 600
echo "Password" >/etc/rsyncd.password
chmod 600/etc/rsyncd.password
Execute command
RSYNC-VZRTOPG--delete [Email protected]::web/var/www/html/www.rsync-server.com/--password-file=/etc/ Rsyncd.password
650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/8A/1F/wKioL1goWuuwWhnhAAAkl3Kbw5g301.png "title=" Rsync.png "alt=" Wkiol1gowuuwwhnhaaakl3kbw5g301.png "/>
Third, the service-side installation INotify
TAR-XVF inotify-tools-3.13.tar.gz
CD inotify-tools-3.13
./configure
Make-j $CPU
Make install
modifying kernel parameters
sysctl-a | grep inotify
Fs. inotify. max_queued_events = 16384 indicates the Monitoring event queue
Fs. inotify. max_user_instances = Max indicates the maximum number of monitored instances
Fs. inotify. max_user_watches = 900000 Indicates the maximum number of monitored files per instance
sysctl-a | grep inotify >>/etc/sysctl.conf written into system files
Sysctl-p re-read configuration
INotify Common parameters and configuration
Inotifywait-h
-E is used to specify which events to monitor
These events include: Create Creation, move movement, delete Delete, modify modify file contents, attrib property changes.
-m means continuous monitoring
-R means recursive entire directory
-Q means simplifying output information
INOTIFYWAIT-MRQ-E Create,move,delete,modify/path/filename return to the card will not move, and then in the other terminal to/path/filename directory read, write, change, delete the action, Will trigger its mechanism.
Write a script that lets it monitor the action.
Cat rsync+inotify.sh
#!/usr/bin/bash
INOTIFYWAIT-MRQ-E create,move,delete,modify/var/www/html/www.rsync-server.com/| While Read DNF
Do
RSYNC-VZRTOPG--delete/var/www/html/www.rsync-server.com/[Email protected]::rsync-client--password-file=/etc/ Rsyncd.shadow
Done
chmod 600/etc/rsyncd.shadow (must be 600 or less permission, otherwise it will be an error)
Error:password file must not being other-accessible
Client Configuration Rsync
Useradd-r www synchronization file owner user
Useradd-r rsync Certified Users
echo "RSYNC:RSYNC-PASSWD" >/etc/rsync.pass user, password
Cat/etc/rsyncd.password Password Authentication File The rsync command is used at the same time
rsync:rsync-passwd
Mkdir/var/www/html/www.rsync-server.com-p Creating a directory for synchronization service-side synchronization to clients
Chown-r www:/var/www/html/www.rsync-server.com/www.rsync-server.com/
Rsync configuration
Cat/etc/rsyncd.conf
UID = www
GID = www
Use chroot = no
Max connections = 200
Timeout = 600
PID file =/var/run/rsyncd.pid
Lock file =/var/run/rsyncd.lock
Log file =/var/log/rsyncd.log
[Rsync-client]
Path =/var/www/html/www.rsync-server.com
Ignore errors
Read Only = no
List = no
Hosts allow = 192.168.72.0/24
Auth users = rsync
Secrets file =/etc/rsyncd.password
XINETD Configuration
Cat/etc/xinetd.d/rsync
Service rsync
{
Disable = No
Socket_type = stream
Wait= No
User= root
Server= /usr/bin/rsync
Server_args=--daemon
Log_on_failure+ = USERID
}
Systemctl Restart xinetd
Cat/etc/rsyncd.shadow
rsync-passwd
Viewing port-enabled status
lsof-i:873
COMMAND PID USER FD TYPE DEVICE size/off NODE NAME
xinetd 6469 root 5u IPv6 52078 0t0 TCP *:rsync (LISTEN)
Server Run Script
nohup./rsync+inotify.sh & Create, modify, or delete files in/var/www/html/www.rsync-server.com/directory, when viewed by the client Also automatically creates, modifies, or deletes files as the server does
This article is from the "Silence" blog, make sure to keep this source http://silencezone.blog.51cto.com/3613477/1872445
Rsync+inotify for real-time synchronization