[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 ########### |
---|
[137] | 15 | User_HOME=/home/nutchuser/nutchez |
---|
| 16 | NutchEZ_HOME=/opt/nutchez |
---|
| 17 | Nutch_HOME=$NutchEZ_HOME/nutch |
---|
| 18 | Tomcat_HOME=$NutchEZ_HOME/tomcat |
---|
| 19 | Index_DB=$User_HOME/search |
---|
[130] | 20 | MasterIP_Address=`/sbin/ifconfig eth0 | grep 'inet addr' | sed 's/^.*addr://g' | sed 's/Bcast.*$//g' | sed 's/ .*// '` |
---|
[125] | 21 | |
---|
[137] | 22 | # DNS暫時以IP取代 |
---|
| 23 | MasterDNS=$MasterIP_Address |
---|
[125] | 24 | |
---|
[137] | 25 | function set_install_information () { |
---|
[139] | 26 | set_nutchuser_passwd |
---|
| 27 | read -p "Please enter Administrator's e-mail address: " Admin_email |
---|
[150] | 28 | select_eth |
---|
| 29 | MasterIP_Address=$net_address |
---|
| 30 | # read -p "Please enter the Master DNS: " MasterDNS |
---|
[139] | 31 | } |
---|
| 32 | |
---|
| 33 | function set_nutchuser_passwd () { |
---|
[137] | 34 | read -p "Please enter nutchuser's password : " nutchuser_passwd |
---|
| 35 | read -p "Please enter nutchuser's password again: " nutchuser_passwd_confirm |
---|
[139] | 36 | if [ $nutchuser_passwd != $nutchuser_passwd_confirm ]; then |
---|
| 37 | set_nutchuser_passwd |
---|
[137] | 38 | fi |
---|
[117] | 39 | } |
---|
| 40 | |
---|
[150] | 41 | |
---|
| 42 | function select_eth () { |
---|
| 43 | net_interfaces=$(ifconfig | grep ^eth | cut -d " " -f1) |
---|
| 44 | net_nu=$(echo $net_interfaces | wc -w) |
---|
| 45 | |
---|
| 46 | # 若只有一個 eth 時 |
---|
| 47 | if [ "$net_nu" == "1" ]; then |
---|
| 48 | ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1 |
---|
| 49 | net_address=$(ifconfig $net_interfaces | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1) |
---|
| 50 | # echo "net_address is $net_address" |
---|
| 51 | |
---|
| 52 | # 若有多個 eth 時 |
---|
| 53 | else |
---|
| 54 | declare -i i=1 |
---|
| 55 | echo -e "\nSystem have multiple network device, which network use for this machine: " |
---|
| 56 | |
---|
| 57 | for net in $net_interfaces |
---|
| 58 | do |
---|
| 59 | echo "($i) $net $(ifconfig $net | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1)" |
---|
| 60 | i=i+1 |
---|
| 61 | done |
---|
| 62 | |
---|
| 63 | read -p "Plz choice(1/2/3...): " net_choice |
---|
| 64 | if [ -z $net_choice ]; then |
---|
| 65 | net_choice=1 |
---|
| 66 | fi |
---|
| 67 | |
---|
| 68 | echo "Your choice is $net_choice" |
---|
| 69 | net_interface=$(echo $net_interfaces | cut -d " " -f $net_choice) |
---|
| 70 | ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1 |
---|
| 71 | net_address=$(ifconfig $net_interface | grep "inet addr:" | sed 's/^.*inet addr://g' | cut -d " " -f1) |
---|
| 72 | echo "net_address is $net_address" |
---|
| 73 | fi |
---|
| 74 | } |
---|
| 75 | |
---|
| 76 | |
---|
[137] | 77 | function show_info () { |
---|
[125] | 78 | echo "Administrator's e-mail address is $Admin_email." |
---|
[150] | 79 | echo "The Master IP Address is: $MasterDNS" |
---|
[117] | 80 | } |
---|
| 81 | |
---|
[137] | 82 | function confirm_install_information () { |
---|
[117] | 83 | read -p "Please confirm your install infomation: 1.Yes 2.No " confirm |
---|
| 84 | } |
---|
| 85 | |
---|
[139] | 86 | function make_ssh_key () { |
---|
| 87 | su nutchuser -c 'ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ""' |
---|
| 88 | su nutchuser -c "cp ~/.ssh/id_rsa.pub ~/.ssh/authorized_keys" |
---|
| 89 | } |
---|
| 90 | |
---|
| 91 | |
---|
[137] | 92 | function set_haoop-site () { |
---|
| 93 | echo "set $Nutch_HOME/conf/hadoop-site.xml" |
---|
| 94 | cd $Nutch_HOME/conf/ |
---|
[130] | 95 | cat > hadoop-site.xml << EOF |
---|
[125] | 96 | <configuration> |
---|
[137] | 97 | <property> |
---|
[125] | 98 | <name>fs.default.name</name> |
---|
[137] | 99 | <value>hdfs://$MasterIP_Address:9000</value> |
---|
| 100 | </property> |
---|
| 101 | <property> |
---|
[125] | 102 | <name>mapred.job.tracker</name> |
---|
[137] | 103 | <value>$MasterIP_Address:9001</value> |
---|
| 104 | </property> |
---|
| 105 | <property> |
---|
| 106 | <name>hadoop.tmp.dir</name> |
---|
| 107 | <value>/var/nutchez/nutch-nutchuser</value> |
---|
| 108 | </property> |
---|
[125] | 109 | </configuration> |
---|
| 110 | EOF |
---|
[117] | 111 | } |
---|
| 112 | |
---|
[137] | 113 | # 修改nutch-site.xml中-http.agent.url, http.agent.email |
---|
| 114 | function set_nutch-site () { |
---|
| 115 | echo "set $Nutch_HOME/conf/nutch-site.xml" |
---|
| 116 | Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.url' | sed 's/:.*//g'` |
---|
| 117 | echo "debug...http.agent.url line number = $Line_NO..." |
---|
| 118 | sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml |
---|
| 119 | echo "debug...edit http.agent.url delete line $((Line_NO+1))..." |
---|
| 120 | sed -i ''$Line_NO'a <value>'$MasterIP_Address'</value>' $Nutch_HOME/conf/nutch-site.xml |
---|
| 121 | echo "debug...edit http.agent.url done..." |
---|
[117] | 122 | |
---|
[137] | 123 | Line_NO=`cat $Nutch_HOME'/conf/nutch-site.xml' | grep -n 'http.agent.email' | sed 's/:.*//g'` |
---|
| 124 | echo "debug...http.agent.email line number = $Line_NO..." |
---|
[126] | 125 | |
---|
[137] | 126 | sed -i ''$((Line_NO+1))'d' $Nutch_HOME/conf/nutch-site.xml |
---|
| 127 | echo "debug...edit http.agent.email delete line $((Line_NO+1))..." |
---|
| 128 | sed -i ''$Line_NO'a <value>'$Admin_email'</value>' $Nutch_HOME/conf/nutch-site.xml |
---|
| 129 | echo "debug...edit http.agent.email done..." |
---|
[117] | 130 | } |
---|
| 131 | |
---|
[137] | 132 | function format_HDFS () { |
---|
[125] | 133 | echo "format HDFS..." |
---|
[139] | 134 | su nutchuser -c "$Nutch_HOME/bin/hadoop namenode -format" |
---|
[117] | 135 | } |
---|
| 136 | |
---|
[137] | 137 | function start_up_NutchEZ (){ |
---|
[125] | 138 | echo "start up NutchEZ..." |
---|
[139] | 139 | su nutchuser -c "$Nutch_HOME/bin/start-all.sh" |
---|
[117] | 140 | } |
---|
| 141 | |
---|
[137] | 142 | function Install_Nutch () { |
---|
[136] | 143 | set_haoop-site |
---|
| 144 | set_nutch-site |
---|
| 145 | } |
---|
| 146 | |
---|
[139] | 147 | |
---|
[140] | 148 | function client_PassMasterIPAddr () { |
---|
| 149 | Line_NO=`cat client_install | grep -n '# Master IP here' | sed 's/:.*//g'` |
---|
| 150 | echo "debug...Master IP here line number = $Line_NO..." |
---|
| 151 | sed -i ''$((Line_NO+1))'d' client_install |
---|
| 152 | echo "debug...edit Master IP at line $((Line_NO+1))..." |
---|
| 153 | sed -i ''$Line_NO'a Master_IP_Address='$MasterIP_Address'' client_install |
---|
| 154 | echo "edit client_install done..." |
---|
| 155 | } |
---|
| 156 | |
---|
[139] | 157 | function make_client_install () { |
---|
| 158 | # 將Master_IP_Address給client |
---|
| 159 | # 打包安裝目錄(不含tomcat) |
---|
[140] | 160 | echo "function make_client_install..." |
---|
| 161 | client_PassMasterIPAddr |
---|
[144] | 162 | su nutchuser -c "tar -cvzf /opt/nutchez/NutchezForClientOf_$Master_IP_Address.tar.gz /home/nutchuser/nutchez/" |
---|
[131] | 163 | } |
---|
| 164 | |
---|
[137] | 165 | function start_up_tomcat () { |
---|
[125] | 166 | echo "start up tomcat..." |
---|
[139] | 167 | sleep 10s |
---|
| 168 | echo "su nutchuser -c "$Tomcat_HOME/bin/startup.sh"" |
---|
| 169 | su nutchuser -c "$Tomcat_HOME/bin/startup.sh" |
---|
[117] | 170 | } |
---|
[144] | 171 | |
---|
[150] | 172 | # client簡易步驟 |
---|
[144] | 173 | function client_install_command () { |
---|
| 174 | echo "Client Install Command as Follows:" |
---|
| 175 | echo "cd ~" |
---|
| 176 | echo "mkdir NutchezClientInstall" |
---|
[150] | 177 | echo "scp 安裝的shell檔所在路徑/PATH/ ~/NutchezClientInstall" |
---|
[144] | 178 | echo "./client_install" |
---|
| 179 | } |
---|