磁盘管理,软raid,脚本基础

1、创建一个10G分区,并格式为ext4文件系统;
(1) 要求其block大小为2048, 预留空间百分比为2, 卷标为MYDATA, 默认挂载属性包含acl;
mke2fs -t ext4 -L MYDATA -m 2 /dev/sdb
tune2fs -o acl /dev/sdb
(2) 挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳;
mount -o noatime,noexec /dev/sdb /data/mydata/
2、创建一个大小为1G的swap分区,并创建好文件系统,并启用之;
[root@centos6 data]# fdisk /dev/sdc
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 (1-130, default 1):
Using default value 1
Last cylinder, +cylinders or +size{K,M,G} (1-130, default 130):
Using default value 130
Command (m for help): t
Selected partition 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@centos6 data]# mkswap /dev/sdc2
Setting up swapspace version 1, size = 1044188 KiB
no label, UUID=55387a0a-4c17-4606-a46f-07226752ca5c
[root@centos6 data]# free -m
total used free shared buffers cached
Mem: 980 281 698 1 21 111
-/+ buffers/cache: 149 831
Swap: 2047 0 2047
[root@centos6 data]# swapon /dev/sdc2
[root@centos6 data]# free -m
total used free shared buffers cached
Mem: 980 282 698 1 21 111
-/+ buffers/cache: 149 830
Swap: 3067 0 3067
3、写一个脚本
(1)、获取并列出当前系统上的所有磁盘设备;
(2)、显示每个磁盘设备上每个分区相关的空间使用信息;
[root@centos6 data]# vi 3.sh
#!/bin/bash
#fileName:diskList.sh
#Author:jian
#Date:2017-10-16
#discription:
#print system all disks
echo “*****************print disk device**************”
fdisk -l |grep “^/dev/”
#print all disks partition
echo “*****************print disks partition***************”
df -h
4、总结RAID的各个级别及其组合方式和性能的不同
raid0:读写性能提升;可用空间:N*min;没用容错能力;最少需要两块磁盘。
raid1:读性能提升,写性能略有下降;可用空间:1*min;有容错能力;最少需要两块磁盘
raid5:读写性能提升,可用空间:(N-1)*min有容错能力:允许坏一块硬盘,最少需要3块磁盘
raid6:读写性能提升,可用空间:(N-2)*min;有容错能力,允许坏两块磁盘,最少需要4块磁盘。
raid10:读写性能提升;可用空间:N*min/2;容错能力为每组镜像最多只能坏一块硬盘。
5、创建一个大小为10G的raid1,要求有一个空闲的磁盘,而且chunk大小为128K
mdadm -C /dev/md0 -a yes -n 2 -x 1 -l 1 -c 128 /dev/sdb{5,6,7}
6、创建一个大小为4G的raid5设备,chunk大小为256K,格式化为ext4文件系统,要求开机可用挂载到backup目录。
mdadm -C /dev/md1 -l 5 -c 256 -n 3 /dev/sdb2 /dev/sdb3 /dev/sdb4
UUID=d2b263fa-2c68-4522-8e19-0ceef7686051 ext4 acl,noatime 0 0
7、写一个脚本
(1)接收一个文件路径
(2)显示每个文件拥有得行数;
(3)总结说明本次共为几个文件统计了其行数;
“`
#!bin/bash
#fileName:cuntLine.sh #Author:jian #DATA:2017-10-16 #discription: # declare -i sum=0; if [ $# -lt 1 ] then echo “please input path” exit 1; fi for i in $@ do if [ ! -f $i ];then echo “it is not a path”; exit 2; fi lines=$(wc -l $i); echo “filename:$i lines:$lines” let sum++ done echo “total files count is:$sum”
“`
8、写一个脚本
(1)传递两个以上字符串当作用户名;
(2)创建这些用户;且密码同用户名;
(3)总结说明共创建了几个用户;
“`
#!bin/bash
#fileName:useradd.sh
#Author:jian
#DATA:2017-10-16
#discription:
#
declare -i userCount=0;
if [ $# -lt 2 ]
then
echo “please input two string”
exit 1;
fi
for i in $@
do
id $i &> /dev/null
if [ $? -eq 0 ] ;then
echo “this user is exist”
else
useradd $i
echo $i | passwd –stdin $i &> /dev/null
echo “add $i successful!”
let userCount++;
fi
done
echo “add user:$userCount”
“`
写一个脚本,新建20个用户,vistitor1-vistitor20;计算他们之间得id之和
“`
#!bin/bash
#fileName:cuntLine.sh
#Author:jian
#DATA:2017-10-16
#discription:
#
if [ ! $(id -u) -eq 0 ];then
echo “no perminssion,must use root”
exit 2;
fi
declare -i userCount=0;
for i in {1..20};do
useradd vistitor$i;
echo “vistitor$i”|passwd –stdin vistitor$i &> /dev/null
echo “add vistitor$i”;
done
let userCount+=$(id -u vistitor$i);
echo “userid sum:$userCount”
“`

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

(0)
469008940469008940
上一篇 2017-10-25 18:42
下一篇 2017-10-26 13:01

相关推荐

  • Linux基础

    Linux入门以及文件重定向、用户管理、软件管理等

    Linux干货 2018-03-17
  • 马哥教育21期网络班—第一周课程+练习

    计算机的组成及功能 根据冯·诺依曼原理 现在计算机有五部分组成 分别是:运算器、控制器、存储器、输入设备和输出设备 现在把运算器和控制器做到一块就是所谓的CPU CPU = 运算器+控制器 存储器:memory 用于存储信息的记忆设备,存储器分为ROM和RAM 编址存储设备 ROM:只读存储器,寻址地址空间的组成部分 RAM:随机存储器 输入和输出设备: 输…

    Linux干货 2016-06-26
  • 程序包管理:rpm、yum以及(make)源代码编译安装

    程序包管理:rpm、yum以及(make)源代码编译安装 在Linux上安装程序一般都有三种方法:源代码编译安装,rpm包安装和rpm包的前端安装yum, (rpm,和yum程序包管理器是针对CentOS6平台的) 程序包管理方式都大同小异:  源代码–>目标二进制格式(二进制程序、库文件、配置文件、帮助文件)–&gt…

    Linux干货 2017-01-10
  • N22-妙手-第二周博客作业

    1、Linux上的文件管理类命令都有哪些,其常用的使用方法及其相关示例演示     mkdir: 创建目录         使用方法:mkdir [OPTION]… DIRECTORY…   &n…

    Linux干货 2016-08-29
  • N21天天第十四周课程练习

    系统的INPUT和OUTPUT默认策略为DROP; #把默认策略设置为DROP [root@localhost ~]# iptables -P INPUT DROP [root@localhost ~]# iptables -P OUTPUT DROP 1、限…

    Linux干货 2016-12-05
  • Linux基础知识——SHELL之循环

    1、写一个脚本,判断当前系统用户shell是否都为可登陆shell(即非/sbin/nologin),分别计算两类用户的个数(通过比较字符串实现) #!/bin/bash #       check the user could login&nbsp…

    Linux干货 2016-12-13