集中练习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)
上一篇 2017-10-27 09:44
下一篇 2017-10-27 10:58

相关推荐

  • 管理用户组的命令

    用户账户 管理用户的命令及配置文件, Useradd,usermod,userdel,newusers,chpasswd,passwd,chage,chfn,chsh,id,su,finger Useradd:创建用户,         Useradd 选项 参数  &…

    Linux干货 2016-10-23
  • 用户和组的相关配置文件

      用户,是计算机识别使用者身份的一种唯一使用标识。 而现实生活中为了方便人类记忆使用等,用户名往往是用便于人类识别的语言来记录的。但事实上计算机并不对人类语言敏感,所以有必要把人类语言跟机器语言对应上。于是,linux给每一个创建用户提供了一个UID。当使用用户名登录时,系统换自动对应UID来识别该用户身份。 而用户名与UID的对应信息就储存在一…

    Linux干货 2016-10-23
  • 用户和用户组相关的配置文件

    用户和用户组相关的配置文件 一、与用户相关的配置文件 一般来说,与用户配置相关的几个文件如下: l  /etc/passwd: 最重要的文件,存储着用户的用户名,UID,Shell等信息 l  /etc/shadow: 用户密码文件,使用sha-1算法加密存储(注意该文件的权限) l  /etc/skel/: 用户的模板文件,新…

    Linux干货 2016-10-23
  • 26期全程班-第一周博客作业

    1、描述计算机的组成与功能。 计算机由以下五大单元组成: 一:CPU的算法计算和逻辑判断单元; 二:CPU的控制单元;协调各设备协同工作。 三:内存:RAM(random accace memory)随机读取内存;数据处理的必经路段。 四:输入设备:键盘、鼠标等;负责数据的输入。 五:输出设备:屏幕、终端、文件、硬盘等;负责数据的输出 2、按系列罗列Linu…

    Linux干货 2016-12-30
  • 第四周 N28 (用户及权限管理及BRE、ERE应用)

    1、复制/etc/skel目录为/home/tuser1,要求/home/tuser1及其内部文件的属组和其它用户均没有任何访问权限。 # cp -r /etc/skel /home/tuser1 # chmod -R og= /home/tuser1 2、编辑/etc/group文件,添加组hadoop。 hadoop:x:1000: 3、手动编辑/etc…

    2017-12-22
  • Xtrabackup进行MySQL备份

    使用Xtrabackup进行MySQL备份 一、安装 1、简介 Xtrabackup是由percona提供的mysql数据库备份工具,据官方介绍,这也是世界上惟一一款开源的能够对innodb和xtradb数据库进行热备的工具。 特点: (1)备份过程快速、可靠; (2)备份过程不会打断正在执行的事务; (3)能够基于压缩等功能节约磁盘空间和流量; (4)自动…

    Linux干货 2017-02-20