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