第一步先把安装包放到你指定的一个目录下然后进去找到你要安装的vsftpd安装包

[root@huangzhong ~]# ll

-rw-r--r--. 1 root root     12705 Mar 29 02:00 install.log

-rw-r--r--. 1 root root      3482 Mar 29 01:58 install.log.syslog

-rw-r--r--. 1 root root 304382512 Jan 17 19:30 mysql-5.6.15-linux-glibc2.5-x86_64.tar.gz

-rw-r--r--. 1 root root    192808 Mar 20  2013 vsftpd-3.0.2.tar.gz

第二步把安装包解压到你指定的文件目录下

[root@huangzhong ~]# tar -zxvf vsftpd-3.0.2.tar.gz -C /usr/local/src/

vsftpd-3.0.2/

vsftpd-3.0.2/filestr.h

vsftpd-3.0.2/sysutil.c

vsftpd-3.0.2/README.ssl

vsftpd-3.0.2/vsftpd.conf.5

vsftpd-3.0.2/FAQ

vsftpd-3.0.2/opts.c

vsftpd-3.0.2/ftppolicy.c

从上面可以看出这是是源代码安装

第三步切换到你解压的安装包的目录下看是否能够看到你解压的安装包具体结果如下

[root@huangzhong ~]# cd /usr/local/src/

[root@huangzhong src]# ll

total 4

drwxr-x--x. 8 1000 1000 4096 Sep 18  2012 vsftpd-3.0.2

第四步进入安装包的问中看能否找到安装文件说明

[root@huangzhong src]# cd vsftpd-3.0.2/

[root@huangzhong vsftpd-3.0.2]# ls

AUDIT            builddefs.h    opts.c            sslslave.c

BENCHMARKS       defs.h         opts.h            sslslave.h

BUGS             dummyinc       parseconf.c       standalone.c

INSTALL          ftpcmdio.c     postprivparent.h  sysdeputil.c

COPYING          features.c     parseconf.h       standalone.h

access.c         ls.h           seccompsandbox.h  vsf_findlibs.sh

第五步从上面可以找到INSTALL对打开文件看看安装说明

Step 1) Build vsftpd.

  9 Switch to the directory created when you unpacked the vsftpd .tar.gz file.

 10 e.g.:

 11 cd vsftpd-1.1.2

 12 edit "builddefs.h" to handle compile-time settings (tcp_wrappers build,

Step 2) Satisfy vsftpd pre-requisites

 24 2a) vsftpd needs the user "nobody" in the default configuration. Add this

 25 user in case it does not already exist. e.g.:

...........................

第五步从上面可以看到下一步骤是进入安装文件下要对builddefs.h进行编辑 具体操作如下

[root@huangzhong vsftpd-3.0.2]# vim builddefs.h

打开文件后按i对其编辑如下

1 #ifndef VSF_BUILDDEFS_H

  2 #define VSF_BUILDDEFS_H

  3 

  4 #define VSF_BUILD_TCPWRAPPERS

  5 #define VSF_BUILD_PAM

  6 #undef VSF_BUILD_SSL

对上面文件编辑后绿色为编辑的然后按Esc再按wq保存退出

第六步按操作步骤执行make操作如下

[root@huangzhong vsftpd-3.0.2]# make

-bash: make: command not found

此时可以看本机没有安装make命令因此还要安装make安装包首先查看镜像文件中有没有make安装包操作如下

[root@huangzhong vsftpd-3.0.2]# ll /media/cdrom/Packages/ |grep -i make

-r--r--r--. 3 root root    90996 Jul  3  2011 MAKEDEV-3.24-6.el6.x86_64.rpm

-r--r--r--. 2 root root  5404388 Jul  3  2011 cmake-2.6.4-5.el6.x86_64.rpm

-r--r--r--. 2 root root   267844 Jul  3  2011 imake-1.0.2-11.el6.x86_64.rpm

-r--r--r--. 2 root root   397932 Apr  4  2012 make-3.81-20.el6.x86_64.rpm

从上面可以看到存在make安装包然后对其进行安装

[root@huangzhong vsftpd-3.0.2]# yum --disablerepo=\*  --enablerepo=c6-media install make

安装完后从新执行make命令执行过程中时候可能会发现以下错误

tcpwrap.c:16:20: error: tcpd.h: No such file or directory

tcpwrap.c: In function 'vsf_tcp_wrapper_ok':

tcpwrap.c:29: error: storage size of 'req' isn't known

cc1: warnings being treated as errors

tcpwrap.c:31: error: implicit declaration of function 'request_init'

tcpwrap.c:31: error: 'RQ_DAEMON' undeclared (first use in this function)

tcpwrap.c:31: error: (Each undeclared identifier is reported only once

tcpwrap.c:31: error: for each function it appears in.)

tcpwrap.c:31: error: 'RQ_FILE' undeclared (first use in this function)

tcpwrap.c:32: error: implicit declaration of function 'fromhost'

tcpwrap.c:33: error: implicit declaration of function 'hosts_access'

tcpwrap.c:29: error: unused variable 'req'

make: *** [tcpwrap.o] Error 1

问题解决时重新把原来编辑的文件恢复如下

[root@huangzhong vsftpd-3.0.2]# vim builddefs.h

打开文件后按i对其编辑如下

1 #ifndef VSF_BUILDDEFS_H

  2 #define VSF_BUILDDEFS_H

  3 

  4 #undef VSF_BUILD_TCPWRAPPERS

  5 #define VSF_BUILD_PAM

保存文件后继续执行make此时过程可能还会出现以下错误

/usr/bin/ld: cannot find -lcap

collect2: ld returned 1 exit status

make: *** [vsftpd] Error 1

此时说明缺少文件可以先进行查找有关cap的安装包可以找到以下文件

[root@huangzhong vsftpd-3.0.2]# ll /media/cdrom/Packages/ |grep -i cap

-r--r--r--. 2 root root    17188 Jul  3  2011 compat-libcap1-1.10-1.i686.rpm

-r--r--r--. 2 root root    31516 Dec  9  2011 libcap-2.16-5.5.el6.i686.rpm

-r--r--r--. 3 root root    32448 Dec  9  2011 libcap-2.16-5.5.el6.x86_64.rpm

-r--r--r--. 2 root root    25032 Dec  9  2011 libcap-devel-2.16-5.5.el6.i686.rpm

-r--r--r--. 2 root root    25008 Dec  9  2011 libcap-devel-2.16-5.5.el6.x86_64.

我们可以看到libcap特别像要找的文件我们可以先查看本机是否装有

[root@huangzhong vsftpd-3.0.2]# rpm -qa |grep libcap

libcap-2.16-5.5.el6.x86_64

libcap-ng-0.6.4-3.el6_0.1.x86_64

此时可以看到libcap已安装现在安装libcap-devel

[root@huangzhong vsftpd-3.0.2]# yum --disablerepo=\*  --enablerepo=c6-media install libcap-devel

安装完成后我们在执行make

第六步安装完成后查看安装目录是否生成了一个服务器

[root@huangzhong vsftpd-3.0.2]# ll vsftpd

-rwxr-xr-x. 1 root root 155960 Apr  5 23:04 vsftpd

对vsftpd进行查看看它是一个二进制文件还是一个脚本文件

[root@huangzhong vsftpd-3.0.2]# file vsftpd

vsftpd: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped

从上面可以看到它是一个64位的服务器文件

第七步按照操作说明执行第二步骤

 首先建立一个nobody账号操作如下

[root@huangzhong vsftpd-3.0.2]# useradd nobody

 创建一个空目录

[root@huangzhong vsftpd-3.0.2]# mkdir -pv /usr/share/empty/

 创建ftp账号

[root@huangzhong vsftpd-3.0.2]# mkdir -pv /var/ftp/

[root@huangzhong vsftpd-3.0.2]# useradd -d /var/ftp ftp

useradd: user 'ftp' already exists

此时发现已经存在了这时要看它的家目录在哪

[root@huangzhong vsftpd-3.0.2]# grep ftp /etc/passwd

ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

改变账号权限操作如下

[root@huangzhong vsftpd-3.0.2]# chown root.root /var/ftp

[root@huangzhong vsftpd-3.0.2]# chmod og-w /var/ftp

第八步执行安装命令

[root@huangzhong vsftpd-3.0.2]# make install

if [ -x /usr/local/sbin ]; then \

install -m 755 vsftpd /usr/local/sbin/vsftpd; \

else \

install -m 755 vsftpd /usr/sbin/vsftpd; fi

if [ -x /usr/local/man ]; then \

install -m 644 vsftpd.8 /usr/local/man/man8/vsftpd.8; \

install -m 644 vsftpd.conf.5 /usr/local/man/man5/vsftpd.conf.5; 

安装完后把cp vsftpd.conf拷贝到/etc目录下

[root@huangzhong vsftpd-3.0.2]# cp vsftpd.conf   /etc

最后编辑/etc/vsftpd.conf文件

[root@huangzhong vsftpd-3.0.2]# vim /etc/vsftpd.conf

打开之后发现没有什么需要修改的

第九步启动服务

   启动时看有没有脚本这里没有脚本因此要配置脚本文件按配置说明来先找到vsftpd搜索目录

[root@huangzhong vsftpd-3.0.2]# echo $PATH

/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

以上说明在任何地方都可以启动vffstpd了

[root@huangzhong vsftpd-3.0.2]# vsftpd

查看ftp端口是否已启动操作如下

[root@huangzhong ~]# netstat  -tupln |grep  21

tcp        0      0 0.0.0.0:21                  0.0.0.0:*                   LISTEN      2027/vsftpd       此时表明已启动

第十步连接ftp

连接过程中可能出现下列问题

[root@huangzhong vsftpd-3.0.2]# ftp 127.0.0.1

Connected to 127.0.0.1 (127.0.0.1).

500 OOPS: could not bind listening IPv4 socket

因为xinetd已经启动了vsftpd而vsftpd设置成了stardalone模式所以先停止xinetd服务 service xinetd stop然后再重启vsftpd启动后再重新连接。

[root@huangzhong ~]# ftp 127.0.0.1

Connected to 127.0.0.1 (127.0.0.1).

220 (vsFTPd 3.0.2)

Name (127.0.0.1:root): anonymous

331 Please specify the password.

Password:

230 Login successful.

Remote system type is UNIX.

Using binary mode to transfer files.

ftp> dir

227 Entering Passive Mode (127,0,0,1,181,192).

150 Here comes the directory listing.

-r--r--r--    1 0        0              14 Apr 04 02:06 CentOS_BuildTag

dr-xr-xr-x    3 0        0            4096 Apr 04 02:06 EFI

-r--r--r--    1 0        0             212 Apr 04 02:06 EULA

-r--r--r--    1 0        0           18009 Apr 04 02:06 GPL

dr-xr-xr-x    2 0        0          266240 Apr 04 02:13 Packages

此时可以看到已经连接成功并且是使用匿名登陆的

要使用本地用户登录首先要建立一个账号

[root@huangzhong vsftpd-3.0.2]# useradd user1

[root@huangzhong vsftpd-3.0.2]# passwd user1  

Changing password for user user1.

New password: 

BAD PASSWORD: it is WAY too short

BAD PASSWORD: is too simple

Retype new password: 

passwd: all authentication tokens updated successfully.

创建完后然后进行测试

[root@huangzhong ~]# ftp 127.0.0.1

Connected to 127.0.0.1 (127.0.0.1).

220 (vsFTPd 3.0.2)

Name (127.0.0.1:root): user1

530 This FTP server is anonymous only.

Login failed.

从上面可以看登录失败提示只允许匿名登陆所以要对文件vsftpd.conf

[root@huangzhong ~]# vim /etc/vsftpd.conf

打开文件后进行以下编辑

 12 anonymous_enable=YES

 13 #

 14 # Uncomment this to allow local users to log in.

 15 local_enable=YES

编辑完后按Esc再按wq保存退出然后重新启动vsftpd在进行连接验证操作如下

Connected to 127.0.0.1 (127.0.0.1).

220 (vsFTPd 3.0.2)

Name (127.0.0.1:root): user1

331 Please specify the password.

Password:

230 Login successful.

第十一步进行配置控***务脚本

   在/etc/init.d目录下创建一个文件vsftpd然后在这文件中编辑脚本

[root@huangzhong init.d]# vim vsftpd    //打开文件然后编辑脚本如下

1 #!/bin/bash

  2  prog=/usr/local/sbin/vsftpd

  3  lockfile=/var/lock/subsys/vsftpd

  4  . /etc/init.d/functions

  5 

  6  start() {

  7               if [ -e $lockfile ];then

  8                 echo   "then  vsftpd  server  is started"

  9                else

 10                   echo  -n  " the  vsftpd   server  is  starting ........."

 11                   sleep 1

 12               $prog   &

 13                if [$?] ;then

 14                  echo  "OK"  && touch  $lockfile

 15                  else

 16                     echo "fail"

 17                fi

 18           fi

 19 

 20   }

 21 

 22 stop(){

 23         if [ ! -e $lockfile]; then

 24            echo  "the vsftpd is stoped"

 25           else

 26            killproc  vsftpd && echo  "OK"  && rm  -rf $lockfile || echo  "fail"

 27            fi

 28 }

 29 case  "$1" in

 30  start )

 31       start

 32         ;;

 33  stop)

 34     stop

 35      ;;

 36 restart)

 37      stop

 38      start

 39       ;;

 40  *)

 41 echo "USAGE: start|stop|restart"

 42 esac

编辑完成后先按Esc再按wq保存退出然后先关闭vsftpd服务并查看端口是否关闭具体操作如下

[root@huangzhong init.d]# pkill -9 vsftpd

[root@huangzhong init.d]# netstat  -tupln |grep  21

此时发现已关闭了

然后先查看有没有产生所文件然后启动在查看操作如下

[root@huangzhong init.d]# ll /var/lock/subsys/vsftpd

ls: cannot access /var/lock/subsys/vsftpd: No such file or directory

[root@huangzhong init.d]# service vsftpd start

 the  vsftpd   server  is  starting .........OK

[root@huangzhong init.d]# ll /var/lock/subsys/vsftpd

-rw-r--r--. 1 root root 0 Apr  9 03:48 /var/lock/subsys/vsftpd

此时可以看到开始没有产生所文件启动后就产生了接下来看看关闭和重启

[root@huangzhong init.d]# service vsftpd stop

OK                                                         [  OK  ]

[root@huangzhong init.d]# ll /var/lock/subsys/vsftpd

ls: cannot access /var/lock/subsys/vsftpd: No such file or directory

[root@huangzhong init.d]# service vsftpd restart     

the vsftpd is stoped

 the  vsftpd   server  is  starting .........OK

要使其文件在每个级别下都可以运行因此要执行以下操作    

[root@huangzhong init.d]# vim vsftpd     //进入编辑文件添加以下操作 

 1 #!/bin/bash

  2  prog=/usr/local/sbin/vsftpd

  3  lockfile=/var/lock/subsys/vsftpd

  4  . /etc/init.d/functions

 5 #chkconfig: 2345 88 44

  6 #descrptions: the ftp daemon

编辑完以后保存退出然后添加在查看操作如下

[root@huangzhong init.d]# chkconfig  --add vsftpd

[root@huangzhong init.d]# chkconfig  --list |grep vsftp

vsftpd         0:off1:off2:on3:on4:on5:on6:off

vsftpd:        on

从上面可以看到vsftpd在2、3、4、5级别下是开启状态的这里还可以手动修改改变它在不同级别的状态操作如下

[root@huangzhong init.d]# chkconfig  --level 35 vsftpd off

[root@huangzhong init.d]# chkconfig  --list |grep vsftp

vsftpd         0:off1:off2:on3:off4:on5:off6:off

vsftpd:        on

到此整个vsftpd的安装就完成了。