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