浏览量 4755
2014/02/09 17:55
linux服务器间文件互传及共享办法,本次总结了5种办法包括(ftp、wget、samba、nfs、scp)以供各种不同情况下使用。
1号linux:ipaddr=10.10.10.1
2号linux:ipaddr=192.168.0.1
一、ftp
2号linux
de>ftp 10.10.10.1
根据提示输入用户名密码
get 单个文件
mget 多个文件
ls 查看远端主机目录
!ls 查看本地所在目录,ftp文件下载文件后会下载到本地de>
1号linux
搭好vsftp配置可参考本站文章 VSFTP给单用户绑定多个目录内有如何搭建vsftp的配置。
二、wget
本例演示一次手动网站备份操作。
1号linux
de>tar -jcvp -f ./wzwpbak.tar.bz2 ./wordpress/ /usr/local/mysql/var/wangzi/
find /usr/local/mysql/var/wangzi/ ./wordpress |wc -l
6208
tar tjf ./wzwpbak.tar.bz2 | wc -l
6208de>
对比实际文件数与打包后文件数验证完整性。
tar 所用到的参数
-f, --file [HOSTNAME:]
use archive file or device F (default "-", meaning stdin/stdout)
-j, --bzip2
filter archive through bzip2, use to decompress .bz2 files
-t, --list
list the contents of an archive
-c, --create
create a new archive
-v, --verbose
verbosely list files processed
-p, --preserve-permissions
extract all protection information
2号linux
下载
de>wget ftp://10.10.10.1/wordpress/wzwpbak.tar.bz2 --ftp-user=username --ftp-password=password
tar tjf ./wzwpbak.tar.bz2 | wc -l
6208de>
三、samba
用samba通过mount挂载的方式实现两linux主机传输文件。
1号linux
搭建samba服务--如何搭建linux samba服务请参考本站文章。
2号linux
de>mount -t cifs //10.10.10.1/project /wzmount -o username=username
Password:
[root@localhost /]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda2 99190032 4135624 89934416 5% /
/dev/sda1 99098 12238 81743 14% /boot
tmpfs 8196244 0 8196244 0% /dev/shm
/dev/mapper/wangzivg-wangzilv
576279112 5828764 541177056 2% /opt
//10.10.10.1/project 135960760 101810968 27243376 79% /wzmount
de>
所用参数
mount -t type device dir
This tells the kernel to attach the file system found on device (which
is of type type) at the directory dir. The previous contents (if any)
and owner and mode of dir become invisible, and as long as this file
system remains mounted, the pathname dir refers to the root of the file
system on device.
NAME
mount.cifs - mount using the Common Internet File System (CIFS)
SYNOPSIS
mount.cifs {service} {mount-point} [-o options]
DESCRIPTION
This tool is part of the samba(7) suite.
mount.cifs mounts a Linux CIFS filesystem. It is usually invoked
indirectly by the mount(8) command when using the "-t cifs" option.
This command only works in Linux, and the kernel must support the cifs
filesystem. The CIFS protocol is the successor to the SMB protocol and
is supported by most Windows servers and many other commercial servers
and Network Attached Storage appliances as well as by the popular Open
Source server Samba.
The mount.cifs utility attaches the UNC name (exported network
resource) to the local directory mount-point. It is possible to set the
mode for mount.cifs to setuid root to allow non-root users to mount
shares to directories for which they have write permission.
Options to mount.cifs are specified as a comma-separated list of
key=value pairs. It is possible to send options other than those listed
here, assuming that the cifs filesystem kernel module (cifs.ko)
supports them. Unrecognized cifs mount options passed to the cifs vfs
kernel code will be logged to the kernel log.
mount.cifs causes the cifs vfs to launch a thread named cifsd. After
mounting it keeps running until the mounted resource is unmounted
(usually via the umount utility).
四、nfs
用nfs 通过mount挂载的方式实现两Linux间主机传输文件。
1号linux。
de>#cat /etc/exports
/home/jishu 192.168.0.0/24(rw,no_root_squash)
#service nfs startde>
2号Linux。
de>[root@localhost /]# showmount -e 10.10.10.1
Export list for IP:
/home/jishu 192.168.0.0/24
/home/zhangjian 192.168.0.0/24
/home/wangzi 192.168.0.0/24
/tmp 192.168.0.0/24
[root@localhost /]# mount -t nfs 10.10.10.1:/home/jishu /wzmount/
[root@localhost /]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/sda2 99190032 4135664 89934376 5% /
/dev/sda1 99098 12238 81743 14% /boot
tmpfs 8196244 0 8196244 0% /dev/shm
/dev/mapper/wangzivg-wangzilv
576279112 5828764 541177056 2% /opt
10.10.10.1:/home/jishu
135961088 101811712 27243008 79% /wzmountde>
五、scp
2号Linux
从远端到本地。
de>scp root@10.10.10.1:/root/wz /root/lz de>
#从1号机拷贝wz文件到本机root目录并重命名为lz
de>scp -P 60021 -r 10.10.10.1:/var/www/wordpress ./wzde>
#执行完成后./wz文件夹下会出现/wordpress文件夹。
#-r是拷贝所有文件包括子目录
#-P设置ssh的端口号60021<- sshbr>de>find ./wz/wordpress/ | wc -l
6173de>
从本地到远端。
以上命令scp后的2、3参数对调即可。
注意:scp会覆盖原文件,使用时要谨慎。
上一篇 搜索 下一篇