source: nutchez-0.2/src/test/install_func.sh @ 173

Last change on this file since 173 was 173, checked in by shunfa, 14 years ago

修改執行順序

  • Property svn:executable set to *
File size: 7.8 KB
RevLine 
[116]1#!/bin/bash
2source install_lang
[117]3####### garbage here #############
[116]4function mainFunction ( )
5{
6echo "$Good"
7}
8function braBraBra ( )
9{
10echo "$Bra_Bra_Bra"
11}
[117]12####### garbage end ###############
13
14####### fafa code here ###########
[158]15
16
17# shell檔及壓縮檔在同一目錄中
18
19
20####### 環境變數section###########
[137]21User_HOME=/home/nutchuser/nutchez
22NutchEZ_HOME=/opt/nutchez
23Nutch_HOME=$NutchEZ_HOME/nutch
24Tomcat_HOME=$NutchEZ_HOME/tomcat
25Index_DB=$User_HOME/search
[158]26Admin_email=nutchuser@nutch
[163]27Start_PATH=`pwd`
28MasterIP_Address=`/sbin/ifconfig eth0 | grep 'inet addr' |  sed 's/^.*addr://g' | sed 's/Bcast.*$//g' | sed 's/ .*// '` 
29net_MacAddr=`/sbin/ifconfig eth0 | grep 'HW' | sed 's/^.*HWaddr //g'`
[125]30
[158]31######function section section#######
32
33
[164]34function debug_info () {
[158]35  if [ $? -eq 0 ]; then
[164]36    echo -e "\033[1;35;40m info - $1 \033[0m"
37  fi
38}
39
40
41function show_info () {
42  if [ $? -eq 0 ]; then
[158]43    echo -e "\033[1;32;40m $1 \033[0m"
44  fi
45}
46
47
48check_info () {
49  check_root
50  check_systemInfo
[173]51  install_packages
[158]52  check_nez_installed
53  check_sunJava
54  check_ssh
55  check_dialog
56}
57
[137]58function set_install_information () { 
[139]59  set_nutchuser_passwd
[150]60  select_eth
61  MasterIP_Address=$net_address
[139]62}
63
64function set_nutchuser_passwd () {
[161]65  read -sp "Please enter nutchuser's password :  " Nutchuser_Passwd
[173]66  echo -e "\n"
[161]67  read -sp "Please enter nutchuser's password again:  " Nutchuser_Passwd2
[173]68  echo -e "\n"
[161]69  if [ $Nutchuser_Passwd != $Nutchuser_Passwd2 ]; then
[139]70    set_nutchuser_passwd
[137]71  fi
[117]72}
73
[150]74
75function select_eth () {
76  net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
77  net_nu=$(echo $net_interfaces | wc -w)
78
79  # 若只有一個 eth 時
80  if [ "$net_nu" == "1" ]; then
[158]81    #ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
[150]82    net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
[158]83    net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g')
[163]84    #echo "net_address is $net_address"
85    #echo "net_MacAddr is $net_MacAddr"
[150]86
87  # 若有多個 eth 時
88  else
89    declare -i i=1
[164]90    show_info  "\nSystem have multiple network device, which network use for this machine: "
[150]91
92    for net in $net_interfaces
93      do
[164]94        show_info "($i$net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
[150]95        i=i+1
96      done
97
[164]98      read -p "Please choice(1/2/3...): " net_choice
[150]99    if [ -z $net_choice ]; then
100      net_choice=1
101    fi
102
[164]103    show_info "Your choice is $net_choice"
[150]104    net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
[163]105    #ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
[150]106    net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
[164]107    net_MacAddr=$(ifconfig $net_interface | grep 'HW' | sed 's/^.*HWaddr //g')
108    show_info "net_address is $net_address"
109    show_info "net_MacAddr is $net_MacAddr"
[150]110  fi
111}
112
113
[137]114function show_info () {
[164]115  show_info "The Master IP Address is $MasterIP_Address"
116  show_info "The Master MacAddr is $net_MacAddr"
[117]117}
118
[137]119function confirm_install_information () {
[117]120  read -p "Please confirm your install infomation: 1.Yes 2.No  " confirm
121}
122
[139]123function make_ssh_key () {
[164]124  debug_info "Make ssh key(begin...)"
[139]125  su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""'
126  su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"
[158]127  su nutchuser -c "ssh-add /home/nutchuser/.ssh/id_rsa"
[164]128  debug_info "Make ssh key(done!)"
[139]129}
130
131
[137]132function set_haoop-site () {
[164]133  debug_info "set hadoop-site.xml(begin...)"
[137]134  cd $Nutch_HOME/conf/
[130]135  cat > hadoop-site.xml << EOF
[125]136<configuration>
[137]137  <property>
[125]138    <name>fs.default.name</name>
[137]139    <value>hdfs://$MasterIP_Address:9000</value>
140  </property>
141  <property>
[125]142    <name>mapred.job.tracker</name>
[137]143    <value>$MasterIP_Address:9001</value>
144  </property>
145  <property>
146    <name>hadoop.tmp.dir</name>
147    <value>/var/nutchez/nutch-nutchuser</value>
148  </property>
[125]149</configuration>
150EOF
[164]151  debug_info "set hadoop-site.xml(done!)"
[117]152}
153
[137]154# 修改nutch-site.xml中-http.agent.url, http.agent.email
155function set_nutch-site () {
[164]156  debug_info "set nutch-site.xml(begin...)"
[137]157  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.url' | sed 's/:.*//g'`
[164]158  debug_info "debug...http.agent.url line number = $Line_NO..."
[137]159  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
[164]160  debug_info "debug...edit http.agent.url delete line $((Line_NO+1))..."
[137]161  sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml
[164]162  debug_info "debug...edit http.agent.url done..."
[117]163
[137]164  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.email' | sed 's/:.*//g'`
[164]165  debug_info "debug...http.agent.email line number = $Line_NO..."
[126]166
[137]167  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
[164]168  debug_info "debug...edit http.agent.email delete line $((Line_NO+1))..."
[137]169  sed -i ''$Line_NO'a <value>'$Admin_email'</value>' $Nutch_HOME/conf/nutch-site.xml
[164]170  debug_info "debug...edit http.agent.email done..."
171  debug_info "set nutch-site.xml(done!)"
[117]172}
173
[137]174function format_HDFS () {
[164]175  debug_info "format HDFS..."
[139]176  su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format"
[117]177}
178
[137]179function start_up_NutchEZ (){
[164]180  debug_info "start up NutchEZ..."
[139]181  su nutchuser -c "$Nutch_HOME/bin/start-all.sh"
[117]182}
183
[164]184
185function set_hosts () {
186  Line_NO=`cat /etc/hosts | grep -n $(hostname) | sed 's/:.*//g'`
187  content=$(cat /etc/hosts | awk 'NR=='$Line_NO'{printf "# " ; print}' )
188  sed -i ""$Line_NO"c $content" /etc/hosts
189  sed -i '1i '$MasterIP_Address' '$(hostname)'' /etc/hosts
190}
191
[137]192function Install_Nutch () {
[164]193  debug_info "MasterIP_Address=$MasterIP_Address"
194  debug_info "Master_Hostname=$(hostname)"
[171]195  su nutchuser -c "echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/system/nutch_nodes"
[164]196  set_hosts
[136]197  set_haoop-site
198  set_nutch-site
199}
200
[139]201
[140]202function client_PassMasterIPAddr () {
[163]203  cd $Start_PATH
[140]204  Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'`
[164]205  debug_info "debug...Master IP here line number = $Line_NO..."
[140]206  sed -i ''$((Line_NO+1))'d' client_install
[164]207  debug_info "debug...edit Master IP at line $((Line_NO+1))..."
[140]208  sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install
[164]209  debug_info "edit client_install done..."
[140]210}
211
[163]212
[152]213function client_PassMaster_Hostname () {
[163]214  cd $Start_PATH
[152]215  Line_NO=`cat client_install | grep -n '# Master Hostname here' | sed 's/:.*//g'`
[164]216  debug_info "debug...Master hostname here line number = $Line_NO..."
[152]217  sed -i ''$((Line_NO+1))'d' client_install
[164]218  debug_info "debug...edit Master Hostname at line $((Line_NO+1))..."
[152]219  sed -i ''$Line_NO'a Master_Hostname='$(hostname)'' client_install
[164]220  debug_info "edit client_install done..."
[152]221}
222
[163]223
[139]224function make_client_install () {
[158]225  # 建立資料夾(用來存放client的安奘檔)
226  su nutchuser -c "mkdir $User_HOME/source"
227
[139]228  # 將Master_IP_Address給client
229  # 打包安裝目錄(不含tomcat)
[164]230  debug_info "function make_client_install..."
[140]231  client_PassMasterIPAddr
[152]232  client_PassMaster_Hostname
[158]233  cd /opt/nutchez/
[166]234  su nutchuser -c "tar -cvzf NutchezForClientOf_$MasterIP_Address.tar.gz  nutch"
[158]235 
236  # 複製檔案至$User_HOME/source目錄下
[166]237  mv NutchezForClientOf_$MasterIP_Address.tar.gz /home/nutchuser/nutchez/source
[163]238  cp $Start_PATH/client_install $Start_PATH/client_install_func.sh /home/nutchuser/nutchez/source
[131]239}
240
[137]241function start_up_tomcat () {
[164]242  debug_info "start up tomcat..."
243  i=10
244  until [ $i -lt 1 ]
245    do
246      sleep 1s
247      debug_info "wait $i sec..."
248      i=`expr $i - 1`
249    done
[139]250  su nutchuser -c "$Tomcat_HOME/bin/startup.sh"
[164]251  debug_info "tomcat has been started..."
[117]252}
[144]253
[158]254###最後再整理###
[150]255# client簡易步驟
[144]256function client_install_command () {
[164]257  show_info "Client Install Command as Follows:"
258  show_info "cd ~"
259  show_info "mkdir nutchez_client_install"
260  show_info "cd nutchez_client_install"
[169]261  show_info "scp nutchuser@$MasterIP_Address:/home/nutchuser/nutchez/source/* ."
262  show_info "sudo su"
[164]263  show_info "./client_install"
[144]264}
Note: See TracBrowser for help on using the repository browser.