Changeset 164


Ignore:
Timestamp:
Jun 8, 2010, 3:22:23 PM (15 years ago)
Author:
shunfa
Message:
  1. 解決/etc/hosts問題
  2. 新增function: debug_info(), show_info()
  3. 目前測試尚無其他問題(ubuntu9.04@VritualBox?)
Location:
nutchez-0.2/src/test
Files:
2 edited

Legend:

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

    r163 r164  
    1010# *.sh及nutchez-0.2-0531.tar.gz均在同一目錄下
    1111
     12function show_info () {
     13  if [ $? -eq 0 ]; then
     14    echo -e "\033[1;32;40m $1 \033[0m"
     15  fi
     16}
    1217
    1318main () {
    1419  check_info
    15   echo "歡迎使用NutchEZ, 此安裝程序會為您新建一個nutchuser帳號"
     20  show_info "歡迎使用NutchEZ, 此安裝程序會為您新建一個nutchuser帳號並協助您設定密碼"
    1621  set_install_information
    17   show_info
    1822  read -p "Please confirm your install infomation: 1.Yes 2.No  " confirm
    1923  if [ $confirm -eq 1 ]; then
     
    3943    start_up_tomcat   
    4044    # 安裝流程結束,並進入網頁管理頁面設定爬網網址...等 
    41     echo "Install Successfully!!"
    42     echo "Visit http://$MasterIP_Address:8080"
     45    show_info "Install Successfully!!"
     46    show_info "Visit http://$MasterIP_Address:8080"
    4347    client_install_command
    4448  elif [ $confirm -eq 2 ]; then
     
    4751}
    4852
    49 # todo: 處理/etc/hosts
    50 # 多張網卡時的bug
    5153main
  • nutchez-0.2/src/test/install_func.sh

    r163 r164  
    3232
    3333
    34 function debug_echo () {
     34function debug_info () {
     35  if [ $? -eq 0 ]; then
     36    echo -e "\033[1;35;40m info - $1 \033[0m"
     37  fi
     38}
     39
     40
     41function show_info () {
    3542  if [ $? -eq 0 ]; then
    3643    echo -e "\033[1;32;40m $1 \033[0m"
     
    7986  else
    8087    declare -i i=1
    81     echo -e "\nSystem have multiple network device, which network use for this machine: "
     88    show_info "\nSystem have multiple network device, which network use for this machine: "
    8289
    8390    for net in $net_interfaces
    8491      do
    85         echo "($i)  $net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
     92        show_info "($i)  $net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
    8693        i=i+1
    8794      done
    8895
    89       read -p "Plz choice(1/2/3...): " net_choice
     96      read -p "Please choice(1/2/3...): " net_choice
    9097    if [ -z $net_choice ]; then
    9198      net_choice=1
    9299    fi
    93100
    94     echo "Your choice is $net_choice"
     101    show_info "Your choice is $net_choice"
    95102    net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
    96103    #ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
    97104    net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
    98     net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
    99     echo "net_address is $net_address"
    100     echo "net_MacAddr is $net_MacAddr"
     105    net_MacAddr=$(ifconfig $net_interface | grep 'HW' | sed 's/^.*HWaddr //g')
     106    show_info "net_address is $net_address"
     107    show_info "net_MacAddr is $net_MacAddr"
    101108  fi
    102109}
     
    104111
    105112function show_info () {
    106   echo "The Master IP Address is $MasterIP_Address"
    107   echo "The Master MacAddr is $net_MacAddr"
     113  show_info "The Master IP Address is $MasterIP_Address"
     114  show_info "The Master MacAddr is $net_MacAddr"
    108115}
    109116
     
    113120
    114121function make_ssh_key () {
    115   debug_echo "Make ssh key(begin...)"
     122  debug_info "Make ssh key(begin...)"
    116123  su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""'
    117124  su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"
    118125  su nutchuser -c "ssh-add /home/nutchuser/.ssh/id_rsa"
    119   debug_echo "Make ssh key(done!)"
     126  debug_info "Make ssh key(done!)"
    120127}
    121128
    122129
    123130function set_haoop-site () {
    124   debug_echo "set hadoop-site.xml(begin...)"
     131  debug_info "set hadoop-site.xml(begin...)"
    125132  cd $Nutch_HOME/conf/
    126133  cat > hadoop-site.xml << EOF
     
    140147</configuration>
    141148EOF
    142   debug_echo "set hadoop-site.xml(done!)"
     149  debug_info "set hadoop-site.xml(done!)"
    143150}
    144151
    145152# 修改nutch-site.xml中-http.agent.url, http.agent.email
    146153function set_nutch-site () {
    147   debug_echo "set nutch-site.xml(begin...)"
     154  debug_info "set nutch-site.xml(begin...)"
    148155  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.url' | sed 's/:.*//g'`
    149   debug_echo "debug...http.agent.url line number = $Line_NO..."
     156  debug_info "debug...http.agent.url line number = $Line_NO..."
    150157  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
    151   debug_echo "debug...edit http.agent.url delete line $((Line_NO+1))..."
     158  debug_info "debug...edit http.agent.url delete line $((Line_NO+1))..."
    152159  sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml
    153   debug_echo "debug...edit http.agent.url done..."
     160  debug_info "debug...edit http.agent.url done..."
    154161
    155162  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.email' | sed 's/:.*//g'`
    156   debug_echo "debug...http.agent.email line number = $Line_NO..."
     163  debug_info "debug...http.agent.email line number = $Line_NO..."
    157164
    158165  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
    159   debug_echo "debug...edit http.agent.email delete line $((Line_NO+1))..."
     166  debug_info "debug...edit http.agent.email delete line $((Line_NO+1))..."
    160167  sed -i ''$Line_NO'a <value>'$Admin_email'</value>' $Nutch_HOME/conf/nutch-site.xml
    161   debug_echo "debug...edit http.agent.email done..."
    162   debug_echo "set nutch-site.xml(done!)"
     168  debug_info "debug...edit http.agent.email done..."
     169  debug_info "set nutch-site.xml(done!)"
    163170}
    164171
    165172function format_HDFS () {
    166   debug_echo "format HDFS..."
     173  debug_info "format HDFS..."
    167174  su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format"
    168175}
    169176
    170177function start_up_NutchEZ (){
    171   debug_echo "start up NutchEZ..."
     178  debug_info "start up NutchEZ..."
    172179  su nutchuser -c "$Nutch_HOME/bin/start-all.sh"
    173180}
    174181
     182
     183function set_hosts () {
     184  Line_NO=`cat /etc/hosts | grep -n $(hostname) | sed 's/:.*//g'`
     185  content=$(cat /etc/hosts | awk 'NR=='$Line_NO'{printf "# " ; print}' )
     186  sed -i ""$Line_NO"c $content" /etc/hosts
     187  sed -i '1i '$MasterIP_Address' '$(hostname)'' /etc/hosts
     188}
     189
    175190function Install_Nutch () {
     191  debug_info "MasterIP_Address=$MasterIP_Address"
     192  debug_info "Master_Hostname=$(hostname)"
     193  set_hosts
    176194  set_haoop-site
    177195  set_nutch-site
     
    182200  cd $Start_PATH
    183201  Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'`
    184   debug_echo "debug...Master IP here line number = $Line_NO..."
     202  debug_info "debug...Master IP here line number = $Line_NO..."
    185203  sed -i ''$((Line_NO+1))'d' client_install
    186   debug_echo "debug...edit Master IP at line $((Line_NO+1))..."
     204  debug_info "debug...edit Master IP at line $((Line_NO+1))..."
    187205  sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install
    188   debug_echo "edit client_install done..."
     206  debug_info "edit client_install done..."
    189207}
    190208
     
    193211  cd $Start_PATH
    194212  Line_NO=`cat client_install | grep -n '# Master Hostname here' | sed 's/:.*//g'`
    195   debug_echo "debug...Master hostname here line number = $Line_NO..."
     213  debug_info "debug...Master hostname here line number = $Line_NO..."
    196214  sed -i ''$((Line_NO+1))'d' client_install
    197   debug_echo "debug...edit Master Hostname at line $((Line_NO+1))..."
     215  debug_info "debug...edit Master Hostname at line $((Line_NO+1))..."
    198216  sed -i ''$Line_NO'a Master_Hostname='$(hostname)'' client_install
    199   debug_echo "edit client_install done..."
     217  debug_info "edit client_install done..."
    200218}
    201219
     
    207225  # 將Master_IP_Address給client
    208226  # 打包安裝目錄(不含tomcat)
    209   echo "function make_client_install..."
     227  debug_info "function make_client_install..."
    210228  client_PassMasterIPAddr
    211229  client_PassMaster_Hostname
    212230  cd /opt/nutchez/
    213   su nutchuser -c "tar -cvzf NutchezForClientOf_$Master_IP_Address.tar.gz  nutch"
     231  su nutchuser -c "tar -cvzf NutchezForClientOf_"$MasterIP_Address".tar.gz  nutch"
    214232 
    215233  # 複製檔案至$User_HOME/source目錄下
     
    219237
    220238function start_up_tomcat () {
    221   debug_echo "start up tomcat..."
    222   sleep 10s
     239  debug_info "start up tomcat..."
     240  i=10
     241  until [ $i -lt 1 ]
     242    do
     243      sleep 1s
     244      debug_info "wait $i sec..."
     245      i=`expr $i - 1`
     246    done
    223247  su nutchuser -c "$Tomcat_HOME/bin/startup.sh"
    224   debug_echo "tomcat has been started..."
     248  debug_info "tomcat has been started..."
    225249}
    226250
     
    228252# client簡易步驟
    229253function client_install_command () {
    230   echo "Client Install Command as Follows:"
    231   echo "cd ~"
    232   echo "mkdir nutchez_client_install"
    233   echo "cd nutchez_client_install"
    234   echo "scp nutchuser@masterIP:/home/nutchuser/nutchez/source/* ."
    235   echo "./client_install"
    236 }
     254  show_info "Client Install Command as Follows:"
     255  show_info "cd ~"
     256  show_info "mkdir nutchez_client_install"
     257  show_info "cd nutchez_client_install"
     258  show_info "scp nutchuser@$Master_IP_Address:/home/nutchuser/nutchez/source/* ."
     259  show_info "./client_install"
     260}
Note: See TracChangeset for help on using the changeset viewer.