马哥教育网络21期+第七周练习博客
1、创建一个10G分区,并格式为ext4文件系统; 首先挂载一个新的硬盘使用fdisk /dev/sdb进入相应的磁盘空间划分一个10G的磁盘空间; 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 The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. 使用partx -a /dev/sdb查看是否读取到sdb中的磁盘分区; [root@wanghongkai ~]# partx -a /dev/sdb BLKPG: Device or resource busy error adding partition 1 查看内核是否识别到刚刚创建的磁盘空间; [root@wanghongkai ~]# cat /proc/partitions major minor #blocks name 8 0 125829120 sda 8 1 512000 sda1 8 2 20971520 sda2 8 3 10485760 sda3 8 4 1 sda4 8 5 2097152 sda5 8 6 10486742 sda6 8 7 10490413 sda7 8 16 20971520 sdb 8 17 10490413 sdb1 使用mkfs.ext4将需要挂载磁盘文件系统变成ext4文件系统: [root@wanghongkai ~]# mkfs.ext4 /dev/sdb1 mke2fs 1.41.12 (17-May-2010) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 655776 inodes, 2622603 blocks 131130 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=2688548864 81 block groups 32768 blocks per group, 32768 fragments per group 8096 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632 Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done This filesystem will be automatically checked every 37 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override. (1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;fdis [root@wanghongkai ~]# blkid /dev/sdb1 /dev/sdb1: LABEL="MYDATA" UUID="058d82fb-8dbe-4284-b588-4b5e2677bf75" TYPE="ext4" [root@wanghongkai ~]# tune2fs -o acl,fdis /dev/sdb1 tune2fs 1.41.12 (17-May-2010) Invalid mount option set: acl,fdis (2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; 先建立新的文件夹: [root@wanghongkai mydata]# pwd /data/mydata [root@wanghongkai ~]# mount -o noauto,noexec /dev/sdb1 /data/mydata/ 2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之; [root@wanghongkai ~]# mkswap /dev/sdb2 Setting up swapspace version 1, size = 1060284 KiB no label, UUID=9757cdbd-1fee-4822-b301-735e3271fbdf [root@wanghongkai ~]# blkid /dev/sdb2 /dev/sdb2: UUID="9757cdbd-1fee-4822-b301-735e3271fbdf" TYPE="swap" [root@wanghongkai ~]# swapon /dev/sdb2 3、写一个脚本 (1)、获取并列出当前系统上的所有磁盘设备; #!/bin/bash # i=`fdisk -l | egrep "^Disk /" | cut -d ',' -f1` echo "yong you $i " (2)、显示每个磁盘设备上每个分区相关的空间使用信息; [root@wanghongkai ~]# cat yingpan.sh #!/bin/bash YP1=`fdisk -l | egrep "^Disk /dev/(h|s)d[a-z]" | cut -d'/' -f3 | cut -d':' -f1 | head -n1` YP2=`fdisk -l | egrep "^Disk /dev/(h|s)d[a-z]" | cut -d'/' -f3 | cut -d':' -f1 | tail -n1` fdisk -l /dev/$YP1 fdisk -l /dev/$YP2 4、总结RAID的各个级别及其组合方式和性能的不同; RAID:独立荣耀磁盘阵列 提高IO能力:磁盘并行读写; 提高耐用性:磁盘冗余来实现 目的是:将多块磁盘组织在一起的工作方式; RAID0:读写性能提升,无容错能力,至少需要2块磁盘 RAID1:读性能提升,写性能降低,有冗余能力,至少需要2块磁盘; RAID4:至少需要三块磁盘;单块盘用于校验盘,出现问题性能下降; RAID5:读写性能提升,可用空间(N-1)*min(取决于最小空间大小),有冗余能力(1块磁盘);最少要有三块磁盘; RAID6:读写性能提升,可用空间(N-2)*min,有冗余能力(2块磁盘);最少要有四块磁盘; RAID-10:读、写性能提升,可用空间:N*min(S1,S2,...)/2;有容错能力:每组镜像最多只能坏一块;最少磁盘数:4, 4+; JBOD:Just a Bunch Of Disks 功能:将多块磁盘的空间合并一个大的连续空间使用; 可用空间:sum(S1,S2,...) 5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k; 1,fdisk分配磁盘空间 2,partx -a内核读取分区表 mdadm -C /dev/md0 -n 2 -c 128k -l 1 -x 1 -a yes /dev/sdb{1,2,3} 6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能; [root@wanghongkai dev]# mdadm -C /dev/md0 -a yes -l 5 -n 3 -x 1 -c 256 /dev/sdb{1,2,3,4} 7、写一个脚本 (1) 接受一个以上文件路径作为参数; (2) 显示每个文件拥有的行数; (3) 总结说明本次共为几个文件统计了其行数; [root@wanghongkai ~]# cat wenben.sh #!/bin/bash # if [ -z $1 ]; then echo "qing shu ru wen jian ming." elif [ $# -lt 2 ]; then echo "qing shu ru 2 ge wen jian lu jing." elif hanshu=`cat $@ | wc -l`; then echo "yi gong $# ge wen jian tong ji le yi gong $hanshu." fi 8、写一个脚本 (1) 传递两个以上字符串当作用户名; (2) 创建这些用户;且密码同用户名; ❤(3) 总结说明共创建了几个用户; [root@wanghongkai ~]# cat 1.sh #!/bin/bash # if [ -z $1 ]; then echo "qing shu ru you xiao zi fu ." elif id $1 &> /dev/null; then echo "yong hu yijingcunzai" elif useradd $1 &> /dev/null && echo "$1" | passwd --stdin $1 &> /dev/null; then echo "yong hu yi jing chuang jian." fi [root@wanghongkai ~]# cat 1.sh #!/bin/bash # if [ -z $1 ]; then echo "qing shu ru you xiao zi fu ." elif id $1 &> /dev/null; then echo "yong hu yijingcunzai" elif useradd $1 &> /dev/null && echo "$1" | passwd --stdin $1 &> /dev/null; then echo "yong hu yi jing chuang jian." echo "yi gong chuang jian le $# yong hu." fi # 9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和; [root@wanghongkai ~]# cat yonghu.sh #!/bin/bash # for i in {1..20}; do if id visitor$i > /dev/null; then echo "yong hu visitor$i yi jing cun zai." elif useradd visitor$i &> /dev/null && echo "visitor$i" | passwd --stdin visitor$i &> /dev/null; then echo "yong hu visitor$i yi jing chuang jian." fi done A=`cat /etc/passwd | egrep "^visitor" | wc -l` echo "yi gong chuang jian le $A ge yong hu." # for i in {1..20};do uid=`grep "\<visitor$i\>" /etc/passwd | cut -d: -f3` sumid=$[ $sumid + $uid ] done echo "ID sum:$sumid" 10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数; [root@wanghongkai ~]# cat hangshutongji.sh #!/bin/bash A=`egrep "^#" /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab | wc -l` echo "yi # kaitou de hang shu yi gong $A." B=`egrep "^$" /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab | wc -l` echo "kong bai hang yi gong $B." C=$[$A + $B] echo "yi gong you $C hang." 11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和; [root@wanghongkai ~]# cat 2.sh #!/bin/bash A=`egrep "\<bash\>$" /etc/passwd | cut -d: -f1,3` echo -e "mo ren wei bash jie wei\n$A" # for i in $(egrep "\<bash\>$" /etc/passwd | cut -d: -f3); do let sumuid+=$i done # echo "uid de zong he wei $sumuid ." 12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户; [root@wanghongkai bin]# cat group2.sh #!/bin/bash #ban ben 1.0 #time 2016.8.21-13.49 #zuo zhe wostop # while read line; do if [ -n $[`echo $line | cut -d':' -f4`] ]; then echo -e -n "username: `cat $line | cut -d':' -f4 | sort -r | uniq -c | head -n9`\t" echo "gid:`echo $line | cut -d: -f3 `" fi done < /etc/group 13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl; 1,使用磁盘fdisk中创建磁盘分区,并将磁盘类型更改成8e [root@wanghongkai ~]# pvcreate /dev/sdb1 /dev/sdb2 Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdb2" successfully created [root@wanghongkai ~]# pvdisplay "/dev/sdb1" is a new physical volume of "5.01 GiB" --- NEW Physical volume --- PV Name /dev/sdb1 VG Name PV Size 5.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID aF1V23-pou8-fzli-xkf1-AiBc-nm1M-FtHsuM "/dev/sdb2" is a new physical volume of "5.01 GiB" --- NEW Physical volume --- PV Name /dev/sdb2 VG Name PV Size 5.01 GiB Allocatable NO PE Size 0 Total PE 0 Free PE 0 Allocated PE 0 PV UUID SgPudz-z0xI-joDL-FJe5-n6MI-cD0y-M73Tu6 [root@wanghongkai ~]# vgcreate -s 8m vgdata /dev/sdb1 /dev/sdb2 [root@wanghongkai ~]# vgdisplay --- Volume group --- VG Name vgdata 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 10.02 GiB PE Size 8.00 MiB Total PE 1282 Alloc PE / Size 0 / 0 Free PE / Size 1282 / 10.02 GiB VG UUID 78w7zD-vmRI-1PlH-vfuN-mlPW-8kj6-g96FfD [root@wanghongkai ~]# lvcreate -n mylv -L 5G vgdata [root@wanghongkai ~]# lvdisplay --- Logical volume --- LV Path /dev/vgdata/mylv LV Name mylv VG Name vgdata LV UUID 3qlBWR-mRRZ-LnsH-zguC-L6bE-GOHX-veFZOA LV Write Access read/write LV Creation host, time wanghongkai, 2016-08-09 07:23:51 -0400 LV Status available # open 0 LV Size 5.00 GiB Current LE 640 Segments 1 Allocation inherit Read ahead sectors auto - currently set to 256 Block device 253:0 [root@wanghongkai ~]# mkfs.ext4 /dev/vgdata/mylv 进入到/etc/fstab文件下编辑此文本内容; proc /proc proc defaults 0 0 UUID=ee5ad1f3-5f95-4642-91cb-1e9bf91b81eb /users ext4 defaults,acl 0 0 14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录; [root@wanghongkai /]# useradd magedu -d /users/magedu [magedu@wanghongkai /]$ cp /etc/passwd /etc/fstab /etc/issue /users/magedu/ [root@wanghongkai /]# cd /users/magedu/ [root@wanghongkai magedu]# ls fstab issue passwd 15、扩展mylv1至9G,确保扩展完成后原有数据完全可用; [root@wanghongkai magedu]# lvextend -L +4G /dev/vgdata/mylv Size of logical volume vgdata/mylv changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv successfully resized. [root@wanghongkai magedu]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda2 20G 4.7G 14G 26% / tmpfs 499M 80K 499M 1% /dev/shm /dev/sda1 477M 54M 398M 12% /boot /dev/sda3 9.8G 26M 9.2G 1% /home /dev/sr0 4.1G 4.1G 0 100% /media/CentOS_6.4_Final /dev/mapper/vgdata-mylv 8.8G 12M 8.3G 1% /users [root@wanghongkai magedu]# ll /users/magedu/ total 8 -rw-r--r--. 1 magedu magedu 971 Aug 9 08:10 fstab -rw-r--r--. 1 magedu magedu 47 Aug 9 08:10 issue 16、缩减mylv1至7G,确保缩减完成后原有数据完全可用; (取消挂载,强制检查、缩减文件系统、缩减lv、重新挂载) root@wanghongkai ~]# e2fsck -f /dev/vgdata/mylv e2fsck 1.41.12 (17-May-2010) Pass 1: Checking inodes, blocks, and sizes Pass 2: Checking directory structure Pass 3: Checking directory connectivity Pass 4: Checking reference counts Pass 5: Checking group summary information /dev/vgdata/mylv: 22/589824 files (0.0% non-contiguous), 72682/2359296 blocks [root@wanghongkai ~]# resize2fs /dev/vgdata/mylv 7G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/vgdata/mylv to 1835008 (4k) blocks. The filesystem on /dev/vgdata/mylv is now 1835008 blocks long. [root@wanghongkai ~]# lvreduce -L 7G /dev/vgdata/mylv WARNING: Reducing active logical volume to 7.00 GiB. THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce vgdata/mylv? [y/n]: y Size of logical volume vgdata/mylv changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv successfully resized. 17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息; [root@wanghongkai ~]# lvcreate -s -L 1G -n mylv-snap -p r /dev/vgdata/mylv Logical volume "mylv-snap" created. [root@wanghongkai ~]# mount /dev/vgdata/mylv-snap /mnt mount: block device /dev/mapper/vgdata-mylv--snap is write-protected, mounting read-only
原创文章,作者:wostop,如若转载,请注明出处:http://www.178linux.com/38322
评论列表(1条)
写的很好,排版也很棒,加油,不要用拼音了