第七周练习

1、创建一个10G分区,并格式为ext4文件系统; 
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl; 
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;

1.[root - gwx ~]#>fdisk /dev/sdb
2.Welcome to fdisk (util-linux 2.23.2).
3.
4.Changes will remain in memory only, until you decide to write them.
5.Be careful before using the write command.
6.
7.Device does not contain a recognized partition table
8.Building a new DOS disklabel with disk identifier 0x71cbf14f.
9.
10.Command (m for help): p
11.
12.Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
13.Units = sectors of 1 * 512 = 512 bytes
14.Sector size (logical/physical): 512 bytes / 512 bytes
15.I/O size (minimum/optimal): 512 bytes / 512 bytes
16.Disk label type: dos
17.Disk identifier: 0x71cbf14f
18.
19.   Device Boot      Start         End      Blocks   Id  System
20.
21.Command (m for help): n
22.Partition type:
23.   p   primary (0 primary, 0 extended, 4 free)
24.   e   extended
25.Select (default p): p
26.Partition number (1-4, default 1): 1
27.First sector (2048-41943039, default 2048):
28.Using default value 2048
29.Last sector, +sectors or +size{K,M,G} (2048-41943039, default 41943039): +10G
30.Partition 1 of type Linux and of size 10 GiB is set
31.
32.Command (m for help): w
33.The partition table has been altered!
34.
35.Calling ioctl() to re-read partition table.
36.Syncing disks.
37.[root - gwx ~]#>mke2fs -t ext4  -b 2048 -L MYDATA -m 2 /dev/sdb1
38.mke2fs 1.42.9 (28-Dec-2013)
39.Filesystem label=MYDATA
40.OS type: Linux
41.Block size=2048 (log=1)
42.Fragment size=2048 (log=1)
43.Stride=0 blocks, Stripe width=0 blocks
44.655360 inodes, 5242880 blocks
45.104857 blocks (2.00%) reserved for the super user
46.First data block=0
47.Maximum filesystem blocks=273678336
48.320 block groups
49.16384 blocks per group, 16384 fragments per group
50.2048 inodes per group
51.Superblock backups stored on blocks:
52.    16384, 49152, 81920, 114688, 147456, 409600, 442368, 802816, 1327104,
53.    2048000, 3981312
54.
55.Allocating group tables: done                            
56.Writing inode tables: done                            
57.Creating journal (32768 blocks): done
58.Writing superblocks and filesystem accounting information: done  
59.
60.[root - gwx ~]#>tune2fs -o acl /dev/sdb1
61.tune2fs 1.42.9 (28-Dec-2013)
62.[root - gwx ~]#>tune2fs -l /dev/sdb1
63.tune2fs 1.42.9 (28-Dec-2013)
64.Filesystem volume name:   MYDATA
65.Last mounted on:          <not available>
66.Filesystem UUID:          ae8426e6-ee50-431c-a301-878237c60548
67.Filesystem magic number:  0xEF53
68.Filesystem revision #:    1 (dynamic)
69.Filesystem features:      has_journal ext_attr resize_inode dir_index filetype extent 64bit flex_bg sparse_super huge_file uninit_bg dir_nlink extra_isize
70.Filesystem flags:         signed_directory_hash
71.Default mount options:    user_xattr acl
72.Filesystem state:         clean
73.Errors behavior:          Continue
74.Filesystem OS type:       Linux
75.Inode count:              655360
76.Block count:              5242880
77.Reserved block count:     104857
78.Free blocks:              5121266
79.Free inodes:              655349
80.First block:              0
81.Block size:               2048
82.Fragment size:            2048
83.Group descriptor size:    64
84.Reserved GDT blocks:      512
85.Blocks per group:         16384
86.Fragments per group:      16384
87.Inodes per group:         2048
88.Inode blocks per group:   256
89.Flex block group size:    16
90.Filesystem created:       Sat Dec 10 02:01:35 2016
91.Last mount time:          n/a
92.Last write time:          Sat Dec 10 02:01:43 2016
93.Mount count:              0
94.Maximum mount count:      -1
95.Last checked:             Sat Dec 10 02:01:35 2016
96.Check interval:           0 (<none>)
97.Lifetime writes:          65 MB
98.Reserved blocks uid:      0 (user root)
99.Reserved blocks gid:      0 (group root)
100.First inode:              11
101.Inode size:           256
102.Required extra isize:     28
103.Desired extra isize:      28
104.Journal inode:            8
105.Default directory hash:   half_md4
106.Directory Hash Seed:      74676b17-d083-49f6-9d12-a3c6c1d82913
107.Journal backup:           inode blocks
108.[root - gwx ~]#>mkdir /data/mydata
109.[root - gwx ~]#>mount -o nodiratime,noexec -L MYDATA /data/mydata
110.[root - gwx ~]#>mount |grep /dev/sdb1
111./dev/sdb1 on /data/mydata type ext4 (rw,noexec,nodiratime,relatime,seclabel,data=ordered)

2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;

1.[root - gwx ~]#>free
2.              total        used        free      shared  buff/cache   available
3.Mem:         472964       78956      299120         956       94888      348944
4.Swap:       1048572       50228      998344
5.[root - gwx ~]#>fdisk /dev/sdb
6.Welcome to fdisk (util-linux 2.23.2).
7.
8.Changes will remain in memory only, until you decide to write them.
9.Be careful before using the write command.
10.
11.
12.Command (m for help): n
13.Partition type:
14.   p   primary (1 primary, 0 extended, 3 free)
15.   e   extended
16.Select (default p): p
17.Partition number (2-4, default 2): 2
18.First sector (20973568-41943039, default 20973568):
19.Using default value 20973568
20.Last sector, +sectors or +size{K,M,G} (20973568-41943039, default 41943039): +1G
21.Partition 2 of type Linux and of size 1 GiB is set
22.
23.Command (m for help): t
24.Partition number (1,2, default 2): 2
25.Hex code (type L to list all codes): 82  
26.Changed type of partition 'Linux' to 'Linux swap / Solaris'
27.
28.Command (m for help): w
29.The partition table has been altered!
30.
31.Calling ioctl() to re-read partition table.
32.
33.WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
34.The kernel still uses the old table. The new table will be used at
35.the next reboot or after you run partprobe(8) or kpartx(8)
36.Syncing disks.
37.[root - gwx ~]#>partprobe
38.Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
39.Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
40.Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
41.[root - gwx ~]#>mkswap /dev/sdb2
42.Setting up swapspace version 1, size = 1048572 KiB
43.no label, UUID=c3755cf5-f46c-4407-b4ab-cbc9f3443da3
44.[root - gwx ~]#>swapon /dev/sdb2
45.[root - gwx ~]#>free
46.              total        used        free      shared  buff/cache   available
47.Mem:         472964       79776      290240         988      102948      348072
48.Swap:       2097144       50152     2046992
49.[root - gwx ~]#>swapon -s
50.Filename                Type        Size    Used    Priority
51./dev/dm-1                               partition   1048572 50152   -1
52./dev/sdb2                               partition   1048572 0   -2

3、写一个脚本 
(1)、获取并列出当前系统上的所有磁盘设备; 
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;

1.[root - gwx ~]#>./disk.sh 
2.当前系统磁盘设备情况:
3.Disk /dev/sdb: 21.5 GB, 21474836480 bytes, 41943040 sectors
4.Disk /dev/sda: 21.5 GB, 21474836480 bytes, 41943040 sectors
5.Disk /dev/mapper/centos-root: 19.8 GB, 19826475008 bytes, 38723584 sectors
6.Disk /dev/mapper/centos-swap: 1073 MB, 1073741824 bytes, 2097152 sectors
7.磁盘各分区使用情况:
8./dev/mapper/centos-root   19G  2.3G   17G  13% /
9./dev/sda1                497M  125M  373M  25% /boot
10./dev/sdb1                9.8G   13M  9.6G   1% /data/mydata
11.[root - gwx ~]#>cat disk.sh
12.#/bin/bash
13.echo "当前系统磁盘设备情况:"
14.fdisk -l |grep "^Disk /dev/"
15.echo "磁盘各分区使用情况:"
16.df -h |grep "^/dev"

4、总结RAID的各个级别及其组合方式和性能的不同; 
raid级别 容错能力 性能情况 硬盘限制 
0 无容错 性能最佳 1块及以上 
1 完全备份 占用一半硬盘资源 2块及以上 
01 有容错 相比10方式 读取数度快 可靠性比低 4块及以上 
10 有容错 相比01方式 可靠性高 4块及以上 
5 有容错 占用1/n硬盘资源 n为硬盘数 3块及以上 
5、创建一个大小为3G的RAID1,要求有一个空闲盘,而且CHUNK大小为128k;

1.#添加过程略
2.[root - gwx ~]#>fdisk -l |grep "/dev/sd[b|c|d]1"
3./dev/sdb1            2048    20973567    10485760   fd  Linux raid autodetect
4./dev/sdc1            2048    20973567    10485760   fd  Linux raid autodetect
5./dev/sdd1            2048    20973567    10485760   fd  Linux raid autodetect
6.[root - gwx ~]#>mdadm -C /dev/md0 -a yes -n 2 -l 1 -c 128 -x 1 /dev/sdb1 /dev/sdc1 /dev/sdd1
7.mdadm: /dev/sdb1 appears to contain an ext2fs file system
8.       size=10485760K  mtime=Sat Dec 10 02:05:30 2016
9.mdadm: Note: this array has metadata at the start and
10.
   may not be suitable as a boot device.  If you plan to
11.    store '/boot' on this device please ensure that
12.    your boot-loader understands md/v1.x metadata, or use
13.    --metadata=0.90
14.Continue creating array? y
15.mdadm: Defaulting to version 1.2 metadata
16.mdadm: array /dev/md0 started.
17.[root - gwx ~]#>mdadm -D /dev/md0
18./dev/md0:
19.        Version : 1.2
20.  Creation Time : Sat Dec 10 19:43:24 2016
21.     Raid Level : raid1
22.     Array Size : 10477568 (9.99 GiB 10.73 GB)
23.  Used Dev Size : 10477568 (9.99 GiB 10.73 GB)
24.   Raid Devices : 2
25.  Total Devices : 3
26.    Persistence : Superblock is persistent
27.
28.    Update Time : Sat Dec 10 19:44:09 2016
29.          State : clean, resyncing
30. Active Devices : 2
31.Working Devices : 3
32. Failed Devices : 0
33.  Spare Devices : 1
34.
35.  Resync Status : 91% complete
36.
37.           Name : gwx:0 (local to host gwx)
38.           UUID : a99f0ac3:5b75a364:a5d17abf:b0ee9970
39.         Events : 14
40.
41.    Number   Major   Minor   RaidDevice State
42.       0       8       17        0      active sync   /dev/sdb1
43.       1       8       33        1      active sync   /dev/sdc1
44.
45.       2       8       49        -      spare   /dev/sdd1

6、创建一个大小为4G的RAID5设备,chunk大小为256k,格式化ext4文件系统,要求可开机自动挂载至/backup目录,而且不更新访问时间戳,且支持acl功能;

1.#创建过程略
2.[root - gwx ~]#>fdisk -l |grep "/dev/sd[b|c|d]2"
3./dev/sdb2        20973568    25167871     2097152   fd  Linux raid autodetect
4./dev/sdc2        20973568    25167871     2097152   fd  Linux raid autodetect
5./dev/sdd2        20973568    25167871     2097152   fd  Linux raid autodetect
6.[root - gwx ~]#>partprobe
7.Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
8.Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
9.Warning: Unable to open /dev/sr0 read-write (Read-only file system).  /dev/sr0 has been opened read-only.
10.[root - gwx ~]#>mdadm -C /dev/md1 -l 5 -a yes -c 256 -n 3 /dev/sdb2 /dev/sdc2 /dev/sdd2
11.mdadm: Defaulting to version 1.2 metadata
12.mdadm: array /dev/md1 started.
13.[root - gwx ~]#>mdadm -D /dev/md1
14./dev/md1:
15.        Version : 1.2
16.  Creation Time : Sat Dec 10 19:50:37 2016
17.     Raid Level : raid5
18.     Array Size : 4190208 (4.00 GiB 4.29 GB)
19.  Used Dev Size : 2095104 (2046.34 MiB 2145.39 MB)
20.   Raid Devices : 3
21.  Total Devices : 3
22.    Persistence : Superblock is persistent
23.
24.    Update Time : Sat Dec 10 19:50:48 2016
25.          State : clean
26. Active Devices : 3
27.Working Devices : 3
28. Failed Devices : 0
29.  Spare Devices : 0
30.
31.         Layout : left-symmetric
32.     Chunk Size : 256K
33.
34.           Name : gwx:1  (local to host gwx)
35.           UUID : 1b2b7e9f:ee12bd05:3181d270:ac24d6ce
36.         Events : 18
37.    Number   Major   Minor   RaidDevice State
38.       0       8       18        0      active sync   /dev/sdb2
39.       1       8       34        1      active sync   /dev/sdc2
40.       3       8       50        2      active sync   /dev/sdd2
41.[root - gwx ~]#>mke2fs -t ext4 /dev/md1
42.mke2fs 1.42.9 (28-Dec-2013)
43.Filesystem label=
44.OS type: Linux
45.Block size=4096 (log=2)
46.Fragment size=4096 (log=2)
47.Stride=64 blocks, Stripe width=128 blocks
48.262144 inodes, 1047552 blocks
49.52377 blocks (5.00%) reserved for the super user
50.First data block=0
51.Maximum filesystem blocks=1073741824
52.32 block groups
53.32768 blocks per group, 32768 fragments per group
54.8192 inodes per group
55.Superblock backups stored on blocks:
56.    32768, 98304, 163840, 229376, 294912, 819200, 884736
57.
58.Allocating group tables: done                            
59.Writing inode tables: done                            
60.Creating journal (16384 blocks): done
61.Writing superblocks and filesystem accounting information: done
62.
63.[root - gwx ~]#>echo "UUID=1b2b7e9f:ee12bd05:3181d270:ac24d6ce /backup ext4 noatime,acl 0 0" >> /etc/fstab
64.[root - gwx ~]#>tail -1 /etc/fstab
65.UUID=1b2b7e9f:ee12bd05:3181d270:ac24d6ce /backup ext4 noatime,acl 0 0

7、写一个脚本 
(1) 接受一个以上文件路径作为参数; 
(2) 显示每个文件拥有的行数; 
(3) 总结说明本次共为几个文件统计了其行数;

1.[root - gwx ~]#>./file-wc.sh 
2.请至少输入一个文件路径!
3.[root - gwx ~]#>./file-wc.sh file-wc.sh
4.file-wc.sh 文件行数为:12
5.本次统计 1 个文件
6.[root - gwx ~]#>./file-wc.sh file-wc.sh /etc/passwd
7.file-wc.sh 文件行数为:12
8./etc/passwd 文件行数为:34
9.本次统计 2 个文件
10.[root - gwx ~]#>cat file-wc.sh
11.#!/bin/bash
12.if [ $# -eq 0 ];then              
13.echo "请至少输入一个文件路径!"      
14.exit 1
15.fi
16.for i in $*;do                    
17.    echo "$i 文件行数为:$(cat $i | wc -l) 行"  
18.done
19.echo "本次统计 $# 个文件"

8、写一个脚本 
(1) 传递两个以上字符当作用户名; 
(2) 创建这些用户;且密码同用户名; 
(3) 总结说明共创建了几个用户;

1.[root - gwx ~]#>./useradd.sh cat ca 
2.用户名cat 已存在
3.用户名不得低于2个字符串
4.本次添加0 个用户
5.[root - gwx ~]#>./useradd.sh cat caa
6.用户名cat 已存在
7.用户名caa 已存在
8.本次添加0 个用户
9.[root - gwx ~]#>./useradd.sh cat caaa
10.用户名cat 已存在
11.用户caaa 已添加,密码同用户名,请及时修改!
12.本次添加1 个用户
13.[root - gwx ~]#>cat useradd.sh
14.#!/bin/bash
15.for i in $*;do                            
16.j=0
17.    if [ $(echo "$i" | wc -c) -le 3 ];then    
18.        echo "用户名不得低于2个字符串"
19.    elif
20.        id $i &> /dev/null;then                  
21.        echo "用户名$i 已存在"
22.    else                                      
23.        useradd $i                                  
24.        echo "$i" | passwd --stdin $i >> /dev/null      
25.        echo "用户$i 已添加,密码同用户名,请及时修改!"
26.        let j++
27.    fi
28.done
29.echo "本次添加$j 个用户"                  

9、写一个脚本,新建20个用户,visitor1-visitor20;计算他们的ID之和;

1.[root - gwx ~]#>./visitor.sh 
2.用户visitor1 已添加
3.用户visitor2 已添加
4.用户visitor3 已添加
5.用户visitor4 已添加
6.用户visitor5 已添加
7.用户visitor6 已添加
8.用户visitor7 已添加
9.用户visitor8 已添加
10.用户visitor9 已添加
11.用户visitor10 已添加
12.用户visitor11 已添加
13.用户visitor12 已添加
14.用户visitor13 已添加
15.用户visitor14 已添加
16.用户visitor15 已添加
17.用户visitor16 已添加
18.用户visitor17 已添加
19.用户visitor18 已添加
20.用户visitor19 已添加
21.用户visitor20 已添加
22.所添加用户的UID之和为:20490
23.[root - gwx ~]#>tail -20 /etc/passwd |cut -d: -f3
24.1015
25.1016
26.1017
27.1018
28.1019
29.1020
30.1021
31.1022
32.1023
33.1024
34.1025
35.1026
36.1027
37.1028
38.1029
39.1030
40.1031
41.1032
42.1033
43.1034
44.[root - gwx ~]#>cat visitor.sh
45.#!/bin/bash
46.sum=0                          
47.for i in {1..20};do                  
48.    if [ id visitor$i ] &> /dev/null ;then    
49.        echo "用户visitor$i 已存在"
50.    else
51.        useradd visitor$i >> /dev/null        
52.        echo "用户visitor$i 已添加"          
53.    fi
54.        let sum+=$(id -u visitor$i)     ##如果要计算visitor1-20的和的话就将计数代码放置此处,如果只计算添加成功的,之前存在的用户的ID不计算的话,需要把计数代码放入判断块中的else分支的下面      
55.done
56.echo "所添加用户的UID之和为:$sum"

10、写一脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数;

1.[root - gwx ~]#>./line-sum.sh 
2.cat: /etc/rc.d/rc.sysinit: No such file or directory
3.cat: /etc/rc.d/rc.sysinit: No such file or directory
4.给出的文档中以#开头的行数和为:31
5.给出的文档中以空格开头的行数和为:443
6.[root - gwx ~]#>cat line-sum.sh
7.#!/bin/bash
8.sum1=0              
9.sp=0                
10.for i in {/etc/rc.d/rc.sysinit,/etc/rc.d/init.d/functions,/etc/passwd};do            
11.    let sum1+=$(cat $i | grep -o "^#.*" | wc -l)  
12.    let sp+=$(cat $i | egrep -o "^[[:space:]].*" | wc -l)  
13.done
14.echo "给出的文档中以#开头的行数和为:$sum1"      
15.echo "给出的文档中以空格开头的行数和为:$sp"

11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名、UID以及此类所有用户的UID之和;

1.[root - gwx ~]#>./shell-sum.sh 
2.root:0:/bin/bash
3.gwx:1000:/bin/bash
4.user10:1001:/bin/bash
5.user11:1002:/bin/bash
6.user12:1003:/bin/bash
7.user13:1004:/bin/bash
8.user14:1005:/bin/bash
9.user15:1006:/bin/bash
10.user16:1007:/bin/bash
11.user17:1008:/bin/bash
12.user18:1009:/bin/bash
13.user19:1010:/bin/bash
14.test:1011:/bin/bash
15.cat:1012:/bin/bash
16.caa:1013:/bin/bash
17.caaa:1014:/bin/bash
18.visitor1:1015:/bin/bash
19.visitor2:1016:/bin/bash
20.visitor3:1017:/bin/bash
21.visitor4:1018:/bin/bash
22.visitor5:1019:/bin/bash
23.visitor6:1020:/bin/bash
24.visitor7:1021:/bin/bash
25.visitor8:1022:/bin/bash
26.visitor9:1023:/bin/bash
27.visitor10:1024:/bin/bash
28.visitor11:1025:/bin/bash
29.visitor12:1026:/bin/bash
30.visitor13:1027:/bin/bash
31.visitor14:1028:/bin/bash
32.visitor15:1029:/bin/bash
33.visitor16:1030:/bin/bash
34.visitor17:1031:/bin/bash
35.visitor18:1032:/bin/bash
36.visitor19:1033:/bin/bash
37.visitor20:1034:/bin/bash
38.以上UID之和为:35595
39.[root - gwx ~]#>cat shell-sum.sh
40.#!/bin/bash
41.sum=0          
42.cat /etc/passwd | egrep "/bash$" | cut -d: -f1,3,7  
43.for i in $(cat /etc/passwd | egrep "/bash$" | cut -d: -f3);do  
44.    let sum+=$i            
45.done
46.echo "以上UID之和为:$sum"

12、写一个脚本,显示当前系统上所有,拥有附加组的用户的用户名;并说明共有多少个此类用户;

1.[root - gwx ~]#>chmod +x group.sh
2.[root - gwx ~]#>./group.sh
3.postfix : postfix mail
4.此类用户共有1
5.[root - gwx ~]#>cat group.sh
6.#!/bin/bash
7.sum=0                  
8.for i in $(cat /etc/passwd | cut -d: -f1);do  
9.    if [ $(groups $i | wc -w) -gt 3 ];then        
10.        echo "$(groups $i)"          
11.        let sum+=1                    
12.    fi
13.done
14.echo "此类用户共有$sum 个"

13、创建一个由至少两个物理卷组成的大小为20G的卷组;要求,PE大小为8M;而在卷组中创建一个大小为5G的逻辑卷mylv1,格式化为ext4文件系统,开机自动挂载至/users目录,支持acl;

1.[root - gwx ~]#>pvcreate /dev/sdb1 /dev/sdc1
2.  Physical volume "/dev/sdb1" successfully created
3.  Physical volume "/dev/sdc1" successfully created
4.[root - gwx ~]#>vgcreate -s 8m myvg /dev/sdb1 /dev/sdc1
5.  Volume group "myvg" successfully created
6.[root - gwx ~]#>lvcreate -L 5G -n mylv1 myvg
7.  Logical volume "mylv1" created.
8.[root - gwx ~]#>mke2fs -t ext4 /dev/mapper/myvg-mylv1
9.mke2fs 1.42.9 (28-Dec-2013)
10.Filesystem label=
11.OS type: Linux
12.Block size=4096 (log=2)
13.Fragment size=4096 (log=2)
14.Stride=0 blocks, Stripe width=0 blocks
15.327680 inodes, 1310720 blocks
16.65536 blocks (5.00%) reserved for the super user
17.First data block=0
18.Maximum filesystem blocks=1342177280
19.40 block groups
20.32768 blocks per group, 32768 fragments per group
21.8192 inodes per group
22.Superblock backups stored on blocks:
23.    32768, 98304, 163840, 229376, 294912, 819200, 884736
24.
25.Allocating group tables: done                            
26.Writing inode tables: done                            
27.Creating journal (32768 blocks): done
28.Writing superblocks and filesystem accounting information: done
29.
30.[root - gwx ~]#>mkdir /users
31.[root - gwx ~]#>echo  "/dev/mapper/myvg-mylv1 /users ext4 acl 0 0" >> /etc/fstab
32.[root - gwx ~]#>tail -1 /etc/fstab
33./dev/mapper/myvg-mylv1 /users ext4 acl 0 0

14、新建用户magedu;其家目录为/users/magedu,而后su切换至此用户,复制多个文件至家目录;

1.[root - gwx ~]#>useradd -d /users/magedu magedu
2.[root - gwx ~]#>su - magedu
3.[magedu@gwx ~]$ cp /etc/httpd/conf/
4.httpd.conf  magic      
5.[magedu@gwx ~]$ cp /etc/httpd/conf/* ~
6.[magedu@gwx ~]$ ll
7.total 28
8.-rw-r--r--. 1 magedu magedu 11753 Dec 10 21:19 httpd.conf
9.-rw-r--r--. 1 magedu magedu 13077 Dec 10 21:19 magic

15、扩展mylv1至9G,确保扩展完成后原有数据完全可用;

1.[root - gwx ~]#>echo "test for lv" >> /users/test-lv
2.[root - gwx ~]#>cat /users/test-lv
3.test for lv
4.[root - gwx ~]#>lvextend -L +4G /dev/mapper/myvg-mylv1
5.  Size of logical volume myvg/mylv1 changed from 5.00 GiB (640 extents) to 9.00 GiB (1152 extents).
6.  Logical volume mylv1 successfully resized.
7.[root - gwx ~]#>resize2fs /dev/mapper/myvg-mylv1
8.resize2fs 1.42.9 (28-Dec-2013)
9.Filesystem at /dev/mapper/myvg-mylv1 is mounted on /users; on-line resizing required
10.old_desc_blocks = 1, new_desc_blocks = 2
11.The filesystem on /dev/mapper/myvg-mylv1 is now 2359296 blocks long.
12.
13.[root - gwx ~]#>cat /users/test-lv
14.test for lv
15.[root - gwx ~]#>df -h |grep mylv
16./dev/mapper/myvg-mylv1  ext4      8.8G   23M  8.3G   1% /users

16、缩减mylv1至7G,确保缩减完成后原有数据完全可用;

1.[root - gwx ~]#>cat /users/test-lv
2.test for lv
3.[root - gwx ~]#>umount /dev/mapper/myvg-mylv1
4.[root - gwx ~]#>e2fsck -f /dev/mapper/myvg-mylv1
5.e2fsck 1.42.9 (28-Dec-2013)
6.Pass 1: Checking inodes, blocks, and sizes
7.Pass 2: Checking directory structure
8.Pass 3: Checking directory connectivity
9.Pass 4: Checking reference counts
10.Pass 5: Checking group summary information
11./dev/mapper/myvg-mylv1: 12/589824 files (0.0% non-contiguous), 75552/2359296 blocks
12.[root - gwx ~]#>resize2fs /dev/mapper/myvg-mylv1 7G
13.resize2fs 1.42.9 (28-Dec-2013)
14.Resizing the filesystem on /dev/mapper/myvg-mylv1 to 1835008 (4k) blocks.
15.The filesystem on /dev/mapper/myvg-mylv1 is now 1835008 blocks long.
16.
17.[root - gwx ~]#>lvreduce -L -2G /dev/mapper/myvg-mylv1
18.  WARNING: Reducing active logical volume to 7.00 GiB
19.  THIS MAY DESTROY YOUR DATA (filesystem etc.)
20.Do you really want to reduce mylv1? [y/n]: y
21.  Size of logical volume myvg/mylv1 changed from 9.00 GiB (1152 extents) to 7.00 GiB (896 extents).
22.  Logical volume mylv1 successfully resized.
23.[root - gwx ~]#>lvdisplay
24.  --- Logical volume ---
25.  LV Path                /dev/myvg/mylv1
26.  LV Name                mylv1
27.  VG Name                myvg
28.  LV UUID                VtF2bw-NWvf-08ON-mvob-nGb8-qgQk-UVzzqL
29.  LV Write Access        read/write
30.  LV Creation host, time gwx, 2016-12-10 21:12:12 -0500
31.  LV Status              available
32.  # open                 0
33.  LV Size                7.00 GiB
34.  Current LE             896
35.  Segments               1
36.  Allocation             inherit
37.  Read ahead sectors     auto
38.  - currently set to     8192
39.  Block device           253:2
40.#....其他lv略
41.[root - gwx ~]#>mount -a
42.[root - gwx ~]#>cat /users/test-lv
43.test for lv

17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息;

1.[root - gwx ~]#>su - test
2.Last login: Sat Dec 10 21:39:07 EST 2016 on pts/0
3.[test@gwx ~]$ touch /users/test-sn
4.[test@gwx ~]$ ll /users/test-sn
5.-rw-rw-r--. 1 test test 0 Dec 10 21:41 /users/test-sn
6.[test@gwx ~]$ su -
7.Password:
8.Last login: Sat Dec 10 21:40:31 EST 2016 on pts/0
9.[root - gwx ~]#>lvcreate -L 1G -s -n mylv1-sn1 /dev/mapper/myvg-mylv1
10.  Logical volume "mylv1-sn1" created.
11.[root - gwx ~]#>mkdir /sn
12.[root - gwx ~]#>mount /dev/myvg/mylv1-sn1 /sn
13.[root - gwx ~]#>ll /sn
14.total 20K
15.drwx------. 2 root root 16K Dec 10 21:14 lost+found/
16.-rw-r--r--. 1 root root  12 Dec 10 21:22 test-lv
17.-rw-rw-r--. 1 test test   0 Dec 10 21:41 test-sn

原创文章,作者:N24-wenxuan,如若转载,请注明出处:http://www.178linux.com/63237

(0)
N24-wenxuanN24-wenxuan
上一篇 2016-12-11
下一篇 2016-12-11

相关推荐

  • puppet部署多台服务器

    利用puppet实现自动化部署 配置前准备:   图中:蓝线表示各个服务器之间通信      红线表示puppetmaster主机向各个agent主机部署信道 A主机puppet-master主机:192.168.126.129 B主机做两种服务:keepalived高性能和nginx反代  &nb…

    2017-07-23
  • 通过Xshell 5连接VirtualBox的centos

    环境:VirtualBox  centos6.5 1、使用VirtualBox Host-Only Network模式 2、打开宽带连接,设置属性,选择VirtualBox Host-Only Network共享。(在这里虚拟机centos的IP地址是自动获得,并且可以上网。) 3、虚拟机centos需要     关闭防火墙 :…

    Linux干货 2015-11-07
  • LVM详解

    一、概述     LVM全称为Logical Volume Manager,即逻辑卷管理器。LVM可以弹性的调整文件系统的容量,可以将多个物理分区整合在一起,并且根据需要划分空间或动态的修改文件系统空间。     LVM有两个版本: lvm,lvm2 二、LVM的相关概念   &…

    Linux干货 2015-04-28
  • N26-第二周

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示。(盗图了,哈哈哈) 文件查看类命令:cat, tac, head, tail, more, less,touch    cat 查看文件内容   tac命令   反向查看文件内容  注:可对照上图 分屏查看命令:more  …

    Linux干货 2017-01-07
  • Kickstart+PXE自动部署CentOS6.6

        生产环境中对于部署大量的相同系统的服务器,如果逐台安装操作系统的话是非常浪费时间的工作,还好CentOS提供了无人值守安装系统的功能,下面就详细介绍一下配置步骤。 一、配置本机的yum源     因为需要安装一些软件来达到我们的目的,所以最好先把yum源配置好。 &nbs…

    Linux干货 2015-05-12
  • 有关shell脚本

    SHELL脚本 在Linux运维工作中有着大量的重复性质的工作,比如同时给很多台的服务器备份,查看多台的内存情况,等等。这样的情况下总不能一个一个服务器自己去看,那样耗时,费力,还容易出错。所以编写程序来做这些事情就成了必要的工作。而SHELL就是完成这项工作的。   脚本第一行的开头写上#!/bin/bash 这是属于格式性质的,作用在于加上执行…

    2017-08-12

评论列表(1条)

  • 马哥教育
    马哥教育 2016-12-14 14:48

    完成的非常好,给出了详细的操作过程,加油!