环境:centos6.4 x86_64

所需应用程序:vsftpd-3.0.2.tar.gz

在我的另一篇博文中详细介绍过httpd源代码安装。(博文地址:http://mading.blog.51cto.com/8252187/1341185)那么在这里我要介绍一下vsftpd源代码安装,比较一下和httpd源代码安装有什么不同的地方。关于源代码安装的步骤我在这里就不在详细介绍了。

源代码安装软件系统中当然少不了编译环境,在这里就不再介绍编译环境的搭建,我在前面关于httpd安装的博文中有过详细介绍,如有不懂可以先看那篇博文。下面开始介绍vsftpd的安装与测试。

首先解压缩vsftpd-3.0.2.tar.gz,使用命令 tar –zxvf vsftpd-3.0.2.tar.gz –C /usr/local/src 切换到/usr/local/src目录中就可以看到刚刚解压的所形成的目录

Centos中vsftpd源代码安装与测试_vsftpd

切换到该目录下,比较一下和前面httpd有什么不同

Centos中vsftpd源代码安装与测试_源代码_02

发现这里面并没有configure文件,那么怎么办呢?没关系,在INSTALL这个文件中已经详细的告诉我们该怎么做。那么我们就按照上面的步骤来走吧。

首先编辑builddefs.h这个文件

Centos中vsftpd源代码安装与测试_源代码_03

在这里我需要使用tcpwrappers,我们就修改tcpwrapper那一行为:define VSF_BUILD_TCPWRAPPERS 保存退出

接下来就执行 make;可是当我们make的时候发现出现错误,如图所示

Centos中vsftpd源代码安装与测试_应用程序_04

发现关于tcpwrap的错误,通过查询我们的系统中安装了一个tcpwrap的库,查询光盘时发现还有其他关于tcpwrap相关的软件

Centos中vsftpd源代码安装与测试_应用程序_05

那我们就来安装一下tcp_wrappers tcp_wrapper-devel

安装后继续执行make ,执行前先使用make clean all 清除前面make过的,然后make

但又有错误了

Centos中vsftpd源代码安装与测试_源代码_06

那就再安装libcap了,安装之后,再执行上面的步骤,这时候就可以make通过了,然后查看一下当前目录中有没有形成一个vsftpd的文件

Centos中vsftpd源代码安装与测试_vsftpd_07

接下来需要为vsftpd创建一个nobody的帐号,首先查看一下有没有这个帐号,

Centos中vsftpd源代码安装与测试_vsftpd_08

发现已经存在,那么就不需要再创建了,继续下一步,vsftpd需要一个空目录,在/usr/shaer/empty下,创建时会提示有一个这样的目录,那就继续下一步,因为ftp需要匿名登录,并且有自己的家目录,我们需要创建这样一个目录,再建立一个ftp的帐号

Centos中vsftpd源代码安装与测试_源代码_09

修改/var/ftp 的所有者和所属组为root 并且修改other用户和组用户权限为不可写

Centos中vsftpd源代码安装与测试_vsftpd_10

接下来执行 make install

Centos中vsftpd源代码安装与测试_源代码_11

然后创建/usr/local/man/man5  /usr/local/man/man8  

Centos中vsftpd源代码安装与测试_vsftpd_12

分别拷贝vsftpd.conf.5/usr/local/man/man5 vsftpd.8/usr/local/man/man8

Centos中vsftpd源代码安装与测试_源代码_13

同时还需要把vsftpd.conf 拷贝到/etc目录下

Centos中vsftpd源代码安装与测试_应用程序_14

实际上到了这里我们的ftp已经安装完成了,然后我们运行一下:

/usr/local/sbin/vsftpd &    这里面的&符号表示后台运行

Centos中vsftpd源代码安装与测试_源代码_15

通过上图可以看到ftp已经运行了

这时候我们就可以使用ftp localhost 或者lftp localhost登录测试了,ftplftp是不一样,用ftp登陆时必须输入用户名才能登录,而lftp则不需要


Centos中vsftpd源代码安装与测试_应用程序_16

Centos中vsftpd源代码安装与测试_vsftpd_17

如果我们想要使用本地帐号登录必须要有/etc/pam.d/ftp这个文件,如果没有我们就要拷贝一个;我们可以直接把 RedHat/vsftpd.pam 拷贝成/etc/pam.d/ftp

Centos中vsftpd源代码安装与测试_vsftpd_18

然后修改/etc/vsftpd.conf #local_enable=YES前面的#号去掉

Centos中vsftpd源代码安装与测试_应用程序_19

重启一下vsftpd服务

然后使用本地帐号测试

Centos中vsftpd源代码安装与测试_应用程序_20

登录成功。

接下就是该编写控制脚本了,代码如下:

#!/bin/bash

[ -e /etc/init.d/functions ] && ./etc/init.d/functions

prog=/usr/local/sbin/vsftpd

lockfile=/var/lock/subsys/vsftpd

start(){

      if [ -e $lockfile ];then

      echo "vsftpd server is started"

      else echo -n "vsftpd server is starting... "

      sleep 1

      $prog &

       if [ $? ];then

       echo  "[ ok ]"&& touch $lockfile

       else

       echo "[ failer ]"

       fi

      fi

}

stop(){

      if [ ! -e $lockfile ];then

      echo "vsftpd server is stoped"

      else echo -n "vsftpd server is stoping... "

      sleep 1

      killproc vsftpd && echo "[ ok ]" && rm -rf$lockfile ||echo "[ failer ]"


      fi

}

status(){

      if [ -e $lockfile ];then

      echo "vsftpd server is started"

      else echo "vsftpd server no found"

      fi

}

case $1 in

start)

 start

  ;;

stop)

 stop

  ;;

restart)

 stop

 start

  ;;

status)

 status

  ;;

*)

echo"USAGE:start|stop|restart|status"

 ;;

Esac

好了,到这里我们的vsftpd已经安装和测试完成了