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