之所以写这个blog是因为在virtual box下给centos安装增强功能失败,导致不能在虚拟机及主机之间传文件。后来想到了使用ftp工具或者是使用ftp来传输文件。所以就有了这个文章吧。
首先说明环境:Virtual Box 4.3.12,centos5.5,虚拟机网络设置为“网络地址转换(NAT)”,使用的ftp工具为FlashFXP。
1.判断是否安装vsftpd(因为我安装centos时已经选择ftp服务器了,所以vsftpd已经安装,这里大概给出安装步骤,具体没有实验过。可以参考:http://blog.163.com/023_dns/blog/static/118727366201172592145617/)。
1)查看有没有安装vsftpd:rpm -qa | grep vsftpd
2)yum安装:yum install vsftpd
3)如果虚拟机不能联网,则使用rpm安装:
可以从下面两个地方获得最新的vsftpd的RPM包https://www.redhat.com/或者http://www.rpmfind.net/
安装命令:rpm -Uvh vsftpd-1.1.3-8.i386.rpm
2.确认安装有vsftpd后,设置成开机启动
1)设置成开机启动:chkconfig vsftpd on(具体chkconfig命令可以使用man chkconfig查看具体意思)
2)手工启动vsftpd服务:service vsftpd start(停止为stop,重启为restart)
3.配置vsftpd.conf文件(路径:/ect/vsftpd/vsftpd.conf):
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
#anonymous_enable=YES
anonymous_enable=NO (设置不准匿名访问)# Uncomment this to allow local users to log in.
local_enable=YES (设置本地用户可以访问)# Uncomment this to enable any form of FTP write command.
write_enable=YES (设置可以进行写操作)# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
local_umask=022 (设置文件上传后的文件掩码)# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES(设置开启目录标语功能,具体有什么作用没有测试出来,可以不打开)# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES (设置20端口进行数据连接)# You may change the default value for timing out an idle session.
idle_session_timeout=600 (设置空闲连接超时时间,可以根据自己情况设置)
# You may change the default value for timing out a data connection.
data_connection_timeout=300 (设置单次最大传输时间,可以根据自己情况设置)# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
ascii_upload_enable=YES
ascii_download_enable=YES(设置支持ascⅡ模式的上传和下载)# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES (设定该Vsftpd服务工作在StandAlone模式下。顺便展开说明一下,所谓StandAlone模式就是该服务拥有自己的守护进程支持,在ps -A命令下我们将可用看到vsftpd的守护进程名。如果不想工作在StandAlone模式下,则可以选择SuperDaemon模式,在该模式下 vsftpd将没有自己的守护进程,而是由超级守护进程Xinetd全权代理,与此同时,Vsftp服务的许多功能将得不到实现。)pam_service_name=vsftpd (设定PAM服务下Vsftpd的验证配置文件名。因此,PAM验证将参考/etc/pam.d/下的vsftpd文件配置)
#userlist_enable=NO(还有一个选项为userlist_deny,两个参数联合起来,控制ftpusers和user_list来限制用户登录,具体详细可以参考:http://os.51cto.com/art/201008/221842.htm和http://blog.chinaunix.net/uid-24625974-id-2845256.html,写的非常之详细)
tcp_wrappers=YES
port_enable=NO(这里设置使用pasv模式,端口号为9001-9003,主要方便ftp连接时使用virtual box的端口转发功能,具体port和pasv模式可以参考:http://blog.chinaunix.net/uid-20639775-id-154476.html)
pasv_enable=YES
pasv_min_port=9001
pasv_max_port=9003上面只是我设置过的几个选项,至于其他选项可以根据自己情况自己设置,可以参考:http://www.cnblogs.com/hhuai/archive/2011/02/12/1952647.html中的“三.调整vsftpd的配置文件”)
4.重启vsftpd服务
service vsftpd restart
5.检查防火墙是否放行ftp服务端口
因为我比较暴力所以这里我直接关掉了防火墙(如果想设置防火墙,可以自行百度,也可以参阅http://www.myhack58.com/Article/48/66/2013/37314.htm及http://www.cnblogs.com/rockee/archive/2012/05/17/2506671.html。但是这里我测试了一下貌似没有阻断我的ftp连接,这里自行设置,简单的就是关掉防火墙
6.关闭selinux
刚开始lz就是因为没有关闭selinux导致ftp工具连上服务器后只能显示服务器上的部分文件,百思不得其解,郁闷的整了半天才发现这个问题。
关闭方法:(参考:http://blog.163.com/zhaoweibiao87@126/blog/static/13479948120126995044266/)
vi /etc/selinux/config
#SELINUX=enforcing #注释掉
#SELINUXTYPE=targeted #注释掉
SELINUX=disabled #增加
:wq #保存,关闭。
reboot #重启系统7.剩下的就是添加virtual box的端口转发功能了
右击虚拟机列表中在运行的虚拟机->设置->网络->端口转发->插入新规则
添加
“主机端口21到子系统端口21”,
“主机端口20到子系统端口20”,
“主机端口9001到子系统端口9001”,
“主机端口9002到子系统端口9002”,
“主机端口9003到子系统端口9003”
扩展:这里因为刚开始写blog的时候使用的虚拟机网络方式为nat+端口转发。后面发现其实使用虚拟机的host-only更方便,完全不需要端口转发的问题。这里简单说一下设置,后面会单独写一篇blog来说明虚拟机网络方式及配置方法,这里简单说一下,网络选择host-only即可,在虚拟机里这种模式下,主机和虚拟机是通过虚拟网卡:VirtualBox Host-Only Network通信。该网卡默认ip为192.168.56.1,子网掩码为255.255.255.0。然后虚拟机里ip只要设置为192.168.56.*,就可以通过虚拟机ip访问到虚拟机中的数据库服务。
然后设置虚拟机ip地址(参考:http://www.cnblogs.com/coacaio/archive/2011/12/12/2284715.html)
#vi /etc/sysconfig/network-scripts/ifcfg-eth0(编辑配置文件)
参考配置如下:
DEVICE=eth0 #网卡0
BOOTPROTO=static #获取ip方式:静态
BROADCAST=192.168.56.255
HWADDR=08:00:27:50:C3:D2
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.56.101 #ip地址
NETMASK=255.255.255.0 #子网掩码
NETWORK=192.168.56.0
:wq保存
#service network restart (重启网卡使配置生效)
这里就不会受到端口号的限制!
到这里大功已经告成,该文章主要是为了防止有些同学和我一样,在virtualbox上安装增强功能一直不成功的情况下这样搞,或者是不想安装增强功能。
安装增强功能后可以使用文件共享的方式传递文件。但是如果装不上去只能安装ftp了。
通过这次,我大概了解了如何配置linux下的ftp服务,当然如果要配置ftp服务器的话应该还要考虑很多安全问题,但是本帖只适合virtualbox下向虚拟机传送文件,无需注意安全的ftp服务配置及需要注意的问题,如果有什么错误或者没有注意的地方,还望及时指出~~~
virtual box下centos5.5 vsftpd搭建步骤
最新推荐文章于 2022-01-09 12:35:44 发布