Description
1. Rsync Service End
System: Ubuntu Server 11.10
IP Address: 192.168.21.168
Data storage directory:/home/mysql_data
2, Cwrsync client
System: Windows Server 2003
IP Address: 192.168.21.130
Synchronized Directories: D:\mysql_data
to achieve the purpose:
Cwrsync Client automatically synchronizes data from/home/mysql_data directory in rsync server to D:\mysql_data directory every day 3:00
First, rsync service-side configuration
1, open Firewall TCP 873 port (rsync default port)
Note: The Ubuntu default installation is not open any firewall, for the security of the server, we recommend that you install the firewall settings, it is recommended to use the Iptables firewall.
Whereis iptables #查看系统是否安装防火墙
Iptables:/sbin/iptables/usr/share/iptables/usr/share/man/man8/iptables.8.gz #表示已经安装iptables防火墙
Apt-get Install iptables #如果默认没有安装, please run this command to install the firewall
Iptables-l #查看防火墙配置信息, shown below:
Chain INPUT (Policy ACCEPT)
Target Prot opt source destination
Chain FORWARD (Policy ACCEPT)
Target Prot opt source destination
Chain OUTPUT (Policy ACCEPT)
Target Prot opt source destination
nano/etc/iptables.default.rules #设置防火墙规则, add the following
##################################################################################################
*filter
# allows all loopback (lo0) Traffic and drop all traffic to 127/8 this doesn ' t use Lo0
-A input-i lo-j ACCEPT
# accepts all established inbound connections
-A input-m State--state established,related-j ACCEPT
# allows all outbound traffic
# You could modify the Allow certain traffic
-A output-j ACCEPT
# allows HTTP and mysqlconnections from anywhere (the normal ports for websites)
-A input-p tcp--dport 80-j ACCEPT
-A input-p tcp--dport 3306-j ACCEPT
-A input-p tcp--dport 873-j ACCEPT
# allows SSH connections for script kiddies
# the-dport number is the SAME one your SET up in the Sshd_config FILE
-A input-p tcp-m State--state NEW--dport 22-j ACCEPT
# Now, should read up on iptables rules and consider whether SSH access
# for the everyone is really desired. Most likely you'll only have allow access from certain IPs.
# Allow Ping
-A input-p icmp-m ICMP--icmp-type 8-j ACCEPT
# Log Iptables denied calls (access via ' DMESG ' command)
-A input-m limit--limit 5/min-j LOG--log-prefix "iptables denied:"--log-level 7
# Reject All other inbound-default deny unless explicitly allowed policy:
-A input-j REJECT
-A forward-j REJECT
COMMIT
##################################################################################################
Ctrl+o #保存
Ctrl+x #退出
Note: 873 is the rsync port
Iptables-restore </etc/iptables.default.rules #使防火墙规则生效
Nano/etc/network/if-pre-up.d/iptables #创建文件, add the following to enable the firewall to boot
##########################################################
#!/bin/bash
/sbin/iptables-restore </etc/iptables.default.rules
##########################################################
chmod +x/etc/network/if-pre-up.d/iptables #添加执行权限
2, install Rsync Server Software
Whereis rsync #查看系统是否已安装rsync, the following prompts show that you have installed
Rsync:/usr/bin/rsync/usr/share/man/man1/rsync.1.gz
Apt-get Install rsync #如果没有安装, please execute this line of command to install rsync
Nano/etc/default/rsync #编辑配置文件
Rsync_enable=true #把false改为true, set power-on start rsync
Ctrl+o #保存
Ctrl+x #退出
3. Create rsyncd.conf configuration file
Nano/etc/rsyncd.conf #创建配置文件, add the following code
Log file =/var/log/rsyncd.log #日志文件位置, which automatically generates this file when you start rsync, without having to create it in advance.
[Mysql_backup] #自定义名称
Path =/home/mysql_data #Rsync服务端数据目录路径
Comment = Mysql_backup #模块名称与 [mysql_backup] Custom name is the same
UID = root #设置rsync运行权限为root
GID = root #设置rsync运行权限为root
port=873 #默认端口
Read Only = no #设置为no, Cwrsync client can upload file, yes Read only
Write only = no #设置为no, cwrsync client can download files, yes can not download
Auth users = Mysqlbakuser #执行数据同步的用户名, you can set multiple, separated by commas in English state
Secrets file =/etc/rsync.pass #用户认证配置文件, which saves the user name and password, which is later created
Hosts allow = 192.168.21.130 #允许进行数据同步的客户端IP地址, you can set multiple, separated by commas in English state
Hosts deny = 192.168.21.254 #禁止数据同步的客户端IP地址, you can set multiple, separated by commas in English state
List = yes #显示Rsync服务端资源列表
Ctrl+o #保存
Ctrl+x #退出
4, the creation of user certification files
Nano/etc/rsync.pass #配置文件, add the following
mysqlbakuser:123456 #格式, Username: password, you can set multiple, one user name per line: password
Ctrl+o #保存
Ctrl+x #退出
5. Set file permissions
chmod 600/etc/rsyncd.conf #设置文件所有者读取, Write permissions
chmod 600/etc/rsync.pass #设置文件所有者读取, Write permissions
6. Start rsync
/etc/init.d/rsync Start #启动
Service rsync Stop #停止
Service rsync Restart #重新启动
Second, Cwrsync client settings
1, download Cwrsync client software
Download Address: http://s.jb51.net
2. Install Cwrsync client
Decompression Cwrsync_4.0.3_installer.zip Double hit Open cwrsync_4.0.3_installer.exe
Next Next
Iagree agreed to install
Next
Default installation path C:\Program Files\cwrsync
Install Installation
Close installation Complete, closing
3. Test if communication with Rsync server is successful
Start-run-cmd
Input CD C:\Program files\cwrsync\bin carriage return
Re-enter Telnet 192.168.21.168 873 back to the car
The following interface appears, stating that communication with Rsync server is successful
Note C:\Program Files\cwrsync\bin refers to the Cwrsync program installation path
4, Cwrsync client synchronization rsync Server data
Start-run-cmd, enter CD C:\Program files\cwrsync\bin carriage return
Re-enter RSYNC-VZRTOPG--progress--delete [email protected]::mysql_backup/cygdrive/d/mysql_data
Input password: 123,456 back to the car
The following interface appears, indicating successful data synchronization
You can turn on D:\mysql_data and compare the data in the/home/mysql_data directory on the rsync server to see if the same
Related instructions:
D/mysql_data Representative D:\mysql_data
Mysql_backup represents a custom module name in the/etc/rsyncd.conf file comment = Mysql_backup
192.168.21.168 #Rsync服务端IP地址
Mysqlbakuser #执行数据同步的用户
-VZRTOPG--progress #显示同步过程详细信息
--delete #从cwRsync客户端D: Delete data in the \mysql_data directory that is not the same as the/home/mysql_data directory in the rsync server, ensuring that the data on both sides is consistent
third, add batch script files to the Cwrsync client's task schedule to automatically synchronize the data in the/home/mysql_data directory of the rsync server to the D:\mysql_data directory every day 3:00
1, open C:\Program Files\cwrsync\bin directory, new Passwd.txt
Enter 123456
Save
Continue in C:\Program Files\cwrsync\bin directory, new Mysql_backup.bat
Input
@echo off
Echo.
Echo begins synchronizing data, please wait ...
Echo.
CD C:\Program Files\cwrsync\bin
RSYNC-VZRTOPG--port=873--progress--delete [email Protected]::mysql_backup/cygdrive/d/mysql_data < Passwd.txt
Echo.
echo Data Synchronization complete
Echo.
Last Saved exit
2, add batch script to Windows Task Scheduler
Start-Settings-Control Panel-Task Scheduler
Open Add Task Schedule, Next
Browse, choose to open the Mysql_backup.bat in the C:\Program files\cwrsync\bin directory
Perform this task: Select Daily, Next
Starting Time: 3:00
Run this task: every day, next
Enter the login password for the Windows system administrator, and next
Complete
Extension Description: If you want to adjust the time of synchronization, open the Mysql_backup in the task plan
Switch to schedule to option settings, and you can open advanced to set the script to run once every few minutes Mysql_backup.bat
at this point, the Ubuntu Server rsync service is synchronized with the Windows Cwrsync client to achieve data synchronization