Raid
Performance of disks
1.定位 2.旋转 3.命令队列 4.数据库传输
HBA: Host-based adapter
Raid:redundent array of inexpensive Disks inexpensive disk array
Independent Standalone disk array
Level: Only used to identify the different ways of disk composition, can not replace data backup
raid0:提高读写性能,没有容错能力。至少需要两块磁盘 100% raid1:至少需要两块硬盘,镜像,硬件容错能力,读性能提升,写性能下降 50% raid4:至少需要三块硬盘,允许一块盘出错,读写性能提升,(n-1)/n raid5: 至少需要三块硬盘,允许一块盘出错,读写性能提升,(n-1)/n raid6: 至少需要四块磁盘,允许两块盘出错。读写性能提升,(n-2)/n raid10:至少需要四块磁盘。允许不同组内个各坏一块盘,读写性能提升,50% raid01: jbod:两个盘结合起来当一个盘用,写完一个盘写另外一个。
MD, any block device can be combined
命令的配置文件: mdadm,/etc/mdadm.conf
Mdadm: a modular tool
-A Assemble 装配模式-C Create 创建模式 -n #:用于创建RAID设备的个数 -x #: 热备磁盘的个数 -l :指定RAID级别 -a :=yes(自动为创建的RAID设备创建设备文件) md mdp part p 如何创建设备文件 -c:指定块的大小,默认为512KB-F FOLLOW 监控-S 停止RAID-D --detail: 显示阵列详细信息
Create a raid0:2*6g,3*4g 4*3g with a size of 12G 6*2g
mdadm -C /dev/md0 -a yes -l 0 -n 2 /dev/sdb{1,2}
Watch ' '
-n #:每个#执行一次指定的命令,单位为s
Issue one: mdadm-c/dev/md0-a yes-l 0-n 2/dev/sdb{1,2}
mdadm: cannot open /dev/sdb1: Device or resource busy
Exercise: Create a RAID5 of size 4G that requires a free disk directly
Bash knowledge points: while loops and until loops
For loop
for varName in 列表;do 循环体 done
Condition test:
执行条件:命令成功,条件测试成功;否则为失败根据$?,状态返回值
An expression:
[ expreession ] [[ expression ]] test expression
While loop
while 条件测试:do 循环体 done
How do I exit?
必须有时刻,条件测试不成功 ? :条件控制变量
Exercise: To find all positive integers within 100 and
sum=0 i=1 while [ $i -le 100 ];do let sum+=$i let i++ done echo $sum
Exercise: The keyboard prompts the user to enter characters, the user input lowercase letters converted to uppercase, after conversion, remind again, then lose and then convert, and then enter quit
while [[ "$word" != "quit" ]];do echo $word | tr "a-z" "A-z" read -p "Enter a word again:" word done
Until:
bash编程之until循环; until 测试条件;do 循环体 done 条件不满足,则循环;否则,退出
Bash programming combines test conditions in depth
Logic and: Multiple conditions satisfy simultaneously
[ 条件1 ] && [ 条件2 ] [ 条件1 -a 条件2 ] [[ 条件1 && 条件2 ]] 注意:前两个使用单双中括号都可,但&&不允许用于单个中括号中,所有第三者只能用于双中括号中
Logical OR: Multiple conditions satisfy a
[ 条件1 ] || [ 条件2 ] [ 条件1 -o 条件2 ] [[ 条件1 || 条件2 ]] 注意 || 不允许出现在单中括号中
Morgan's law.
!(条件1或者 条件2) = !条件1 并且!条件2 !(条件1且条件2)=!条件1 或者 !条件2
Practice
Exercise: Prompt the user to enter a user name, if present, display the user UID and shell information, if not present, show no such user; After the display is complete, prompt the user to enter again, if quit is quit
#!/bin/bash # read -p "Enter input name:" username while [[ $username != "quit" ]];do if id $username &>/dev/null;then grep "^$username\>" /etc/passwd | cut -d: -f3,7 else echo "No such user." fi read -p "Enter a user name again(quit to exit):" username done
Exercise: Provide the user input a user name, determine whether the user is logged in the current system, if not logged in and stop 5 seconds after the judgment, until the user logged on to the system, the user is displayed, and then quit
#!/bin/bash # read -p "Enter a user name :" userName while ! id $userName &> /dev/null;do read -p "Enter a user name again :" userName done who | grep "^$userName" &>/dev/null retVal=$? while [ $retVal -ne 0 ];do sleep 5 who | grep "^$userName" &>/dev/null retVal=$? done echo "$userName is on"
Exercise: Write a script that accomplishes the following tasks
1. Prompt the user to enter a disk device file path does not exist or is not a block device, the user is prompted to re-enter, know that the input is correct, or enter quit to 9 as the exit Code end script
2. Prompt the user "the following action will erase the disk's data and ask whether to continue"
If the user gives the character Y or Yes, continue, otherwise the end script is provided with 8 as the exit code
3. Empty the partition on the user-specified disk and create two partitions, 100M and 512M, respectively
4 Format the two partitions
5 mount the first partition to the/mnt/boot directory, and the second partition to the/mnt/sysroot directory
#!/bin/bash read -p "Enter you dev " devdir umonut /mnt/boot umonut /mnt/sysroot while [[ "$devdir" != "quit" ]];do [ -a $devdir ] && [ -b $devdir ] if [[ $? -eq 0 ]];then read -p "Are you sure[y|yes]: " option if [[ "$option" == "y" || "$option" == "yes" ]];then dd if=/dev/zero of=$devdir bs=512 count=1 &> /dev/null echo -e "n\np\n1\n\n+100M\nn\np\n2\n\n+512M\nw" |fdisk $devdir mke2fs -t ext4 ${devdir}1 mke2fs -t ext4 ${devdir}2 mount ${devdir}1 /mnt/boot mount ${devdir}2 /mnt/sysroot echo "${devdir}1 /mnt/boot ext4 default 0 0" >> /etc/fstab echo "${devdir}2 /mnt/sysroot ext4 default 0 0" >> /etc/fstab exit 7 else exit 8 fi else read -p "Enter you dev again: " devdir fi done
Lvm:logical Volume Manager, combine multiple pieces of equipment into one to use
Device files
/dev/卷组名/逻辑卷名 /dev/mapper/卷组名-逻辑卷名
Physical Volume command command: PV
pvcreate pvremove psdisplay pvscan pvs pvmove(移动数据) pvcreate 物理卷
Management commands for volume groups: VG
vgcreate vgscan vgs vgextend(扩充)、vgremove(删除) vgreduce(移除,缩容)vgcreate -s:pe大小,默认4M
Management commands for logical volumes: LV
lvcreate lvscan lvs lvextend(扩充)、lvremove(删除) vgreduce(移除,缩容) lvcreate -n:指定名称 -L: 指定大小 -l:%vg|pvs|FREE,打算分配%
Steps for Logical Volume expansion:
1.先确保扩展的大小;并确保所属的卷组有足够的剩余空间 2、扩展物理边界 lvextend -L [+]size /path/to/lv_device 3、扩展逻辑边界 resize2fs /path/to/lv_devive
Steps to reduce a logical volume:
1、卸载卷,并执行强制检查 e2fsck -f /path/to/lv_devive 2、缩减逻辑边界 resize2fs /path/to/lv_device SIZE 3、缩减物理边界: lvreduce -L [-]size /path/to/lv_device 4、挂载卷
Snapshot Volume:
也是逻辑卷的一种,提供过去某一时间的元卷的通道 lvcreate -s -L Size -n name 卷组名 -p r,rw /path/to/lv_devsive -p:访问权限
To extend a volume group:
1.准备要添加的物理卷 2 扩展卷组: 添加物理卷至卷组中 vgextend vg_name /path/to/device
To shrink a volume group:
1.确定要移除的物理卷的总空间大小,要小于VG当前的可用空间大小2.将要移除的物理卷上的所有pe移动至其他PV pvmove /path/to/pv_device3.缩减vg #vgreduce vg_name /path/to/pv/device
Practice:
1, the creation of a two physical volume composed of 20G volume group MYVG, requires PE size 16M, and then the new size of the 7G logical volume MYLV1, the file system is required to EXT4, the block size is 2048, and the boot can automatically mount to/users;
2, new user OpenStack, whose home directory is/users/openstack, then switch to OpenStack users, copy some files to their home directory;
3, reduce MYLV1 to 5G size, and then switch to OpenStack users to ensure that their data is not lost;
e2fsck -f /dev/myvg/mylv1
4, create snapshot volume Snap-mylv1 to Mylv1, and through its backup data to/tmp/user.tar.bz2;
lvcreate -s -n snap-mylv1 -L 200M /dev/myvg/mylv1 tar -jcf /tmp/user.tar.bz2 /tmp/*
Linux Learning log (vii)