1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
[root@centos7study ~]# fdisk /dev/sdc Welcome to fdisk (util-linux 2.23.2). Changes will remain in memory only, until you decide to write them. Be careful before using the write command. Device does not contain a recognized partition table Building a new DOS disklabel with disk identifier 0xe879321a. Command (m for help): n Partition type: p primary (0 primary, 0 extended, 4 free) e extended Select (default p): Using default response p Partition number (1-4, default 1): First sector (2048-41943039, default 2048): Using default value 2048 Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G Partition 1 of type Linux and of size 10 GiB is set Command (m for help): w The partition table has been altered! Calling ioctl() to re-read partition table. Syncing disks. [root@centos7study ~]# cat /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 512000 sda1 8 2 10488832 sda2 8 3 4194304 sda3 8 16 5242880 sdb 8 17 1048576 sdb1 8 18 1048576 sdb2 8 19 1048576 sdb3 8 32 20971520 sdc 8 33 10485760 sdc1 11 0 617472 sr0 253 0 8388608 dm-0 253 1 2097152 dm-1 253 2 307200 dm-2 [root@centos7study ~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdc1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label=MYDATA OS type: Linux Block size=2048 (log=1) Fragment size=2048 (log=1) Stride=0 blocks, Stripe width=0 blocks 655360 inodes, 5242880 blocks 104857 blocks (2.00%) reserved for the super user First data block=0 Maximum filesystem blocks=273678336 320 block groups 16384 blocks per group, 16384 fragments per group 2048 inodes per group Superblock backups stored on blocks: 16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104, 2048000, 3981312 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@centos7study ~]# mkdir -pv /data/mydata mkdir: created directory ‘/data’ mkdir: created directory ‘/data/mydata’ [root@centos7study ~]# echo '/dev/sdc1 /data/mydata ext4 defaults,noexec,nodiratime,acl 0 0' >> /etc/fstab [root@centos7study ~]# mount -a [root@centos7study ~]# mount | grep /dev/sdc1 /dev/sdc1 on /data/mydata type ext4 (rw,noexec,nodiratime,relatime,seclabel,data=ordered)
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@centos7study ~]# fdisk /dev/sdc Command (m for help): n Partition type: p primary (1 primary, 0 extended, 3 free) e extended Select (default p): Using default response p Partition number (2-4, default 2): First sector (20973568-41943039, default 20973568): +1G Value out of range. First sector (20973568-41943039, default 20973568): Using default value 20973568 Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G Partition 2 of type Linux and of size 1 GiB is set Command (m for help): t Partition number (1,2, default 2): 2 Hex code (type L to list all codes): 82 Changed type of partition 'Linux' to '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@centos7study ~]# partx -a /dev/sdc partx: /dev/sdc: error adding partition 1 [root@centos7study ~]# !cat cat /proc/partitions major minor #blocks name 8 0 20971520 sda 8 1 512000 sda1 8 2 10488832 sda2 8 3 4194304 sda3 8 16 5242880 sdb 8 17 1048576 sdb1 8 18 1048576 sdb2 8 19 1048576 sdb3 8 32 20971520 sdc 8 33 10485760 sdc1 8 34 1048576 sdc2 11 0 617472 sr0 253 0 8388608 dm-0 253 1 2097152 dm-1 253 2 307200 dm-2 [root@centos7study ~]# mkswap /dev/sdc2 Setting up swapspace version 1, size = 1048572 KiB no label, UUID=0340f886-5d37-4c99-bb32-bd3cef571c02 [root@centos7study ~]# swapon -a /dev/sdc2 [root@centos7study ~]# swapon -s Filename Type Size Used Priority /dev/dm-1 partition 2097148 0 -1 /dev/sdc2 partition 1048572 0 -2
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
[root@centos7study tmp]# cat fdisklist.sh #!/bin/bash echo -e "All of disk:\n`fdisk -l | grep -o "[sh]d[a-z]" | uniq `\n" echo "The Disk information:" for i in `fdisk -l | grep "^/dev/[sh]d[a-z][1-9]" | cut -d' ' -f1`; do df -h $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 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@centos7study ~]# fdisk -l /dev/sdd Disk /dev/sdd: 10.7 GB, 10737418240 bytes, 20971520 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0x645d84fd Device Boot Start End Blocks Id System /dev/sdd1 2048 4196351 2097152 83 Linux /dev/sdd2 4196352 8390655 2097152 83 Linux /dev/sdd3 8390656 12584959 2097152 83 Linux [root@centos7study ~]# mdadm -C /dev/md0 -n 2 -l 1 -a yes -c 128 -x 1 /dev/{sdd1,sdd2,sdd3} mdadm: Note: this array has metadata at the start and may not be suitable as a boot device. If you plan to store '/boot' on this device please ensure that your boot-loader understands md/v1.x metadata, or use --metadata=0.90 Continue creating array? Continue creating array? (y/n) y mdadm: Defaulting to version 1.2 metadata mdadm: array /dev/md0 started. [root@centos7study ~]# mdadm -D /dev/md0 /dev/md0: Version : 1.2 Creation Time : Mon Aug 22 21:44:43 2016 Raid Level : raid1 Array Size : 2095104 (2046.34 MiB 2145.39 MB) Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB) Raid Devices : 2 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Aug 22 21:44:54 2016 State : clean Active Devices : 2 Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Name : centos7study:0 (local to host centos7study) UUID : aeda4ef4:d7aaac0b:b062855f:81bfab77 Events : 17 Number Major Minor RaidDevice State 0 8 49 0 active sync /dev/sdd1 1 8 50 1 active sync /dev/sdd2 2 8 51 - spare /dev/sdd3
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
[root@centos7study ~]# mdadm -C /dev/md1 -n 3 -l 5 -a yes -c 256 /dev/{sdd1,sdd2,sdd3} [root@centos7study ~]# mdadm -D /dev/md1 /dev/md1: Version : 1.2 Creation Time : Mon Aug 22 21:51:51 2016 Raid Level : raid5 Array Size : 4190208 (4.00 GiB 4.29 GB) Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB) Raid Devices : 3 Total Devices : 3 Persistence : Superblock is persistent Update Time : Mon Aug 22 21:52:04 2016 State : clean Active Devices : 3 Working Devices : 3 Failed Devices : 0 Spare Devices : 0 Layout : left-symmetric Chunk Size : 256K Name : centos7study:1 (local to host centos7study) UUID : efffa3b7:b5728600:73535e40:c313a55c Events : 18 Number Major Minor RaidDevice State 0 8 49 0 active sync /dev/sdd1 1 8 50 1 active sync /dev/sdd2 3 8 51 2 active sync /dev/sdd3 [root@centos7study ~]# cat /proc/mdstat Personalities : [raid1] [raid6] [raid5] [raid4] md1 : active raid5 sdd3[3] sdd2[1] sdd1[0] 4190208 blocks super 1.2 level 5, 256k chunk, algorithm 2 [3/3] [UUU] unused devices: <none> [root@centos7study ~]# mkdir /backup [root@centos7study ~]# mke2fs -t ext4 /dev/md1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=64 blocks, Stripe width=128 blocks 262144 inodes, 1047552 blocks 52377 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1073741824 32 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (16384 blocks): done Writing superblocks and filesystem accounting information: done [root@centos7study ~]# echo '/dev/md1 /backup ext4 defaults,noatime,acl 0 0' >> /etc/fstab [root@centos7study ~]# mount -a [root@centos7study ~]# mount | grep /dev/md1 /dev/md1 on /backup type ext4 (rw,noatime,seclabel,stripe=128,data=ordered)
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
[root@centos7study tmp]# cat sumlines.sh #!/bin/bash if [ $# -eq 0 ];then echo "Please give a file name at least!" exit 1 fi for i in $* do echo "$i have $(wc -l $i | cut -d' ' -f1) lines" done echo "SUM $# FILES LINES!"
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
[root@centos7study tmp]# cat createuser.sh #!/bin/bash if [ $# -lt 2 ];then echo "Please give 2 usernames at least !" exit 1 fi for i in $*;do useradd $i echo "$i:$i" | chpasswd done echo "Total Add $# users !"
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
[root@centos7study tmp]# cat sumuid.sh #!/bin/bash declare -i sumuid for i in {1..20} do useradd visitor$i let sumuid+=$(id -u visitor$i) done echo "Total id is $sumuid !"
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
[root@centos7study tmp]# cat sumlines2.sh #!/bin/bash declare -i line declare -i nullline for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/fstab} do let line+=$(grep '^#' $i | wc -l | cut -d' ' -f1) let nullline+=$(grep '^[[:space:]]*$' $i | wc -l | cut -d' ' -f1) done echo "The lines with a beginning of '#' is $line lines !" echo "The lines with nothing is $nullline lines !"
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
[root@centos7study tmp]# cat sumuid2.sh #!/bin/bash declare -i sum_uid grep "/bin/bash" /etc/passwd | cut -d':' -f 1,3 for i in `grep "/bin/bash" /etc/passwd | cut -d':' -f 3`;do let sum_uid+=i done echo "The uid sum is $sum_uid !"
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;
[root@centos7study tmp]# cat sumuid2.sh #!/bin/bash declare -i sum_user for i in `cut -d: -f1 /etc/passwd`; do group=`id $i | awk -F, '{print $2}' ` if [ -n "$group" ];then echo "$i" let sum_user+=1 fi done echo "sum_user is $sum_user !"
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
[root@centos7study data]# fdisk -l /dev/sdc Disk /dev/sdc: 21.5 GB, 21474836480 bytes, 41943040 sectors Units = sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I/O size (minimum/optimal): 512 bytes / 512 bytes Disk label type: dos Disk identifier: 0xe879321a Device Boot Start End Blocks Id System /dev/sdc1 2048 16779263 8388608 8e Linux LVM /dev/sdc2 16779264 33556479 8388608 8e Linux LVM [root@centos7study data]# pvcreate /dev/sdc{1,2} WARNING: ext4 signature detected on /dev/sdc1 at offset 1080. Wipe it? [y/n]: y Wiping ext4 signature on /dev/sdc1. Physical volume "/dev/sdc1" successfully created Physical volume "/dev/sdc2" successfully created [root@centos7study data]# pvs PV VG Fmt Attr PSize PFree /dev/sda2 centos_centos7study lvm2 a-- 10.00g 0 /dev/sdc1 lvm2 --- 8.00g 8.00g /dev/sdc2 lvm2 --- 8.00g 8.00g [root@centos7study data]# vgcreate -s 8M myvg1 /dev/sdc1 /dev/sdc2 Volume group "myvg1" successfully created [root@centos7study data]# vgdisplay -v myvg1 Using volume group(s) on command line. --- Volume group --- VG Name myvg1 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 15.98 GiB PE Size 8.00 MiB Total PE 2046 Alloc PE / Size 0 / 0 Free PE / Size 2046 / 15.98 GiB VG UUID AWmd0l-iTIY-pv1z-lSGP-8mPB-QmcA-e7vdLI --- Physical volumes --- PV Name /dev/sdc1 PV UUID 0unhfN-c18W-TSnm-BTSp-5cFJ-aFdO-k2hfL3 PV Status allocatable Total PE / Free PE 1023 / 1023 PV Name /dev/sdc2 PV UUID 9z9ZOJ-ysmD-JTbH-VrCy-9LOB-aOV6-NSKcLH PV Status allocatable Total PE / Free PE 1023 / 1023 [root@centos7study data]# lvcreate -L 5G -n mylv1 myvg1 Logical volume "mylv1" created. [root@centos7study data]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos_centos7study -wi-ao---- 8.00g swap centos_centos7study -wi-ao---- 2.00g mylv1 myvg1 -wi-a----- 5.00g [root@centos7study data]# mke2fs -t ext4 /dev/myvg1/mylv1 mke2fs 1.42.9 (28-Dec-2013) Filesystem label= OS type: Linux Block size=4096 (log=2) Fragment size=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user First data block=0 Maximum filesystem blocks=1342177280 40 block groups 32768 blocks per group, 32768 fragments per group 8192 inodes per group Superblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736 Allocating group tables: done Writing inode tables: done Creating journal (32768 blocks): done Writing superblocks and filesystem accounting information: done [root@centos7study data]# mkdir /users [root@centos7study data]# cat /etc/fstab /dev/myvg1/mylv1 /users ext4 defaults,acl 0 0 [root@centos7study data]# mount -a
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
[root@centos7study ~]# useradd -d /users/magedu magedu [root@centos7study ~]# su magedu [magedu@centos7study root]$ cp /etc/fstab /users/magedu [magedu@centos7study root]$ cp -r /tmp/mytest1 /users/magedu [magedu@centos7study root]$ cp -r /tmp/mylinux/ /users/magedu
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
[root@centos7study ~]# lvextend -L +4g /dev/myvg1/mylv1 /dev/sdc{1,2} Size of logical volume myvg1/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized. [root@centos7study ~]# lvs LV VG Attr LSize Pool Origin Data% Meta% Move Log Cpy%Sync Convert root centos_centos7study -wi-ao---- 8.00g swap centos_centos7study -wi-ao---- 2.00g mylv1 myvg1 -wi-ao---- 9.00g [root@centos7study ~]# resize2fs /dev/myvg1/mylv1 resize2fs 1.42.9 (28-Dec-2013) Filesystem at /dev/myvg1/mylv1 is mounted on /users; on-line resizing required old_desc_blocks = 1, new_desc_blocks = 2 The filesystem on /dev/myvg1/mylv1 is now 2359296 blocks long. [root@centos7study ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/mapper/centos_centos7study-root 8.0G 1.9G 6.2G 24% / devtmpfs 479M 0 479M 0% /dev tmpfs 489M 0 489M 0% /dev/shm tmpfs 489M 6.8M 483M 2% /run tmpfs 489M 0 489M 0% /sys/fs/cgroup /dev/mapper/myvg1-mylv1 8.8G 25M 8.3G 1% /users /dev/sda1 497M 123M 375M 25% /boot tmpfs 98M 0 98M 0% /run/user/0 [root@centos7study ~]# ls /users/magedu/ fstab mylinux mytest1 sysconfig [root@centos7study ~]# su magedu [magedu@centos7study root]$ cd ~ [magedu@centos7study ~]$ pwd /users/magedu
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
[root@centos7study ~]# umount /dev/myvg1/mylv1 [root@centos7study ~]# e2fsck -f /dev/myvg1/mylv1 e2fsck 1.42.9 (28-Dec-2013) 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/myvg1/mylv1: 30/589824 files (0.0% non-contiguous), 75874/2359296 blocks [root@centos7study ~]# lvreduce -L -2g /dev/myvg1/mylv1 WARNING: Reducing active logical volume to 7.00 GiB THIS MAY DESTROY YOUR DATA (filesystem etc.) Do you really want to reduce mylv1? [y/n]: y Size of logical volume myvg/mylv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents). Logical volume mylv1 successfully resized [root@centos7study ~]# resize2fs /dev/myvg1/mylv1 [root@centos7study ~]# mount -a [root@centos7study ~]# su magedu [magedu@centos7study root]$ cd ~ [magedu@centos7study ~]$ pwd /users/magedu
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
[root@centos7study ~]# lvcreate -L 3g -p r -s -n mylv_snapshot /dev/myvg1/mylv1 Logical volume "mylv_snapshot" created.
原创文章,作者:N21-孟然,如若转载,请注明出处:http://www.178linux.com/38621
评论列表(1条)
非常的棒,给出了操作详细的过程,能把相关的知识在总结一下就更好哈,^_^