公司服务器自动分区,IP=192.168.0.100
现上级要求使用软件磁盘阵列为服务器上的普通用户家目录进行配额限制,且此服务器所有日志信息都写到192.168.0.10这台机器上
服务器上用户有10个 用户名自定义 ip地址自定义,限额数值自定义,但需要在文档中标明。
服务器IP:192.168.0.100
添加5块硬盘 建立raid5
[root@localhost ~]# fdisk /dev/sdb
nàpà1àw
sdc sdd sde sdf 同上
[root@localhost ~]# mdadm --create --auto=yes /dev/md1 --level=5 --raid-devices=4 --spare-devices=1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
mdadm: array /dev/md1 started. #建立raid5
[root@localhost ~]# mdadm --detail /dev/md1 #查看raid设备的信息
[root@localhost ~]# cat /proc/mdstat #查看raid设备的信息
[root@localhost ~]# mkfs.ext3 /dev/md1 #格式化
[root@localhost ~]# partprobe #强制更新分区列表
[root@localhost ~]# mkdir /mnt/raid5
[root@localhost ~]# mount /dev/md1 /mnt/raid5/ #挂载到/mnt下
[root@localhost ~]# df
文件系统 1K-块 已用 可用 已用% 挂载点
/dev/md1 61906876 184272 58577904 1% /mnt/raid5
设置自动挂载
[root@localhost ~]# mdadm --detail /dev/md1 | grep UUID #获取UUID
UUID : f0986088:d9eb2e27:eedd1395:471b472f
[root@localhost ~]# vim /etc/mdadm.conf #配置文件
ARRAY /dev/md1 UUID=f0986088:d9eb2e27:eedd1395:471b472f
[root@localhost ~]# vim /etc/fstab
/dev/md1 /mnt/raid5 ext3 defaults 0 0
创建用户和组
[root@localhost ~]# vim username.sh
#!/bin/bash
groupadd group
for i in user{1..10};do
useradd -g group $i
echo "123456" | passwd --stdin $i
done
[root@localhost ~]# sh username.sh
设置磁盘配额
[root@localhost ~]# mount -o remount,usrquota,grpquota /mnt/raid5/
[root@localhost ~]# mount –a
[root@localhost ~]# mount
/dev/md1 on /mnt/raid5 type ext3 (rw,usrquota,grpquota)
[root@localhost ~]# vim /etc/fstab
/dev/md1 /mnt/raid5 ext3 defaults,usrqouta,grpqouta 0 0
[root@localhost raid5]# quotacheck –avug #建立数据文件
quotacheck: Scanning /dev/md1 [/mnt/raid5]
done
quotacheck: Checked 3 directories and 4 files
[root@localhost raid5]# ls
aquota.group aquota.user lost+found
[root@localhost raid5]# quotaon –auvg #启动配额
/dev/md1 [/mnt/raid5]: group quotas turned on
/dev/md1 [/mnt/raid5]: user quotas turned on
[root@localhost raid5]# edquota -u user1 #设置用户的配额
Disk quotas for user user1 (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/md1 0 250000 300000 0 0 0
[root@localhost raid5]# edquota -p user1 -u user2
…
[root@localhost raid5]# edquota -p user1 -u user10
[root@localhost raid5]# edquota -g group #设置组的配额
Disk quotas for group group (gid 500):
Filesystem blocks soft hard inodes soft hard
/dev/md1 0 2500000 3000000 0 0 0
[root@localhost raid5]# edquota –t
[root@localhost ~]# mv /home/ /mnt/raid5/
[root@localhost ~]# ln -s /mnt/raid5/home/ / #建立软连接
[root@localhost /]# ll
lrwxrwxrwx 1 root root 16 12-31 22:55 home -> /mnt/raid5/home/
日志服务器IP:192.168.0.10
所有用户IP设置为192.168.0.101…192.168.0.110
配置日志服务器
[root@localhost ~]# vim /etc/sysconfig/syslog
SYSLOGD_OPTIONS="-m 0 -r"
其他服务器和用户端配置
[root@localhost /]# vim /etc/syslog.conf
*.* @192.168.0.10
[root@localhost /]# /etc/init.d/syslog restart #所有重启日志服务器
测试日志服务器
[root@localhost ~]# tail -f /var/log/messages
Dec 31 23:06:59 localhost kernel: klogd 1.4.1, log source = /proc/kmsg started.
Dec 31 23:08:51 192.168.0.100 syslogd 1.4.1: restart.
Dec 31 23:08:51 192.168.0.100 kernel: klogd 1.4.1, log source = /proc/kmsg started.
Dec 31 23:13:17 192.168.0.101 syslogd 1.4.1: restart.
Dec 31 23:13:17 192.168.0.101 kernel: klogd 1.4.1, log source = /proc/kmsg started.
测试磁盘配额
[user1@localhost ~]$ dd if=/dev/zero of=/home/user1/text bs=1M count=260
md1: warning, user block quota exceeded.
260+0 records in
260+0 records out
272629760 bytes (273 MB) copied, 25.1123 seconds, 10.9 MB/s
[user1@localhost ~]$ mail #收到警告
Mail version 8.1 6/6/93. Type ? for help.
"/var/spool/mail/user1": 1 message 1 new
>N 1 [email protected] Mon Dec 31 23:25 27/1076 "NOTE: You are exceedi"
Message 1:
From [email protected] Mon Dec 31 23:25:50 2012
Date: Mon, 31 Dec 2012 23:25:49 +0800
From: root <[email protected]>
Reply-To: [email protected]
Subject: NOTE: You are exceeding your allocated disk space limits
Your disk usage has exceeded the agreed limits on this server
Please delete any unnecessary files on following filesystems:
你的磁盘使用量已经超过了同意限制该服务器,请删除任何不必要的文件在以下文件系统:
/dev/md1
Block limits File limits
Filesystem used soft hard grace used soft hard grace
/dev/md1 +- 266536 250000 300000 7days 9 0 0
root@localhost
[user1@localhost ~]$ dd if=/dev/zero of=/home/user1/text bs=1M count=300
md1: warning, user block quota exceeded.
md1: write failed, user block limit reached.
dd: 写入 “/home/user1/text”: 超出磁盘限额
293+0 records in
292+0 records out
306855936 bytes (307 MB) copied, 2.67052 seconds, 115 MB/s