集中练习5-磁盘分区、文件系统挂载、RAID管理

集中练习5-磁盘分区、文件系统挂载、RAID管理

1. 创建一个10G分区,并格式化为ext4文件系统;
(1) 要求其block大小为2048,预留空间百分比为2%,卷标为MYDATA,默认挂载属性包含acl;
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动执行,且不更新文件的访问时间戳;
“`
/]# fdisk /dev/sdb
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.

 

Command (m for help): n
All primary partitions are in use
Adding logical partition 6
First sector (31463424-209715199, default 31463424):
Using default value 31463424
Last sector, +sectors or +size{K,M,G} (31463424-209715199, default 209715199): +10G
Partition 6 of type Linux and of size 10 GiB is set

Command (m for help): p

Disk /dev/sdb: 107.4 GB, 107374182400 bytes, 209715200 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: 0x277399ec

Device Boot      Start         End      Blocks   Id  System
/dev/sdb1            2048    20973567    10485760   83  Linux
/dev/sdb2        20973568    23070719     1048576   82  Linux swap / Solaris
/dev/sdb3        23070720    27265023     2097152   83  Linux
/dev/sdb4        27265024   209715199    91225088    5  Extended
/dev/sdb5        27267072    31461375     2097152   8e  Linux LVM
/dev/sdb6        31463424    52434943    10485760   83  Linux

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.
~]# kpartx -af /dev/sdb

~]# mke2fs -t ext4 -b 2048 -L MYDATA -m 2 /dev/sdb6
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
“`
2. 创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
“`
~]# fdisk /dev/sdb
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.

 

Command (m for help): n
All primary partitions are in use
Adding logical partition 7
First sector (52436992-209715199, default 52436992):
Using default value 52436992
Last sector, +sectors or +size{K,M,G} (52436992-209715199, default 209715199): +1G
Partition 7 of type Linux and of size 1 GiB is set

Command (m for help): t
Partition number (1-7, default 7): 7
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.
Syncing disks.
~]# kpartx -af /dev/sdb
~]# free -m
total        used        free      shared  buff/cache   available
Mem:           7806         182        7404           8         220        7353
Swap:          2048           0        2048

~]# mkswap /dev/sdb7
Setting up swapspace version 1, size = 1048572 KiB
no label, UUID=e9426246-b5b3-48e6-b034-5ec5f26646a9
~]# swapon /dev/sdb7
~]# free -m
total        used        free      shared  buff/cache   available
Mem:           7806         180        7401           8         224        7353
Swap:          3072           0        3072
“`
3. 写一个脚本
(1) 获取并列出当前系统上的所有磁盘设备
(2) 显示每个磁盘设备上每个分区相关的空间使用信息
“`
#!/bin/bash
#
for i in `fdisk -l | grep “^Disk /dev” | grep -o “/dev/[[:alpha:]]\+\>”`; do
echo -e “\n$i disk usage: \n”
fdisk -l $i | grep “^/dev/”
done
“`
4. 总结RAID的各个级别及其组合方式和性能的不同;

RAID级别 | 可用空间 | 允许坏盘个数 | 磁盘数限制 | 读写性能
————- | ———— | ———— | ————– | ————–
JBOD | Size = S1+S2+…+SN | 0 | 2+ | 读写性能均没有变化
RAID0 | Size = 2 x min(S1,S2,…) | 0 | 2+ | 读、写性能均有提升
RAID1 | Size = min(S1,S2,S3…) | N-1 | 2+ | 读性能有提升,写性能略有下降
RAID4 | Size = (N-1) x min(S1,S2,…,SN) | 1 | 3+ | 读、写性能均有提升
RAID5 | Size = (N-1) x min(S1,S2,…,SN) | 1 | 3+ | 读、写性能均有提升
RAID6 | Size = (N-2) x min(S1,S2,…,SN) | 2 | 4+ | 读、写性能均有提升
RAID1+0 | Size = N x min(S1,S2,…,SN)/2 | 每个RAID1剩一块健康盘即可 | 4+ | 读、写性能均有提升
RAID0+1 | Size = N x min(S1,S2,…,SN)/2 | RAID1有一个健康的RAID0组即可 | 4+ | 读、写性能均有提升

5. 创建一个大小为10G的RAID1,要求有一个空闲盘,而且CHUNK大小为128K;

“`
通过fdisk命令创建3个10G的分区
~]# fdisk /dev/sdb
/dev/sdb7        52436992    73408511    10485760   fd  Linux raid autodetect
/dev/sdb8        73410560    94382079    10485760   fd  Linux raid autodetect
/dev/sdb9        94384128   115355647    10485760   fd  Linux raid autodetect

~]# mdadm -C /dev/md0 -n 2 -x 1 -l 1 -c 256 /dev/sdb{7,8,9}
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? y
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md0 started.

~]# mdadm -D /dev/md0
/dev/md0:
Version : 1.2
Creation Time : Thu Oct 26 13:54:04 2017
Raid Level : raid1
Array Size : 10477568 (9.99 GiB 10.73 GB)
Used Dev Size : 10477568 (9.99 GiB 10.73 GB)
Raid Devices : 2
Total Devices : 3
Persistence : Superblock is persistent

Update Time : Thu Oct 26 13:54:56 2017
State : clean
Active Devices : 2
Working Devices : 3
Failed Devices : 0
Spare Devices : 1

Name : sapbcs.mageedu.com:0  (local to host sapbcs.mageedu.com)
UUID : 88dca9de:813c1f6b:a28ec904:b9f37d67
Events : 17

Number   Major   Minor   RaidDevice State
0       8       23        0      active sync   /dev/sdb7
1       8       24        1      active sync   /dev/sdb8

2       8       25        –      spare   /dev/sdb9
“`

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

“`
~]# fdisk /dev/sdb
新建4个4G分区,并调整格式为fd
/dev/sdb10      115357696   123746303     4194304   fd  Linux raid autodetect
/dev/sdb11      123748352   132136959     4194304   fd  Linux raid autodetect
/dev/sdb12      132139008   140527615     4194304   fd  Linux raid autodetect
/dev/sdb13      140529664   148918271     4194304   fd  Linux raid autodetect

~]# mdadm -C /dev/md1 -n 3 -x 1 -l 5 -c 256 /dev/sdb{10,11,12,13}
mdadm: Defaulting to version 1.2 metadata
mdadm: array /dev/md1 started.

~]# mke2fs -t ext4 /dev/md1

~]# vim /etc/fstab
/dev/md1          /backup            ext4          defaults,acl,noatime   0  0
“`
7. 写一个脚本
(1) 接受一个以上文件路径作为参数;
(2) 显示每个文件拥有的行数;
(3) 总结说明本次共为几个文件统计了行数;
“`
#!/bin/bash
#
if [ $# -lt 1 ];then
echo “Please input at least one path.”
exit 1
fi
for i in `seq 1 $#`; do
file=`echo $@ | cut -d’ ‘ -f$i`
lines=`wc -l $file | cut -d’ ‘ -f1`
echo “There are $lines lines in $file.”
done
echo “There are $# files counted by this script.”

~]# ./count.sh /etc/fstab /etc/rc.d/init.d/functions
There are 12 lines in /etc/fstab.
There are 654 lines in /etc/rc.d/init.d/functions.
There are 2 files counted by this script.
“`
8. 写一个脚本
(1) 传递两个以上字符串当作用户名;
(2) 创建这些用户,且密码同用户名;
(3) 总结说明共创建了几个用户;
“`
#!/bin/bash
#
if [ $# -lt 2 ]; then
echo “You must input at least two username.”
exit
fi

let skipnum=0

for i in `seq 1 $#`; do
user_name=`echo $@ | cut -d’ ‘ -f$i`
if id $user_name &> /dev/null; then
skipnum=$(($skipnum+1))
echo “User $user_name already exist in system.”
else
useradd $user_name &> /dev/null
echo $user_name | passwd $user_name –stdin &> /dev/null
echo “User $user_name has been created.”
fi
done

let sum=$(($#-$skipnum))
echo “There are $sum users created by this script.”
“`
9. 写一个脚本
创建20个用户,visitor1-visitor20;计算他们的ID之和;
“`
#!/bin/bash
#
let sum=0

for i in `seq 1 20`; do
id visitor$i &> /dev/null || useradd visitor$i &> /dev/null
let User_id=`id -u visitor$i`
sum=$(($sum+$User_id))
done

echo “User ID sum is $sum.”
“`

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/88077

(0)
N27_sapbcsN27_sapbcs
上一篇 2017-10-27 09:44
下一篇 2017-10-27 10:58

相关推荐

  • centos系统启动流程详解

    centos系统启动流程详解 CentOS启动流程: POST 加电自检 主板上有一个ROM芯片,有只读程序,CPU被设计为一旦通电就会自动去找ROM芯片上的程序并运行,即检查各种硬件设备是否存在。 BootSequence 引导过程 加电自检后按BIOS中设定的次序查找各引导设备,第一个有引导程序的设备即是本次启动用到的设备 MBR(BootLoader)…

    Linux干货 2017-09-04
  • 文件查找命令之find

    文件查找命令一共有两种,locate 和find ,那么他们在用法和功能上面有什么区别呢?     locate:查找速度快,模糊查找,遍历整个文件系统的目录到数据库中,然后在去数据库中查找,依赖于事先创建好的索引库,该数据库属于系统自动创建,定期自动更新,也可手动跟新,更新命令updatedb,更新数据库需要遍历整个根文件系统…

    Linux干货 2016-08-16
  • 一起学DHCP系列(二)三种途径

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://jeffyyko.blog.51cto.com/28563/162176 《一起学DHCP》系列第二节。      和WINS服务类似,DHCP大体上也由两部分组成,DHC…

    Linux干货 2015-03-25
  • 高可用Nginx

    高可用Nginx 基于vrrp流动一个IP地址 各节点时间必须同步; 确保iptables以及selinux不会成为阻碍; 各节点之间可通过主机名互相同喜(对KA而言并非必须) 确保各节点的用于集群服务的接口支持MULTICAST通信 IPv4,D类地址224-239 环境: node1:172.16.253.223 li1.jing.io node1 no…

    Linux干货 2017-06-28
  • VIM编辑器入门

    VIM简介 VIM是一个类似于Vi的著名的功能强大、高度可定制的文本编辑器,在Vi的基础上改进和增加了很多特性。VIM是纯粹的自由软件。 VIM的使用 在介绍基本使用前,先了解下VIM的基本模式 基本模式可分为三种:命令模式、输入模式、末行模式 命令模式:Vim启动后的默认模式,通过输入指令完成对应的编辑操作。输入模式和末行模式从命令模式进入&nb…

    Linux干货 2016-04-05
  • Ansible安装及简单使用

    简介: ansible是新出现的自动化运维工具,基于Python开发,集合了众多运维工具(puppet、cfengine、chef、func、fabric)的优点,实现了批量系统配置、批量程序部署、批量运行命令等功能。ansible是基于模块工作的,本身没有批量部署的能力。真正具有批量部署的是ansible所运行的模块,ansible只是提供一种框架。主要包…

    Linux干货 2016-08-07