Linux如何进行分区和目录管理

第七周作业

 

1、创建一个10G分区,并格式为ext4文件系统:

1、要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包括acl;

~]# mke2fs -t ext4 -b 2048 -m 2 -L MYDATA /dev/sdb1

2、挂载至/data/mydata目录,要求挂载时禁止程序自动运行,县不更新文件的访问时间戳;

~]# mkdir /data/mydata

~]# mount -o noexec,noatime,acl /dev/sdb1 /data/mydata

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

[root@yangjifeng ~]# fdisk /dev/sda

 

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): p

 

Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000658d7

 

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2             64        1370    10485760   83  Linux

/dev/sda3           1370        1892     4194304   82  Linux swap / Solaris

/dev/sda4           1892        6527    37235039+   5  Extended

/dev/sda5           1892        3197    10486783   83  Linux

 

Command (m for help): n

First cylinder (3198-6527, default 3198):

Using default value 3198

Last cylinder, +cylinders or +size{K,M,G} (3198-6527, default 6527): +1G

 

Command (m for help): p

 

Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000658d7

 

Device Boot    Start         End      Blocks   Id  System

/dev/sda1   *           1          64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2             64        1370    10485760   83  Linux

/dev/sda3           1370        1892     4194304   82  Linux swap / Solaris

/dev/sda4           1892        6527    37235039+   5  Extended

/dev/sda5           1892        3197    10486783   83  Linux

/dev/sda6           3198        3329     1060258+  83  Linux

 

Command (m for help): t

Partition number (1-6): 6

Hex code (type L to list codes): 82

Changed system type of partition 6 to 82 (Linux swap / Solaris)

 

Command (m for help): p

 

Disk /dev/sda: 53.7 GB, 53687091200 bytes

255 heads, 63 sectors/track, 6527 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: 0x000658d7

 

Device Boot      Start         End      Blocks   Id  System

/dev/sda1   *           1        64      512000   83  Linux

Partition 1 does not end on cylinder boundary.

/dev/sda2             64        1370    10485760   83  Linux

/dev/sda3           1370        1892     4194304   82  Linux swap / Solaris

/dev/sda4           1892        6527    37235039+   5  Extended

/dev/sda5           1892        3197    10486783   83  Linux

/dev/sda6           3198        3329     1060258+  82  Linux swap / Solaris

 

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.

~]# partx -a /dev/sda

3、写一个脚本:

1、获取并列出妆前系统上的所有磁盘设备;

2、显示每个磁盘设备上的分区相关的空间使用信息;

[root@yangjifeng scripts]# vim aboutdisk.sh

 

#!/bin/bash

#

FILESYSTEM=`fdisk -l|grep -o ‘/dev/s[hd][a-z]\>’`

 

for i in $FILESYSTEM;do

 

echo -e  “\033[31m disk : $i \033[0m”

 

echo

 

df -h|egrep “文件系统|Filesystem|$i”

 

echo “——————————————”

 

 

done

[root@yangjifeng scripts]# chmod +x aboutdisk.sh

[root@yangjifeng scripts]# ./aboutdisk.sh

4、总结RAID的各个级别及其组合方式和性能的不同;

    RAID:Redundant Arrays of Inexpensive Disks

RAID级别:RAID0,RAID1,RAID5,RAID10,RAID01,RAID6,RAID50,RAID60

RAID-0

  • 条带卷
  • 至少需要两块磁盘并行处理,将数据分两部分读写
  • 读写性能提高,raid中性能最高
  • 无容错性
  • 可用空间:N*min(s1,s2,…)

RAID-1

  • 镜像卷
  • 至少需要两块磁盘,两块磁盘存储相同数据,用于备份
  • 读写性能相当于一块独立磁盘,无提升
  • 容错性高,raid中容错性最高
  • 可用空间1*min(s1,s2,…)

RAID-4

  • 至少三块磁盘
  • 两块磁盘做数据存储,第三块用作独立存储数据校验码
  • 读写性能提高
  • 有容错性为一块磁盘

RAID-5

  • 至少三块磁盘
  • 三块磁盘存储数据及校验码,校验码分别存储在三个磁盘上
  • 读写性能提高
  • 有容错性为一块磁盘
  • 可用空间:(N-1)*min(s1,s2,…)

RAID-6

  • 至少四块磁盘
  • 增加第二个独立的奇偶校验信息块,分别以不同算法计算
  • 有容错性为两块磁盘
  • 可用空间:(N-2)*min(s1,s2,…)

RAID-10

  • 至少四块磁盘
  • 两两磁盘分别做raid1,再将两raid1阵列做raid0
  • 读写性能提高
  • 有容错性为两块,不同raid1中最多损失一块
  • 可用空间:N*min(s1,s2,…)/2

RAID-50

  • 至少六块磁盘
  • 三三磁盘分别做raid5,再将两raid5阵列做raid0
  • 读写能力提高
  • 有容错性为两块磁盘,不同raid5中做多损失一块磁盘

RAID-60

  • 至少八块磁盘
  • 四四磁盘分别做raid6,再将两raid6阵列做raid0
  • 读写能力提高
  • 有容错性为四块磁盘,不同raid6中最多损坏两块磁盘

 

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

~]# mdadm -C /dev/md1 -n 2 -x 1 -c 128 -l 1 /dev/sdb2 /dev/sdb3 /dev/sdb4

     ~]# mdadm -D /dev/md1

 

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

 ~]# mdadm -C /dev/md5 -n 3 -c 256 -l 5 /dev/sdb1 /dev/sdb2 /dev/sdb3

     ~]# mdadm -D /dev/md5

     ~]# mkfs -t ext4 /dev/md5

     ~]# mount -o auto,acl,noatime /dev/md5 /backup

 

7、写一个脚本:

1、接受一个以上文件路径作为参数;

2、显示每个拥有的行数;

3、总结说明本次共为几个文件统计了其行数;

scripts]# vim filelines.sh

#!/bin/bash

#

SUM=0

[ $# -lt 1 ] && echo “Son,you must input something” && exit 2

 

for file in $@;do

 

if [ -f $file ];then

 

LINES=`cat $file |wc -l`

 

echo “$file have $LINES lines”

 

let SUM=$SUM+$LINES

else

echo “$file is not exist”

fi

done

echo “$@ have $SUM lines in total.”

scripts]# chmod +x filelines.sh

scripts]# ./filelines.sh /etc/issue /etc/rc.d/init.d/functions

/etc/issue have 3 lines

/etc/rc.d/init.d/functions have 815 lines

/etc/issue /etc/rc.d/init.d/functions have 818 lines in total.

8、写一个脚本:

1、传递两个以上字符串当作用户名;

2、创建这些用户,且密码同用户名;

3、总结说明共创建几个用户;

#!/bin/bash

#

SUM=0

 

[ $# -lt 1 ] && echo “Son,you are wrong” && exit 2

 

for string in $*;do

 

[ $(echo “$string” |wc -c) -le 3 ] && echo “$string less than 3 letters” && continue

 

if id $string &> /dev/null;then

 

echo “user $string is exist!”

 

else

useradd $string

 

echo “$string” |passwd –stdin $string &> /dev/null

 

echo “add user $string sucess!”

 

let SUM+=1

fi

done

 

echo “add $SUM users in total.”

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

scripts]# vim useradd1.sh

#!/bin/bash

#

SUM_UID=0

 

for((i=1;i<=20;i++));do

adduser visitor$i

UID1=`id -u visitor$i`

let SUM_UID+=$UID1

 

done

 

echo “ID intotle $SUM_UID”

[root@yangjifeng scripts]# chmod +x useradd1.sh

[root@yangjifeng scripts]# ./useradd1.sh

ID intotle 10290

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

(0)
上一篇 2017-09-18 11:01
下一篇 2017-09-18 11:52

相关推荐

  • grep常见应用实例

      在我们实际应用中,正则表达式的应用是非常广泛的,今天我就大家分享几个比较常见的正则表达式的应用实例,不周之处,还望高人多多指点!   一:使用正则表达式搜索邮箱地址 二:使用正则表达式搜索手机号 三:使用正则表达式搜索身份证号 四:使用正则表达式取网络配置文件中的IP地址的过程解析   一:使用正则表达式搜索邮箱地址: [r…

    系统运维 2016-08-08
  • mysqld_multi 多实例部署

    序言:多实例?Why?   随着硬件层面的发展,linux系统多核已经是普通趋势,而mysql是单进程多线程,所以先天上对多进程的利用不是很高,虽然5.6版本已经在这方面改进很多,但是也没有达到100%,所以为了充分的利用系统资源,mysql有自己的补充,那就是可以部署多实例,一个实例一个端口。     1,准备好mysql环境…

    2017-11-16
  • 在CentOS 7上实现私有CA及申请和吊销证书

    – 创建私有CA openssl的配置文件:/etc/pki/tls/openssl.cnf 42 dir     = /etc/pki/CA       # Where everythi…

    Linux干货 2016-12-01
  • 马哥教育网络班N22期+第8周课程练习

    1、请描述网桥、集线器、二层交换机、三层交换机、路由器的功能、使用场景与区别。 网桥:是连接两个局域网的基于MAC地址数据存储转发设备,工作于数据链路层集线器:所有端口处于同一个广播域和冲突域中,带宽共享,工作于物理层二层交换机:多端口网桥,一个端口一个冲突域,默认所有端口位于同一个广播域中,可以划分vlan,隔离广播域,带宽独享三层交换机:具有路由功能的二…

    Linux干货 2016-10-19
  • 堡垒机-麒麟堡垒机动态口令使用手册

      一.管理员部分 1.在其它-licenses菜单查看动态口令许可是否打开,如果未打开联系厂商重新生成许可   2.找厂商生成密钥文件,密钥文件中包含令牌种子,在其它–动态令牌菜单将密钥文件导入即可看到所有的令牌种子,每个令牌可以绑定给多个用户     3.令牌绑定可以在 资源管理–…

    安全运维 2016-05-29
  • vsftpd 配置文件的一些设置

    ftp:File Transfer protocol 文件传输协议 两个连接: tcp:命令连接 tcp:数据连接 主动模式:服务器端通过20端口主动连接客户端,客户端监听在于服务器端的建立连接的端口+1上,服务器工作在tcp/20 被动模式:客户端使用自己与服务器端建立端口+1上连接客户端的随机端口 防火墙上连接追踪 数据要流失化文本:文件流二进制 c/s…

    Linux干货 2017-09-10