磁盘管理,软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

相关推荐

  • 企业实时同步方案—-Rsync+Sersync

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://nolinux.blog.51cto.com/4824967/1433623     在博文企业实时同步方案—-Sersync介绍中我们详细介绍了Sersync的原理,设计架构以及…

    Linux干货 2015-03-30
  • sed讲解与使用

            sed是一种流编辑器,它是文本处理中非常中的工具,能够完美的配合正则表达式使用,功能不同凡响。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理…

    Linux干货 2016-08-15
  • 文本处理工具基础应用

                                                      &nbsp…

    Linux干货 2016-08-07
  • 软件安装包的管理

    rpm安装包的管理 rpm的数据库( 公共) :/var/lib/rpm 程序包名称及版本 依赖关系 功能说明 包安装后生成的各文件路径及校验码信息 安装 rpm:{-i} -v:显示详细信息 -h:以#显示程序包管理执行进度 rpm -ivh PACKAGE_FILE … [install-options] –test :测试安装,但不真正执行安装过程 –…

    Linux干货 2017-04-23
  • DNS 正反向解析 主从配置

    我的环境是     192.168.1.130    主DNS      192.168.1.112    从DNS DNS 的安装包有bind bind-libs bind-utils 安…

    Linux干货 2016-01-05
  • mysql基础

      mysql基础 数据模型: 数据模型:层次模型、网状模型、关系模型、…… 关系模型: 二维关系:表     行:row, entity     列:colume, attribution 索引:数据结构,辅助完成数据查找;  &nbsp…

    Linux干货 2016-11-01