Changeset 167 for nutchez-0.2/src


Ignore:
Timestamp:
Jun 8, 2010, 5:05:25 PM (14 years ago)
Author:
shunfa
Message:
  1. 新增function: debug_info(目的為列印訊息給開發者)
  2. 新增function: show_info(目的為列印訊息給使用者)
  3. 新增寫入mac至master:/home/nutchuser/nutchez/nutch_node
Location:
nutchez-0.2/src/test
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • nutchez-0.2/src/test/client_install

    r152 r167  
    1414# 需要 master_install 設定的參數區
    1515# Master IP here
    16 Master_IP_Address="a.a.a.a";
     16Master_IP_Address=192.168.56.101
    1717# Master Hostname here
    18 Master_Hostname="Master_Hostname";
     18Master_Hostname=shunfa-VBox1
    1919# 此檔自己用的參數區
    2020Linux_Distribution="";
     
    2424# 參數詢問
    2525yesno="no"
    26 echo -e "\n\033[31mYour master IP: $Master_IP_Address\033[0m"
     26show_info "Your master IP: $Master_IP_Address"
    2727read -p "Is this data cooect? (yes/no): " yesno
    2828             
    2929if [ "$yesno" == "yes" ] || [ "$yesno" == "y" ] ; then
    30     echo "These parameters are correct."
     30    show_info "These parameters are correct."
    3131else
    32     echo "Plz edit these parameters in this file."
     32    show_info "Please edit these parameters in this file."
    3333    exit
    3434fi
  • nutchez-0.2/src/test/client_install_func.sh

    r159 r167  
    88
    99# 正式版之後,記的將不必要的 echo 拿掉
     10function debug_info () {
     11  if [ $? -eq 0 ]; then
     12    echo -e "\033[1;35;40m info - $1 \033[0m"
     13  fi
     14}
     15
     16function show_info () {
     17  if [ $? -eq 0 ]; then
     18    echo -e "\033[1;32;40m $1 \033[0m"
     19  fi
     20}
    1021
    1122
     
    1324function check_root(){
    1425# 正式版後可拿掉此 echo
    15 echo -e "\n\033[31m= check_root (debug) =\033[0m"
    16 if [ $USER != "root" ]; then
    17     echo -e "\nPlz Change root to execute it!!!"
    18     exit
    19 fi
     26  debug_info "check_root"
     27  if [ $USER != "root" ]; then
     28    show_info "Please Change root to execute it!!!"
     29    exit
     30  fi
    2031# 正式版後可拿掉此 echo
    21 echo -e "Identify is root."
     32  show_info "Identify is root."
    2233}
    2334
     
    2536# 查出此主機的作業系統,以及版本
    2637function check_systemInfo(){
    27 echo -e "\n\033[31m= check_systemInfo (debug) =\033[0m"
    28 echo -e "\nYour system information are:"
     38  debug_info "check systemInfo"
     39  show_info "Your system information are:"
    2940Linux_Distribution=$(lsb_release -a 2> /dev/null | grep "Distributor ID:" | awk '{print $3}')
    3041Linux_Version=$(lsb_release -a 2> /dev/null | grep "Release" | awk '{print $2}')
    31 echo $Linux_Distribution , $Linux_Version
     42  show_info "$Linux_Distribution , $Linux_Version"
    3243}
    3344
     
    3546# 安裝需要的相依套件 (目前只支援 deb 套件的系統自動安裝,yum或其他套件系統的則需手動安裝)
    3647function install_packages(){
    37 # deb 系列系統
    38 echo -e "\n\033[31m= install_packages (debug) =\033[0m"
    39 echo -e "\nCheck dependent packages"
    40 if [ "$Linux_Distribution" == "Ubuntu" ] || [ "$Linux_Distribution" == "Debian" ] ;then
     48  # deb 系列系統
     49  debug_info "install_packages"
     50  debug_info "Check dependent packages"
     51  if [ "$Linux_Distribution" == "Ubuntu" ] || [ "$Linux_Distribution" == "Debian" ] ;then
    4152    echo -e "\nIt will install sime packages (expect, ssh, and dialog).\n"
    4253    aptitude install -y expect ssh dialog
    43 # rpm 系列系統
    44 elif [ "$Linux_Distribution" == "Fedora" ] || [ "$Linux_Distribution" == "CentOS" ] ;then
    45     echo -e "Plz install expect, ssh, and dialog."
    46     exit
    47 else
    48     echo -e "Plz install expect, ssh, and dialog."
    49     exit
    50 fi
     54  # rpm 系列系統
     55  elif [ "$Linux_Distribution" == "Fedora" ] || [ "$Linux_Distribution" == "CentOS" ] ;then
     56    show_info "Please install expect, ssh, and dialog."
     57    exit
     58  else
     59    show_info "Please install expect, ssh, and dialog."
     60    exit
     61  fi
    5162}
    5263
     
    5566# 目前先檢查是否有/opt/nutchez 這個資料夾即可
    5667function check_nez_installed(){
    57 echo -e "\n\033[31m= chcheck_nez_installed (debug) =\033[0m"
    58 if [ -d /opt/nutchez ]; then
    59     echo -e "\nSystem already had NutchEz."
    60     exit
    61 else
    62     echo -e "\nSystem does not has NutchEz."
    63 fi
     68  debug_info "chcheck_nez_installed"
     69  if [ -d /opt/nutchez ]; then
     70    show_info "System already had NutchEz."
     71    exit
     72  else
     73    show_info "System does not has NutchEz."
     74  fi
    6475}
    6576
     
    6980# (3)系統有安裝但Sun Java 在非預設路徑下 (4)以正確安裝 Sun JAVA 預設路徑下
    7081function check_sunJava(){
    71 echo -e "\n\033[31m= check_sunJava (debug) =\033[0m"
    72 echo -e "\nNutchEz need Sun Java JDK 1.6.x or above version"
    73 
    74 javaPath="/usr"
    75 yesno="no"
    76 choice="3"
    77 
    78     if [ -e $javaPath/bin/java ]; then
    79       JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
    80       JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
    81       awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
     82  debug_info "check_sunJava"
     83  debug_info "NutchEz need Sun Java JDK 1.6.x or above version"
     84
     85  javaPath="/usr"
     86  yesno="no"
     87  choice="3"
     88
     89  if [ -e $javaPath/bin/java ]; then
     90    JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
     91    JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
     92    awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
    8293   
    83         if [ "$JAVA_org" == "" ]; then
    84             echo "Java is not Sun version, plz install sun Java 1.6.X"
    85             echo -e "\nPlz input your choice: "
    86             echo "(1)System don't have Sun Java (2)Sun Java is in other path (3)Exit"
    87             read -p "plz input (1/2/3): " choice
    88             case $choice  in
    89                 "1")
    90                 echo -e "Plz install Sun Java manually!"
    91                 exit
    92                 ;;
    93                 "2")
    94                     read -p "Input Sun Java home path(ex. '/usr/lib/jvm/java-6-sun-1.6.0.12' or using default '/usr' ): " javaPath
    95                 ;;
    96                 "*")
    97                 exit
    98                 ;;
    99             esac
    100 
    101             if [ $choice == "2" ]; then
    102                 JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
    103                 JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
    104                 awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
    105                
    106                 if [ "$JAVA_org" == "" ]; then
    107                 echo -e "It is not Sun Java! Plz install Sun Java manually!"
    108                 exit
    109                 fi
     94  if [ "$JAVA_org" == "" ]; then
     95    show_info "Java is not Sun version, plz install sun Java 1.6.X"
     96    show_info "Please input your choice: "
     97    show_info "(1)System don't have Sun Java (2)Sun Java is in other path (3)Exit"
     98    read -p "plz input (1/2/3): " choice
     99    case $choice  in
     100      "1")
     101        show_info "Please install Sun Java manually!"
     102        exit
     103        ;;
     104      "2")
     105        read -p "Input Sun Java home path(ex. '/usr/lib/jvm/java-6-sun-1.6.0.12' or using default '/usr' ): " javaPath
     106        ;;
     107        "*")
     108        exit
     109        ;;
     110        esac
     111
     112        if [ $choice == "2" ]; then
     113          JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)")
     114          JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \
     115          awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2)
     116             
     117          if [ "$JAVA_org" == "" ]; then
     118            show_info "It is not Sun Java! Plz install Sun Java manually!"
     119            exit
    110120            fi
     121          fi
    111122        fi 
    112123
    113124      large16=$(echo "$JAVA_version >= 1.6" | bc)
    114125      if [ "${large16}" == 0 ]; then
    115           echo "Java version is too old (it need 1.6.X above)"
    116           exit
     126        show_info "Java version is too old (it need 1.6.X above)"
     127        exit
    117128      fi 
    118129     
    119       echo "System has Sun Java 1.6 above version."
    120   else
    121       echo "Plz install Sun JAVA 1.6.X or above version"
    122       exit
    123   fi
    124 
    125 unset JAVA_org
    126 unset JAVA_version
     130      show_info "System has Sun Java 1.6 above version."
     131  else
     132    show_info "Please install Sun JAVA 1.6.X or above version"
     133    exit
     134  fi
     135
     136  unset JAVA_org
     137  unset JAVA_version
    127138}
    128139
     
    130141# 檢查是否有安裝openssh, openssh-server
    131142function check_ssh(){
    132 echo -e "\n\033[31m= check_ssh (debug) =\033[0m"
    133 if [ -e /usr/bin/ssh ]; then
    134     echo -e "\nSystem has ssh."
    135 else
    136     echo "Plz install ssh."
    137     exit
    138 fi
    139 
    140 if [ -e /usr/sbin/sshd ]; then
    141     echo "System has ssh Server (sshd)."
    142 else
    143     echo "Plz install ssh Server (sshd)."
    144     exit
    145 fi
     143  debug_info "check_ssh"
     144  if [ -e /usr/bin/ssh ]; then
     145    show_info "System has ssh."
     146  else
     147    show_info "Please install ssh."
     148    exit
     149  fi
     150
     151  if [ -e /usr/sbin/sshd ]; then
     152    show_info "System has ssh Server (sshd)."
     153  else
     154    show_info "Please install ssh Server (sshd)."
     155    exit
     156  fi
    146157}
    147158
     
    149160# 檢查是否有安裝dialog
    150161function check_dialog(){
    151 echo -e "\n\033[31m= check_dialog (debug) =\033[0m"
    152 if [ -e /usr/bin/dialog ]; then
    153     echo -e "\nSystem has dialog."
    154 else
    155     echo "Plz install dialog."
    156     exit
    157 fi
     162  debug_info "check_dialog"
     163  if [ -e /usr/bin/dialog ]; then
     164    show_info "System has dialog."
     165  else
     166    show_info "Please install dialog."
     167    exit
     168  fi
    158169}
    159170
     
    163174# 此步驟若無法連到 master 則跳出
    164175function scp_master_nutchuser_sshkey(){
    165   echo -e "\n\033[31m= scp_master_nutchuser_sshkey (debug) =\033[0m"
    166   echo -e "mkdir -p /home/nutchuser/"
     176  debug_info "scp_master_nutchuser_sshkey"
     177  debug_info "mkdir -p /home/nutchuser/"
    167178  mkdir -p /home/nutchuser/.ssh/
    168179  rm -fr /home/nutchuser/.ssh/*
    169 
    170180  unset Nutchuser_Passwd2
    171181
    172   echo -e "scp nutchuser@$1:~/.ssh /home/nutchuser/"
     182  debug_info "scp nutchuser@$1:~/.ssh /home/nutchuser/"
    173183expect -c "spawn scp -r -o StrictHostKeyChecking=no nutchuser@$1:~/.ssh /home/nutchuser/
    174184expect \"*: \" { send \"$Nutchuser_Passwd\r\" }
     
    177187
    178188  if [ -e "/home/nutchuser/.ssh/authorized_keys" ]; then
    179         echo -e "\nscp correct."   
     189    show_info "scp correct."   
    180190    else
    181       echo -e "\nscp is error,\n(1)plz check nutchuser password in server\n(2)nutchuser's authorized_keys in server\n(3)server's network status"
    182       exit
    183     fi
     191      show_info "scp error,\n(1)plese check nutchuser password in server\n(2)nutchuser's authorized_keys in server\n(3)server's network status"
     192    exit
     193  fi
    184194  ssh-add /home/nutchuser/.ssh/id_rsa
    185   echo "chown -R nutchuser:nutchuser /home/nutchuser/.ssh"
     195  debug_info "chown -R nutchuser:nutchuser /home/nutchuser/.ssh"
    186196  chown -R nutchuser:nutchuser /home/nutchuser/.ssh
    187197}
    188 
    189198
    190199# 新增nutchuser 帳號時用 Nutchuser_Passwd 當密碼
    191200function creat_nutchuser_account(){
    192 echo -e "\n\033[31m= creat_nutchuser_account (debug) =\033[0m"
    193 
    194 while [ "$Nutchuser_Passwd" != "$Nutchuser_Passwd2" ]
    195 do
    196     echo -e "\n"
    197     read -sp "Plz input nutchuser password of master node: " Nutchuser_Passwd
    198     echo
    199     read -sp "plz input nutchuser password, again: " Nutchuser_Passwd2
    200     echo
     201  debug_info "creat_nutchuser_account"
     202  while [ "$Nutchuser_Passwd" != "$Nutchuser_Passwd2" ]
     203  do
     204      echo -e "\n"
     205      read -sp "Plz input nutchuser password of master node: " Nutchuser_Passwd
     206      echo
     207      read -sp "plz input nutchuser password, again: " Nutchuser_Passwd2
     208      echo
    201209        if [ "$Nutchuser_Passwd" == "$Nutchuser_Passwd2" ]; then
    202             echo "Two Passwords match."
     210          show_info "Two Passwords match."
    203211        else
    204             echo "Two passwords don't match, plz re-input nutchuser's password."
     212          show_info "Two passwords don't match, please re-input nutchuser's password."
    205213        fi
    206 done                                                                                                                                   
    207    
    208 unset Nutchuser_Passwd2
    209 
    210 if [ $(cat /etc/passwd | grep nutchuser) ]; then
    211     echo "System already has nutchuser, change nutchuser password."
     214  done                                                                                                                                   
     215  unset Nutchuser_Passwd2
     216
     217  if [ $(cat /etc/passwd | grep nutchuser) ]; then
     218    show_info "System already has nutchuser, change nutchuser password."
    212219    expect -c "spawn passwd nutchuser
    213220    set timeout 1
     
    217224    send \"$Nutchuser_Passwd\r\"
    218225    expect eof"
    219 else
    220     echo "Create nutchuser and change password."
    221     useradd -m nutchuser -s /bin/bash
    222     expect -c "spawn passwd nutchuser
    223     set timeout 1
    224     expect \"*: \"
    225     send \"$Nutchuser_Passwd\r\"
    226     expect \"*: \"
    227     send \"$Nutchuser_Passwd\r\"
    228     expect eof"
    229 fi
     226    else
     227      echo "Create nutchuser and change password."
     228      useradd -m nutchuser -s /bin/bash
     229      expect -c "spawn passwd nutchuser
     230      set timeout 1
     231      expect \"*: \"
     232      send \"$Nutchuser_Passwd\r\"
     233      expect \"*: \"
     234      send \"$Nutchuser_Passwd\r\"
     235      expect eof"
     236  fi
    230237}
    231238
     
    233240# 目前僅需做到能無礙的複製遠端的/opt/nutchez/到local的/opt/
    234241function scp_packages(){
    235   echo -e "\n\033[31m= scp_packages (debug) =\033[0m"
     242  debug_info "scp_packages"
    236243  mkdir /opt/nutchez
    237244  mkdir /var/nutchez
     
    240247  chmod 777 /opt/nutchez
    241248  #su nutchuser -c "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/opt/nutchez /opt/"
    242   echo "scp -r nutchuser@$1:/opt/nutchez/NutchezForClientOf_$Master_IP_Address.tar.gz /opt/nutchez/"
     249  debug_info "scp -r nutchuser@$1:/opt/nutchez/NutchezForClientOf_$Master_IP_Address.tar.gz /opt/nutchez/"
    243250  su nutchuser -c "scp -r -o StrictHostKeyChecking=no nutchuser@$1:/home/nutchuser/nutchez/source/NutchezForClientOf_$Master_IP_Address.tar.gz /home/nutchuser/nutchez/source"
    244251
    245   echo -e "\nchown -R nutchuser:nutchuser /opt/nutchez"
     252  debug_info "chown -R nutchuser:nutchuser /opt/nutchez"
    246253  chown -R nutchuser:nutchuser /opt/nutchez
    247254  chown -R nutchuser:nutchuser /var/nutchez
     
    252259
    253260function install_nutch_package(){
    254   echo -e "\n\033[31m= install_nutch_package (debug) =\033[0m"
     261  debug_info "install_nutch_package"
    255262  tar -zxvf /home/nutchuser/nutchez/source/NutchezForClientOf_$Master_IP_Address.tar.gz -C /opt/nutchez
    256263  sed -i '1a '$Master_IP_Address' '$Master_Hostname'' /etc/hosts
     
    260267
    261268function recall_hostname_ip(){
    262 echo -e "\n\033[31m= recall_hostname_ip (debug) =\033[0m"
    263 
    264 net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
    265 net_nu=$(echo $net_interfaces | wc -w)
    266 
    267 # 若只有一個 eth 時
    268 if [ "$net_nu" == "1" ]; then
    269 
    270 # ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
    271 net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
    272 net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
    273 echo "net_address is $net_address"
    274 echo "net_MacAddr is $net_MacAddr"
    275 
    276 # 若有多個 eth 時
    277 else
    278     declare -i i=1
    279     echo -e "\nSystem have multiple network device, which network use for this machine: "
     269  debug_info "recall_hostname_ip"
     270  net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
     271  net_nu=$(echo $net_interfaces | wc -w)
     272  # 若只有一個 eth 時
     273  if [ "$net_nu" == "1" ]; then
     274  # ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
     275  net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
     276  net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
     277  show_info "net_address is $net_address"
     278  show_info "net_MacAddr is $net_MacAddr"
     279
     280  # 若有多個 eth 時
     281    else
     282      declare -i i=1
     283      show_info "System have multiple network device, which network use for this machine: "
    280284       
    281     for net in $net_interfaces
    282         do 
    283             echo "($i)  $net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
    284             i=i+1
    285         done
     285      for net in $net_interfaces
     286      do 
     287        echo "($i)  $net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
     288        i=i+1
     289      done
    286290       
    287         read -p "Plz choice(1/2/3...): " net_choice
    288     if [ -z $net_choice ]; then
    289         net_choice=1
    290     fi   
    291 
    292     echo "choice is $net_choice"
    293     net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
    294     # config $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
    295     net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
    296     net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
    297     echo "net_address is $net_address"
    298     echo "net_MacAddr is $net_MacAddr"
    299 fi
    300 
    301 echo "ssh nutchuser@$1 echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/nutch_nodes"
    302 su nutchuser -c "ssh nutchuser@$1 echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/nutch_nodes"
     291      read -p "Please choice(1/2/3...): " net_choice
     292  if [ -z $net_choice ]; then
     293    net_choice=1
     294  fi   
     295
     296  show_info "choice is $net_choice"
     297  net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
     298  # config $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
     299  net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
     300  net_MacAddr=$(ifconfig $net_interface | grep 'HW' | sed 's/^.*HWaddr //g')
     301  show_info "net_address is $net_address"
     302  show_info "net_MacAddr is $net_MacAddr"
     303  fi
     304
     305  debug_info "ssh nutchuser@$1 echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/nutch_nodes"
     306  su nutchuser -c "ssh nutchuser@$1 echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/nutch_nodes"
    303307
    304308#su nutchuser -c expect -c "spawn ssh nutchuser@$1
Note: See TracChangeset for help on using the changeset viewer.