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

Last change on this file since 158 was 158, checked in by shunfa, 14 years ago
  1. 修正clinet tar.gz包及路徑
  2. 修正ip及hostname
  3. 新增function: debug_echo
  4. 新增ssh-add
  5. 新增紀錄mac address

註:所有功能目前僅分別測試單一function

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