案例:
搭建一个ftp服务器 ,并实现以下要求:
ftp需要大量空间 ,需要新增硬盘,然后分区->格式化->挂载 /mnt/ftppart
新建目录:公共目录 /mnt/ftppart/public ro只读
个人目录 /mnt/ftppart/home/
每个用户的空间10M
速度 :匿名用户100k/s 本地用户 1M/s
同时在线用户数量不能超过20,每个用户可以开启的连接数目最大2
步骤:
磁盘分区:
[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 1318 10482412+ 83 Linux
/dev/sda3 1319 1383 522112+ 82 Linux swap / Solaris
Disk /dev/sdb: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 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 6527.
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-6527, default 1): 起始
Using default value 1
Last cylinder or +size or +sizeM or +sizeK (1-6527, default 6527): 结束
Using default value 6527
Command (m for help): p 查看
Disk /dev/sdb: 53.6 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Device Boot Start End Blocks Id System
/dev/sdb1 1 6527 52428096 83 Linux
Command (m for help): w 保存退出
格式化并挂载:
[root@localhost ~]# partprobe /dev/sdb1 内核识别
[root@localhost ~]# mkfs -t ext3 /dev/sdb1 格式化
[root@localhost ~]# mkdir /mnt/ftppart 创建挂载点
[root@localhost ~]# mount /dev/sdb1 /mnt/ftppart 挂载磁盘
[root@localhost ~]# df –h 查看
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 9.7G 5.0G 4.3G 54% /
/dev/sda1 99M 12M 83M 12% /boot
tmpfs 125M 0 125M 0% /dev/shm
/dev/hdc 2.9G 2.9G 0 100% /media/RHEL_5.3 i386 DVD
/dev/sdb1 50G 180M 47G 1% /mnt/ftppart
安装vsftpd:
[root@localhost ~]# mkdir /mnt/cdrom 创建光盘挂载点
[root@localhost ~]# mount /dev/cdrom /mnt/cdrom 挂在光盘
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@localhost ~]# cd /mnt/cdrom/Server 切换到Server 目录下
[root@localhost Server]# ll |grep ftp
-r--r--r-- 99 root root 55322 2008-07-22 ftp-0.17-35.el5.i386.rpm
-r--r--r-- 99 root root 959765 2007-01-19 gftp-2.0.18-3.2.2.i386.rpm
-r--r--r-- 71 root root 870301 2007-01-19 lftp-3.5.1-2.fc6.i386.rpm
-r--r--r-- 99 root root 21509 2007-01-19 tftp-0.42-3.1.i386.rpm
-r--r--r-- 99 root root 28797 2007-01-19 tftp-server-0.42-3.1.i386.rpm
-r--r--r-- 99 root root 141003 2007-12-17 vsftpd-2.0.5-12.el5.i386.rpm
[root@localhost Server]# rpm -ivh vsftpd-2.0.5-12.el5.i386.rpm 安装vsftpd
创建公共目录和个人目录:
[root@localhost Server]# cd /mnt/ftppart
[root@localhost ftppart]# mkdir public 创建public目录
[root@localhost ftppart]# mkdir home 创建home目录
[root@localhost ftppart]# ll
总计 24
drwxr-xr-x 2 root root 4096 03-20 11:51 home
drwx------ 2 root root 16384 03-20 11:38 lost+found
drwxr-xr-x 2 root root 4096 03-20 11:43 public
[root@localhost ftppart]# cd public/
[root@localhost public]# touch p1 p2
[root@localhost public]# ll
总计 0
-rw-r--r-- 1 root root 0 03-20 11:43 p1
-rw-r--r-- 1 root root 0 03-20 11:43 p2
创建两个账号并设置密码:
[root@localhost public]# useradd user1
[root@localhost public]# useradd user2
[root@localhost public]# echo "123" |passwd --stdin user1
[root@localhost public]# echo "123" |passwd --stdin user2
修改用户默认家目录:
[root@localhost public]# grep user /etc/passwd
rpc:x:32:32:Portmapper RPC user:/:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
sabayon:x:86:86:Sabayon user:/home/sabayon:/sbin/nologin
user1:x:501:502::/home/user1:/bin/bash
user2:x:502:503::/home/user2:/bin/bash
[root@localhost public]# vim /etc/passwd 修改两个用户家目录
[root@localhost public]# cd /mnt/ftppart
[root@localhost home]# cd /home
[root@localhost home]# mv * /mnt/ftppart/home
[root@localhost home]# cd /mnt/ftppart/home
[root@localhost home]# ll
总计 8
drwx------ 3 user1 user1 4096 03-20 11:44 user1
drwx------ 3 user2 user2 4096 03-20 11:44 user2
此时用户家目录已经更改:
[root@localhost home]# su - user1
[user1@localhost ~]$ pwd
/mnt/ftppart/home/user1
每创建一个用户手动更改家目录很麻烦,这时可以修改useradd参数:
[root@localhost home]# useradd -D -b /mnt/ftppart/home 修改用户默认家目录
[root@localhost home]# useradd -D
GROUP=100
HOME=/mnt/ftppart/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
磁盘配额:
[root@localhost home]# vim /etc/fstab编辑文件系统表格(系统启动时读取,在这个表格里加载分区)
[root@localhost home]# 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.3 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 home]# mount -o remount /dev/sdb1 重新挂载,让参数生效
[root@localhost home]# 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.3 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 ftppart]# cd /mnt/ftppart 在目录下做磁盘配额
[root@localhost ftppart]# quotacheck –augvc 扫描
[root@localhost ftppart]# edquota -u user1 修改user1的磁盘配额文件
[root@localhost ftppart]# edquota -u user2 修改user2的磁盘配额文件
[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
[root@localhost ftppart]# vim /etc/vsftpd/vsftpd.conf 编辑vsftpd主配置文件
anon_root=/mnt/ftppart/public 匿名账号的根
anon_max_rate=100000 匿名账号最大的速度传输速率(字节的形式,0表示无限制)
local_max_rat e=1000000 本地用户最大传输速率
max_clients=20 客户端的最大连接数量
max_per_ip=2 从同一个ip上连接的最大数
[root@localhost ftppart]# service vsftpd start 启动服务
测试:
匿名用户只可以下载,不可以上传,修改文件名等
本地用户登录后到自己的家目录 可以上传下载文件,也可以新建文件夹,重命名等
当连接数超过限制时就会有如下提醒