1.用rsync软件做文件定时备份,但不是做到实时备份,所以单独使用效果不是很好.
服务器A:
[root@centos ~]# ifconfig eth0 -- 查看IP地址 eth0 Link encap:Ethernet HWaddr 08:00:27:56:AA:AA inet addr:2.2.2.135 Bcast:2.255.255.255 Mask:255.0.0.0 inet6 addr: fe80::a00:27ff:fe56:aaaa/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:13072 errors:0 dropped:0 overruns:0 frame:0 TX packets:328 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1009592 (985.9 KiB) TX bytes:31733 (30.9 KiB) [root@centos ~]# vim /etc/hosts --添加以下行 2.2.2.145 centos1 2.2.2.135 centos [root@centos ~]# yum install rsync --安装rsync软件,记住两台电脑必须全部安装 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package rsync.i686 0:3.0.6-9.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================= Installing: rsync i686 3.0.6-9.el6 c6-media 329 k Transaction Summary ============================================================================================================================================= Install 1 Package(s) Total download size: 329 k Installed size: 672 k Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : rsync-3.0.6-9.el6.i686 1/1 Verifying : rsync-3.0.6-9.el6.i686 1/1 Installed: rsync.i686 0:3.0.6-9.el6 Complete! [root@centos ~]#
服务器B:
[root@centos1 ~]$ ifconfig eth0 --查看IP地址 eth0 Link encap:Ethernet HWaddr 08:00:27:56:AA:AA inet addr:2.2.2.145 Bcast:2.2.2.255 Mask:255.255.255.0 inet6 addr: fe80::a00:27ff:fe56:aaaa/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:14005 errors:0 dropped:0 overruns:0 frame:0 TX packets:503 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:1081748 (1.0 MiB) TX bytes:46832 (45.7 KiB) [root@centos1 ~]$ vim /etc/hosts --添加以下两行 2.2.2.135 centos 2.2.2.145 centos1 [root@centos1 ~]$ ping 2.2.2.135 -c 1 --是否相通 PING 2.2.2.135 (2.2.2.135) 56(84) bytes of data. 64 bytes from 2.2.2.135: icmp_seq=1 ttl=64 time=0.438 ms --- 2.2.2.135 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.438/0.438/0.438/0.000 ms [root@centos ~]# yum install rsync PING 2.2.2.135 (2.2.2.135) 56(84) bytes of data. 64 bytes from 2.2.2.135: icmp_seq=1 ttl=64 time=0.438 ms --- 2.2.2.135 ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.438/0.438/0.438/0.000 ms [root@centos ~]# yum install rsync --安装软件 Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile Setting up Install Process Resolving Dependencies --> Running transaction check ---> Package rsync.i686 0:3.0.6-9.el6 will be installed --> Finished Dependency Resolution Dependencies Resolved ============================================================================================================================================= Package Arch Version Repository Size ============================================================================================================================================= Installing: rsync i686 3.0.6-9.el6 c6-media 329 k Transaction Summary ============================================================================================================================================= Install 1 Package(s) Total download size: 329 k Installed size: 672 k Is this ok [y/N]: y Downloading Packages: Running rpm_check_debug Running Transaction Test Transaction Test Succeeded Running Transaction Installing : rsync-3.0.6-9.el6.i686 1/1 Verifying : rsync-3.0.6-9.el6.i686 1/1 Installed: rsync.i686 0:3.0.6-9.el6 Complete! [root@centos1 ~]$ rsync 2.2.2.135:/home/*.txt /home/ --远程复制文件,-r是目录 root@2.2.2.135's password: [root@centos1 ~]$ ll /home/*.txt --复制成功 -rw-r--r-- 1 root root 36 Dec 16 14:40 /home/1.txt -rw-r--r-- 1 root root 12 Dec 16 14:34 /home/2.txt -rw-r--r-- 1 root root 0 Dec 16 15:48 /home/3.txt [root@centos1 ~]$ crontab -e * 24 * * * /usr/bin/rsync 2.2.2.135:/home/*.txt /home/ --每天24点备份
2.rsync+inotify做文件实时备份工作(inotify文件系统监控)
服务器A: 备份文件
[root@centos1 samba]$ tar xvf inotify-tools-3.14.tar.gz [root@centos1 samba]$ cd inotify-tools-3.14 [root@centos1 inotify-tools-3.14]$ ./configure --prefix=/usr/local/inotify && make && make install --安装软件 [root@centos inotify-tools-3.14]# cd /usr/local/inotify/ [root@centos inotify]# ll total 16 drwxr-xr-x. 2 root root 4096 Dec 16 16:08 bin drwxr-xr-x. 3 root root 4096 Dec 16 16:08 include drwxr-xr-x. 2 root root 4096 Dec 16 16:08 lib drwxr-xr-x. 4 root root 4096 Dec 16 16:08 share [root@centos inotify]# cd bin/ [root@centos bin]# ll total 72 -rwxr-xr-x. 1 root root 36447 Dec 16 16:08 inotifywait -rwxr-xr-x. 1 root root 34961 Dec 16 16:08 inotifywatch [root@centos bin]# vim inotifywait [root@centos bin]# vim start.sh #!/bin/sh SRC=/home/* DST=root@2.2.2.145:/home /usr/local/inotify/bin/inotifywait -mrq -e modify,delete,create,attrib ${SRC} | while read status do /usr/bin/rsync -ahqzt --delete $SRC $DST echo "`date +'%Y-%m-%d %H:%M:%S'` ${status} has rsynced" >>rsync.log done
服务器B:用于读写文件
3.unison文件双向同步