| 1 | #!/bin/bash |
|---|
| 2 | |
|---|
| 3 | # shell檔及壓縮檔在同一目錄中 |
|---|
| 4 | ####### 環境變數section########### |
|---|
| 5 | User_HOME=/home/nutchuser/nutchez |
|---|
| 6 | NutchEZ_HOME=/opt/nutchez |
|---|
| 7 | Nutch_HOME=$NutchEZ_HOME/nutch |
|---|
| 8 | Tomcat_HOME=$NutchEZ_HOME/tomcat |
|---|
| 9 | Index_DB=$User_HOME/search |
|---|
| 10 | Admin_email=nutchuser@nutch |
|---|
| 11 | # Work_Path=(define on install) |
|---|
| 12 | Install_Dir=`cd "$Work_Path/../"; pwd` |
|---|
| 13 | MasterIP_Address=`/sbin/ifconfig eth0 | grep 'inet addr' | sed 's/^.*addr://g' | sed 's/Bcast.*$//g' | sed 's/ .*// '` |
|---|
| 14 | net_MacAddr=`/sbin/ifconfig eth0 | grep 'HW' | sed 's/^.*HWaddr //g'` |
|---|
| 15 | |
|---|
| 16 | ######function section####### |
|---|
| 17 | |
|---|
| 18 | ########## echo function ########## |
|---|
| 19 | function debug_info () { |
|---|
| 20 | if [ $? -eq 0 ]; then |
|---|
| 21 | echo -e "\033[1;35;40m info - $1 \033[0m" |
|---|
| 22 | fi |
|---|
| 23 | } |
|---|
| 24 | |
|---|
| 25 | |
|---|
| 26 | function show_info () { |
|---|
| 27 | if [ $? -eq 0 ]; then |
|---|
| 28 | echo -e "\033[1;32;40m $1 \033[0m" |
|---|
| 29 | fi |
|---|
| 30 | } |
|---|
| 31 | ##########end echo function ########## |
|---|
| 32 | |
|---|
| 33 | function load_default_lang(){ |
|---|
| 34 | |
|---|
| 35 | lang=$(locale | grep 'LANG=' | cut -d "=" -f2) |
|---|
| 36 | |
|---|
| 37 | # Default: source english |
|---|
| 38 | . $Work_Path/lang/lang_en_US |
|---|
| 39 | # if locale is zh then source chinese |
|---|
| 40 | |
|---|
| 41 | echo $lang | grep 'zh' >> /dev/null && source $Work_Path/lang/lang_zh_TW |
|---|
| 42 | } |
|---|
| 43 | |
|---|
| 44 | function check_root(){ |
|---|
| 45 | debug_info "check_root" |
|---|
| 46 | if [ $USER != "root" ]; then |
|---|
| 47 | show_info "$MI_check_root_1" |
|---|
| 48 | exit |
|---|
| 49 | fi |
|---|
| 50 | show_info "$MI_check_root_2" |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | function check_systemInfo(){ |
|---|
| 54 | debug_info "$MI_check_sys_1" |
|---|
| 55 | show_info "$MI_check_sys_2" |
|---|
| 56 | Linux_Distribution=$(lsb_release -a 2> /dev/null | grep "Distributor ID:" | awk '{print $3}') |
|---|
| 57 | Linux_Version=$(lsb_release -a 2> /dev/null | grep "Release" | awk '{print $2}') |
|---|
| 58 | show_info "$Linux_Distribution , $Linux_Version" |
|---|
| 59 | } |
|---|
| 60 | |
|---|
| 61 | function install_packages(){ |
|---|
| 62 | # deb 系列系統 |
|---|
| 63 | debug_info "$MI_install_pack_1" |
|---|
| 64 | debug_info "$MI_install_pack_2" |
|---|
| 65 | if [ "$Linux_Distribution" == "Ubuntu" ] || [ "$Linux_Distribution" == "Debian" ] ;then |
|---|
| 66 | echo -e "\n$MI_install_pack_if_1\n" |
|---|
| 67 | aptitude install -y expect ssh dialog |
|---|
| 68 | # rpm 系列系統 |
|---|
| 69 | elif [ "$Linux_Distribution" == "Fedora" ] || [ "$Linux_Distribution" == "CentOS" ] ;then |
|---|
| 70 | show_info "$MI_install_pack_if_2" |
|---|
| 71 | else |
|---|
| 72 | show_info "$MI_install_pack_if_2" |
|---|
| 73 | fi |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | function unzip_nV2_pack(){ |
|---|
| 77 | local pac_name=nutchez-0.2pack-current.tar.gz |
|---|
| 78 | if [ ! -d "$Install_Dir/package" ];then |
|---|
| 79 | mkdir $Install_Dir/package |
|---|
| 80 | fi |
|---|
| 81 | if [ ! -e "$Install_Dir/package/$pac_name" ];then |
|---|
| 82 | wget "http://nutchez.googlecode.com/files/$pac_name"; |
|---|
| 83 | if [ $? -eq 0 ];then |
|---|
| 84 | mv $pac_name $Install_Dir/package; |
|---|
| 85 | echo "movied"; |
|---|
| 86 | else |
|---|
| 87 | show_info "$pac_name not found, installation was not finished!"; |
|---|
| 88 | exit 8; |
|---|
| 89 | fi |
|---|
| 90 | fi |
|---|
| 91 | tar -zxvf $Install_Dir/package/$pac_name -C /opt/ |
|---|
| 92 | } |
|---|
| 93 | |
|---|
| 94 | function check_nez_installed(){ |
|---|
| 95 | debug_info "$MI_check_nez_1" |
|---|
| 96 | if [ -d "/opt/nutchez" ]; then |
|---|
| 97 | show_info "$MI_check_nez_2" |
|---|
| 98 | exit |
|---|
| 99 | else |
|---|
| 100 | show_info "$MI_check_nez_3" |
|---|
| 101 | fi |
|---|
| 102 | } |
|---|
| 103 | |
|---|
| 104 | function check_sunJava(){ |
|---|
| 105 | debug_info "$MI_check_sunJava_1" |
|---|
| 106 | debug_info "$MI_check_sunJava_2" |
|---|
| 107 | |
|---|
| 108 | javaPath="/usr" |
|---|
| 109 | yesno="no" |
|---|
| 110 | choice="3" |
|---|
| 111 | |
|---|
| 112 | if [ -e $javaPath/bin/java ]; then |
|---|
| 113 | JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)") |
|---|
| 114 | JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \ |
|---|
| 115 | awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2) |
|---|
| 116 | |
|---|
| 117 | if [ "$JAVA_org" == "" ]; then |
|---|
| 118 | show_info "$MI_check_sunJava_if_1" |
|---|
| 119 | show_info "$MI_check_sunJava_if_2" |
|---|
| 120 | show_info "$MI_check_sunJava_if_3" |
|---|
| 121 | read -p "$MI_check_sunJava_if_4" choice |
|---|
| 122 | case $choice in |
|---|
| 123 | "1") |
|---|
| 124 | show_info "$MI_check_sunJava_if_5" |
|---|
| 125 | exit |
|---|
| 126 | ;; |
|---|
| 127 | "2") |
|---|
| 128 | read -p "$MI_check_sunJava_if_6" javaPath |
|---|
| 129 | ;; |
|---|
| 130 | "*") |
|---|
| 131 | exit |
|---|
| 132 | ;; |
|---|
| 133 | esac |
|---|
| 134 | |
|---|
| 135 | if [ $choice == "2" ]; then |
|---|
| 136 | JAVA_org=$($javaPath/bin/java -version 2>&1 | grep "Java(TM)") |
|---|
| 137 | JAVA_version=$($javaPath/bin/java -version 2>&1 | grep "java version" | \ |
|---|
| 138 | awk '{print $3}' | cut -d "." -f1-2 | cut -d "\"" -f2) |
|---|
| 139 | |
|---|
| 140 | if [ "$JAVA_org" == "" ]; then |
|---|
| 141 | show_info "$MI_check_sunJava_if_7" |
|---|
| 142 | exit |
|---|
| 143 | fi |
|---|
| 144 | fi |
|---|
| 145 | fi |
|---|
| 146 | |
|---|
| 147 | large16=$(echo "$JAVA_version >= 1.6" | bc) |
|---|
| 148 | if [ "${large16}" == 0 ]; then |
|---|
| 149 | show_info "$MI_check_sunJava_if_8" |
|---|
| 150 | exit |
|---|
| 151 | fi |
|---|
| 152 | |
|---|
| 153 | show_info "$MI_check_sunJava_if_9" |
|---|
| 154 | else |
|---|
| 155 | show_info "$MI_check_sunJava_if_10" |
|---|
| 156 | exit |
|---|
| 157 | fi |
|---|
| 158 | |
|---|
| 159 | unset JAVA_org |
|---|
| 160 | unset JAVA_version |
|---|
| 161 | } |
|---|
| 162 | |
|---|
| 163 | # 檢查是否有安裝openssh, openssh-server |
|---|
| 164 | function check_ssh(){ |
|---|
| 165 | debug_info "$MI_check_ssh_1" |
|---|
| 166 | if [ -e /usr/bin/ssh ]; then |
|---|
| 167 | show_info "$MI_check_ssh_2" |
|---|
| 168 | else |
|---|
| 169 | show_info "$MI_check_ssh_3" |
|---|
| 170 | exit |
|---|
| 171 | fi |
|---|
| 172 | |
|---|
| 173 | if [ -e /usr/sbin/sshd ]; then |
|---|
| 174 | show_info "$MI_check_ssh_4" |
|---|
| 175 | else |
|---|
| 176 | show_info "$MI_check_ssh_5" |
|---|
| 177 | exit |
|---|
| 178 | fi |
|---|
| 179 | } |
|---|
| 180 | |
|---|
| 181 | |
|---|
| 182 | # 檢查是否有安裝dialog |
|---|
| 183 | function check_dialog(){ |
|---|
| 184 | debug_info "$MI_check_dialog_1" |
|---|
| 185 | if [ -e /usr/bin/dialog ]; then |
|---|
| 186 | show_info "$MI_check_dialog_2" |
|---|
| 187 | else |
|---|
| 188 | show_info "$MI_check_dialog_3" |
|---|
| 189 | exit |
|---|
| 190 | fi |
|---|
| 191 | } |
|---|
| 192 | |
|---|
| 193 | check_info () { |
|---|
| 194 | check_root |
|---|
| 195 | check_systemInfo |
|---|
| 196 | install_packages |
|---|
| 197 | check_nez_installed |
|---|
| 198 | check_sunJava |
|---|
| 199 | check_ssh |
|---|
| 200 | check_dialog |
|---|
| 201 | } |
|---|
| 202 | |
|---|
| 203 | function set_install_information () { |
|---|
| 204 | set_nutchuser_passwd |
|---|
| 205 | select_eth |
|---|
| 206 | MasterIP_Address=$net_address |
|---|
| 207 | } |
|---|
| 208 | |
|---|
| 209 | function set_nutchuser_passwd () { |
|---|
| 210 | read -sp "$MI_set_nutchuser_passwd_echo_1" Nutchuser_Passwd |
|---|
| 211 | # read -sp "Please enter nutchuser's password : " Nutchuser_Passwd |
|---|
| 212 | echo -e "\n" |
|---|
| 213 | read -sp "$MI_set_nutchuser_passwd_echo_2" Nutchuser_Passwd2 |
|---|
| 214 | # read -sp "Please enter nutchuser's password again: " Nutchuser_Passwd2 |
|---|
| 215 | echo -e "\n" |
|---|
| 216 | if [ $Nutchuser_Passwd != $Nutchuser_Passwd2 ]; then |
|---|
| 217 | set_nutchuser_passwd |
|---|
| 218 | fi |
|---|
| 219 | } |
|---|
| 220 | |
|---|
| 221 | # 新增nutchuser 帳號時用 Nutchuser_Passwd 當密碼 |
|---|
| 222 | function creat_nutchuser_account(){ |
|---|
| 223 | debug_info "$create_nutchuser_d1" |
|---|
| 224 | while [ "$Nutchuser_Passwd" != "$Nutchuser_Passwd2" ] |
|---|
| 225 | do |
|---|
| 226 | echo -e "\n" |
|---|
| 227 | read -sp "$create_nutchuser_1" Nutchuser_Passwd |
|---|
| 228 | echo |
|---|
| 229 | read -sp "$create_nutchuser_2" Nutchuser_Passwd2 |
|---|
| 230 | echo |
|---|
| 231 | if [ "$Nutchuser_Passwd" == "$Nutchuser_Passwd2" ]; then |
|---|
| 232 | show_info "$create_nutchuser_3" |
|---|
| 233 | else |
|---|
| 234 | show_info "$create_nutchuser_4" |
|---|
| 235 | fi |
|---|
| 236 | done |
|---|
| 237 | unset Nutchuser_Passwd2 |
|---|
| 238 | |
|---|
| 239 | if [ $(cat /etc/passwd | grep nutchuser) ]; then |
|---|
| 240 | show_info "$create_nutchuser_s1" |
|---|
| 241 | expect -c "spawn passwd nutchuser |
|---|
| 242 | set timeout 1 |
|---|
| 243 | expect \"*: \" |
|---|
| 244 | send \"$Nutchuser_Passwd\r\" |
|---|
| 245 | expect \"*: \" |
|---|
| 246 | send \"$Nutchuser_Passwd\r\" |
|---|
| 247 | expect eof" |
|---|
| 248 | else |
|---|
| 249 | show_info "$create_nutchuser_s2" |
|---|
| 250 | useradd -m nutchuser -s /bin/bash |
|---|
| 251 | expect -c "spawn passwd nutchuser |
|---|
| 252 | set timeout 1 |
|---|
| 253 | expect \"*: \" |
|---|
| 254 | send \"$Nutchuser_Passwd\r\" |
|---|
| 255 | expect \"*: \" |
|---|
| 256 | send \"$Nutchuser_Passwd\r\" |
|---|
| 257 | expect eof" |
|---|
| 258 | fi |
|---|
| 259 | } |
|---|
| 260 | |
|---|
| 261 | function select_eth () { |
|---|
| 262 | net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1) |
|---|
| 263 | net_nu=$(echo $net_interfaces | wc -w) |
|---|
| 264 | |
|---|
| 265 | # 若只有一個 eth 時 |
|---|
| 266 | if [ "$net_nu" == "1" ]; then |
|---|
| 267 | net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1) |
|---|
| 268 | net_MacAddr=$(ifconfig $net_interfaces | grep 'HW' | sed 's/^.*HWaddr //g') |
|---|
| 269 | |
|---|
| 270 | # 若有多個 eth 時 |
|---|
| 271 | else |
|---|
| 272 | declare -i i=1 |
|---|
| 273 | show_info "$MI_select_eth_echo_1" |
|---|
| 274 | # show_info "\nSystem have multiple network device, which network use for this machine: " |
|---|
| 275 | |
|---|
| 276 | for net in $net_interfaces |
|---|
| 277 | do |
|---|
| 278 | show_info "($i) $net $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)" |
|---|
| 279 | i=i+1 |
|---|
| 280 | done |
|---|
| 281 | read -p "$MI_select_eth_echo_2" net_choice |
|---|
| 282 | # read -p "Please choice(1/2/3...): " net_choice |
|---|
| 283 | if [ -z $net_choice ]; then |
|---|
| 284 | net_choice=1 |
|---|
| 285 | fi |
|---|
| 286 | |
|---|
| 287 | show_info "$MI_select_eth_echo_3 $net_choice" |
|---|
| 288 | # show_info "Your choice is $net_choice" |
|---|
| 289 | net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice) |
|---|
| 290 | #ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1 |
|---|
| 291 | net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1) |
|---|
| 292 | net_MacAddr=$(ifconfig $net_interface | grep 'HW' | sed 's/^.*HWaddr //g') |
|---|
| 293 | |
|---|
| 294 | show_info "$MI_select_eth_echo_4 $net_address" |
|---|
| 295 | # show_info "net_address is $net_address" |
|---|
| 296 | show_info "$MI_select_eth_echo_5 $net_MacAddr" |
|---|
| 297 | # show_info "net_MacAddr is $net_MacAddr" |
|---|
| 298 | fi |
|---|
| 299 | } |
|---|
| 300 | |
|---|
| 301 | |
|---|
| 302 | function show_master_info () { |
|---|
| 303 | show_info "$MI_show_master_info_echo_1 $MasterIP_Address" |
|---|
| 304 | show_info "$MI_show_master_info_echo_2 $net_MacAddr" |
|---|
| 305 | |
|---|
| 306 | # show_info "The Master IP Address is $MasterIP_Address" |
|---|
| 307 | # show_info "The Master MacAddr is $net_MacAddr" |
|---|
| 308 | } |
|---|
| 309 | |
|---|
| 310 | function make_ssh_key () { |
|---|
| 311 | debug_info "$MI_make_ssh_key_echo_1" |
|---|
| 312 | # debug_info "Make ssh key(begin...)" |
|---|
| 313 | su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""' |
|---|
| 314 | su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys" |
|---|
| 315 | su nutchuser -c "ssh-add /home/nutchuser/.ssh/id_rsa" |
|---|
| 316 | debug_info "$MI_make_ssh_key_echo_2" |
|---|
| 317 | # debug_info "Make ssh key(done!)" |
|---|
| 318 | } |
|---|
| 319 | |
|---|
| 320 | |
|---|
| 321 | function set_haoop-site () { |
|---|
| 322 | debug_info "$MI_set_haoop_site_echo_1" |
|---|
| 323 | # debug_info "set hadoop-site.xml(begin...)" |
|---|
| 324 | cd $Nutch_HOME/conf/ |
|---|
| 325 | cat > hadoop-site.xml << EOF |
|---|
| 326 | <configuration> |
|---|
| 327 | <property> |
|---|
| 328 | <name>fs.default.name</name> |
|---|
| 329 | <value>hdfs://$MasterIP_Address:9000</value> |
|---|
| 330 | </property> |
|---|
| 331 | <property> |
|---|
| 332 | <name>mapred.job.tracker</name> |
|---|
| 333 | <value>$MasterIP_Address:9001</value> |
|---|
| 334 | </property> |
|---|
| 335 | <property> |
|---|
| 336 | <name>hadoop.tmp.dir</name> |
|---|
| 337 | <value>/var/nutchez/nutch-nutchuser</value> |
|---|
| 338 | </property> |
|---|
| 339 | </configuration> |
|---|
| 340 | EOF |
|---|
| 341 | debug_info "$MI_set_haoop_site_echo_2" |
|---|
| 342 | # debug_info "set hadoop-site.xml(done!)" |
|---|
| 343 | } |
|---|
| 344 | |
|---|
| 345 | # 修改nutch-site.xml中-http.agent.url, http.agent.email |
|---|
| 346 | function set_nutch-site () { |
|---|
| 347 | debug_info "$MI_set_nutch_site_echo_1" |
|---|
| 348 | # debug_info "set nutch-site.xml(begin...)" |
|---|
| 349 | Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.url' | sed 's/:.*//g'` |
|---|
| 350 | debug_info "$MI_set_nutch_site_echo_2" |
|---|
| 351 | # debug_info "debug...http.agent.url line number = $Line_NO..." |
|---|
| 352 | sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml |
|---|
| 353 | debug_info "$MI_set_nutch_site_echo_3" |
|---|
| 354 | # debug_info "debug...edit http.agent.url delete line $((Line_NO+1))..." |
|---|
| 355 | sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml |
|---|
| 356 | debug_info "$MI_set_nutch_site_echo_4" |
|---|
| 357 | # debug_info "debug...edit http.agent.url done..." |
|---|
| 358 | |
|---|
| 359 | Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.email' | sed 's/:.*//g'` |
|---|
| 360 | debug_info "$MI_set_nutch_site_echo_5" |
|---|
| 361 | # debug_info "debug...http.agent.email line number = $Line_NO..." |
|---|
| 362 | |
|---|
| 363 | sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml |
|---|
| 364 | debug_info "$MI_set_nutch_site_echo_6" |
|---|
| 365 | # debug_info "debug...edit http.agent.email delete line $((Line_NO+1))..." |
|---|
| 366 | sed -i ''$Line_NO'a <value>'$Admin_email'</value>' $Nutch_HOME/conf/nutch-site.xml |
|---|
| 367 | debug_info "$MI_set_nutch_site_echo_7" |
|---|
| 368 | # debug_info "debug...edit http.agent.email done..." |
|---|
| 369 | debug_info "$MI_set_nutch_site_echo_8" |
|---|
| 370 | # debug_info "set nutch-site.xml(done!)" |
|---|
| 371 | } |
|---|
| 372 | |
|---|
| 373 | function format_HDFS () { |
|---|
| 374 | debug_info "$MI_format_HDFS_echo_1" |
|---|
| 375 | su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format" |
|---|
| 376 | debug_info "$MI_format_HDFS_echo_2" |
|---|
| 377 | } |
|---|
| 378 | |
|---|
| 379 | function start_up_NutchEZ (){ |
|---|
| 380 | debug_info "$MI_start_up_NutchEZ_echo_1" |
|---|
| 381 | # debug_info "start up NutchEZ..." |
|---|
| 382 | su nutchuser -c "$Nutch_HOME/bin/start-all.sh" |
|---|
| 383 | } |
|---|
| 384 | |
|---|
| 385 | |
|---|
| 386 | function set_hosts () { |
|---|
| 387 | debug_info "$MI_set_hosts_echo_1" |
|---|
| 388 | cp /etc/hosts /home/nutchuser/nutchez/system/hosts.bak |
|---|
| 389 | Line_NO=`cat /etc/hosts | grep -n $(hostname) | sed 's/:.*//g'` |
|---|
| 390 | content=$(cat /etc/hosts | awk 'NR=='$Line_NO'{printf "# " ; print}' ) |
|---|
| 391 | sed -i ""$Line_NO"c $content" /etc/hosts |
|---|
| 392 | sed -i '1i '$MasterIP_Address' '$(hostname)'' /etc/hosts |
|---|
| 393 | } |
|---|
| 394 | |
|---|
| 395 | function Install_Nutch () { |
|---|
| 396 | debug_info "$MI_install_Nutch_echo_1 $MasterIP_Address " |
|---|
| 397 | # debug_info "MasterIP_Address=$MasterIP_Address" |
|---|
| 398 | debug_info "$MI_install_Nutch_echo_2 $(hostname)" |
|---|
| 399 | # debug_info "Master_Hostname=$(hostname)" |
|---|
| 400 | su nutchuser -c "ssh -o StrictHostKeyChecking=no localhost echo $net_address $(hostname) $net_MacAddr \>\> ~/nutchez/system/nutch_nodes" |
|---|
| 401 | set_hosts |
|---|
| 402 | set_haoop-site |
|---|
| 403 | set_nutch-site |
|---|
| 404 | } |
|---|
| 405 | |
|---|
| 406 | |
|---|
| 407 | function client_PassMasterIPAddr () { |
|---|
| 408 | cd $Work_Path |
|---|
| 409 | Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'` |
|---|
| 410 | debug_info "$MI_client_PassMasterIPAddr_echo_1" |
|---|
| 411 | # debug_info "debug...Master IP here line number = $Line_NO..." |
|---|
| 412 | sed -i ''$((Line_NO+1))'d' client_install |
|---|
| 413 | debug_info "$MI_client_PassMasterIPAddr_echo_2" |
|---|
| 414 | # debug_info "debug...edit Master IP at line $((Line_NO+1))..." |
|---|
| 415 | sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install |
|---|
| 416 | debug_info "$MI_client_PassMasterIPAddr_echo_3" |
|---|
| 417 | # debug_info "edit client_install done..." |
|---|
| 418 | } |
|---|
| 419 | |
|---|
| 420 | |
|---|
| 421 | function client_PassMaster_Hostname () { |
|---|
| 422 | cd $Work_Path |
|---|
| 423 | Line_NO=`cat client_install | grep -n '# Master Hostname here' | sed 's/:.*//g'` |
|---|
| 424 | debug_info "$MI_client_PassMaster_Hostname_echo_1" |
|---|
| 425 | # debug_info "debug...Master hostname here line number = $Line_NO..." |
|---|
| 426 | sed -i ''$((Line_NO+1))'d' client_install |
|---|
| 427 | debug_info "$MI_client_PassMaster_Hostname_echo_2" |
|---|
| 428 | # debug_info "debug...edit Master Hostname at line $((Line_NO+1))..." |
|---|
| 429 | sed -i ''$Line_NO'a Master_Hostname='$(hostname)'' client_install |
|---|
| 430 | debug_info "$MI_client_PassMaster_Hostname_echo_3" |
|---|
| 431 | # debug_info "edit client_install done..." |
|---|
| 432 | } |
|---|
| 433 | |
|---|
| 434 | function client_PassMasterIPAddr_for_Remove () { |
|---|
| 435 | cd $Work_Path |
|---|
| 436 | Line_NO=`cat client_remove | grep -n "# Master IP here" | sed 's/:.*//g'` |
|---|
| 437 | sed -i ''$((Line_NO+1))'d' client_remove |
|---|
| 438 | sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_remove |
|---|
| 439 | } |
|---|
| 440 | |
|---|
| 441 | |
|---|
| 442 | function client_PassMasterIPAddr_for_deploy () { |
|---|
| 443 | cd $Work_Path |
|---|
| 444 | Line_NO=`cat client_deploy | grep -n "# Master IP here" | sed 's/:.*//g'` |
|---|
| 445 | sed -i ''$((Line_NO+1))'d' client_deploy |
|---|
| 446 | sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_deploy |
|---|
| 447 | } |
|---|
| 448 | |
|---|
| 449 | function make_client_install () { |
|---|
| 450 | # 建立資料夾(用來存放client的安奘檔) |
|---|
| 451 | |
|---|
| 452 | if [ ! -d "$User_HOME/source" ]; then |
|---|
| 453 | su nutchuser -c "mkdir $User_HOME/source" |
|---|
| 454 | fi |
|---|
| 455 | |
|---|
| 456 | |
|---|
| 457 | # 將Master_IP_Address給client |
|---|
| 458 | # 打包安裝目錄(不含tomcat) |
|---|
| 459 | |
|---|
| 460 | debug_info "$MI_make_client_install_echo_1" |
|---|
| 461 | # debug_info "function make_client_install..." |
|---|
| 462 | |
|---|
| 463 | client_PassMasterIPAddr |
|---|
| 464 | client_PassMaster_Hostname |
|---|
| 465 | client_PassMasterIPAddr_for_Remove |
|---|
| 466 | client_PassMasterIPAddr_for_deploy |
|---|
| 467 | cd /opt/nutchez/ |
|---|
| 468 | su nutchuser -c "tar -cvzf NutchezForClientOf_$MasterIP_Address.tar.gz nutch" |
|---|
| 469 | |
|---|
| 470 | # 複製檔案至$User_HOME/source目錄下 |
|---|
| 471 | mv NutchezForClientOf_$MasterIP_Address.tar.gz /home/nutchuser/nutchez/source |
|---|
| 472 | cp $Work_Path/client_install $Work_Path/client_install_func.sh $Work_Path/client_remove $Work_Path/lang_link $Work_Path/client_deploy /home/nutchuser/nutchez/source |
|---|
| 473 | cp -r $Work_Path/lang /home/nutchuser/nutchez/source |
|---|
| 474 | cp -r $Work_Path/lang /home/nutchuser/nutchez/system |
|---|
| 475 | cp $Work_Path/nutchez $Work_Path/lang_link $Work_Path/add_hosts $Work_Path/duplicate_del $Work_Path/master_remove $Work_Path/go.sh /home/nutchuser/nutchez/system |
|---|
| 476 | |
|---|
| 477 | # 複製 nutchez/source 到使用者的安裝資料夾 |
|---|
| 478 | |
|---|
| 479 | |
|---|
| 480 | |
|---|
| 481 | if [ ! -d "$Install_Dir/Client_Install_DIR" ]; then |
|---|
| 482 | mkdir $Install_Dir/Client_Install_DIR |
|---|
| 483 | fi |
|---|
| 484 | cp -rf /home/nutchuser/nutchez/source/* $Install_Dir/Client_Install_DIR/ |
|---|
| 485 | |
|---|
| 486 | # cp $Work_Path/client_install $Work_Path/client_install /home/nutchuser/nutchez/source |
|---|
| 487 | # cp $Work_Path/client_install $Work_Path/client_remove /home/nutchuser/nutchez/source |
|---|
| 488 | # cp $Work_Path/client_install $Work_Path/lang* /home/nutchuser/nutchez/source |
|---|
| 489 | } |
|---|
| 490 | |
|---|
| 491 | function start_up_tomcat () { |
|---|
| 492 | debug_info "$MI_start_up_tomcat_echo_1" |
|---|
| 493 | # debug_info "start up tomcat..." |
|---|
| 494 | |
|---|
| 495 | i=10 |
|---|
| 496 | debug_info "$MI_start_up_tomcat_echo_2" |
|---|
| 497 | until [ $i -lt 1 ] |
|---|
| 498 | do |
|---|
| 499 | sleep 1s |
|---|
| 500 | i=`expr $i - 1` |
|---|
| 501 | done |
|---|
| 502 | su nutchuser -c "$Tomcat_HOME/bin/startup.sh" |
|---|
| 503 | debug_info "$MI_start_up_tomcat_echo_3" |
|---|
| 504 | # debug_info "tomcat has been started..." |
|---|
| 505 | } |
|---|
| 506 | |
|---|
| 507 | ###最後再整理### |
|---|
| 508 | # client簡易步驟 |
|---|
| 509 | function client_install_commands () { |
|---|
| 510 | show_info "$MI_client_install_commands_echo_1" |
|---|
| 511 | show_info "$MI_client_install_commands_echo_2" |
|---|
| 512 | show_info "$MI_client_install_commands_echo_3" |
|---|
| 513 | show_info "$MI_client_install_commands_echo_4" |
|---|
| 514 | show_info "$MI_client_install_commands_echo_5" |
|---|
| 515 | } |
|---|