1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
[root@bogon ~]# fdisk /dev/sde Command (m for help): p Disk /dev/sde: 21.5 GB, 21474836480 bytes 255 heads, 63 sectors/track, 2610 cylinders Units = cylinders of 16065 * 512 = 8225280 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk identifier: 0xd606697d Device Boot Start End Blocks Id System 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): Using default value 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +10G Command (m for help): w
[root@bogon ~]# mkfs.ext4 -b 2048 -m 2 -L 'MYDATA' /dev/sde1 mke2fs 1.41.12 (17-May-2010) Filesystem label=MYDATA OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 657408 inodes, 5245206 blocks 104904 blocks (2.00%) reserved for the super user ....
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@bogon ~]# mkdir /data/mydata [root@bogon ~]# mount -o noauto,noatime /dev/sde1 /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@bogon ~]# fdisk /dev/sde
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 2 First cylinder (1307-2610, default 1307): Using default value 1307 Last cylinder, +cylinders or +size{K,M,G} (1307-2610, default 2610): +1G Command (m for help): t Partition number (1-4): 2 Hex code (type L to list codes): 82 Command (m for help): w [root@bogon ~]# mkswap /dev/sde2 [root@bogon ~]# swapon /dev/sde2
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
#!/bin/bash # echo "All Device:" fdisk -l | grep -o "^Disk /dev/[sh]d[a-z]" echo echo "Disk usage:" df -h [root@bogon job]# ./disk.sh All Device: Disk /dev/sda Disk /dev/sdb Disk /dev/sdc Disk /dev/sdd Disk /dev/sde Disk usage: Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 37G 3.3G 32G 10% / /dev/sde1 9.9G 77M 9.6G 1% /data/mydata tmpfs 198M 0 198M 0% /dev/shm /dev/sdd1 1004M 18M 936M 2% /backup
4、总结RAID的各个级别及其组合方式和性能的不同;
RAID 0:条带卷,strips; 把文件分成块分散存放在磁盘上 读、写性能提升 可用空间:N*min(S1,S2...) 有冗余能力 最少盘数:2, 2+ RAID 1:镜像卷,morror 读性能提升、写性能略有下降 可用空间:1*min(S1,S2....) 有冗余能力 最少磁盘数:2, 2+ RAID 5: 读、写性能提升 可用空间:(N-1)/n*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@bogon ~]#mdadm -C /dev/md0 -a yes -n 2 -x 1 -c 128 -l 1 /dev/sdf{1,2,3}
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
Command (m for help): n Command action e extended p primary partition (1-4) p Partition number (1-4): 1 Last cylinder, +cylinders or +size{K,M,G} (1-2610, default 2610): +4G .... 创建3个4G分区 [root@bogon ~]# mdadm -C /dev/md1 -n 3 -c 256 -l 5 /dev/sde{1,2,3} [root@bogon ~]# mkfs.ext4 /dev/md1 [root@bogon ~]# echo "/dev/md1 /backup ext4 noatime,acl 0 0" &>> /etc/fstab
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
#!/bin/bash # if [ $# -eq 0 ];then echo "At least a file path" exit 8 fi for i in $*;do if [ -e $i ];then echo "$i total lines : $(cat $i | wc -l)" echo "File total:$#" else echo "No such file" fi done [root@bogon job]# bash line.sh At least a file path [root@bogon job]# bash line.sh /etc/passw No such file [root@bogon job]# bash line.sh /etc/passwd /etc/passwd total lines : 72 File total:1 [root@bogon job]# bash line.sh /etc/passwd /etc/fstab /etc/passwd total lines : 72 File total:2 /etc/fstab total lines : 16 File total:2
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
#!/bin/bash # if [ $# -lt 2 ];then echo "At least two users!" exit 8 fi for i in $*;do if id $i &>> /dev/null;then echo "$i exist" continue else useradd $i echo $i | passwd --stdin $i &>> /dev/null fi done echo "Already create $# users!"
[root@bogon job]# bash adduser.sh m n m exist n exist [root@bogon job]# bash adduser.sh m At least two users! [root@bogon job]# bash adduser.sh user100 user101 Already create 2 users!
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
#!/bin/bash # declare -i sum=0 U=visitor for i in {1..20};do useradd $U$i uid=`id -u $U$i` let sum+=$uid done echo "User ID sum:$sum" [root@bogon job]# bash -x 20user.sh + declare -i sum=0 + U=visitor + for i in '{1..20}' + useradd visitor1 ++ id -u visitor1 + uid=5580 + let sum+=5580 + for i in '{1..20}' + useradd visitor2 ++ id -u visitor2 + uid=5581 + let sum+=5581 + for i in '{1..20}' + useradd visitor3 .... User ID sum:111790
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
#!/bin/bash # declare -i linesum=0 declare -i spaceline=0 for i in /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab;do line=`cat $i | grep "^#" | wc -l` let linesum+=$line done echo "# Line sum is :$linesum" for i in /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab;do space=`cat $i | grep "^$" | wc -l` let spaceline+=$space done echo "Space line sum is : $spaceline" [root@bogon job]# bash etc.sh # Line sum is :90 Space line sum is : 169
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
#!/bin/bash # name=`cat /etc/passwd | grep "/bin/bash" | cut -d: -f1` echo -e "The default shell is bash user:\n$name" namesum=`cat /etc/passwd | grep "/bin/bash" | cut -d: -f1 | wc -l` echo "The default shell is bash user sum:$namesum" declare -i uidsum=0 uid=`cat /etc/passwd | grep "/bin/bash" | cut -d: -f3` for i in $uid;do let uidsum+=$i done echo -e "The default shell is bash UID:\n$uid" echo "The default shell is bash UID sum:$uidsum" [root@bogon job]# bash usershell.sh The default shell is bash user: root student 12 user12 user11 user13 user15 hello3 hello2 user7 user8 .... visitor18 visitor19 visitor20 The default shell is bash user sum:70 The default shell is bash UID: 0 500 5002 5003 5004 5005 .... 5598 5599 The default shell is bash UID sum:358806
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
#!/bin/bash # declare -i gpnum=0 echo "The have apendgroup user name is:" for i in `cat /etc/passwd | cut -d: -f1`;do num=`id -G $i | wc -w` if [ $num -gt 1 ];then echo "$i" let gpnum+=1 fi done echo "The have apendgroup user sum is :$gpnum" [root@bogon job]# bash apendgroup.sh The have apendgroup user name is: bin daemon adm postfix kourong slackware openstack The have apendgroup user sum is :7
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@bogon ~]# pvcreate /dev/sde1 Physical volume "/dev/sde1" successfully created [root@bogon ~]# pvcreate /dev/sde2 Physical volume "/dev/sde2" successfully created [root@bogon ~]# vgcreate -s 8m MyVG /dev/sde{1,2} Volume group "MyVG" successfully created [root@bogon ~]# vgdisplay --- Volume group --- VG Name MyVG System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 1 VG Access read/write VG Status resizable MAX LV 0 Cur LV 0 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 19.98 GiB PE Size 8.00 MiB Total PE 2558 Alloc PE / Size 0 / 0 Free PE / Size 2558 / 19.98 GiB VG UUID uZSpxW-fB22-y4vR-0c61-nrel-ofGu-b7MBMt [root@bogon ~]# lvcreate -L 5G -n mylv1 MyVG Logical volume "mylv1" created [root@bogon ~]# lvs LV VG Attr LSize Pool Origin Data% Move Log Cpy%Sync Convert mylv1 MyVG -wi-a----- 5.00g lv_root vg_centos -wi-ao---- 37.57g lv_swap vg_centos -wi-a----- 1.94g [root@bogon ~]# mkfs.ext4 /dev/MyVG/mylv1 [root@bogon ~]# echo "/dev/MyVG/mylv1 /users ext4 defaults,acl 0 0" >> /etc/fstab
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@bogon ~]# mkdir /users [root@bogon ~]# useradd -d /users/magedu magedu [root@bogon ~]# su - magedu [magedu@bogon ~]$ cp /etc/passwd . [magedu@bogon ~]$ cp /etc/fstab . [magedu@bogon ~]$ cp /etc/issue . [magedu@bogon ~]$ ls fstab issue passwd
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@bogon ~]# lvextend -L 9G -n /dev/MyVG/mylv1 [root@bogon ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 37G 3.3G 32G 10% / /dev/sde1 37G 3.3G 32G 10% /data/mydata tmpfs 198M 0 198M 0% /dev/shm /dev/sdd1 37G 3.3G 32G 10% /backup /dev/mapper/MyVG-mylv1 5.0G 138M 4.6G 3% /users [root@bogon ~]# resize2fs /dev/MyVG/mylv1 [root@bogon ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/vg_centos-lv_root 37G 3.3G 32G 10% / /dev/sde1 37G 3.3G 32G 10% /data/mydata tmpfs 198M 0 198M 0% /dev/shm /dev/sdd1 37G 3.3G 32G 10% /backup /dev/mapper/MyVG-mylv1 8.9G 140M 8.3G 2% /users
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@bogon ~]# cp /etc/passwd /users/ [root@bogon ~]# ls /users/ lost+found passwd [root@bogon ~]# umount /users/ [root@bogon ~]# e2fsck -f /dev/MyVG/mylv1 [root@bogon ~]# resize2fs /dev/MyVG/mylv1 7G [root@bogon ~]# lvreduce -L 7G /dev/MyVG/mylv1 [root@bogon ~]# mount /dev/MyVG/mylv1 /users/ [root@bogon ~]# ls /users/ lost+found passwd
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@bogon ~]# lvcreate -L 5G -p r -s -n mylv1_snapshot /dev/MyVG/mylv1 Logical volume "mylv1_snapshot" created
原创文章,作者:凸b男波万,如若转载,请注明出处:http://www.178linux.com/51218
评论列表(2条)
第一个问题解答的并不严谨,其它不错,加油
@马哥教育:嗯,我再看看第一个问题,上次博客作业计划任务那个问题我后面知道了!不知道怎么回复您