1. 程式人生 > >筆記本連結桌上型電腦的HDFS叢集只需幾步

筆記本連結桌上型電腦的HDFS叢集只需幾步

第一步:

第二步:

學會怎麼配置虛擬網路之後我們看一下這個配置檔案 hdfs-site.xml

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<property>
		<name>dfs.nameservices</name>
 		<value>mycluster</value>
 	</property>
 	<property>
 		<name>dfs.ha.namenodes.mycluster</name>
 		<value>nn1,nn2</value>
 	</property>
        <property>  
		 <name>dfs.namenode.rpc-address.mycluster.nn1</name>
                 <value>node01:8020</value>
        </property>
	<property>
       		 <name>dfs.namenode.rpc-address.mycluster.nn2</name>     		                
       		 <value>node02:8020</value>
       	</property>
	<property>
             <name>dfs.namenode.http-address.mycluster.nn1</name>
      		 <value>node01:50070</value>
        </property>
        <property>
        	<name>dfs.namenode.http-address.mycluster.nn2</name>
                <value>node02:50070</value>
 	</property>
 	<property>
 		<name>dfs.namenode.shared.edits.dir</name>
 		<value>qjournal://node01:8485;node02:8485;node03:8485/mycluster</value>
 	</property>
	<property>
                <name>dfs.journalnode.edits.dir</name>
                <value>/var/abc/hadoop/ha/jn</value>
        </property>
        <property>
 	       <name>dfs.client.failover.proxy.provider.mycluster</name>  	
 	       <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
 	</property>
        <property>
               <name>dfs.ha.fencing.methods</name>
               <value>sshfence</value>
        </property>
        <property>
               <name>dfs.ha.fencing.ssh.private-key-files</name>
               <value>/root/.ssh/id_rsa</value>
        </property>
        <property>
 	       <name>dfs.ha.automatic-failover.enabled</name>
               <value>true</value>
        </property>

</configuration>

第三步 修改虛擬機器和本機的Ip埠對映

可以看到上面有許多埠號,是虛擬機器的埠.我們去VMware修改這些埠的對映 修改方法參看:區域網下用其他電腦連線VM虛擬機器方法 在這裡插入圖片描述 如此一來我們就把虛擬機器node01的50070埠對映為本機的50071埠下了,同樣的我們將上面程式碼所有的埠全部用本機埠對映一遍, 在這裡插入圖片描述 在這裡插入圖片描述 在這裡插入圖片描述 在這裡插入圖片描述 這裡就不全部貼出來了,修改完成之後

第四步 修改配置檔案

為本機的Ip加對應的埠號

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
	<property>
		<name>dfs.nameservices</name>
 		<value>mycluster</value>
 	</property>
 	<property>
 		<name>dfs.ha.namenodes.mycluster</name>
 		<value>nn1,nn2</value>
 	</property>
        <property>  
		 <name>dfs.namenode.rpc-address.mycluster.nn1</name>
                 <value>172.17.36.93:18020</value>
        </property>
	<property>
       		 <name>dfs.namenode.rpc-address.mycluster.nn2</name>     		                
       		 <value>172.17.36.93:28020</value>
       	</property>
	<property>
             <name>dfs.namenode.http-address.mycluster.nn1</name>
      		 <value>172.17.36.93:50073</value>
        </property>
        <property>
        	<name>dfs.namenode.http-address.mycluster.nn2</name>
                <value>172.17.36.93:50072</value>
 	</property>
 	<property>
 		<name>dfs.namenode.shared.edits.dir</name>
 		<value>qjournal://172.17.36.93:18485;172.17.36.93:28485;172.17.36.93:38485/mycluster</value>
 	</property>
	<property>
                <name>dfs.journalnode.edits.dir</name>
                <value>/var/abc/hadoop/ha/jn</value>
        </property>
        <property>
 	       <name>dfs.client.failover.proxy.provider.mycluster</name>  	
 	       <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value>
 	</property>
        <property>
               <name>dfs.ha.fencing.methods</name>
               <value>sshfence</value>
        </property>
        <property>
               <name>dfs.ha.fencing.ssh.private-key-files</name>
               <value>/root/.ssh/id_rsa</value>
        </property>
        <property>
 	       <name>dfs.ha.automatic-failover.enabled</name>
               <value>true</value>
        </property>

</configuration>

到這裡還沒完,還有一個配置檔案需要修改 core-site.xml 同樣的操作,將原來2181埠對映為本機的埠,修改配置檔案為

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>

	<property> 
		<name>fs.defaultFS</name>
      		<value>hdfs://mycluster</value>
      </property>
      <property>
         	<name>ha.zookeeper.quorum</name>
         	<value>172.17.36.93:21812,172.17.36.93:21813,172.17.36.93:21814</value>
      </property>


</configuration>

完成上述操作後在本機啟動你的web專案已經和原來一樣可以用了 但是用其他電腦執行web專案仍然報404什麼原因呢? 答案是本機的防火牆需要放出剛才設定的那些埠,或者直接將防火牆關閉 在這裡插入圖片描述 如此一來,在同一區域網下的所有電腦,只要帶著你修改後的配置檔案,就可以訪問你的HDFS叢集了.

感謝您的瀏覽