FTP服务器搭建
目的及要求:
匿名用户可以看到公司的公共文档,但不能上传,本地账号拥有自己的私有空间,限制为10M,同时在线用户数量100,每用户最大连接数2,本地速率1M/S,匿名100k/s,ftp服务器只能在上班时间访问(08-20:00)。
磁盘分区
[root@localhost ~]# fdisk –l //查看磁盘分区
Disk /dev/sda: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sda1 * 1 13 104391 83 Linux
/dev/sda2 14 1288 10241437+ 83 Linux
/dev/sda3 1289 1353 522112+ 82 Linux swap / Solaris
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk /dev/sdb doesn't contain a valid partition table
[root@localhost ~]# fdisk /dev/sdb //进行分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel. Changes will remain in memory only,
until you decide to write them. After that, of course, the previous
content won't be recoverable.
The number of cylinders for this disk is set to 2610.
There is nothing wrong with that, but this is larger than 1024,
and could in certain setups cause problems with:
1) software that runs at boot time (e.g., old versions of LILO)
2) booting and partitioning software from other OSs
(e.g., DOS FDISK, OS/2 FDISK)
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
Command (m for help): n //添加一个分区
Command action
e extended
p primary partition (1-4)
p //主分区
Partition number (1-4): 1 //分区编号
First cylinder (1-2610, default 1): //起始柱面,直接回车使用默认
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): //结束柱面,直接回车
Using default value 2610
Command (m for help): p //查看
Disk /dev/sdb: 21.4 GB, 21474836480 bytes
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux
Command (m for help): w //保存退出
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
格式化并挂载
[root@localhost ~]# partprobe /dev/sdb1 //内核识别
[root@localhost ~]# mkfs -t ext3 /dev/sdb1 //格式化
mke2fs 1.39 (29-May-2006)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
2621440 inodes, 5241198 blocks
262059 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
160 block groups
32768 blocks per group, 32768 fragments per group
16384 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done
This filesystem will be automatically checked every 34 mounts or
180 days, whichever comes first. Use tune2fs -c or -i to override.
[root@localhost ~]# mkdir /mnt/ftppart //创建挂载点
[root@localhost ~]# mount /dev/sdb1 /mnt/ftppart/ //进行挂载
[root@localhost ~]# df –h //查看
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 9.5G 6.4G 2.7G 71% /
/dev/sda1 99M 12M 83M 12% /boot
tmpfs 252M 0 252M 0% /dev/shm
/dev/hdc 2.8G 2.8G 0 100% /media/RHEL_5.4 i386 DVD
/dev/sdb1 20G 173M 19G 1% /mnt/ftppart
安装vsftpd
使用源码安装:
[root@localhost ~]# tar -zxvf vsftpd-3.0.2.tar.gz -C /usr/local/src/ //解压缩到/usr.local/src目录下
[root@localhost ~]# cd /usr/local/src/ //切换到解压缩后的目录下
[root@localhost src]# ll
总计 8
drwxr-xr-x 12 user1 user1 4096 03-09 17:06 httpd-2.2.19
drwxr-x--x 8 1000 1000 4096 2012-09-18 vsftpd-3.0.2
[root@localhost src]# cd vsftpd-3.0.2/
我们可以读取INSTALL文档获取详细的安装步骤。
[root@localhost vsftpd-3.0.2]# vim builddefs.h //首先需要编辑builddefs.h文件
#ifndef VSF_BUILDDEFS_H
#define VSF_BUILDDEFS_H
#define VSF_BUILD_TCPWRAPPERS //我们将原本的undef改为define即可
#define VSF_BUILD_PAM
#undef VSF_BUILD_SSL
#endif /* VSF_BUILDDEFS_H */
[root@localhost vsftpd-3.0.2]# make //保存退出后执行make指令
接下来需要创建nobody账户,通过查看可以发现已经存在该账户
[root@localhost vsftpd-3.0.2]# grep nobody /etc/passwd
nobody:x:99:99:Nobody:/:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
[root@localhost vsftpd-3.0.2]# grep ftp /etc/passwd
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
[root@localhost vsftpd-3.0.2]#
接下来需要创建empty、ftp目录:
[root@localhost vsftpd-3.0.2]# mkdir -pv /usr/share/empty
[root@localhost vsftpd-3.0.2]# mkdir -pv /var/ftp
[root@localhost vsftpd-3.0.2]# make install //然后执行make install
[root@localhost vsftpd-3.0.2]# cd RedHat/
[root@localhost RedHat]# ll
总计 12
-rw-r--r-- 1 1000 1000 125 2008-02-02 README.spec
-rw-r--r-- 1 1000 1000 95 2008-12-18 vsftpd.log
-rw-r--r-- 1 1000 1000 314 2008-02-02 vsftpd.pam
[root@localhost RedHat]# cp vsftpd.pam /etc/pam.d/ftp //登录验证对pam模块的依赖
[root@localhost ~]# cp /etc/vsftpd/vsftpd.conf /etc/vsftpd.conf //拷贝主配置文件
[root@localhost ~]# vim /etc/vsftpd.conf //编辑vsftpd主配置文件
anon_root=/mnt/ftppart/public/
anon_max_rate=102400
local_max_rate=1024000
max_clients=100
max_per_ip=2
创建个人目录和公共目录
[root@localhost ~]# cd /mnt/ftppart/
[root@localhost ftppart]# mkdir public //创建公共目录
[root@localhost ftppart]# mkdir home //个人目录
[root@localhost ftppart]# ll
总计 24
drwxr-xr-x 2 root root 4096 05-04 15:09 home
drwx------ 2 root root 16384 05-04 09:53 lost+found
drwxr-xr-x 2 root root 4096 05-04 15:09 public
[root@localhost ftppart]# cd public/
[root@localhost public]# touch p1 p2
[root@localhost public]# ll
总计 0
-rw-r--r-- 1 root root 0 05-04 15:10 p1
-rw-r--r-- 1 root root 0 05-04 15:10 p2
[root@localhost user1]# cd /mnt/ftppart/home/user1/
[root@localhost user1]# touch u1
[root@localhost user1]# ll
总计 0
-rw-r--r-- 1 root root 0 05-05 10:02 u1
修改默认家目录
[root@localhost public]# useradd -D -b /mnt/ftppart/home/ //修改useradd参数
[root@localhost public]# useradd -D
GROUP=100
HOME=/mnt/ftppart/home/
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
创建本地账号并设置密码
[root@localhost ~]# useradd user1 //创建账号user1
[root@localhost ~]# echo "123" |passwd --stdin user1 //密码123
Changing password for user user1.
passwd: all authentication tokens updated successfully.
[root@localhost ~]# su - user1
[user1@localhost ~]$ pwd
/mnt/ftppart/home//user1 //家目录已经修改
修改相关属性文件
[root@localhost user1]# vim /etc/fstab //编辑文件系统表格(系统启动时读取,在这个表格里加载分区)
[root@localhost user1]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/RHEL_5.4 i386 DVD type iso9660 (ro,noexec,nosuid,nodev,uid=0)
/dev/sdb1 on /mnt/ftppart type ext3 (rw)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
[root@localhost user1]# mount -o remount /dev/sdb1 //重新挂载,让参数生效
[root@localhost user1]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
none on /proc/fs/vmblock/mountPoint type vmblock (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
/dev/hdc on /media/RHEL_5.4 i386 DVD type iso9660 (ro,noexec,nosuid,nodev,uid=0)
/dev/sdb1 on /mnt/ftppart type ext3 (rw,usrquota)
/dev/hdc on /mnt/cdrom type iso9660 (ro)
[root@localhost user1]# cd /mnt/ftppart/ //做磁盘配额
[root@localhost ftppart]# quotacheck -augv –c //扫描
[root@localhost ftppart]# edquota -u user1 //修改user1的磁盘配额
[root@localhost ftppart]# quotaon /dev/sdb1 //激活
[root@localhost ftppart]# echo "quotaon /dev/sdb1" >>/etc/rc.d/rc.local //加入开机脚本中
[root@localhost ftppart]# vim /etc/rc.d/rc.local
ftp基于时间的配置:
[root@localhost ftppart]# cp /usr/share/doc/vsftpd-2.0.5/vsftpd.xinetd /etc/xinetd.d/vsftpd
[root@localhost ftppart]# vim /etc/xinetd.d/vsftpd
FTP服务器初步验证
[root@localhost ~]# /usr/local/sbin/vsftpd & //后台运行
[1] 4475
[root@localhost ~]# netstat -tupln | grep vsftpd //查看端口状态
tcp 0 0 0.0.0.0:21 0.0.0.0:* LISTEN 4475/vsftpd
(说明:如果ftp服务无法启动,可能是进程端口号冲突,可以关闭xinetd进程)
如上图所示,成功访问家目录(匿名)。
接下来便是本地账户的访问:
![linux下ftp服务器搭建_模拟企业网环境_linux vdftp源码安装 ftp服_09](http://img1.51cto.com/album/6754177/136800289555.jpg?x-oss-process=image/resize,m_fixed,w_1184)
![linux下ftp服务器搭建_模拟企业网环境_linux vdftp源码安装 ftp服_10](http://img1.51cto.com/album/6754177/136800289911.jpg?x-oss-process=image/resize,m_fixed,w_1184)