设为首页 收藏本站
查看: 472|回复: 0

[经验分享] Create Soft Raid On RedHat Linux

[复制链接]

尚未签到

发表于 2018-5-12 06:44:51 | 显示全部楼层 |阅读模式

  • #!/bin/sh
  • #
  • #Author:jacky.lee
  • #date:2010/4/17
  • #This scripts create soft raid 0,1,5,6,10
  • #The test platform on redhat linux.                                                                          
  • #define main function
  • main () {
  •     clear
  •     echo '          ------------------------------------------------------          '
  •     echo '          1.Create a software raid array          '
  •     echo '          2.View raid array sync status           '
  •     echo '          3.View raid array detail            '
  •     echo '          4.Create mdadm.conf file            '
  •     echo '          5.Add hotspare device on raid array     '
  •     echo '          6.Replace a fault device on raid array      '
  •     echo '          7.Delete a software raid array          '
  •     echo '          8.Renaming a raid array             '
  •     echo '          9.Resync raid array             '
  •     echo '          q,exit                      '
  •     echo '          ------------------------------------------------------          '   
  •     while true
  •         do
  •         echo -n "   Please choice [1-q]:"
  •         read choice
  •         case $choice in
  •             1)
  •             create_raid
  •             sleep 10
  •             clear
  •             main
  •             ;;
  •             2)
  •             view_sync
  •             clear
  •             main
  •             ;;
  •             3)
  •             view_detail
  •             sleep 10
  •             clear
  •             main
  •             ;;
  •             4)
  •             create_configure_file
  •             sleep 3
  •             clear
  •             main
  •             ;;
  •             5)
  •             add_hot
  •             sleep 10
  •             clear
  •             main
  •             ;;
  •             6)
  •             view_detail
  •             sleep 5
  •             rep_dev
  •             clear
  •             main
  •             ;;
  •             7)
  •             del_rd
  •             clear
  •             main
  •             ;;
  •             8)
  •             ren_rd
  •             view_detail
  •             sleep 5
  •             clear
  •             main
  •             ;;
  •             9)
  •             res_rd
  •             clear
  •             view_sync
  •             clear
  •             main
  •             ;;
  •             q)
  •             exit
  •             ;;
  •         esac
  •         done
  • }

  • #create raid
  • create_raid (){
  •     if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
  •         echo
  •         echo "Please input the name:[like:md0,md1....]"
  •         read name
  •         echo
  •         echo "which level do you want to create it?[0,1,5,6]"
  •         echo "The level 0 and 1 at least 2 device,The level 5 at least 3 device,level 6 at least 4."
  •         read level
  •         echo
  •         echo "How many device for use?"
  •         read num
  •         echo "The device name like:/dev/sda,/dev/sda1,/dev/sd[abcd],/dev/sd[abcd]1"
  •         echo "Please input the device name:"
  •         read input
  •         mdadm -C /dev/$name -l$level -n$num $input
  •     fi
  •     }

  • #view sync status
  • view_sync () {
  •     if [ -e /proc/mdstat ]&&[ -r /proc/mdstat ];then
  •         watch -n .2  'cat /proc/mdstat'
  •     fi
  •     }

  • #view detail of md information
  • view_detail () {
  •     if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
  •         echo "which md device you want to view detail:"
  •         read input
  •         if [ $input=`grep $input /proc/mdstat |awk '{print $1}'` ];then
  •             mdadm --detail /dev/$input
  •         else
  •             sleep 5
  •         fi
  •     fi
  •     }

  • #create mdadm configure file
  • create_configure_file () {
  •     if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
  •         echo "The mdadm.conf file default location is /etc."
  •         mdadm --examine --scan >/etc/mdadm.conf
  •         echo "The mdadm.conf file content by follow:"
  •             cat /etc/mdadm.conf
  •     fi
  •     }

  • #add hotspare device
  • add_hot () {
  •     if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
  •         echo "which md do you for add a hotspare device?"   
  •         read name
  •         echo "which device you want set a hotspare?"
  •         read device
  •         mdadm /dev/$name -a $device
  •         mdadm --detail /dev/$name
  •     fi
  •     }

  • #remove a fault device
  • rep_dev () {
  •     if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
  •         echo "Which device you want to remove?"
  •         read device1
  •         echo "Which device you want to add?"
  •         read device2
  •         mdadm -r $device1 -a $device2
  •     fi
  •     }
  •      

  • #delete a raid
  • del_rd () {
  •     echo "First,stop all I/O access on md devices."
  •     if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
  •         echo "Which md do you want to delete?"
  •         read md
  •         mdadm -S /dev/$md
  •         echo "Please input the device name:"
  •         read name
  •         mdadm --misc --zero-superblock $name
  •     fi
  •     }   
  • #renaming a raid array
  • ren_rd () {
  •     echo "First,you must stop the raid array!"
  •     if [ -e /sbin/mdadm ]&&[ -x /sbin/mdadm ];then
  •         echo "Which md do you want stop?"
  •         read md
  •         mdadm -S /dev/$md
  •         echo "What's the new md name?"
  •         read name
  •         echo "What's the device name on the old md?"
  •         read device
  •         mdadm --assemble /dev/$name  --super-minor=0 --update=super-minor $device
  •     fi
  •     }

  • #resync a raid array
  • res_rd  () {
  •     echo "Which raid array need resync?"
  •     read input
  •     if [ -e /sys/block/$input/md/sync_action ]&&[ -f /sys/block/$input/md/sync_action ];then
  •     echo check >/sys/block/$input/md/sync_action
  •     fi
  •     }
  • #Calling main function
  • main

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-458865-1-1.html 上篇帖子: linux redhat5+11g 下篇帖子: vmware 下redhat 6 无法上网
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表