器量大者,福泽必厚
全部博文(587)
分类: LINUX
2010-03-01 15:36:57
[root@nodelb2 ~]# rsync -avz -e ssh backupuser@nodelb1.domain.com:/usr/local/httpd2.2/htdocs/ /usr/local/httpd2.2/htdocs/
ssh: node1: Temporary failure in name resolution
显然是因为nodelb1.domain.com没有被解析所致:
解决方法:在nodelb1.domain.com和nodelb2.domain.com同时进行设置:
[root@nodelb2 ~]# ping nodelb1.domain.com
64 bytes from nodelb1 (172.17.61.126): icmp_seq=0 ttl=64 time=10.2 ms
64 bytes from nodelb1 (172.17.61.126): icmp_seq=1 ttl=64 time=0.213 ms
--- nodelb1 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
rtt min/avg/max/mdev = 0.213/5.223/10.234/5.011 ms, pipe 2
[root@nodelb2 ~]# rsync -avz -e ssh backupuser@nodelb1:/usr/local/httpd2.2/htdocs/ /usr/local/httpd2.2/htdocs/
The authenticity of host 'nodelb1 (172.17.61.126)' can't be established.
RSA key fingerprint is 46:75:f2:73:c7:72:7d:61:c8:05:e7:37:42:8a:30:b4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'nodelb1,172.17.61.126' (RSA) to the list of known hosts.
backupuser@nodelb1's password:
receiving file list ... done
./
hello/
hello/index.html
sent 36 bytes received 157 bytes 22.71 bytes/sec
total size is 59 speedup is 0.31
显然已经rsync可以使用了。
4:Create The Keys On nodelb2.domain.com
[root@nodelb2 ~]# mkdir /root/rsync
[root@nodelb2 ~]# ssh-keygen -t dsa -b 1024 -f /root/rsync/mirror-rsync-key
Generating public/private dsa key pair.
Enter passphrase (empty for no passphrase): <-- ENTER
Enter same passphrase again: <-- ENTER
Your identification has been saved in /root/rsync/mirror-rsync-key.
Your public key has been saved in /root/rsync/mirror-rsync-key.pub.
The key fingerprint is:
68:1e:9c:12:f1:f5:7f:53:d5:1d:d0:f2:dd:c2:88:f3 root@server2.example.com
The key's randomart image is:
去/root/rsync目录查看如下:
[root@nodelb2 rsync]# pwd
/root/rsync
[root@nodelb2 rsync]# ll
total 8
-rw------- 1 root root 668 Mar 1 14:27 mirror-rsync-key
-rw-r--r-- 1 root root 602 Mar 1 14:27 mirror-rsync-key.pub
[root@nodelb2 rsync]#
5:接着copy public key到nodelb1.domain.com
在nodelb2.domain.com上执行:
scp /root/rsync/mirror-rsync-key.pub backup
在nodelb1上执行:
su - backupuser
mkdir ~/.ssh
chmod 700 ~/.ssh
mv ~/mirror-rsync-key.pub ~/.ssh/
cd ~/.ssh
mv mirror-rsync-key.pub authorized_keys
chmod 600 authorized_keys
将command="/home/someuser/rsync/checkrsync",from="server2.example.com",no-port-forwarding,no-X11-forwarding,no-pty 添加到/home/backupuser/.ssh/authorized_keys的开头:
添加后如下:
|
|
修改权限:
chmod 700 ~/rsync/checkrsync
6:测试:在nodelb2.domain.com上运行如下:
[root@nodelb2 rsync]# rsync -avz --delete --exclude=**/stats --exclude=**/error --exclude=**/files/pictures -e "ssh -i /root/rsync/mirror-rsync-key" /usr/local/httpd2.2/htdocs/
说明:(The --delete option means that files that have been deleted on server1.example.com should also be deleted on server2.example.com. The --exclude option means that these files/directories should not be mirrored; e.g. --exclude=**/error means "do not mirror /usr/local/httpd2.2/htdocs/error". You can use multiple
--exclude options.(当然nodelb1.domain.com上的/usr/local/httpd2.2/htdocs目录下必须有stats,error,files/pictures目录才可以测出效果来)