学习Linux系统中的文件传输优化
Linux系统中的文件传输优化
1.1 实验环境
两个虚拟机,保证两虚拟机之间可以互相连接
rhel8:192.168.1.32
rhel7: 192.168.1.33
2.1 scp命令
scp 本地文件 远程用户@远程主机ip:远程主机目录
scp -r 本地目录 远程用户@远程主机ip:远程主机目录
2.2 实验步骤
在rhel7虚拟机中
测试
在rhel7中连接rhel8 监控mnt目录
a> 将本地文件复制到远程主机目录中 scp westos [email protected]:/mnt/
将本地目录复制到远程主机目录中 scp -r dir [email protected]:/mnt/
将本地文件复制到远程主机目录中 scp -q westos [email protected]:/mnt/ (不显示进度条)
b> 将远程文件复制到本地 scp [email protected]:/mnt/westos /root/Desktop
3. rsync
3.1 scp和rsync对比
实验素材:
1> rhel7中建立文件
dd if=/dev/zero of=/mnt/file1 bs=1M count=10 在dev文件中截取10块大小为1M的内容放到file1中
dd if=/dev/zero of=/mnt/file2 bs=1M count=20 在dev文件中截取20块大小为1M的内容放到file2中
dd if=/dev/zero of=/mnt/file3 bs=1M count=30 在dev文件中截取30块大小为1M的内容放到file3中
2> 在主机之间建立免密登录,使远程文件传输可以直接执行
在rhel7中
ssh-****** 生成**
ssh-copy-id -i /root/.ssh/id_rsa.pub [email protected] 给远程用户上锁
3> 创建测试脚本
vim check_scp.sh
vim check_rsync.sh
4> 执行
scp执行所用时间
rsync执行所用时间
3.3.rsync用法
rsync 文件 远程用户@远程用户ip:目录
rsync 远程用户 @远程用户:ip目录 本地目录
实验环境:
在rhel8中 watch -n 1 ls -lR /mnt
在rhel7中
执行命令查看效果
rsync -r /mnt [email protected]:/mnt/ 将/mnt中的文件连同目录本身同步到远程主机rhel8的/mnt中
rsync -r /mnt/ [email protected]:/mnt/ 将/mnt中的文件同步到远程主机rhel8的/mnt中
rsync -rl /mnt [email protected]:/mnt/
rsync -rlp /mnt [email protected]:/mnt/ 将/mnt中的文件连同目录、权限同步到远程主机rhel8的/mnt中
rsync -rlpt /mnt [email protected]:/mnt/ 将/mnt中的文件连同目录、权限、时间同步到远程主机rhel8的/mnt中
rsync -rlpto /mnt [email protected]:/mnt/ 将/mnt中的文件连同目录、权限、时间、拥有者同步到远程主机rhel8的/mnt中
rsync -rlpto /mnt [email protected]:/mnt/ 将/mnt中的文件连同目录、权限、时间、拥有者拥有组同步到远程主机rhel8的/mnt中
rsync -rD /dev/pts [email protected]:/mnt/ 将rhel7 /dev/pts 中的设备文件同步到 rhel8 /mnt中
4.文件的归档压缩
4.1文档归档
4.2实验步骤
cp -r /etc . 将etc文件复制在桌面
tar cf tar.etc etc 对桌面的etc文档进行归档
tar rf etc.tar westos 将指定的westos添加到归档包etc.tar中
tar xf etc.tar 将归档包进行解档
tar f etc.tar --get westos 将指定文件从归档中取出
tar f etc.tar --delete westos 将指定文件westos从归档中删除
tar xf etc.tar -C /mnt/ 指定/mnt为解档路径
4.2文件的压缩
zip
zip -r etc.tar.zip etc.tar zip格式压缩
unzip etc.tar.zip zip格式解压缩
gzip
gzip etc.tar gzip格式压缩
gunzip etc.tar.gz gzip格式解压缩
bzip2
bzip2 etc.tar bzip2格式压缩
bunzip2 etc.tar.bz2 bzip2格式解压缩
xz
xz etc.tar xz格式压缩
unxz etc.tar.xz xz格式解压缩
4.3 tar+压缩
gzip
tar zcf etc.tar.zip /etc/ gzip格式的打包压缩
tar zxf etc.tar.zip gzip格式解压
bzip2
tar jcf etc.tar.bzip2 /etc/ bzip2格式的打包压缩
tar jxf etc.tar.bzip2 bzip2解压
xz
tar Jcf etc.tar.xz /etc/ xz格式的打包压缩
tar Jxf etc.tar.xz xz格式的解压