手机版
你好,游客 登录 注册
背景:
阅读新闻

CentOS 6系统利用rsync与ssh实现文件同步

[日期:2012-10-25] 来源:Linux社区  作者:chenjiuling [字体:大 中 小]

二、配置双机互信(root用户):
1)、开启root用户ssh认证权限

首先由于要运行的rsync的root用户,有通过ssh做互信的权限。
vim /etc/ssh/sshd_config

PermitRootLogin yes 将其注释去掉

 
2)、在 10.10上:
cd /root
mkdir .ssh chmod 755 .ssh
ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

b5:02:63:6f:93:30:a0:f2:a6:e6:e0:a1:05:f3:23:79 root@idc010vm010

The key's randomart image is:

+--[ RSA 2048]----+

|    .            |

|  . .          |

|. .  *  .      |

| o  . * o .    |

|o o    S .      |
| B    . o      |

|=oE              |
|*+..            |
|.o              |
+-----------------+
cat .ssh/id_rsa.pub >> authorized_keys

scp authorized_keys root@10.100.10.12:/root/.ssh 要在12服务器mkdir .ssh 之后进行,

输入12机器的root用户密码即可。
 
3)、在10.12 上:
mkdir .ssh
chmod 750 .ssh
ssh-keygen -t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/root/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /root/.ssh/id_rsa.

Your public key has been saved in /root/.ssh/id_rsa.pub.

The key fingerprint is:

5b:fd:ab:b1:bd:10:5a:8d:2d:f1:77:78:4b:1f:8b:2b root@idc010vm012

The key's randomart image is:

+--[ RSA 2048]----+

|                |
|                |
|            .    |

|          . * . |
|        S . * =o+|
|        o o +oo*|
|        . . o..o.|
|          E =.. |
|            +o+. |
+-----------------+
cat .ssh/id_rsa.pub >> authorized_keys

scp authorized_keys root@10.100.10.10:/root/.ssh 输入10机器的root用户密码即可。

 
4)、结果实现:
[root@idc010vm012 ~]# ssh 10.100.10.10
Warning: Permanently added '10.100.10.10' (RSA) to the list of known hosts.

Last login: Wed Sep 12 15:17:03 2012 from idc010vm012.idc.lecast

[root@idc010vm010 ~]#
 
三、配置双机互信(普通用户):
1)、10.10:
useradd loguser
passwd loguser
 
su loguser
mkdir .ssh chmod 755 .ssh
ssh-keygen –t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/loguser/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/loguser/.ssh/id_rsa.

Your public key has been saved in /home/loguser/.ssh/id_rsa.pub.

The key fingerprint is:

5d:3c:e7:af:8c:5a:60:13:17:a9:87:e8:98:8b:9e:ed loguser@idc010vm010

The key's randomart image is:

+--[ RSA 2048]----+
|            ..  |

|          ...  |

|        ..o= . |
|        ..o+.+  |

|      +S =. . |
|      o .. o  . |

|    . .    .  .|

|    .o.    . o . |

|  .o.E  ... o |

+-----------------+
 
cp /home/loguser/.ssh/id_rsa.pub /home/loguser/authorized_keys

scp /home/loguser/authorized_keys loguser@10.100.10.12:/home/loguser/.ssh/

输入密码
chmod –R 600 .ssh/*

 
2)、10.12上:
useradd loguser
passwd loguser
 
su loguser
mkdir .ssh chmod 755 .ssh
ssh-keygen –t rsa

Generating public/private rsa key pair.

Enter file in which to save the key (/home/loguser/.ssh/id_rsa):

Enter passphrase (empty for no passphrase):

Enter same passphrase again:

Your identification has been saved in /home/loguser/.ssh/id_rsa.

Your public key has been saved in /home/loguser/.ssh/id_rsa.pub.

The key fingerprint is:

c4:95:5a:5a:89:93:34:45:e3:9f:d2:f4:79:86:89:4c loguser@idc010vm012

The key's randomart image is:

+--[ RSA 2048]----+

|      .o==o    |

|      .++=.    |

|        o*. E    |

|      .o * + + |
|        S . * = o|
|          .  o |

|                |
|                |
|                |
+-----------------+
 
cp /home/loguser/.ssh/id_rsa.pub /home/loguser/authorized_keys

scp /home/loguser/authorized_keys loguser@10.100.10.12:/home/loguser/.ssh/

输入密码
chmod –R 600 .ssh/*

 
3)、测试:
[loguser@idc010vm012 ~]$ ssh 10.100.10.10 date
Warning: Permanently added '10.100.10.10' (RSA) to the list of known hosts.

Wed Sep 12 17:11:16 CST 2012
 
4)、拷贝rsync的配置文件:
scp 10.100.10.10:/etc/rsyncd.conf /etc/ 普通用户是没有这个权限的,会报错。
scp 10.100.10.10:/etc/rsyncd.conf ./      放在家目录下,随后用root用户cp至/etc下。

Warning: Permanently added '10.100.10.10' (RSA) to the list of known hosts.

rsyncd.conf                  100% 905    0.9KB/s  00:00               

 
创建密码文件:
echo "loguser123" > /etc/rsync.passwf 客户端的rsync密码文件只能存放密码,而不要用户名。
 
5)、使用rsync拷贝文件试试:
[loguser@idc010vm012 .ssh]$ rsync -vzrtopg --progress --stats -e ssh /opt/GeoDB.dat loguser@10.100.10.10:/tmp/cmake

Warning: Permanently added '10.100.10.10' (RSA) to the list of known hosts.

sending incremental file list

GeoDB.dat
    4333568 100%  11.52MB/s    0:00:00 (xfer#1, to-check=0/1)

 
Number of files: 1

Number of files transferred: 1

Total file size: 4333568 bytes

Total transferred file size: 4333568 bytes

Literal data: 4333568 bytes

Matched data: 0 bytes

File list size: 27

File list generation time: 0.001 seconds

File list transfer time: 0.000 seconds

Total bytes sent: 554522

Total bytes received: 31

 
sent 554522 bytes received 31 bytes 369702.00 bytes/sec

total size is 4333568 speedup is 7.81

 
 [root@idc010vm010 tmp]# ll cmake

-rw-r--r--. 1 loguser loguser 4333568 Sep 1 17:08 cmake 

linux
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款