1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
答:
[root@mageeduCentos7 ~]# fdisk /dev/sdb
欢迎使用 fdisk (util-linux 2.23.2)。
更改将停留在内存中,直到您决定将更改写入磁盘。
使用写入命令前请三思。
Device does not contain a recognized partition table
使用磁盘标识符 0xf2e3118b 创建新的 DOS 磁盘标签。
命令(输入 m 获取帮助):n #新建分区
Partition type:
p primary (0 primary, 0 extended, 4 free)
e extended
Select (default p): p
分区号 (1-4,默认 1):
起始 扇区 (2048-41943039,默认为 2048):
将使用默认值 2048
Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+10G
分区 1 已设置为 Linux 类型,大小设为 10 GiB
命令(输入 m 获取帮助):p
磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区
Units = 扇区 of 1 * 512 = 512 bytes
扇区大小(逻辑/物理):512 字节 / 512 字节
I/O 大小(最小/最佳):512 字节 / 512 字节
磁盘标签类型:dos
磁盘标识符:0xf2e3118b
设备 Boot Start End Blocks Id System
/dev/sdb1 2048 20973567 10485760 83 Linux
命令(输入 m 获取帮助):w
The partition table has been altered!
Calling ioctl() to re-read partition table.
正在同步磁盘。
[root@mageeduCentos7 ~]# lsblk #查看分区是已写入
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sda 8:0 0 120G 0 disk
├─sda1 8:1 0 500M 0 part /boot
└─sda2 8:2 0 119.5G 0 part
├─centos-root 253:0 0 50G 0 lvm /
├─centos-swap 253:1 0 2G 0 lvm [SWAP]
└─centos-home 253:2 0 67.5G 0 lvm /home
sdb 8:16 0 20G 0 disk
└─sdb1 8:17 0 10G 0 part #刚才新建的10G的分区
sr0 11:0 1 7.2G 0 rom
[root@mageeduCentos7 ~]# mke2fs -t ext4 -b 2048 -m 2 -L "MYDATA" /dev/sdb1 #将分区格式化为ext4格式,指明大小,预留百分比及卷标
mke2fs 1.42.9 (28-Dec-2013)
文件系统标签=MYDATA
OS type: Linux
块大小=2048 (log=1)
分块大小=2048 (log=1)
Stride=0 blocks, Stripe width=0 blocks
655360 inodes, 5242880 blocks
104857 blocks (2.00%) reserved for the super user
第一个数据块=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: 完成
正在写入inode表: 完成
Creating journal (32768 blocks): 完成
Writing superblocks and filesystem accounting information: 完成
[root@mageeduCentos7 ~]# tune2fs -o acl /dev/sdb1 #设置默认挂在属性
tune2fs 1.42.9 (28-Dec-2013)
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
答:
[root@mageeduCentos7 /]# mkdir -p /data/mydata #创建需要挂载的目录[root@mageeduCentos7 /]# mount -o noexec,nodiratime /dev/sdb1 /data/mydata/ ####挂载/dev/sdb1到/data/mydata目录下,noexec表示禁止程序自动运行,nodiratime不更新文件的访问时间戳[root@mageeduCentos7 /]# mount #使用mount命令查看挂载后的结果...../dev/sdb1 on /data/mydata type ext4 (rw,noexec,nodiratime,relatime,seclabel,data=ordered)
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
答:
[root@mageeduCentos7 /]# fdisk /dev/sdb欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。使用写入命令前请三思。命令(输入 m 获取帮助):nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): p分区号 (2-4,默认 2):起始 扇区 (20973568-41943039,默认为 20973568):将使用默认值 20973568Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):+1G分区 2 已设置为 Linux 类型,大小设为 1 GiB命令(输入 m 获取帮助):t #改变分区的系统id分区号 (1,2,默认 2):2Hex 代码(输入 L 列出所有代码):82 #82代表swap分区类型已将分区“Linux”的类型更改为“Linux swap / Solaris”命令(输入 m 获取帮助):wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)正在同步磁盘。[root@mageeduCentos7 /]# lsblk #这时候查看分区并没有看到我们新添加的1G的swap分区NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 120G 0 disk├─sda1 8:1 0 500M 0 part /boot└─sda2 8:2 0 119.5G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 2G 0 lvm [SWAP] └─centos-home 253:2 0 67.5G 0 lvm /homesdb 8:16 0 20G 0 disk└─sdb1 8:17 0 10G 0 part /data/mydatasr0 11:0 1 7.2G 0 rom[root@mageeduCentos7 /]# partparted partprobe partx[root@mageeduCentos7 /]# partparted partprobe partx[root@mageeduCentos7 /]# partx -a /dev/sdb #重新读取磁盘分区表partx: /dev/sdb: error adding partition 1[root@mageeduCentos7 /]# partx -a /dev/sdb partx: /dev/sdb: error adding partitions 1-2[root@mageeduCentos7 /]# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 120G 0 disk├─sda1 8:1 0 500M 0 part /boot└─sda2 8:2 0 119.5G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 2G 0 lvm [SWAP] └─centos-home 253:2 0 67.5G 0 lvm /homesdb 8:16 0 20G 0 disk├─sdb1 8:17 0 10G 0 part /data/mydata└─sdb2 8:18 0 1G 0 part #再次查看可以看到sr0 11:0 1 7.2G 0 rom[root@mageeduCentos7 /]# fdisk -l /dev/sdb磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:dos磁盘标识符:0xf2e3118b 设备 Boot Start End Blocks Id System/dev/sdb1 2048 20973567 10485760 83 Linux/dev/sdb2 20973568 23070719 1048576 82 Linux swap / Solaris #可以看到sdb2就是swap类型的分区[root@mageeduCentos7 /]# mkswap /dev/sdb2 #创建swap文件系统正在设置交换空间版本 1,大小 = 1048572 KiB无标签,UUID=29f135ba-4ac1-42aa-a978-2bc04c587a65[root@mageeduCentos7 /]# swapon /dev/sdb2 #启用swap
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息
答:
[root@mageeduCentos7 bin]# vim disktest.sh#!/bin/bashecho "All of disk as follows:"fdisk -l | grep "^磁盘[[:space:]]/dev/[sh]d[a-z]" | cut -d' ' -f2 | cut -d: -f1 ##这里记得正则表达式中^的含义哦,在[^]表示意思相反,在^[]表示定位在行首.我的系统装的是中文版的,所以这里用了中文的"磁盘",如果是英文版的要用"Disk";这一行显示的是系统中每块硬盘的大小echo '' #这里加个空白行,为了更加清晰的显示,我看很多脚本都这么写的echo "All of partitions as follows:" #每块硬盘分区的详细信息for i in $(fdisk -l | grep "^/dev/[sh]d[a-z][1-9][0-9]\{0,\}" | cut -d' ' -f1);do #cut命令很强大,都是我查资料弄的 echo "$i partition's information:" df -h $idone##脚本执行结果:[root@mageeduCentos7 bin]# bash disktest.shAll of disk as follows:/dev/sdb:53.7/dev/sda:128.8All of partitions as follows:/dev/sdb1 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev/dev/sdb2 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev/dev/sdb3 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev/dev/sdb4 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev/dev/sdb5 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev/dev/sdb6 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev/dev/sdb7 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev/dev/sdb8 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev/dev/sda1 partition's information:文件系统 容量 已用 可用 已用% 挂载点/dev/sda1 497M 125M 373M 26% /boot/dev/sda2 partition's information:文件系统 容量 已用 可用 已用% 挂载点devtmpfs 479M 0 479M 0% /dev[root@mageeduCentos7 bin]#
4、总结RAID的各个级别及其组合方式和性能的不同
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;
答:
[root@mageeduCentos7 ~]# fdisk /dev/sdb #建立连个10G的raid盘欢迎使用 fdisk (util-linux 2.23.2)。更改将停留在内存中,直到您决定将更改写入磁盘。使用写入命令前请三思。命令(输入 m 获取帮助):nPartition type: p primary (0 primary, 0 extended, 4 free) e extendedSelect (default p): p分区号 (1-4,默认 1):1起始 扇区 (2048-41943039,默认为 2048):将使用默认值 2048Last 扇区, +扇区 or +size{K,M,G} (2048-41943039,默认为 41943039):+10G分区 1 已设置为 Linux 类型,大小设为 10 GiB命令(输入 m 获取帮助):nPartition type: p primary (1 primary, 0 extended, 3 free) e extendedSelect (default p): p分区号 (2-4,默认 2):起始 扇区 (20973568-41943039,默认为 20973568):将使用默认值 20973568Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):+10G值超出范围。Last 扇区, +扇区 or +size{K,M,G} (20973568-41943039,默认为 41943039):将使用默认值 41943039分区 2 已设置为 Linux 类型,大小设为 10 GiB命令(输入 m 获取帮助):t分区号 (1,2,默认 2):1Hex 代码(输入 L 列出所有代码):fd已将分区“Linux”的类型更改为“Linux raid autodetect”命令(输入 m 获取帮助):t分区号 (1,2,默认 2):2Hex 代码(输入 L 列出所有代码):fd已将分区“Linux”的类型更改为“Linux raid autodetect”命令(输入 m 获取帮助):p磁盘 /dev/sdb:21.5 GB, 21474836480 字节,41943040 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:dos磁盘标识符:0xf2e3118b 设备 Boot Start End Blocks Id System/dev/sdb1 2048 20973567 10485760 fd Linux raid autodetect/dev/sdb2 20973568 41943039 10484736 fd Linux raid autodetect命令(输入 m 获取帮助):wThe partition table has been altered!Calling ioctl() to re-read partition table.WARNING: Re-reading the partition table failed with error 16: 设备或资源忙.The kernel still uses the old table. The new table will be used atthe next reboot or after you run partprobe(8) or kpartx(8)正在同步磁盘。[root@mageeduCentos7 ~]# partprobe /dev/sdb #重新读取分区[root@mageeduCentos7 ~]# lsblkNAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 120G 0 disk├─sda1 8:1 0 500M 0 part /boot└─sda2 8:2 0 119.5G 0 part ├─centos-root 253:0 0 50G 0 lvm / ├─centos-swap 253:1 0 2G 0 lvm [SWAP] └─centos-home 253:2 0 67.5G 0 lvm /homesdb 8:16 0 50G 0 disk├─sdb1 8:17 0 10G 0 part├─sdb2 8:18 0 10G 0 part└─sdb3 8:19 0 10G 0 part #注意我这里在分区的时候少分了一个空闲盘,所以sdb3是后来分的前面没有写出来sr0 11:0 1 7.2G 0 rom[root@mageeduCentos7 ~]# mdadm -C /dev/md0 -a yes -n 2 -x 1 -l 1 -c 128 /dev/sdb{1,2,3}mdadm: /dev/sdb1 appears to contain an ext2fs file system size=10485760K mtime=Tue Sep 20 15:07:55 2016mdadm: 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.90Continue creating array? ymdadm: Defaulting to version 1.2 metadatamdadm: array /dev/md0 started.## 说明一下 -C:建立RAID的选项; -a(yes|no):是否自动创建目标rai设备的设备文件; -n:使用多少个硬盘来创建此raid; -x:指明空闲盘的个数; -l:指明raid的级别; -c: 指明CHUNK大小[root@mageeduCentos7 ~]# mdadm --detail /dev/md0 #查看md0的详细信息/dev/md0: #RAID名 Version : 1.2 Creation Time : Tue Sep 20 18:32:41 2016 #建立RAID的时间 Raid Level : raid1 #RAID的等级 Array Size : 10476544 (9.99 GiB 10.73 GB) #整个RAID的可用容量 Used Dev Size : 10476544 (9.99 GiB 10.73 GB) #每个硬盘的容量 Raid Devices : 2 #组成RAID的硬盘数量 Total Devices : 3 #包括空闲硬盘的硬盘数量 Persistence : Superblock is persistent Update Time : Tue Sep 20 18:33:33 2016 State : clean Active Devices : 2Working Devices : 3 Failed Devices : 0 Spare Devices : 1 Name : mageeduCentos7.2:0 (local to host mageeduCentos7.2) UUID : cdf346ca:c8575fed:9c904829:d5bbb927 Events : 17 Number Major Minor RaidDevice State 0 8 17 0 active sync /dev/sdb1 1 8 18 1 active sync /dev/sdb2 2 8 19 - spare /dev/sdb3[root@mageeduCentos7 ~]#
6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;
答:
[root@mageeduCentos7 ~]# mdadm -C /dev/md1 -a yes -n3 -l 5 -c 256 -x 1 /dev/sdb{5,6,7,8}mdadm: Defaulting to version 1.2 metadatamdadm: array /dev/md1 started.[root@mageeduCentos7 ~]# mdadm -D /dev/md1/dev/md1: Version : 1.2 Creation Time : Tue Sep 20 19:28:04 2016 Raid Level : raid5 Array Size : 8380416 (7.99 GiB 8.58 GB) Used Dev Size : 4190208 (4.00 GiB 4.29 GB) Raid Devices : 3 Total Devices : 4 Persistence : Superblock is persistent Update Time : Tue Sep 20 19:28:25 2016 State : clean Active Devices : 3Working Devices : 4 Failed Devices : 0 Spare Devices : 1 Layout : left-symmetric Chunk Size : 256K Name : mageeduCentos7.2:1 (local to host mageeduCentos7.2) UUID : efd19c25:ec5bf8e9:f4d1ee13:55a282fb Events : 18 Number Major Minor RaidDevice State 0 8 21 0 active sync /dev/sdb5 1 8 22 1 active sync /dev/sdb6 4 8 23 2 active sync /dev/sdb7 3 8 24 - spare /dev/sdb8[root@mageeduCentos7 ~]# mke2fs -t ext4 /dev/md1 ##格式化为ext4文件类型mke2fs 1.42.9 (28-Dec-2013)文件系统标签=OS type: Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=64 blocks, Stripe width=128 blocks524288 inodes, 2095104 blocks104755 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=214538649664 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632Allocating group tables: 完成正在写入inode表: 完成Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information: 完成[root@mageeduCentos7 ~]# tune2fs -o acl /dev/md1 ## 设置acl属性tune2fs 1.42.9 (28-Dec-2013)[root@mageeduCentos7 ~]# blkid /dev/md1 ##查看md1的uuid号,写入/etc/fstab中/dev/md1: UUID="d64ecac9-5c32-4f1a-9f8d-be229c1aa4c1" TYPE="ext4"[root@mageeduCentos7 ~]# vim /etc/fstab## /etc/fstab# Created by anaconda on Wed Aug 10 14:44:03 2016## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#/dev/mapper/centos-root / xfs defaults 0 0UUID=e93341c0-4e34-47df-8110-f52f1346e118 /boot xfs defaults 0 0#UUID=6c500166-5b1d-40f3-84fc-2957f6828a99 /srv/raid xfs defaults 0 0/dev/mapper/centos-home /home xfs defaults,usrquota,prjquota 0 0/dev/mapper/centos-swap swap swap defaults 0 0UUID=d64ecac9-5c32-4f1a-9f8d-be229c1aa4c1 /data/mydata ext4 defaults,acl,nodiratime 0 0
7、写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了其行数;
答:
[root@mageeduCentos7 bin]# vim mg7z7t.sh#!/bin/bashnum=0line=0if [ $# -eq 0 ];then echo "please input filename"fifor i in $*;do line=$(wc -l $i | cut -d' ' -f1) let num=$num+1 echo "file $i lines is $line"doneecho files num is $num[root@mageeduCentos7 bin]# bash mg7z7t.sh /etc/fstab /etc/sysconfig/network-scripts/ifcfg-eno16777736file /etc/fstab lines is 14file /etc/sysconfig/network-scripts/ifcfg-eno16777736 lines is 18files num is 2
8、写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户;且密码同用户名;
(3) 总结说明共创建了几个用户;
答:
[root@mageeduCentos7 bin]# vim mg7z8t.sh#!/bin/bashcount=0if [ $# -ge 2 ];then for i in $@;do if id $i &> /dev/null;then echo "$i exists,please try another name." else useradd $i &> /dev/null && echo "$i" | passwd --stdin $i &> /dev/null let count++ echo "$i is added" fi doneelse echo "At lease need two agrument!" exit 1fiecho "added $count users"[root@mageeduCentos7 bin]# bash mg7z8t.sh mgjy1 mgjy2mgjy1 is addedmgjy2 is addedadded 2 users[root@mageeduCentos7 bin]# tail -n 2 /etc/passwdmgjy1:x:1005:1005::/home/mgjy1:/bin/bashmgjy2:x:1006:1006::/home/mgjy2:/bin/bash
9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;
答:
[root@mageeduCentos7 bin]# vim mg7z9t.sh#!/bin/bashfor i in {1..20};do useradd visitor$i echo "visitor$i is added" value=$(cat /etc/passwd | grep "^visitor$i" | cut -d: -f3) sum=$(($sum+$value))doneecho "All the ID is $sum"[root@mageeduCentos7 bin]# bash mg7z9t.shvisitor1 is addedvisitor2 is addedvisitor3 is addedvisitor4 is addedvisitor5 is addedvisitor6 is addedvisitor7 is addedvisitor8 is addedvisitor9 is addedvisitor10 is addedvisitor11 is addedvisitor12 is addedvisitor13 is addedvisitor14 is addedvisitor15 is addedvisitor16 is addedvisitor17 is addedvisitor18 is addedvisitor19 is addedvisitor20 is addedAll the ID is 20330[root@mageeduCentos7 bin]# tail -n 20 /etc/passwd | cut -d: -f1,3 #之和对不对,自己算啊哈哈哈visitor1:1007visitor2:1008visitor3:1009visitor4:1010visitor5:1011visitor6:1012visitor7:1013visitor8:1014visitor9:1015visitor10:1016visitor11:1017visitor12:1018visitor13:1019visitor14:1020visitor15:1021visitor16:1022visitor17:1023visitor18:1024visitor19:1025visitor20:1026
10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;
答:
[root@megeeducentos6 bin]# vim mg7z10t.sh#!/bin/bashfor i in $@;do if [ -f $i ];then line=$(grep '^#' $i | wc -l) echo "$i begin with #'s line:$line" spaceLine=$(grep '^$' $i | wc -l) spaceSum=$(($spaceSum+$spaceLine)) else echo "You should input a file." exit 1 fidoneecho "spaceLine:$spaceSum"[root@megeeducentos6 bin]# bash mg7z10t.sh /etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab/etc/rc.d/rc.sysinit begin with #'s line:44/etc/rc.d/init.d/functions begin with #'s line:43/etc/fstab begin with #'s line:7spaceLine:206
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;
答:
[root@mageeduCentos7 bin]# vim mg7z11t.sh#!/bin/bashfor i in $(grep '/bin/bash$' /etc/passwd);do userName=$(echo $i | cut -d: -f1) userUid=$(echo $i | cut -d: -f3) sumUid=$(($sumUid+$userUid)) echo "username:$userName" echo "UID:$userUid"doneecho "Sum of the UID:$sumUid"[root@mageeduCentos7 bin]# bash mg7z11t.shusername:rootUID:0username:myquota1UID:1000username:myquota2UID:1001username:myquota3UID:1002username:myquota4UID:1003username:myquota5UID:1004username:mgjy1UID:1005username:mgjy2UID:1006username:visitor1UID:1007username:visitor2UID:1008username:visitor3UID:1009username:visitor4UID:1010username:visitor5UID:1011username:visitor6UID:1012username:visitor7UID:1013username:visitor8UID:1014username:visitor9UID:1015username:visitor10UID:1016username:visitor11UID:1017username:visitor12UID:1018username:visitor13UID:1019username:visitor14UID:1020username:visitor15UID:1021username:visitor16UID:1022username:visitor17UID:1023username:visitor18UID:1024username:visitor19UID:1025username:visitor20UID:1026Sum of the UID:27351
12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户
答:
[root@mageeduCentos7 bin]# vim mg7z12t.sh#!/bin/bashfor i in $(cut -d: -f1 /etc/passwd);do id $i | cut -d' ' -f3 | grep ',' &> /dev/null if [ $? -eq 0 ];then echo $i let sum++ fidoneecho "totail:$sum"[root@mageeduCentos7 bin]# bash mg7z12t.shpostfixtotail:1
13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;
答:
[root@mageeduCentos7 ~]# fdisk -l /dev/sdb磁盘 /dev/sdb:107.4 GB, 107374182400 字节,209715200 个扇区Units = 扇区 of 1 * 512 = 512 bytes扇区大小(逻辑/物理):512 字节 / 512 字节I/O 大小(最小/最佳):512 字节 / 512 字节磁盘标签类型:dos磁盘标识符:0x678c114d 设备 Boot Start End Blocks Id System/dev/sdb1 2048 20973567 10485760 8e Linux LVM/dev/sdb2 20973568 41945087 10485760 8e Linux LVM[root@mageeduCentos7 ~]# pvcreate /dev/sdb1 /dev/sdb2 #将两个10G的卷组成卷组WARNING: dos signature detected on /dev/sdb1 at offset 510. Wipe it? [y/n]: y Wiping dos signature on /dev/sdb1. Physical volume "/dev/sdb1" successfully created Physical volume "/dev/sdb2" successfully created[root@mageeduCentos7 ~]# vgcreate -s 8m myvg /dev/sdb1 /dev/sdb2 #设置卷组的pe大小为8m Volume group "myvg" successfully created[root@mageeduCentos7 ~]# lvcreate -L 5G -n mylv1 myvg #创建5G的逻辑卷 Logical volume "mylv1" created.[root@mageeduCentos7 ~]# mkfs.ext4 /dev/myvg/mylv1 #格式化逻辑卷myly1为ext4文件系统mke2fs 1.42.9 (28-Dec-2013)文件系统标签=OS type: Linux块大小=4096 (log=2)分块大小=4096 (log=2)Stride=0 blocks, Stripe width=0 blocks327680 inodes, 1310720 blocks65536 blocks (5.00%) reserved for the super user第一个数据块=0Maximum filesystem blocks=134217728040 block groups32768 blocks per group, 32768 fragments per group8192 inodes per groupSuperblock backups stored on blocks: 32768, 98304, 163840, 229376, 294912, 819200, 884736Allocating group tables: 完成正在写入inode表: 完成Creating journal (32768 blocks): 完成Writing superblocks and filesystem accounting information: 完成[root@mageeduCentos7 ~]# blkid /dev/myvg/mylv1/dev/myvg/mylv1: UUID="b8f0046d-be05-40e0-aad0-e3eb229ff577" TYPE="ext4" #得到UUID后用vim命令编辑/etc/fstab文件,把属性写进去[root@mageeduCentos7 ~]# cat /etc/fstab## /etc/fstab# Created by anaconda on Wed Aug 10 14:44:03 2016## Accessible filesystems, by reference, are maintained under '/dev/disk'# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info#/dev/mapper/centos-root / xfs defaults 0 0UUID=e93341c0-4e34-47df-8110-f52f1346e118 /boot xfs defaults 0 0/dev/mapper/centos-home /home xfs defaults 0 0/dev/mapper/centos-swap swap swap defaults 0 0UUID=b8f0046d-be05-40e0-aad0-e3eb229ff577 /users ext4 defaults,acl 0 0[root@mageeduCentos7 ~]# vgdisplay....系统默认的略过....--- Volume group --- VG Name myvg System ID Format lvm2 Metadata Areas 2 Metadata Sequence No 2 VG Access read/write VG Status resizable MAX LV 0 Cur LV 1 Open LV 0 Max PV 0 Cur PV 2 Act PV 2 VG Size 19.98 GiB #卷组的大小 PE Size 8.00 MiB #PE的大小 Total PE 2558 Alloc PE / Size 640 / 5.00 GiB Free PE / Size 1918 / 14.98 GiB VG UUID O2fCjR-C5UP-t1qu-KZA1-V56h-kCfd-f9CTr4
14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;
答:
[root@mageeduCentos7 /]# useradd -d /users/magedu magedu[root@mageeduCentos7 /]# su magedu[magedu@mageeduCentos7 /]$ cp /etc/fstab /etc/issue ~[magedu@mageeduCentos7 /]$ pwd/[magedu@mageeduCentos7 /]$ cd[magedu@mageeduCentos7 ~]$ lsfstab issue
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;
答:
[root@mageeduCentos7 ~]# lvextend -L 9G /dev/myvg/mylv1 Size of logical volume myvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents). Logical volume mylv1 successfully resized.[root@mageeduCentos7 ~]# resize2fs /dev/myvg/mylv1resize2fs 1.42.9 (28-Dec-2013)Resizing the filesystem on /dev/myvg/mylv1 to 2359296 (4k) blocks.The filesystem on /dev/myvg/mylv1 is now 2359296 blocks long.
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;
答:
[root@mageeduCentos7 ~]# umount /users/[root@mageeduCentos7 ~]# e2fsck -f /dev/myvg/mylv1e2fsck 1.42.9 (28-Dec-2013)第一步: 检查inode,块,和大小第二步: 检查目录结构第3步: 检查目录连接性Pass 4: Checking reference counts第5步: 检查簇概要信息/dev/myvg/mylv1: 11/589824 files (0.0% non-contiguous), 75551/2359296 blocks[root@mageeduCentos7 ~]# resize2fs /dev/myvg/mylv1 7Gresize2fs 1.42.9 (28-Dec-2013)Resizing the filesystem on /dev/myvg/mylv1 to 1835008 (4k) blocks.The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long.[root@mageeduCentos7 ~]# lvreduce -L 7G /dev/myvg/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@mageeduCentos7 ~]# mount /dev/myvg/mylv1 /users/
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;
答:
[root@mageeduCentos7 ~]# lvcreate -s -L 1G -p r -n snap-mylv1 /dev/myvg/mylv1 Logical volume "snap-mylv1" created. ##-s:表示快照功能的意思[root@mageeduCentos7 ~]# cd /dev/myvg/[root@mageeduCentos7 myvg]# ll总用量 0lrwxrwxrwx. 1 root root 7 9月 21 17:09 mylv1 -> ../dm-3lrwxrwxrwx. 1 root root 7 9月 21 17:09 snap-mylv1 -> ../dm-6