虚拟机与主机间的文件传输

来源:互联网 发布:万方数据库账号 编辑:程序博客网 时间:2024/05/16 14:57

实现虚拟机与主机间的文件传输

本文介绍实现虚拟机和主机间的文件传输三种方法

Linux版本为CentOS 6.8虚拟主机名为xwz

方法一:安转VMware Tools

选择虚拟机菜单栏--安装VMware tools


下载VMwareTools

新建一个文件夹,将下载的压缩包文件放至该文件夹下

 

 

打开终端,先转至超级用户

[xwz@localhost Desktop]$ su

Password:

 

解压安装

tar zxvf VMwareTools-9.2.3-1031360.tar.gz

 

安装VMware Tools

[root@localhost vmware-tools-distrib]# ./vmware-install.pl


下面的选项就按照默认值。一路回车就可以:

In which directory do you want to install the binary files?

[/usr/bin]

What is the directory that contains the init directories (rc0.d/ to rc6.d/)?

[/etc/rc.d]

What is the directory that contains the init scripts?

[/etc/rc.d/init.d]

In which directory do you want to install the daemon files?

[/usr/sbin]

In which directory do you want to install the library files?

[/usr/lib/vmware-tools]

The path /usr/lib/vmware-toolsdoes not exist currently. This program is goingto create it, including needed parent directories. Is this what you want?

[yes] .........

 

出现[/USR/bin]之后一直开始按回车键

直接按到/dev/hdc...停止为止

 

重启虚拟机之后就可以直接从实体机拖拽文件至虚拟机桌面。


方法二:建立共享文件夹 

选择虚拟机菜单-》虚拟机设置-》选项-》点击共享文件夹-》添加

选择一个现有文件夹作为共享文件夹,这里为D:\shared

 

 

共享文件夹的使用

打开虚拟机终端

虚拟机共享文件夹的位置在 /mnt/hgfs/shared

转置该文件夹下 [xwz@localhost shared]$ cd /mnt/hgfs/shared

查看该文件夹下的所有文件 [xwz@localhost shared]$ ls

复制所需文件至桌面 [xwz@localhost shared]$ cp a.txt /home/xwz/Desktop


方法三:搭建ftp服务器

配置虚拟机中的ftp服务器,实现主机与虚拟机之间的文件传输。

 

要点:

虚拟主机:桥接模式、关闭防火墙 、下载安装vsftpd服务器、开启ftp服务器,更改文件夹(change directory:/home/

实体机:开启ftp服务功能,连接

 

一、启动桥接模式

 

 

二、vsftpd服务的安装,启动及关闭

1、获得超级用户权限

[xwz@localhost Desktop]$ su

Password:

 

2、安装vsftpd

--必须配置yum源才能使用yum命令来安装vsftpd,或者挂载光盘,找到Packages目录下的vsftpd包,使用rpm命令安装

[root@localhost Desktop]# yum install vsftpd --安装vsftpd

 

3vsftpd服务的启动及关闭

[root@localhost Desktop]# chkconfig --list vsftpd

vsftpd 0:off 1:off 2:off 3:off 4:off 5:off 6:off

 

[root@localhost Desktop]# chkconfig --level 35 vsftpd on

 

[root@localhost Desktop]# service vsftpd restart --启动/关闭命令为:service vsftpd start/stop

Shutting down vsftpd: [FAILED]

Starting vsftpd for vsftpd: [ OK ]

 

[root@localhost Desktop]# service vsftpd status --查看vsftpd状态

vsftpd (pid 5087) is running... --看到这个状态才能进行文件传输

 

三、文件的上传及下载

 

1、关闭虚拟机防火墙

1) 重启后生效

开启: chkconfig iptables on

关闭: chkconfig iptables off

2) 即时生效,重启后失效

开启: service iptables start

关闭: service iptables stop

 

2、更改访问文件目录

CentOS系统安装了SELinux,因为默认下是没有开启FTP的支持,所以访问时都被阻止了

//查看SELinux设置

# getsebool -a|grep ftp

ftpd_disable_trans --> off

或者

ftp_home_dir-->off

//使用setsebool命令开启

# setsebool ftpd_disable_trans 1

或者

# setsebool ftp_home_dir 1

//查看当前状态是否是on的状态

# getsebool -a|grep ftp

ftpd_disable_trans --> on

或者

ftp_home_dir-->on

//setsebool使用-P参数,无需每次开机都输入这个命令

# setsebool -P ftpd_disable_trans 1

或者

# setsebool -P ftp_home_dir 1

# service vsftpd restart --重启vsftpd服务

 

 

3、打开我的电脑连接虚拟机ftp服务器

格式为:ftp://虚拟机ip地址,再回车

 

 

 

12步未设置好这一步会出错,显示不能连接服务器。

 

4、登录虚拟机

右键选择登录

 

 

输入虚拟机任一用户名和密码



之后就可以看到虚拟机的文件目录了


 

参考资料

http://www.cnblogs.com/i-shu/articles/4895577.html

http://www.cnblogs.com/weaver1/archive/2012/03/05/2380559.html

https://jingyan.baidu.com/article/6dad5075ca4d6da123e36e34.html

原创粉丝点击