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

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

修改安裝檔

  • Property svn:executable set to *
File size: 7.0 KB
Line 
1#!/bin/bash
2source install_lang
3####### garbage here #############
4function mainFunction ( )
5{
6echo "$Good"
7}
8function braBraBra ( )
9{
10echo "$Bra_Bra_Bra"
11}
12####### garbage end ###############
13
14####### fafa code here ###########
15
16
17# shell檔及壓縮檔在同一目錄中
18
19
20####### 環境變數section###########
21User_HOME=/home/nutchuser/nutchez
22NutchEZ_HOME=/opt/nutchez
23Nutch_HOME=$NutchEZ_HOME/nutch
24Tomcat_HOME=$NutchEZ_HOME/tomcat
25Index_DB=$User_HOME/search
26Admin_email=nutchuser@nutch
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'`
30
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
51function set_install_information () { 
52  set_nutchuser_passwd
53  select_eth
54  MasterIP_Address=$net_address
55}
56
57function set_nutchuser_passwd () {
58  read -sp "Please enter nutchuser's password :  " Nutchuser_Passwd
59  read -sp "Please enter nutchuser's password again:  " Nutchuser_Passwd2
60  if [ $Nutchuser_Passwd != $Nutchuser_Passwd2 ]; then
61    set_nutchuser_passwd
62  fi
63}
64
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
72    #ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
73    net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
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"
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)
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"
101  fi
102}
103
104
105function show_info () {
106  echo "The Master IP Address is $MasterIP_Address"
107  echo "The Master MacAddr is $net_MacAddr"
108}
109
110function confirm_install_information () {
111  read -p "Please confirm your install infomation: 1.Yes 2.No  " confirm
112}
113
114function make_ssh_key () {
115  debug_echo "Make ssh key(begin...)"
116  su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""'
117  su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"
118  su nutchuser -c "ssh-add /home/nutchuser/.ssh/id_rsa"
119  debug_echo "Make ssh key(done!)"
120}
121
122
123function set_haoop-site () {
124  debug_echo "set hadoop-site.xml(begin...)"
125  cd $Nutch_HOME/conf/
126  cat > hadoop-site.xml << EOF
127<configuration>
128  <property>
129    <name>fs.default.name</name>
130    <value>hdfs://$MasterIP_Address:9000</value>
131  </property>
132  <property>
133    <name>mapred.job.tracker</name>
134    <value>$MasterIP_Address:9001</value>
135  </property>
136  <property>
137    <name>hadoop.tmp.dir</name>
138    <value>/var/nutchez/nutch-nutchuser</value>
139  </property>
140</configuration>
141EOF
142  debug_echo "set hadoop-site.xml(done!)"
143}
144
145# 修改nutch-site.xml中-http.agent.url, http.agent.email
146function set_nutch-site () {
147  debug_echo "set nutch-site.xml(begin...)"
148  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..."
150  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))..."
152  sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml
153  debug_echo "debug...edit http.agent.url done..."
154
155  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..."
157
158  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))..."
160  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!)"
163}
164
165function format_HDFS () {
166  debug_echo "format HDFS..."
167  su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format"
168}
169
170function start_up_NutchEZ (){
171  debug_echo "start up NutchEZ..."
172  su nutchuser -c "$Nutch_HOME/bin/start-all.sh"
173}
174
175function Install_Nutch () {
176  set_haoop-site
177  set_nutch-site
178}
179
180
181function client_PassMasterIPAddr () {
182  cd $Start_PATH
183  Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'`
184  debug_echo "debug...Master IP here line number = $Line_NO..."
185  sed -i ''$((Line_NO+1))'d' client_install
186  debug_echo "debug...edit Master IP at line $((Line_NO+1))..."
187  sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install
188  debug_echo "edit client_install done..."
189}
190
191
192function client_PassMaster_Hostname () {
193  cd $Start_PATH
194  Line_NO=`cat client_install | grep -n '# Master Hostname here' | sed 's/:.*//g'`
195  debug_echo "debug...Master hostname here line number = $Line_NO..."
196  sed -i ''$((Line_NO+1))'d' client_install
197  debug_echo "debug...edit Master Hostname at line $((Line_NO+1))..."
198  sed -i ''$Line_NO'a Master_Hostname='$(hostname)'' client_install
199  debug_echo "edit client_install done..."
200}
201
202
203function make_client_install () {
204  # 建立資料夾(用來存放client的安奘檔)
205  su nutchuser -c "mkdir $User_HOME/source"
206
207  # 將Master_IP_Address給client
208  # 打包安裝目錄(不含tomcat)
209  echo "function make_client_install..."
210  client_PassMasterIPAddr
211  client_PassMaster_Hostname
212  cd /opt/nutchez/
213  su nutchuser -c "tar -cvzf NutchezForClientOf_$Master_IP_Address.tar.gz  nutch"
214 
215  # 複製檔案至$User_HOME/source目錄下
216  mv NutchezForClientOf_$Master_IP_Address.tar.gz /home/nutchuser/nutchez/source
217  cp $Start_PATH/client_install $Start_PATH/client_install_func.sh /home/nutchuser/nutchez/source
218}
219
220function start_up_tomcat () {
221  debug_echo "start up tomcat..."
222  sleep 10s
223  su nutchuser -c "$Tomcat_HOME/bin/startup.sh"
224  debug_echo "tomcat has been started..."
225}
226
227###最後再整理###
228# client簡易步驟
229function 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}
Note: See TracBrowser for help on using the repository browser.