Clusterware Console脚本分享

1,436 Views
『作者:RickyZhu 转载务必注明出处和作者』
Tag:,

做Clusterware和RAC的测试的时候,节点多的时候,需要不停的在节点之间切换,而且容易出错,于是写了这样一个脚本,跟大家分享一下。
目前主要完成一些简单的功能,支持的平台有Linux,Solaris, AIX and HP,打算继续扩展。也欢迎使用并提出意见,

  1.  
  2. [ractest@sun880-1 ~]$ more console
  3. #!/bin/bash
  4.  
  5. #This script is used to control the whole cluster nodes in one interface
  6.  
  7. echo "******************************************************************"
  8. echo "                  Welcome to Cluster Console                      "
  9. echo "                                                                  "
  10. echo "The console is used to control the whole cluster nodes in one node"
  11. echo "now it can support start/stop stack,check stack status, process   "
  12. echo "priority, check node uptime and will support more in the future   "
  13. echo "                                                                  "
  14. echo "  Any bug or comment please report to ricky.zhu@gmail.com        "
  15. echo "******************************************************************"
  16.  
  17. get_nodename () {
  18.   $CH/bin/olsnodes -n > tmp
  19.   name=`head -n $1 tmp | tail -1 | awk ‘{print $1}’`
  20.   echo "$name"
  21. }
  22. check_uptime() {
  23.  
  24.   nl=`$CH/bin/olsnodes `
  25.   for node in $nl
  26.   do
  27.     echo "node=$node"
  28.     $RSH $node "hostname; date; /usr/bin/uptime"
  29.   done
  30. }
  31.  
  32. UNAME=‘/bin/uname’
  33. PLATFORM=`$UNAME`
  34. <a id="more-444"></a>
  35. case $PLATFORM in
  36. SunOS)
  37.   RSH=/usr/bin/rsh
  38.   SSH=/usr/bin/ssh
  39.   GREP=/usr/xpg4/bin/grep
  40.   PSEF="/usr/bin/ps -cafe"
  41.   ;;
  42. Linux)
  43.   RSH=/usr/bin/rsh
  44.   SSH=/usr/bin/ssh
  45.   GREP=/bin/grep
  46.   PSEF="/bin/ps -cafe"
  47.   ;;
  48. HP-UX)
  49.   RSH=/usr/bin/remsh
  50.   SSH=/usr/bin/ssh
  51.   GREP=/usr/bin/grep
  52.   PSEF="/usr/bin/ps -afe"
  53.   CH=$CRS_HOME
  54.   ;;
  55. AIX)
  56.   RSH=/bin/rsh
  57.   SSH=/bin/ssh
  58.   GREP=/bin/grep
  59.   PSEF="/bin/ps -afe"
  60.   CH=$CRS_HOME
  61.   ;;
  62. esac
  63.  
  64.  
  65. nodelist=`$CH/bin/olsnodes`
  66. nl="$nodelist All"
  67.  
  68. PS3="Please select node: "
  69. TITLE="\******************************************************************/"
  70.  
  71. select node in $nl
  72. do
  73.     PS3="Please select command: "
  74. #    name=`get_nodename $node`
  75.     name=$node
  76.  
  77.     if [[ $node == "All"  ]]
  78.     then
  79.         select command in "Start the crs stack" "Stop the crs stack" "Back" "Quit"
  80.         do
  81.           case $command in
  82.           "Start the crs stack")
  83.             echo $TITLE
  84.             echo "Now to start crs on node: $name"
  85.             for name in $nodelist
  86.             do
  87.                 $RSH $name "hostname; date; $CH/bin/crsctl start crs"
  88.             done
  89.             echo $TITLE
  90.             ;;
  91.           "Stop the crs stack")
  92.             echo $TITLE
  93.             echo "Now to stop crs on node: $name"
  94.             for name in $nodelist
  95.             do
  96.                 $RSH $name "hostname; date; $CH/bin/crsctl stop crs"
  97.             done
  98.             echo $TITLE
  99.             ;;
  100.           "Back")
  101.             PS3="Please select node: "
  102.             echo "Back to cluster node list"
  103.             break
  104.             ;;
  105.           Quit)
  106.             echo "Quit. Thanks for using."
  107.             exit 0
  108.             ;;
  109.           esac
  110.         done
  111.     fi
  112.  
  113.     $RSH $name date
  114.     if [[ $? == 0 ]]
  115.     then
  116.       RSH=$RSH
  117.     else
  118.       RSH=$SSH
  119.     fi
  120.  
  121.  
  122.     select command in "Start the crs stack" "Stop the crs stack" "Check stack status" "Check process priority" "Check node uptime" "
  123. Back to nodelist" "User command" "Enable the crs next reboot" "Disable the crs next reboot" "Stop ASM instance" "Start ASM instance"
  124.  "Start nodeapps" "Stop nodeapps" "Start listener" "Stop listener" "Quit"
  125.     do
  126.       case $command in
  127.       "Start the crs stack")
  128.         echo $TITLE
  129.         echo "Now to start crs on node: $name"
  130.         $RSH $name "hostname; date; $CH/bin/crsctl start crs"
  131.         echo $TITLE
  132.         ;;
  133.       "Stop the crs stack")
  134.         echo $TITLE
  135.         echo "Now to stop crs on node: $name"
  136.         $RSH $name "hostname; date; $CH/bin/crsctl stop crs"
  137.         echo $TITLE
  138.         ;;
  139.       "Check stack status")
  140.         echo $TITLE
  141.         echo "Now to check crs on node: $name"
  142.         $RSH $name "hostname; date; $CH/bin/crs_stat -t -v"
  143.         echo $TITLE
  144.         ;;
  145.       "Check process priority")
  146.         echo $TITLE
  147.         echo "Now check priority on node: $name"
  148.         $RSH $name "hostname;date; $PSEF | $GREP -e lmon -e dlm -e ucmm -e ocssd.bin -e oclsomon -e oprocd -e oclsvmon -e lms -e lmo
  149. n | $GREP -v grep | $GREP -v tail"
  150.         echo $TITLE
  151.         ;;
  152.       "Check node uptime")
  153.         echo $TITLE
  154.         echo "Now check all node uptime"
  155.         check_uptime;
  156.         echo $TITLE
  157.         ;;
  158.       "User command")
  159.         echo $TITLE
  160.         echo "Input your command"
  161.         read cmd
  162.         source .profile; $RSH $name "hostname; date; $cmd"
  163.         echo $TITLE
  164.         ;;
  165.       "Back to nodelist")
  166.         PS3="Please select node: "
  167.         echo "Back to cluster node list"
  168.         break
  169.         ;;
  170.       "Enable the crs next reboot")
  171.         echo $TITLE
  172.         echo "Now enable crs on next reboot on node: $name"
  173.         $RSH $name "hostname;date; /etc/init.d/init.crs enable"
  174.         echo $TITLE
  175.         ;;
  176.       "Disable the crs next reboot")
  177.         echo $TITLE
  178.         echo "Now disable crs on next reboot on node: $name"
  179.         $RSH $name "hostname;date; /etc/init.d/init.crs disable"
  180.         echo $TITLE
  181.         ;;
  182.       "Stop ASM instance")
  183.         echo $TITLE
  184.         echo "Now stop ASM instance on node: $name"
  185.         $RSH $name "hostname;date; $CH/bin/srvctl stop asm -n $name"
  186.         echo $TITLE
  187.         ;;
  188.       "Start ASM instance")
  189.         echo $TITLE
  190.         echo "Now start ASM instance on node: $name"
  191.         $RSH $name "hostname;date; $CH/bin/srvctl start asm -n $name"
  192.         echo $TITLE
  193.         ;;
  194.       "Start nodeapps")
  195.         echo $TITLE
  196.         echo "Now start nodeapps on node: $name"
  197.         $RSH $name "hostname;date; $CH/bin/srvctl start nodeapps -n $name"
  198.         echo $TITLE
  199.         ;;
  200.       "Stop nodeapps")
  201.         echo $TITLE
  202.         echo "Now stop nodeapps on node: $name"
  203.         $RSH $name "hostname;date; $CH/bin/srvctl stop nodeapps -n $name"
  204.         echo $TITLE
  205.         ;;
  206.       "Stop listener")
  207.         echo $TITLE
  208.         echo "Now stop listener on node: $name"
  209.         $RSH $name "hostname;date; $CH/bin/srvctl stop listener -n $name"
  210.         echo $TITLE
  211.         ;;
  212.       "Start listener")
  213.         echo $TITLE
  214.         echo "Now start listener on node: $name"
  215.         $RSH $name "hostname;date; $CH/bin/srvctl start listener -n $name"
  216.         echo $TITLE
  217.         ;;
  218.       Quit)
  219.         echo "Quit. Thanks for using."
  220.         exit 0
  221.         ;;
  222.       *)
  223.         echo "$REPLY is not one of your choice" 1>&2
  224.         ;;
  225.       esac
  226.     done
  227. done
  228.  

随机文章

沙发

(Required)
(Required, not published)


Close
E-mail It