1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
[root@localhost ~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). 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, +cylinders or +size{K,M,G} (1-6527, default 6527): +10g^HG Unsupported suffix: 'G'. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +10g Unsupported suffix: 'g'. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) Last cylinder, +cylinders or +size{K,M,G} (1-6527, default 6527): +10G Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@localhost ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sda1 [root@localhost ~]# tune2fs -o acl /dev/sda1
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@localhost ~]# mount -o noexec,nodiratime /dev/sda1 /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@localhost ~]# fdisk /dev/sda WARNING: DOS-compatible mode is deprecated. It's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u'). Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-6527, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-6527, default 6527): +10g^H Unsupported suffix: ''. Supported: 10^N: KB (KiloByte), MB (MegaByte), GB (GigaByte) 2^N: K (KibiByte), M (MebiByte), G (GibiByte) Last cylinder, +cylinders or +size{K,M,G} (1307-6527, default 6527): +10G Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 Changed system type of partition 2 to 82 (Linux swap / Solaris) Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. WARNING: Re-reading the partition table failed with error 16: Device or resource busy. The kernel still uses the old table. The new table will be used at the next reboot or after you run partprobe(8) or kpartx(8) Syncing disks. [root@localhost bin]# mkswap /dev/sda2 [root@localhost bin]# swapon /dev/sda2
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bash # echo "disk info:$(fdisk -l | grep -o "^Disk[[:space:]]/dev/sd[a-z]")" for i in $(fdisk -l | grep -o "^Disk[[:space:]]/dev/sd[a-z]"| cut -d" " -f2);do echo "$(fdisk -l $i)" done
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID-0: 读、写性能提升; 可用空间:N*min(S1,S2,...) 无容错能力 最少磁盘数:2, 2+ RAID-1: 读性能提升、写性能略有下降; 可用空间:1*min(S1,S2,...) 有冗余能力 最少磁盘数:2, 2+ RAID-4: 1101, 0110, 1011 最少磁盘数:3,3+ RAID-5: 读、写性能提升 可用空间:(N-1)*min(S1,S2,...) 有容错能力:1块磁盘 最少磁盘数:3, 3+ RAID-6: 读、写性能提升 可用空间:(N-2)*min(S1,S2,...) 有容错能力:2块磁盘 最少磁盘数:4, 4+ 混合类型 RAID-10: 读、写性能提升 可用空间:N*min(S1,S2,...)/2 有容错能力:每组镜像最多只能坏一块; 最少磁盘数:4, 4+
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
[root@localhost ~]# mdadm -C /dev/md0 -a yes -n 3 -x 1 -l 1 -c 128 /dev/sda{1,2,3}
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@localhost ~]# mdadm -C /dev/md0 -n 3 -l 5 -a yes -c 256 -x 1 /dev/sda{1,2,3,4}
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash # if [ $# -le 1 ]; then echo "At least 2 parameter.Try again!" exit 3 else for i in $*; do echo "$i total lines: `wc -l $i | cut -d' ' -f1`" done fi echo "Total parameters: $#"
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bash # if [ $# -le 2 ]; then echo "Enter at least 3 para. Try again!" exit 3 fi for i in $*; do id $i &> /dev/null if [ $? -eq 0 ]; then echo "$i exists." else useradd $i && echo "$i" | passwd --stdin "$i" echo "add $i finished" let j++ fi done echo "add $j users"
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bash # declare -i idsum=0 for i in {1..20}; do useradd visitor$i &> /dev/null let idsum+=$(id -u visitor$i) done echo "The idsum is $idsum"
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash # declare -i sum1=0 declare -i sum2=0 for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab};do let sum1+=$(grep "^#" $i | wc -l ) let sum2+=$(grep "^$" $i | wc -l ) done echo "The #lines:$sum1" echo "The spacelins:$sum2"
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash # declare -i UIDsum=0 for i in $(grep "bash$" /etc/passwd | cut -d":" -f3); do let UIDsum+=$i done echo "Username&UID:" echo "$(grep "bash$" /etc/passwd | cut -d":" -f1,3)" echo "UIDsum=$UIDsum"
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash # declare -i j=0 for i in $(cut -d: -f1 /etc/passwd); do id $i | grep ',' &> /dev/null if [ $? -eq 0 ]; then echo "USER: $i" let j++ fi done echo "Sum: $j."
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@CentOS6 ~]# pvcreate /dev/sdb /dev/sdc [root@CentOS6 ~]# vgcreate -s 8M myvg /dev/sd{b,c} [root@CentOS6 ~]# lvcreate -L 5G -n mylv1 /dev/myvg [root@CentOS6 ~]# mkfs.ext4 /dev/myvg/mylv1 [root@CentOS6 ~]# echo "/dev/myvg/mylv1 /users ext4 defaults,acl,nodiratime 0 0" >> /etc/fstab
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@CentOS6 test]# useradd -d /users/magedu magedu [root@CentOS6 test]# su - magedu [magedu@CentOS6 ~]$ pwd /users/magedu [magedu@CentOS6 ~]$ cp /etc/fstab /etc/issue ./
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@CentOS6 users]# cp /etc/fstab ./ [root@CentOS6 users]# lvextend -L +4G -n /dev/myvg/mylv1 [root@CentOS6 users]# resize2fs /dev/myvg/mylv1 [root@CentOS6 users]# ls fstab lost+found
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@CentOS6 ~]# umount /users [root@CentOS6 ~]# e2fsck -f /dev/myvg/mylv1 [root@CentOS6 ~]# resize2fs /dev/myvg/mylv1 7G [root@CentOS6 ~]# lvreduce -L 7G -n /dev/myvg/mylv1
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@CentOS6 ~]# lvcreate -L 3G -p r -s -n mylv1_snapshot /dev/myvg/mylv1
原创文章,作者:Bazinga,如若转载,请注明出处:http://www.178linux.com/38445
评论列表(1条)
如果raid的描述能够做到图文并茂就更好了