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