公司服务器自动分区,IP=192.168.0.100
现上级要求使用软件磁盘阵列为服务器上的普通用户家目录进行配额限制,且此服务器所有日志信息都写到192.168.0.10这台机器上 服务器上用户有10个 用户名自定义 ip地址自定义,限额数值自定义,但需要在文档中标明。1.首先装一个自动分区的linux系统,添加4个硬盘 然后添加ip ifconfig eth0 192.168.0.100 或者setup 网路设置一下ip
2.重新分区并格式化
fdisk -l fdisk /dev/sdb 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): 1 Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): Using default value 2610Command (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.fdisk /dev/sdc
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): 1 Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): Using default value 2610Command (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.fdisk /dev/sdd
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): 1 Last cylinder or +size or +sizeM or +sizeK (1-2610, default 2610): Using default value 2610Command (m for help): w
The partition table has been altered!Calling ioctl() to re-read partition table.
Syncing disks.格式化
mkfs.ext3 /dev/sdb1 mkfs.ext3 /dev/sdc1 mkfs.ext3 /dev/sdd1 partprobe强制内核分区表建立raid设备
mdadm --create --auto=yes /dev/md1 --level=5 --raid-devices=2 --spare-devices=1 /dev/sdb1 /dev/sdc1 /dev/sdd1 mdadm --detail /dev/md1 查看raid设备信息 设置raid自动挂载 [root@localhost ~]# mdadm --detail /dev/md1 | grep -i uuid UUID : a7e08091:74630477:aa7d609f:57955eb9 vim /etc/mdadm.conf 偷懒的方法: ARRAY /dev/md1 UUID=a7e08091:74630477:aa7d609f:57955eb9vim /etc/fstab
在最后一行添加 /dev/md1 /mnt/raid5 ext3 defaults 0 0 创建用户和组 vim useradd.sh #!/bin/bash groupadd linfor username in lin1 lin2 lin3 lin4 lin5 lin6 lin7 lin8 lin9 lin10
douseradd -g lin $username
echo "123456" | passwd --stdin $username
donesh useradd.sh
cat /etc/passwd lin1:x:501:501::/home/lin1:/bin/bash lin2:x:502:501::/home/lin2:/bin/bash lin3:x:503:501::/home/lin3:/bin/bash lin4:x:504:501::/home/lin4:/bin/bash lin5:x:505:501::/home/lin5:/bin/bash lin6:x:506:501::/home/lin6:/bin/bash lin7:x:507:501::/home/lin7:/bin/bash lin8:x:508:501::/home/lin8:/bin/bash lin9:x:509:501::/home/lin9:/bin/bash lin10:x:510:501::/home/lin10:/bin/bashmkdir /mnt/raid5 建立一个raid5
挂载 mount /dev/md1 /mnt/raid5 cd /mnt/raid5 ls 里面有lost+found cd mount -o remount,usrquota,grpquota /mnt/raid5 mount /dev/md1 on /mnt/raid5 type ext3 (rw,usrquota,grpquota)vim /etc/fstab
/dev/VolGroup00/LogVol00 / ext3 defaults 1 1 LABEL=/boot /boot ext3 defaults 1 2 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 /dev/VolGroup00/LogVol01 swap swap defaults 0 0 /dev/md1 /mnt/raid5 ext3 defaults 0 0 /dev/md1 /mnt/raid5 ext3 defaults,usrquota,grpquota 0 0测试
mount /dev/md1 on /mnt/raid5 type ext3 (rw,usrquota,grpquota) umount /mnt/raid5 mount查看 mount -a cd /mnt/raid5 ls lost+found cd quotacheck -avug quotacheck: Scanning /dev/md1 [/mnt/raid5] done quotacheck: Checked 3 directories and 4 files cd /mnt/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 onedquota -u lin1
Disk quotas for user lin1 (uid 501): Filesystem blocks soft hard inodes soft hard /dev/md1 0 200000 300000 0 0 0 wq[root@localhost ~]# edquota -p lin1 -u lin2
[root@localhost ~]# edquota -p lin1 -u lin3 [root@localhost ~]# edquota -p lin1 -u lin4 [root@localhost ~]# edquota -p lin1 -u lin5 [root@localhost ~]# edquota -p lin1 -u lin6 [root@localhost ~]# edquota -p lin1 -u lin7 [root@localhost ~]# edquota -p lin1 -u lin8 [root@localhost ~]# edquota -p lin1 -u lin9 [root@localhost ~]# edquota -p lin1 -u lin10[root@localhost ~]# edquota -u lin2 可以看一下
Disk quotas for user lin2 (uid 502): Filesystem blocks soft hard inodes soft hard /dev/md1 0 200000 300000 0 0 0edquota -g lin
Disk quotas for group lin (gid 501): Filesystem blocks soft hard inodes soft hard /dev/md1 0 900000 1000000 0 0 0 wq edquota -t宽限时间 Grace period before enforcing soft limits for users: Time units may be: days, hours, minutes, or seconds Filesystem Block grace period Inode grace period /dev/md1 14days 7days软连接
ln -s /home /mnt/raid5/ cd /mnt/raid5/ [root@localhost raid5]# ls aquota.group aquota.user home lost+found [root@localhost raid5]# ll 总计 32 -rw------- 1 root root 7168 12-28 17:07 aquota.group -rw------- 1 root root 7168 12-28 17:09 aquota.user lrwxrwxrwx 1 root root 5 12-28 17:33 home -> /home drwx------ 2 root root 16384 12-28 14:48 lost+found服务器日志
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 KLOGD_OPTIONS="-x" # SYSLOG_UMASK=077 # set this to a umask value to use for all log files as in umask(1). # By default, all permissions are removed for "group" and "other".service syslog restart
关闭内核日志记录器: [确定] 关闭系统日志记录器: [确定] 启动系统日志记录器: [确定] 启动内核日志记录器: [确定]tail -f /var/log/messages
客户端日志
vim /etc/syslog.conf # Log all kernel messages to the console. # Logging much else clutters up the screen. #kern.* /dev/console *.* @192.168.0.100 # 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# The authpriv file has restricted access.
authpriv.* /var/log/secure# Log all the mail messages in one place.
mail.* -/var/log/maillog # Log cron stuff cron.* /var/log/cron# Everybody gets emergency messages
*.emerg *# Save news errors of level crit and higher in a special file.
tail -f /var/log/messages
测试
给普通用户加个写的权限 chmod o+w /mnt/ ll -d /mnt/raid5 su - lin1 cd /mnt/raid5 [lin1@localhost raid5]$ dd if=/dev/zero of=lin1 bs=1M count=270 md1: warning, user block quota exceeded. 270+0 records in 270+0 records out 283115520 bytes (283 MB) copied, 5.13592 seconds, 55.1 MB/s 但是270也写进去了 ll查看一下 在改一个25的 [lin1@localhost raid5]$ dd if=/dev/zero of=lin11 bs=1M count=25 md1: write failed, user block limit reached. dd: 写入 “lin11”: 超出磁盘限额 23+0 records in 22+0 records out 23773184 bytes (24 MB) copied, 0.302682 seconds, 78.5 MB/s