公司服務器自動分區,IP=192.168.0.100現上級要求使用軟件磁盤陣列爲服務器上的普通用戶家目錄進行配額限制,且此服務器所有日誌信息都寫到192.168.0.10這臺機器,服務器上用戶有10個 用戶名自定義 ip地址自定義,限額數值自定義,但需要在文檔中標明。
步驟
建立10個用戶 rongxin1 rongxin10 rongxin2 rongxin3 rongxin4 rongxin5 rongxin6 rongxin7 rongxin8 rongxin9
配額 soft 250000 hard 300000
1 fdisk -l
2 fdisk /dev/sdb 建立分區
3 fdisk /dev/sdc
4 fdisk /dev/sdd
5 fdisk /dev/sde
6 fdisk /dev/sdf
7 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 2355 18916506 83 Linux
/dev/sda2 2356 2610 2048287+ 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
Device Boot Start End Blocks Id System
/dev/sdb1 1 2610 20964793+ 83 Linux
Disk /dev/sdc: 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/sdc1 1 2610 20964793+ 83 Linux
Disk /dev/sdd: 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/sdd1 1 2610 20964793+ 83 Linux
Disk /dev/sde: 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/sde1 1 2610 20964793+ 83 Linux
Disk /dev/sdf: 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/sdf1 1 2610 20964793+ 83 Linux
Disk /dev/md1: 64.4 GB, 64403472384 bytes
2 heads, 4 sectors/track, 15723504 cylinders
Units = cylinders of 8 * 512 = 4096 bytes
Disk /dev/md1 doesn't contain a valid partition table
8 partprobe
9 partprobe
10 fdisk -l
建立RAID
11 mdadm --create --auto=yes /dev/md1 --level=5 --raid-devices=4 --spare-devices=1 /dev/sdb1 /dev/sdc1 /dev/sdd1 /dev/sde1 /dev/sdf1
12 mdadm --detail /dev/md1
/dev/md1:
Version : 0.90
Creation Time : Fri Dec 28 14:16:33 2012
Raid Level : raid5
Array Size : 62894016 (59.98 GiB 64.40 GB)
Used Dev Size : 20964672 (19.99 GiB 21.47 GB)
Raid Devices : 4
Total Devices : 5
Preferred Minor : 1
Persistence : Superblock is persistent
Update Time : Fri Dec 28 14:58:59 2012
State : clean
Active Devices : 4
Working Devices : 5
Failed Devices : 0
Spare Devices : 1
Layout : left-symmetric
Chunk Size : 64K
UUID : bc0088b9:46636f56:e781e578:029ad957
Events : 0.12
Number Major Minor RaidDevice State
0 8 17 0 active sync /dev/sdb1
1 8 33 1 active sync /dev/sdc1
2 8 49 2 active sync /dev/sdd1
3 8 65 3 active sync /dev/sde1
4 8 81 - spare /dev/sdf1
13 cat /proc/mdstat
格式化硬盤
14 mkfs.ext3 /dev/md1
15 mkd
16 mkdir /mnt/raid5
17 mount /dev/md1 /mnt/raid5/
18 cd /mnt/raid5
19 ls
aquota.group aquota.user home lost+found
20 cd
21 df
建立用戶10個
22 vim /etc/useradd.sh
rongxin1 rongxin10 rongxin2 rongxin3 rongxin4 rongxin5 rongxin6 rongxin7 rongxin8 rongxin9
23 sh useradd.sh
創建用戶
24 sh useradd.sh
25 vim /etc/useradd.sh
26 sh useradd.sh
27 sh /etc/useradd.sh
28 cd /etc/riad5
31 cd
把/Home 軟連接到 RAID5下
34 ln -s /home /mnt/raid5/
35 cd /mnt/raid5
36 ls
37 cd
54 cd /mnt/raid5
55 ls
56 cd
從新掛載到/mnt/raid5下 並開啓用戶和組的配額
57 mount -o remount,usrquota,grpquota /mnt/raid5
開啓加載配額功能
58 vim /etc/fstab
LABEL=/ / ext3 defaults 1 1
tmpfs /dev/shm tmpfs defaults 0 0
devpts /dev/pts devpts gid=5,mode=620 0 0
sysfs /sys sysfs defaults 0 0
proc /proc proc defaults 0 0
LABEL=SWAP-sda2 swap swap defaults 0 0
/dev/md1 /mnt/raid5 ext3 defaults,usrquota,grpquota 0 0
59 cd /mnt /raid5
60 cd /mnt/raid5
建立數據文件
61 quotacheck -avug
開啓用戶和組的配額
62 quotaon -avug
63 ls
編輯rontxin1用戶的配額大小
65 edquota -u rongxin1
Disk quotas for user rongxin1 (uid 500):
Filesystem blocks soft hard inodes soft hard
/dev/md1 0 250000 300000 0 0 0
把rongxin1的用戶配額複製到其他用戶上
66 dequota -p rongxin1 -u rongxin2
67 edquota -p rongxin1 -u rongxin2
68 edquota -p rongxin1 -u rongxin3
69 edquota -p rongxin1 -u rongxin4
70 edquota -p rongxin1 -u rongxin5
71 edquota -p rongxin1 -u rongxin6
72 edquota -p rongxin1 -u rongxin7
73 edquota -p rongxin1 -u rongxin8
74 edquota -p rongxin1 -u rongxin9
75 edquota -p rongxin1 -u rongxin10
查看用戶rongxin6的配額
76 edquota -u rongxin6
Disk quotas for user rongxin6 (uid 505):
Filesystem blocks soft hard inodes soft hard
/dev/md1 0 250000 300000 0 0 0
設置RAID的自動掛載
77 vim /etc/mdadm.conf
RAY /dev/md1 UUID=bc0088b9:46636f56:e781e578:029ad957
設置服務器的IP爲192.168.0.100
78 ifconfig etho
eth0 Link encap:Ethernet HWaddr 00:0C:29:0F:9A:4A
inet addr:192.168.0.100 Bcast:192.168.0.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:1523 errors:0 dropped:0 overruns:0 frame:0
TX packets:93 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:151518 (147.9 KiB) TX bytes:12081 (11.7 KiB)
Interrupt:67 Base address:0x2024
重啓網卡服務
79 service network restart
在服務器上配置修改文件並 把收到日誌信息的IP指向192.168.0.10
80 vim /etc/syslog.conf
# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.* /dev/console
*.* @192.168.0.10
# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none /var/log/messages
重啓SYSLOG的服務
service syslog restart
在192.168.0.10上
vim /etc/sysconfig/syslog
# Options to syslogd
# -m 0 disables 'MARK' messages.
# -r enables logging from remote machines
# -x disables DNS lookups on messages recieved with -r
# See syslogd(8) for more details
SYSLOGD_OPTIONS="-m 0 -r"
# Options to klogd
# -2 prints all kernel oops messages twice; once for klogd to decode, and
# once for processing with 'ksymoops'
# -x disables all klogd processing of oops messages entirely
# See klogd(8) for more details
重啓SYSLOG的服務
service syslog restart
在IP192.168.0.10上查看 郵件信息
[root@localhost ~]# tail -f /var/log/messages
Dec 28 15:43:21 localhost avahi-da
emon[3887]: New relevant interface eth0.IPv4 for mDNS.
Dec 28 15:43:21 localhost avahi-daemon[3887]: Joining mDNS multicast group on interface eth0.IPv4 with address 192.168.0.10.
Dec 28 15:43:21 localhost avahi-daemon[3887]: Registering new address record for 192.168.0.10 on eth0.
Dec 28 15:48:47 localhost kernel: Kernel logging (proc) stopped.
Dec 28 15:48:47 localhost kernel: Kernel log daemon terminating.
Dec 28 15:48:48 localhost exiting on signal 15
Dec 28 15:48:48 localhost syslogd 1.4.1: restart (remote reception).
Dec 28 15:48:48 localhost kernel: klogd 1.4.1, log source = /proc/kmsg started.
Dec 28 15:49:06 192.168.0.100 syslogd 1.4.1: restart.
Dec 28 15:49:06 192.168.0.100 kernel: klogd 1.4.1, log source = /proc/kmsg started.
Dec 28 16:17:50 192.168.0.100 nm-system-settings: ifcfg-rh: updating /etc/sysconfig/network-scripts/ifcfg-eth0
Dec 28 16:18:16 192.168.0.100 kernel: Kernel logging (proc) stopped.
Dec 28 16:18:16 192.168.0.100 kernel: Kernel log daemon terminating.
Dec 28 16:18:17 192.168.0.100 exiting on signal 15
設置權限給RAID5 寫入的權限
81 cd /mnt/raid5
[root@localhost ~]# cd /mnt/raid5
[root@localhost raid5]# chmod o+w /mnt/raid5
切換到普通用戶rongxin1下
[root@localhost raid5]# su - rongxin1
[rongxin1@localhost ~]$ cd /mnt
[rongxin1@localhost mnt]$ ls
hgfs raid5
[rongxin1@localhost mnt]$ cd /mnt/raid5
[rongxin1@localhost raid5]$ ls
aquota.group aquota.user home lost+found
測試:
[rongxin1@localhost raid5]$ dd if=/dev/zero of=rongxin1 bs=1M count=270
md1: warning, user block quota exceeded.
270+0 records in
270+0 records out
283115520 bytes (283 MB) copied, 4.59298 seconds, 61.6 MB/s
[rongxin1@localhost raid5]$ ll
總計 276788
-rw------- 1 root root 7168 12-28 16:03 aquota.group
-rw------- 1 root root 7168 12-28 15:18 aquota.user
lrwxrwxrwx 1 root root 5 12-28 14:33 home -> /home
drwx------ 2 root root 16384 12-28 14:21 lost+found
-rw-r--r-- 1 rongxin1 rongxin 283115520 12-28 16:03 rongxin1
[rongxin1@localhost raid5]$ dd if=/dev/zero of=rongxin11 bs=1M count=50
md1: write failed, user block limit reached.
dd: 寫入 “rongxin11”: 超出磁盤限額
23+0 records in
22+0 records out
23773184 bytes (24 MB) copied, 0.358986 seconds, 66.2 MB/s
完成!