1、创建一个10G分区,并格式为ext4文件系统
(1) 要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl
fdisk /dev/sdb
n
p
1
1
10G
w
[root@llww3317 ~]# mke2fs -t ext4 -b 2048 -m 2 -L 'MYDATA' /dev/sdb1
[root@llww3317 ~]# tune2fs -o acl /dev/sdb1
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳
[root@llww3317 ~]# mkdir -p /data/mydata
[root@llww3317 ~]# mount /dev/sdb1 /data/mydata
[root@llww3317 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/sda3 18G 3.7G 13G 23% /
tmpfs 499M 76K 498M 1% /dev/shm
/dev/sda1 477M 35M 418M 8% /boot
/dev/sdb1 9.8G 13M 9.6G 1% /data/mydata
[root@llww3317 ~]# mount -o noauto,nodiratime /dev/sdb1 /data/mydata
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之
[root@llww3317 ~]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
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
Changed system type of partition 2 to 82 (Linux swap / Solaris)
Command (m for help): W
The partition table has been altered!
Calling ioctl() to re-read partition table.
Syncing disks.
[root@llww3317 ~]# mkswap /dev/sdb2
Setting up swapspace version 1, size = 1060284 KiB
no label, UUID=3ad04c6e-aaa3-4bea-93d4-7cb6fbfd14c4
[root@llww3317 ~]# swapon /dev/sdb2
[root@llww3317 ~]# swapon -s
Filename Type Size Used Priority
/dev/sda2 partition 2097148 0 -1
/dev/sdb2 partition 1060284 0 -2
3、写一个脚本
(1) 获取并列出当前系统上的所有磁盘设备
(2) 显示每个磁盘设备上每个分区相关的空间使用信息
#!/bin/bash
#
disk=$(fdisk -l|egrep -o "/dev/sd.?\>")
for i in $disk;do
echo $i
df -h|awk '/'${i//\//\\/}'/{print $0}'
done
[root@llww3317 tmp]# bash 3.1.sh
/dev/sda
/dev/sda3 18G 3.7G 13G 23% /
/dev/sda1 477M 35M 418M 8% /boot
/dev/sdb
4、总结RAID的各个级别及其组合方式和性能不同
需求:2块硬盘以上
可靠性:1/N
其原理就是将原先顺序写入数据被分散到所有RAID0的硬盘中同时进行读写,例四块硬盘并行同一时间读写的速度提升4倍。
容量:N*其中最小的一块
需求:2块以上
可靠性:只要系统中一对镜像盘至少有一块可以使用,系统都可以正常运行
其原理就是把一磁盘的数据镜像到另一个磁盘
容量:50%
RAID4
RAID1模式加一块异或盘
他对数据访问每次一个盘,一次一竖条
RAID-5
相对于RAID4,异或模式对于硬盘轮流进行
奇偶校验码存在于所有磁盘上,读出效率高,写入一般
RAID-6
RAID1模式加两块异或盘
它是对RAID5的扩展,主要用于数据绝对不能出错的场合
RAID-7
每个磁盘带有高速缓冲存储器,允许使用SNMP进行管理和监视,可连接多台主机,由于加入高速缓冲存储器,当多用户访问系统时,访问时间近乎于0,断电时高速缓冲器内的数据会全部丢失,需要和UPS一起工作,价格可想而知。
RAID-10
一个带区结构加一个镜像结构,用于数据容量不大,但要求速度与差错控制的数据库中
5、创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128K
--------------创建3块5G盘符--------------------
root@llww3317 tmp]# fdisk /dev/sdb
WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
switch off the mode (command 'c') and change display units to
sectors (command 'u').
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): +5G
Command (m for help): n
Command action
e extended
p primary partition (1-4)
p
Partition number (1-4): 2
First cylinder (655-2610, default 655):
Using default value 655
Last cylinder, +cylinders or +size{K,M,G} (655-2610, default 2610): +5G
Command (m for help): N
Command action
e extended
p primary partition (1-4)
P
Partition number (1-4): 3
First cylinder (1309-2610, default 1309):
Using default value 1309
Last cylinder, +cylinders or +size{K,M,G} (1309-2610, default 2610): +5G
Command (m for help): t
Partition number (1-4): 1
Hex code (type L to list codes): fd
Changed system type of partition 1 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 2
Hex code (type L to list codes): fd
Changed system type of partition 2 to fd (Linux raid autodetect)
Command (m for help): t
Partition number (1-4): 3
Hex code (type L to list codes): fd
Changed system type of partition 3 to fd (Linux raid autodetect)
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: 设备或资源忙.
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.
--------------------------------------------------------------------------
mdadm -C /dev/md0 -a yes -n 2 -x 1 -l 1 -c 128 /dev/sdb{1,2,3}
mke2fs -t ext4 /dev/md0
mount /dev/md0 /data/mydata
6、创建一个大小为4G的RAID5设备,chunk大小为256K,格式化ext4文件系统,要求可开机自动挂载到/backup目录,而且不更新访问时间戳,且支持acl功能
mdadm -C /dev/md0 -a yes -n 3 -l 5 -c 256 /dev/sdb{1,2,3}
mke2fs -t ext4 /dev/md0
vi /etc/fstab
/dev/md0 /backup ext4 acl,nodiratime 0 0
7、写一个脚本
(1)接受一个以上文件路径作为参数
(2)显示每个文件拥有的行数
(3)总结说明本次共为几个文件统计了其行数
#!/bin/bash
#
sum=0
directory="/etc"
for file in `ls $directory`;do
if [ -f $directory/$file ];then
l=`cat $directory/$file|wc -l `
echo "$file have $l"
let sum+=1
fi
done
echo "sum:$sum files."
8、写一个脚本
(1)传递两个以上字符串当作用户名
(2)创建这些用户,且密码同用户名
(3)总结说明共创建了几个用户
[root@llww3317 tmp]# cat user
a1
a123
b123
b3324
c4324
c234
d342
d453
#!/bin/bash
#
sum=0
for i in `cat /tmp/user`;do
id $i &>/dev/null
if [ $? -ne 0 ];then
useradd $i 1>/dev/null
echo $i |passwd --stdin $i 1>/dev/null
let sum+=1
fi
done
echo "sum=$sum"
9、写一个脚本,新建20个用户,visitor1-vistitor20;计算他们的ID之和
#!/bin/bash # sum=0 for i in {1..20};do useradd visitor$i let sum+=`cat /etc/passwd|grep "visitor$i"|cut -d: -f3` done echo "sum:$sum"
10、写一个脚本,分别统计/etc/rc.d/rc.sysinit、/etc/rc.d/init.d/functions和/etc/fstab文件中以#号开头的行数之和,以及总的空白行数
#!/bin/bash # sum=0 files=(/etc/rc.d/rc.sysinit /etc/rc.d/init.d/functions /etc/fstab) for i in ${files[@]};do echo $i `cat $i|grep '^#'|wc -l` let sum+=`cat $i|grep '^$'|wc -l` done echo "blank sum:$sum" [root@llww3317 tmp]# bash 10.sh /etc/rc.d/rc.sysinit 44 /etc/rc.d/init.d/functions 43 /etc/fstab 7 blank sum:206
11、写一个脚本,显示当前系统上所有默认shell为bash的用户的用户名,UID以及此类所有用户的UID之和
#!/bin/bash # sum=0 for i in `awk -F: -v OFS=':' '{if($NF=="/bin/bash") print $1,$3}' /etc/passwd`;do echo $i let sum+=`echo $i |cut -d: -f2` done echo "sum:$sum" [root@llww3317 tmp]# bash 11.sh root:0 a11:500 sum:500
12、写一个脚本,显示当前系统上所有拥有附加组的用户名,并说明共有多少个此类用户
#!/bin/bash # sum=0 for i in `awk -F: '{if($4>=0) print $0}' /etc/group`;do echo $i let sum+=1 done echo "sum:$sum" [root@llww3317 tmp]# bash 12.sh mail:x:12:postfix haldaemon:x:68:haldaemon a11:x:500:a12 sum:3
13、创建一个由至少两个物理卷组成的大小为20G卷组:要求PE为8M;而卷组中创建一个大小为5G的逻辑卷mylv1,格式为ext4
[root@llww3317 ~]# fdisk -l /dev/sdb Disk /dev/sdb: 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: 0x0004d60b Device Boot Start End Blocks Id System /dev/sdb1 1 1306 10490413+ 8e Linux LVM [root@llww3317 ~]# fdisk -l /dev/sdc Disk /dev/sdc: 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: 0x000678d8 Device Boot Start End Blocks Id System /dev/sdc1 1 1306 10490413+ 8e Linux LVM [root@llww3317 ~]# pvcreate /dev/sdb1 Physical volume "/dev/sdb1" successfully created [root@llww3317 ~]# pvcreate /dev/sdc1 Physical volume "/dev/sdc1" successfully created [root@llww3317 ~]# vgcreate -s 8M myvg /dev/sdb1 /dev/sdc1 Volume group "myvg" successfully created [root@llww3317 ~]# 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 20.00 GiB PE Size 8.00 MiB Total PE 2560 Alloc PE / Size 0 / 0 Free PE / Size 2560 / 20.00 GiB VG UUID BS42ix-E3bS-EVbZ-8QLH-W1U6-B9VR-RAFZ1n [root@llww3317 ~]# lvcreate -L 5G -n mylv1 myvg Logical volume "mylv1" created. [root@llww3317 ~]# mkfs -t ext4 /dev/myvg/mylv1 mke2fs 1.41.12 (17-May-2010) 鏂囦欢绯荤粺鏍囩= 鎿嶄綔绯荤粺:Linux 鍧楀ぇ灏4096 (log=2) 鍒嗗潡澶у皬=4096 (log=2) Stride=0 blocks, Stripe width=0 blocks 327680 inodes, 1310720 blocks 65536 blocks (5.00%) reserved for the super user 绗竴涓暟鎹潡=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 姝e湪鍐欏叆inode琛 瀹屾垚 Creating journal (32768 blocks): 瀹屾垚 Writing superblocks and filesystem accounting information: 瀹屾垚 This filesystem will be automatically checked every 32 mounts or 180 days, whichever comes first. Use tune2fs -c or -i to override.
14、新建用户magedu;其家目录为/users/magedu,而后su切换到此用户,复制多个文件至家目录
[root@llww3317 ~]# mkdir /users [root@llww3317 ~]# useradd -d /users/magedu magedu [magedu@llww3317 ~]$ pwd /users/magedu [magedu@llww3317 ~]$ ls issue passwd
15、扩展mylv1至9G,确保扩展完成后原有数据完全可用
[root@llww3317 ~]# lvextend -L 9G /users/magedu "/users/magedu": Invalid path for Logical Volume. Please provide a volume group name Run `lvextend --help' for more information. [root@llww3317 ~]# lvextend -L 9G /dev/mapper/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@llww3317 ~]# resize2fs /dev/mapper/myvg-mylv1 resize2fs 1.41.12 (17-May-2010) Filesystem at /dev/mapper/myvg-mylv1 is mounted on /users/magedu; on-line resizing required old desc_blocks = 1, new_desc_blocks = 1 Performing an on-line resize of /dev/mapper/myvg-mylv1 to 2359296 (4k) blocks. The filesystem on /dev/mapper/myvg-mylv1 is now 2359296 blocks long. [root@llww3317 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 3.8G 13G 23% / tmpfs 499M 80K 498M 1% /dev/shm /dev/sda1 190M 34M 147M 19% /boot /dev/mapper/myvg-mylv1 8.8G 12M 8.3G 1% /users/magedu [root@llww3317 ~]# cat /users/magedu/issue CentOS release 6.8 (Final) Kernel \r on an \m [root@llww3317 ~]# tail -n 10 /users/magedu/passwd haldaemon:x:68:68:HAL daemon:/:/sbin/nologin ntp:x:38:38::/etc/ntp:/sbin/nologin apache:x:48:48:Apache:/var/www:/sbin/nologin saslauth:x:498:76:Saslauthd user:/var/empty/saslauth:/sbin/nologin postfix:x:89:89::/var/spool/postfix:/sbin/nologin gdm:x:42:42::/var/lib/gdm:/sbin/nologin pulse:x:497:496:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin tcpdump:x:72:72::/:/sbin/nologin magedu:x:500:500::/users/magedu:/bin/bash
16、缩减mylv1至7G,确保缩减完成后原有数据完全可用
[root@llww3317 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 3.8G 13G 23% / tmpfs 499M 80K 498M 1% /dev/shm /dev/sda1 190M 34M 147M 19% /boot [root@llww3317 ~]# mount /dev/myvg/mylv1 /data/mydata [root@llww3317 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 3.8G 13G 23% / tmpfs 499M 80K 498M 1% /dev/shm /dev/sda1 190M 34M 147M 19% /boot /dev/mapper/myvg-mylv1 8.8G 12M 8.3G 1% /data/mydata [root@llww3317 ~]# cp /etc/issue /data/mydata [root@llww3317 ~]# umount /dev/myvg/mylv1 [root@llww3317 ~]# e2fsck -f /dev/myvg/mylv1 e2fsck 1.41.12 (17-May-2010) 第一步: 检查inode,块,和大小 第二步: 检查目录结构 第3步: 检查目录连接性 Pass 4: Checking reference counts 第5步: 检查簇概要信息 /dev/myvg/mylv1: 12/589824 files (0.0% non-contiguous), 72672/2359296 blocks [root@llww3317 ~]# resize2fs /dev/myvg/mylv1 7G resize2fs 1.41.12 (17-May-2010) Resizing the filesystem on /dev/myvg/mylv1 to 1835008 (4k) blocks. The filesystem on /dev/myvg/mylv1 is now 1835008 blocks long. [root@llww3317 ~]# 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 myvg/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@llww3317 ~]# mount /dev/myvg/mylv1 /data/mydata [root@llww3317 ~]# more /data/mydata/issue CentOS release 6.8 (Final) Kernel \r on an \m
17、对mylv1创建快照,并通过备份数据;要求保留原有的属主属组等信息
[root@llww3317 ~]# lvcreate -L 20M -s -p r -n snap-mylv1 /dev/myvg/mylv1 Rounding up size to full physical extent 24.00 MiB Logical volume "snap-mylv1" created. [root@llww3317 ~]# mount /dev/myvg/snap-mylv1 /mnt mount: block device /dev/mapper/myvg-snap--mylv1 is write-protected, mounting read-only [root@llww3317 ~]# df -h Filesystem Size Used Avail Use% Mounted on /dev/sda3 18G 3.8G 13G 23% / tmpfs 499M 80K 498M 1% /dev/shm /dev/sda1 190M 34M 147M 19% /boot /dev/mapper/myvg-mylv1 6.8G 12M 6.5G 1% /data/mydata /dev/mapper/myvg-snap--mylv1 6.8G 12M 6.5G 1% /mnt [root@llww3317 ~]# cp -a /mnt/* /tmp [root@llww3317 ~]# more /tmp/issue CentOS release 6.8 (Final) Kernel \r on an \m [root@llww3317 ~]# umount /mnt [root@llww3317 ~]# lvremove /dev/mapper/myvg-snap--mylv1 Do you really want to remove active logical volume snap-mylv1? [y/n]: y Logical volume "snap-mylv1" successfully removed
原创文章,作者:laiwen2007,如若转载,请注明出处:http://www.178linux.com/25087
评论列表(1条)
排版很好,但raid写的有点简单,能将raid各级别及应用常见描述一下会更好哦