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

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

加入多張網卡時ip設定

  • Property svn:executable set to *
File size: 5.4 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 ###########
15User_HOME=/home/nutchuser/nutchez
16NutchEZ_HOME=/opt/nutchez
17Nutch_HOME=$NutchEZ_HOME/nutch
18Tomcat_HOME=$NutchEZ_HOME/tomcat
19Index_DB=$User_HOME/search
20MasterIP_Address=`/sbin/ifconfig eth0 | grep 'inet addr' |  sed 's/^.*addr://g' | sed 's/Bcast.*$//g' | sed 's/ .*// '`
21
22# DNS暫時以IP取代
23MasterDNS=$MasterIP_Address
24
25function set_install_information () { 
26  set_nutchuser_passwd
27  read -p "Please enter Administrator's e-mail address: " Admin_email
28  select_eth
29  MasterIP_Address=$net_address
30  # read -p "Please enter the Master DNS:  " MasterDNS
31}
32
33function set_nutchuser_passwd () {
34  read -p "Please enter nutchuser's password :  " nutchuser_passwd
35  read -p "Please enter nutchuser's password again:  " nutchuser_passwd_confirm
36  if [ $nutchuser_passwd != $nutchuser_passwd_confirm ]; then
37    set_nutchuser_passwd
38  fi
39}
40
41
42function select_eth () {
43  net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1)
44  net_nu=$(echo $net_interfaces | wc -w)
45
46  # 若只有一個 eth 時
47  if [ "$net_nu" == "1" ]; then
48    ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
49    net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
50  #  echo "net_address is $net_address"
51
52  # 若有多個 eth 時
53  else
54    declare -i i=1
55    echo -e "\nSystem have multiple network device, which network use for this machine: "
56
57    for net in $net_interfaces
58      do
59        echo "($i$net  $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)"
60        i=i+1
61      done
62
63      read -p "Plz choice(1/2/3...): " net_choice
64    if [ -z $net_choice ]; then
65      net_choice=1
66    fi
67
68    echo "Your choice is $net_choice"
69    net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice)
70    ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1
71    net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)
72    echo "net_address is $net_address"
73  fi
74}
75
76
77function show_info () {
78  echo "Administrator's e-mail address is $Admin_email."
79  echo "The Master IP Address is: $MasterDNS"
80}
81
82function confirm_install_information () {
83  read -p "Please confirm your install infomation: 1.Yes 2.No  " confirm
84}
85
86function make_ssh_key () {
87  su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""'
88  su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys"
89}
90
91
92function set_haoop-site () {
93  echo "set $Nutch_HOME/conf/hadoop-site.xml"
94  cd $Nutch_HOME/conf/
95  cat > hadoop-site.xml << EOF
96<configuration>
97  <property>
98    <name>fs.default.name</name>
99    <value>hdfs://$MasterIP_Address:9000</value>
100  </property>
101  <property>
102    <name>mapred.job.tracker</name>
103    <value>$MasterIP_Address:9001</value>
104  </property>
105  <property>
106    <name>hadoop.tmp.dir</name>
107    <value>/var/nutchez/nutch-nutchuser</value>
108  </property>
109</configuration>
110EOF
111}
112
113# 修改nutch-site.xml中-http.agent.url, http.agent.email
114function set_nutch-site () {
115  echo "set $Nutch_HOME/conf/nutch-site.xml"
116  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.url' | sed 's/:.*//g'`
117  echo "debug...http.agent.url line number = $Line_NO..."
118  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
119  echo "debug...edit http.agent.url delete line $((Line_NO+1))..."
120  sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml
121  echo "debug...edit http.agent.url done..."
122
123  Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.email' | sed 's/:.*//g'`
124  echo "debug...http.agent.email line number = $Line_NO..."
125
126  sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml
127  echo "debug...edit http.agent.email delete line $((Line_NO+1))..."
128  sed -i ''$Line_NO'a <value>'$Admin_email'</value>' $Nutch_HOME/conf/nutch-site.xml
129  echo "debug...edit http.agent.email done..."
130}
131
132function format_HDFS () {
133  echo "format HDFS..."
134  su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format"
135}
136
137function start_up_NutchEZ (){
138  echo "start up NutchEZ..."
139  su nutchuser -c "$Nutch_HOME/bin/start-all.sh"
140}
141
142function Install_Nutch () {
143  set_haoop-site
144  set_nutch-site
145}
146
147
148function client_PassMasterIPAddr () {
149  Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'`
150  echo "debug...Master IP here line number = $Line_NO..."
151  sed -i ''$((Line_NO+1))'d' client_install
152  echo "debug...edit Master IP at line $((Line_NO+1))..."
153  sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install
154  echo "edit client_install done..."
155}
156
157function make_client_install () {
158  # 將Master_IP_Address給client
159  # 打包安裝目錄(不含tomcat)
160  echo "function make_client_install..."
161  client_PassMasterIPAddr
162  su nutchuser -c "tar -cvzf /opt/nutchez/NutchezForClientOf_$Master_IP_Address.tar.gz  /home/nutchuser/nutchez/"
163}
164
165function start_up_tomcat () {
166  echo "start up tomcat..."
167  sleep 10s
168  echo "su nutchuser -c "$Tomcat_HOME/bin/startup.sh""
169  su nutchuser -c "$Tomcat_HOME/bin/startup.sh"
170}
171
172# client簡易步驟
173function client_install_command () {
174  echo "Client Install Command as Follows:"
175  echo "cd ~"
176  echo "mkdir NutchezClientInstall"
177  echo "scp 安裝的shell檔所在路徑/PATH/ ~/NutchezClientInstall"
178  echo "./client_install"
179}
Note: See TracBrowser for help on using the repository browser.