宅客学院hadoop培训费用怎么样?

hadoop2.6.0部署好环境后写的一个简单的test
bruce__ray
发布时间: 10:14:38
实用maven创建java工程,引入hadoop的依赖
&dependencies&&&
&&&&&dependency&&&
&&&&&&&&&groupId&junit&/groupId&&&
&&&&&&&&&artifactId&junit&/artifactId&&&
&&&&&&&&&version&3.8.1&/version&&&
&&&&&&&&&scope&test&/scope&&&
&&&&&/dependency&&&
&&&&&dependency&&&
&&&&&&&&&groupId&org..hadoop&/groupId&&&
&&&&&&&&&artifactId&hadoop-hdfs&/artifactId&&&
&&&&&&&&&version&2.6.0&/version&&&
&&&&&/dependency&&&
&&&&&dependency&&&
&&&&&&&&&groupId&org.apache.hadoop&/groupId&&&
&&&&&&&&&artifactId&hadoop-client&/artifactId&&&
&&&&&&&&&version&2.6.0&/version&&&
&&&&&/dependency&&&
&&&&&dependency&&&
&&&&&&&&&groupId&org.apache.hadoop&/groupId&&&
&&&&&&&&&artifactId&hadoop-mapreduce-examples&/artifactId&&&
&&&&&&&&&version&2.6.0&/version&&&
&&&&&&&&&type&pom&/type&&&
&&&&&/dependency&&&
&/dependencies&&&
另外给main方法设置成jar包入口
&&&&&finalName&${project.artifactId}&/finalName&&&
&&&&&plugins&&&
&&&&&&&&&plugin&&&
&&&&&&&&&&&&&groupId&org.apache.maven.plugins&/groupId&&&
&&&&&&&&&&&&&artifactId&maven-shade-plugin&/artifactId&&&
&&&&&&&&&&&&&version&1.4&/version&&&
&&&&&&&&&&&&&executions&&&
&&&&&&&&&&&&&&&&&execution&&&
&&&&&&&&&&&&&&&&&&&&&phase&package&/phase&&&
&&&&&&&&&&&&&&&&&&&&&goals&&&
&&&&&&&&&&&&&&&&&&&&&&&&&goal&shade&/goal&&&
&&&&&&&&&&&&&&&&&&&&&/goals&&&
&&&&&&&&&&&&&&&&&&&&&configuration&&&
&&&&&&&&&&&&&&&&&&&&&&&&&transformers&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&transformer&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&implementation=&org.apache.maven.plugins.shade.resource.ManifestResourceTransformer&&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&mainClass&my.hadoopstudy.dfs.Test&/mainClass&&&
&&&&&&&&&&&&&&&&&&&&&&&&&&&&&/transformer&&&
&&&&&&&&&&&&&&&&&&&&&&&&&/transformers&&&
&&&&&&&&&&&&&&&&&&&&&/configuration&&&
&&&&&&&&&&&&&&&&&/execution&&&
&&&&&&&&&&&&&/executions&&&
&&&&&&&&&/plugin&&&
&&&&&&&&&plugin&&&
&&&&&&&&&&&&&groupId&org.apache.maven.plugins&/groupId&&&
&&&&&&&&&&&&&artifactId&maven-source-plugin&/artifactId&&&
&&&&&&&&&&&&&version&2.1.2&/version&&&
&&&&&&&&&&&&&configuration&&&
&&&&&&&&&&&&&&&&&attach&true&/attach&&&
&&&&&&&&&&&&&/configuration&&&
&&&&&&&&&&&&&executions&&&
&&&&&&&&&&&&&&&&&execution&&&
&&&&&&&&&&&&&&&&&&&&&phase&compile&/phase&&&
&&&&&&&&&&&&&&&&&&&&&goals&&&
&&&&&&&&&&&&&&&&&&&&&&&&&goal&jar&/goal&&&
&&&&&&&&&&&&&&&&&&&&&/goals&&&
&&&&&&&&&&&&&&&&&/execution&&&
&&&&&&&&&&&&&/executions&&&
&&&&&&&&&/plugin&&&
&&&&&/plugins&&&
&/build&&&
然后去写test这个类
package&my.hadoopstudy.&&
import&java.io.BufferedR&&
import&java.io.FilterInputS&&
import&java.io.IOE&&
import&java.io.InputStreamR&&
import&java.net.URI;&&
import&org.apache.hadoop.conf.C&&
import&org.apache.hadoop.fs.FSDataOutputS&&
import&org.apache.hadoop.fs.FileS&&
import&org.apache.hadoop.fs.FileS&&
import&org.apache.hadoop.fs.P&&
import&org.slf4j.L&&
import&org.slf4j.LoggerF&&
public&class&Test&{&&
&&&&private&static&final&Logger&LOGGER&=&LoggerFactory.getLogger(Test.class);&&
&&&&public&static&void&main(String[]&args)&{&&
&&&&&&&&String&uri&=&&hdfs://192.168.184.128:9000/&;&&
&&&&&&&&Configuration&config&=&new&Configuration();&&
&&&&&&&&FileSystem&fs&=&null;&&
&&&&&&&&try&{&&
&&&&&&&&&&&&fs&=&FileSystem.get(URI.create(uri),&config);&&
&&&&&&&&}&catch&(IOException&e)&{&&
&&&&&&&&&&&&LOGGER.error(&get&url&&+&uri+&error&&+&e);&&
&&&&&&&&}&&
&&&&&&&&//&列出hdfs上/user/fkong/目录下的所有文件和目录&&
&&&&&&&&FileStatus[]&statuses&=&null;&&
&&&&&&&&try&{&&
&&&&&&&&&&&&statuses&=&fs.listStatus(new&Path(&/usr/local&));&&
&&&&&&&&}&catch&(Exception&e)&{&&
&&&&&&&&&&&&LOGGER.error(&listStatus&&/usr/local&error&&+&e);&&
&&&&&&&&}&&
&&&&&&&&for&(FileStatus&status&:&statuses)&{&&
&&&&&&&&&&&&(status&+&&&&);&&
&&&&&&&&}&&
&&&&&&&&//&在hdfs的/user/fkong目录下创建一个文件,并写入一行文本&&
&&&&&&&&FSDataOutputStream&os&=&null;&&
&&&&&&&&try&{&&
&&&&&&&&&&&&os&=&fs.create(new&Path(&/usr/local/test.log&));&&
&&&&&&&&&&&&os.write(&Hello&World!&.getBytes());&&
&&&&&&&&&&&&os.flush();&&
&&&&&&&&}&catch&(Exception&e)&{&&
&&&&&&&&&&&&LOGGER.error(&create&/usr/local/test.log&error&&&+&e);&&
&&&&&&&&}&&
&&&&&&&&try&{&&
&&&&&&&&&&&&os.flush();&&
&&&&&&&&&&&&if&(os&!=&null)&{&&
&&&&&&&&&&&&&&&&os.close();&&
&&&&&&&&&&&&}&&
&&&&&&&&}&catch&(IOException&e)&{&&
&&&&&&&&&&&&LOGGER.error(&close&/usr/local/test.log&error&&&+&e);&&
&&&&&&&&}&&
&&&&&&&&//&显示在hdfs的/user/fkong下指定文件的内容&&
&&&&&&&&FilterInputStream&is&=&null;&&
&&&&&&&&BufferedReader&bufferedReader&=&null;&&
&&&&&&&&InputStreamReader&isr&=&null;&&
&&&&&&&&try&{&&
&&&&&&&&&&&&is&=&fs.open(new&Path(&/usr/local/test.log&));&&
&&&&&&&&&&&&isr&=&new&InputStreamReader(is,&&UTF-8&);&&
&&&&&&&&&&&&bufferedReader&=&new&BufferedReader(isr);&&
&&&&&&&&&&&&String&content&=&null;&&
&&&&&&&&&&&&while&((content&=&bufferedReader.readLine())&!=&null)&{&&
&&&&&&&&&&&&&&&&(&content:&&+&content);&&
&&&&&&&&&&&&}&&
&&&&&&&&}&catch&(Exception&e)&{&&
&&&&&&&&&&&&LOGGER.error(&open&/usr/local/test.log&error&&&+&e);&&
&&&&&&&&}&&
&&&&&&&&(&成功&);&&
写完后将maven打成jar的形式,maven的命令是clean package
打成架包后将架包放入hadoop主机上运行。java -jar ***.jar就可以了
如果碰到由于路由器什么的问题可以看
http://blog.csdn.net/qq_/article/details/这篇文章
&15:11:02,638&DEBUG&[org.apache.hadoop.metrics2.lib.MutableMetricsFactory]:42&-&field&org.apache.hadoop.metrics2.lib.MutableRate&org.apache.hadoop.security.UserGroupInformation$UgiMetrics.loginSuccess&with&annotation&@org.apache.hadoop.metrics2.annotation.Metric(about=,&sampleName=Ops,&always=false,&type=DEFAULT,&valueName=Time,&value=[Rate&of&successful&kerberos&logins&and&latency&(milliseconds)])&&
&15:11:02,659&DEBUG&[org.apache.hadoop.metrics2.lib.MutableMetricsFactory]:42&-&field&org.apache.hadoop.metrics2.lib.MutableRate&org.apache.hadoop.security.UserGroupInformation$UgiMetrics.loginFailure&with&annotation&@org.apache.hadoop.metrics2.annotation.Metric(about=,&sampleName=Ops,&always=false,&type=DEFAULT,&valueName=Time,&value=[Rate&of&failed&kerberos&logins&and&latency&(milliseconds)])&&
&15:11:02,670&DEBUG&[org.apache.hadoop.metrics2.lib.MutableMetricsFactory]:42&-&field&org.apache.hadoop.metrics2.lib.MutableRate&org.apache.hadoop.security.UserGroupInformation$UgiMetrics.getGroups&with&annotation&@org.apache.hadoop.metrics2.annotation.Metric(about=,&sampleName=Ops,&always=false,&type=DEFAULT,&valueName=Time,&value=[GetGroups])&&
&15:11:02,672&DEBUG&[org.apache.hadoop.metrics2.impl.MetricsSystemImpl]:231&-&UgiMetrics,&User&and&group&related&metrics&&
&15:11:02,867&DEBUG&[org.apache.hadoop.security.Groups]:278&-&&Creating&new&Groups&object&&
&15:11:02,879&DEBUG&[org.apache.hadoop.util.NativeCodeLoader]:46&-&Trying&to&load&the&custom-built&native-hadoop&library...&&
&15:11:02,885&DEBUG&[org.apache.hadoop.util.NativeCodeLoader]:55&-&Failed&to&load&native-hadoop&with&error:&java.lang.UnsatisfiedLinkError:&no&hadoop&in&java.library.path&&
&15:11:02,886&DEBUG&[org.apache.hadoop.util.NativeCodeLoader]:56&-&java.library.path=/usr/java/packages/lib/amd64:/usr/lib64:/lib64:/lib:/usr/lib&&
&15:11:02,886&WARN&&[org.apache.hadoop.util.NativeCodeLoader]:62&-&Unable&to&load&native-hadoop&library&for&your&platform...&using&builtin-java&classes&where&applicable&&
&15:11:02,887&DEBUG&[org.apache.hadoop.util.PerformanceAdvisory]:41&-&Falling&back&to&&based&&
&15:11:02,891&DEBUG&[org.apache.hadoop.security.JniBasedUnixGroupsMappingWithFallback]:45&-&Group&mapping&impl=org.apache.hadoop.security.ShellBasedUnixGroupsMapping&&
&15:11:03,101&DEBUG&[org.apache.hadoop.util.Shell]:396&-&setsid&exited&with&exit&code&0&&
&15:11:03,103&DEBUG&[org.apache.hadoop.security.Groups]:91&-&Group&mapping&impl=org.apache.hadoop.security.JniBasedUnixGroupsMappingWithF&cacheTimeout=300000;&warningDeltaMs=5000&&
&15:11:03,123&DEBUG&[org.apache.hadoop.security.UserGroupInformation]:209&-&hadoop&login&&
&15:11:03,124&DEBUG&[org.apache.hadoop.security.UserGroupInformation]:144&-&hadoop&login&commit&&
&15:11:03,139&DEBUG&[org.apache.hadoop.security.UserGroupInformation]:174&-&using&local&user:UnixPrincipal:&root&&
&15:11:03,153&DEBUG&[org.apache.hadoop.security.UserGroupInformation]:180&-&Using&user:&&UnixPrincipal:&root&&with&name&root&&
&15:11:03,154&DEBUG&[org.apache.hadoop.security.UserGroupInformation]:190&-&User&entry:&&root&&&
&15:11:03,159&DEBUG&[org.apache.hadoop.security.UserGroupInformation]:799&-&UGI&loginUser:root&(auth:SIMPLE)&&
&15:11:03,421&DEBUG&[org.apache.hadoop.hdfs.BlockReaderLocal]:443&-&dfs.client.use.legacy.blockreader.local&=&false&&
&15:11:03,421&DEBUG&[org.apache.hadoop.hdfs.BlockReaderLocal]:446&-&dfs.client.read.shortcircuit&=&false&&
&15:11:03,424&DEBUG&[org.apache.hadoop.hdfs.BlockReaderLocal]:449&-&dfs.client.domain.socket.data.traffic&=&false&&
&15:11:03,424&DEBUG&[org.apache.hadoop.hdfs.BlockReaderLocal]:452&-&dfs.domain.socket.path&=&&
&15:11:03,477&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:634&-&No&KeyProvider&found.&&
&15:11:03,557&DEBUG&[org.apache.hadoop.io.retry.RetryUtils]:74&-&multipleLinearRandomRetry&=&null&&
&15:11:03,634&DEBUG&[org.apache.hadoop.ipc.Server]:233&-&rpcKind=RPC_PROTOCOL_BUFFER,&rpcRequestWrapperClass=class&org.apache.hadoop.ipc.ProtobufRpcEngine$RpcRequestWrapper,&rpcInvoker=org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker@31206beb&&
&15:11:03,668&DEBUG&[org.apache.hadoop.ipc.Client]:63&-&getting&client&out&of&cache:&org.apache.hadoop.ipc.Client@77be656f&&
&15:11:04,503&DEBUG&[org.apache.hadoop.util.PerformanceAdvisory]:109&-&Both&short-circuit&local&reads&and&UNIX&domain&socket&are&disabled.&&
&15:11:04,519&DEBUG&[org.apache.hadoop.hdfs.protocol.datatransfer.sasl.DataTransferSaslUtil]:183&-&DataTransferProtocol&not&using&SaslPropertiesResolver,&no&QOP&found&in&configuration&for&dfs.data.transfer.protection&&
&15:11:04,582&DEBUG&[org.apache.hadoop.ipc.Client]:427&-&The&ping&interval&is&60000&ms.&&
&15:11:04,585&DEBUG&[org.apache.hadoop.ipc.Client]:697&-&Connecting&to&/192.168.184.128:9000&&
&15:11:04,754&DEBUG&[org.apache.hadoop.ipc.Client]:961&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root:&starting,&having&connections&1&&
&15:11:04,756&DEBUG&[org.apache.hadoop.ipc.Client]:1024&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&sending&#0&&
&15:11:04,815&DEBUG&[org.apache.hadoop.ipc.Client]:1081&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&got&value&#0&&
&15:11:04,816&DEBUG&[org.apache.hadoop.ipc.ProtobufRpcEngine]:253&-&Call:&getListing&took&276ms&&
&15:11:04,859&INFO&&[my.hadoopstudy.dfs.Test]:44&-&FileStatus{path=hdfs://192.168.184.128:9000/usr/local/&isDirectory=&modification_time=3;&access_time=0;&owner=&group=&permission=rwxr-xr-x;&isSymlink=false}&&
&15:11:04,860&INFO&&[my.hadoopstudy.dfs.Test]:44&-&FileStatus{path=hdfs://192.168.184.128:9000/usr/local/test.&isDirectory=&length=0;&replication=3;&blocksize=;&modification_time=8;&access_time=8;&owner=&group=&permission=rw-r--r--;&isSymlink=false}&&
&15:11:04,863&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1657&-&/usr/local/test.log:&masked=rw-r--r--&&
&15:11:04,923&DEBUG&[org.apache.hadoop.ipc.Client]:1024&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&sending&#1&&
&15:11:04,930&DEBUG&[org.apache.hadoop.ipc.Client]:1081&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&got&value&#1&&
&15:11:04,930&DEBUG&[org.apache.hadoop.ipc.ProtobufRpcEngine]:253&-&Call:&create&took&11ms&&
&15:11:04,940&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1806&-&computePacketChunkSize:&src=/usr/local/test.log,&chunkSize=516,&chunksPerPacket=127,&packetSize=65532&&
&15:11:04,959&DEBUG&[org.apache.hadoop.hdfs.LeaseRenewer]:295&-&Lease&renewer&daemon&for&[DFSClient_NONMAPREDUCE__1]&with&renew&id&1&started&&
&15:11:04,965&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1873&-&DFSClient&writeChunk&allocating&new&packet&seqno=0,&src=/usr/local/test.log,&packetSize=65532,&chunksPerPacket=127,&bytesCurBlock=0&&
&15:11:04,965&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1819&-&Queued&packet&0&&
&15:11:04,966&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:586&-&Allocating&new&block&&
&15:11:04,971&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1819&-&Queued&packet&1&&
&15:11:04,972&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:2137&-&Waiting&for&ack&for:&1&&
&15:11:04,989&DEBUG&[org.apache.hadoop.ipc.Client]:1024&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&sending&#2&&
&15:11:04,995&DEBUG&[org.apache.hadoop.ipc.Client]:1081&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&got&value&#2&&
&15:11:04,996&DEBUG&[org.apache.hadoop.ipc.ProtobufRpcEngine]:253&-&Call:&addBlock&took&11ms&&
&15:11:05,015&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1394&-&pipeline&=&192.168.184.129:50010&&
&15:11:05,017&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1394&-&pipeline&=&192.168.184.130:50010&&
&15:11:05,017&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1605&-&Connecting&to&datanode&192.168.184.129:50010&&
&15:11:05,019&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:1614&-&Send&buf&size&124928&&
&15:11:05,021&DEBUG&[org.apache.hadoop.ipc.Client]:1024&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&sending&#3&&
&15:11:05,023&DEBUG&[org.apache.hadoop.ipc.Client]:1081&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&got&value&#3&&
&15:11:05,025&DEBUG&[org.apache.hadoop.ipc.ProtobufRpcEngine]:253&-&Call:&getServerDefaults&took&4ms&&
&15:11:05,033&DEBUG&[org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslDataTransferClient]:244&-&SASL&client&skipping&handshake&in&unsecured&configuration&for&addr&=&/192.168.184.129,&datanodeId&=&192.168.184.129:50010&&
&15:11:05,312&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:637&-&DataStreamer&block&BP-2.168.184.128-6:blk__1024&sending&packet&packet&seqno:0&offsetInBlock:0&lastPacketInBlock:false&lastByteOffsetInBlock:&12&&
&15:11:05,494&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:876&-&DFSClient&seqno:&0&status:&SUCCESS&status:&SUCCESS&downstreamAckTimeNanos:&1635651&&
&15:11:05,494&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:637&-&DataStreamer&block&BP-2.168.184.128-6:blk__1024&sending&packet&packet&seqno:1&offsetInBlock:12&lastPacketInBlock:true&lastByteOffsetInBlock:&12&&
&15:11:05,502&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:876&-&DFSClient&seqno:&1&status:&SUCCESS&status:&SUCCESS&downstreamAckTimeNanos:&3076249&&
&15:11:05,509&DEBUG&[org.apache.hadoop.ipc.Client]:1024&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&sending&#4&&
&15:11:05,514&DEBUG&[org.apache.hadoop.ipc.Client]:1081&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&got&value&#4&&
&15:11:05,516&DEBUG&[org.apache.hadoop.ipc.ProtobufRpcEngine]:253&-&Call:&complete&took&8ms&&
&15:11:05,543&DEBUG&[org.apache.hadoop.ipc.Client]:1024&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&sending&#5&&
&15:11:05,552&DEBUG&[org.apache.hadoop.ipc.Client]:1081&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root&got&value&#5&&
&15:11:05,554&DEBUG&[org.apache.hadoop.ipc.ProtobufRpcEngine]:253&-&Call:&getBlockLocations&took&23ms&&
&15:11:05,557&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:273&-&newInfo&=&LocatedBlocks{&&
&&fileLength=12&&
&&underConstruction=false&&
&&blocks=[LocatedBlock{BP-2.168.184.128-6:blk__1024;&getBlockSize()=12;&corrupt=&offset=0;&locs=[192.168.184.129:58.184.130:50010];&storageIDs=[DS-b0a4e12f-e888--ef38deb2c0d7,&DS-777e-3a678f1281];&storageTypes=[DISK,&DISK]}]&&
&&lastLocatedBlock=LocatedBlock{BP-2.168.184.128-6:blk__1024;&getBlockSize()=12;&corrupt=&offset=0;&locs=[192.168.184.129:58.184.130:50010];&storageIDs=[DS-b0a4e12f-e888--ef38deb2c0d7,&DS-777e-3a678f1281];&storageTypes=[DISK,&DISK]}&&
&&isLastBlockComplete=true}&&
&15:11:05,564&DEBUG&[org.apache.hadoop.hdfs.DFSClient]:960&-&Connecting&to&datanode&192.168.184.129:50010&&
&15:11:05,587&DEBUG&[org.apache.hadoop.hdfs.protocol.datatransfer.sasl.SaslDataTransferClient]:244&-&SASL&client&skipping&handshake&in&unsecured&configuration&for&addr&=&/192.168.184.129,&datanodeId&=&192.168.184.129:50010&&
&15:11:05,698&INFO&&[my.hadoopstudy.dfs.Test]:75&-&content:Hello&World!&&
&15:11:05,698&INFO&&[my.hadoopstudy.dfs.Test]:80&-&成功&&
&15:11:05,705&DEBUG&[org.apache.hadoop.ipc.Client]:97&-&stopping&client&from&cache:&org.apache.hadoop.ipc.Client@77be656f&&
&15:11:05,705&DEBUG&[org.apache.hadoop.ipc.Client]:103&-&removing&client&from&cache:&org.apache.hadoop.ipc.Client@77be656f&&
&15:11:05,705&DEBUG&[org.apache.hadoop.ipc.Client]:110&-&stopping&actual&client&because&no&more&references&remain:&org.apache.hadoop.ipc.Client@77be656f&&
&15:11:05,709&DEBUG&[org.apache.hadoop.ipc.Client]:1234&-&Stopping&client&&
&15:11:05,710&DEBUG&[org.apache.hadoop.ipc.Client]:1184&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root:&closed&&
&15:11:05,710&DEBUG&[org.apache.hadoop.ipc.Client]:979&-&IPC&Client&()&connection&to&/192.168.184.128:9000&from&root:&stopped,&remaining&connections&&
执行成功的日志
版权声明:本文为博主原创文章,未经博主允许不得转载。
来源:http://blog.csdn.net/bruce__ray/article/details/hadoop学习笔记&&环境搭建
一片相思林
发布时间: 14:25:32
基础环境准备:系统:(VirtualBox)&ubuntu-12.04.2-desktop-i386.isohadoop版本:hadoop-0.20.203.0rc1.tar.gzjdk版本:jdk-6u26--i586.bin&安装ssh服务sudo apt-get install openssh-server&在Ubuntu下创建hadoop用户组和用户$ sudo addgroup hadoop$ sudo adduser --ingroup hadoop hadoop&编辑/etc/sudoers文件,为hadoop用户添加权限$ sudo vim /etc/sudoers给hadoop用户赋予root相同的权限 hadoop &ALL=(ALL:ALL) ALL================================================================================hadoop实战之安装与单机模式-------------------------------------------------------------------------------- & &1. 下载最新的hadoop安装包,这里我使用的是hadoop-0.20.203.0rc1.tar.gz版本。下载地址:http://archive.apache.org/dist/hadoop/core/hadoop-0.20.203.0/hadoop-0.20.203.0rc1.tar.gz2. 解压压缩包到自己的目录,比如解压到/home/hadoop/data目录下(tar &zxvf hadoop-0.20.203.orc1.tar.gz),为了后面说明方便,这里把/home/hadoop/data/hadoop-0.20.203.0定义为$HADOOP_HOME; & 3. 修改$HADOOP_HOME/conf/hadoop-env.sh文件,将JAVA_HOME指定到正确的jdk路径上(echo $JAVA_HOME查看); & &4. 进入$HADOOP_HOME目录下执行以下命令,将会得到hadoop命令的帮助; & && $ bin/hadoop & &5. 进入$HADOOP_HOME目录下执行以下命令来测试安装是否成功 & && $ mkdir input & && $ cp conf/*.xml input & && $ bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+' & && $ cat output/*输出:hadoop@ubuntu-V01:~/data/hadoop-0.20.203.0$ cat output/* & &1&&& dfsadmin经过上面的步骤,如果没有出现错误就算安装成功了。================================================================================hadoop实战之伪分布式模式-------------------------------------------------------------------------------- & &Hadoop可以在单节点上以所谓的伪分布式模式运行,此时每一个Hadoop守护进程都作为一个独立的Java进程运行,这种运行方式的配置和操作如下:关于hadoop的安装和测试可以参考... & 这里仍假定${HADOOP_HOME}为位置是/home/hadoop/data/hadoop-0.20.203.0 & &1. 修改hadoop配置 & &1.1 编辑${HADOOP_HOME}/conf/core-site.xml文件,内容修改如下: & &&configuration& & && &property& & &&&& &name&fs.default.name&/name& & &&&& &value&hdfs://localhost:9000&/value& & && &/property& & &&/configuration& & &1.2 编辑${HADOOP_HOME}/conf/hdfs-site.xml文件,内如修改如下: & &&configuration& & && &property& & &&&& &name&dfs.replication&/name& & &&&& &value&1&/value& & && &/property& & &&/configuration& & &1.3 编辑${HADOOP_HOME}/conf/mapred-site.xml文件,内如修改如下: & &&configuration& & && &property& & &&&& &name&mapred.job.tracker&/name& & &&&& &value&localhost:9001&/value& & && &/property& & &&/configuration&2. 设置linux上ssh是用户可以自动登录 & $ ssh-keygen -t dsa -P '' -f ~/.ssh/id_dsa & &$ cat ~/.ssh/id_dsa.pub && ~/.ssh/authorized_keys3. 格式化一个新的分布式文件系统: & $ bin/hadoop namenode -format4. 执行hadoop & 4.1 启动hadoop后台daemon & &$ bin/start-all.sh & &启动后可以通过网页方式查看NameNode和JobTracker状态 & &NameNode - http://localhost:50070/ & &JobTracker - http://localhost:50030/ & &4.2 复制文件到分布式文件系统上 & &$ bin/hadoop fs -put conf input & &4.3 运行测试 & &$ bin/hadoop jar hadoop-examples-*.jar grep input output 'dfs[a-z.]+' & & & &4.4 获取测试程序的执行结果 & &$ bin/hadoop fs -cat output/*输出:hadoop@ubuntu-V01:~/data/hadoop-0.20.203.0$ bin/hadoop fs -cat output/* &2 dfs.replication &1 dfs.server.namenode. &1 dfsadmin4.5 停止hadoop后台daemon & &$ bin/stop-all.sh================================================================================hadoop实战之分布式模式&-------------------------------------------------------------------------------- & 1. 首先为hadoop的集群准备几台机器,这里机器名如下: & &ubuntu-V01(master) & &ubuntu-V02(slave1) & &ubuntu-V03(slave2)2. 修改每个机器的/etc/hosts文件,确保每个机器都可以通过机器名互相访问;3. 在上面每个机器上的相同位置分别安装hadoop,这里安装的都是hadoop-0.20.203.0rc1.tar.gz包,并且假定安装路径都是/home/hadoop/data/hadoop-0.20.203.0;4. 修改所有机器上的${HADOOP_HOME}/conf/hadoop-env.sh文件,将JAVA_HOME指定到正确的jdk路径上;5. 修改master机器上的${HADOOP_HOME}/conf/slaves文件,修改后文件内容如下: & ubuntu-V02 & &ubuntu-V036. 修改和部署配置文件 & 6.1 编辑${HADOOP_HOME}/conf/core-site.xml文件,内容修改如下: & &&configuration& & && &property& & &&&& &name&fs.default.name&/name& & &&&& &value&hdfs://ubuntu-V01:9000&/value& & && &/property& & && &property& & &&&& &name&hadoop.tmp.dir&/name& & &&&& &value&/home/hadoop/data/hadoop-0.20.203.0/hadoop-${user.name}&/value& & && &/property& & &&/configuration& & &6.2 编辑${HADOOP_HOME}/conf/hdfs-site.xml文件,内如修改如下: & &&configuration& & && &property& & &&&&&& &name&dfs.replication&/name& & &&&&&& &value&1&/value& & && &/property& & &&/configuration& & &6.3 编辑${HADOOP_HOME}/conf/mapred-site.xml文件,内如修改如下: & &&configuration& & && &property& & &&&&&& &name&mapred.job.tracker&/name& & &&&&&& &value&ubuntu-V01:9001&/value& & && &/property& & &&/configuration& & &6.4 将以上三个配置文件分别部署在每个节点上;7. 格式化一个新的分布式文件系统: & $ bin/hadoop namenode -format8. 执行hadoop & 8.1 启动hadoop后台daemon & &$ bin/start-all.sh & &启动后可以通过以下网页方式查看NameNode和JobTracker状态,此时可以从NameNode状态网页上看到&Live Nodes&的数量变成了两个,此时表示已经部署成功 & &NameNode - http://localhost:50070/ & &JobTracker - http://localhost:50030/ 8.2 运行测试 & &在hadoop默认提供了一些可以运行的测试工具在安装包目录下,下面就用这些测试程序来验证分布式模式是否成功8.2.1 测试一 & 运行下面的命令将从本地复制一个文件到hdfs文件系统的/test/目录下 & &$ bin/hadoop fs -copyFromLocal /home/hadoop/data/hadoop-0.20.203.0/hadoop-examples-0.20.203.0.jar /test/hadoop-examples-0.20.203.0.jar & &运行下面的命令将显示hdfs文件系统上/test/目录下的文件 & &$ bin/hadoop fs -ls /test/ & &输出结果如下: & &Found 1 items & &-rw-r--r--&& 1 hadoop supergroup & & 14-01-25 16:22 /test/hadoop-examples-0.20.203.0.jar & &运行完上面的命令以后,可以通过http://localhost:50070/来查看hdfs上的文件,此时可以看到slave节点上已经有刚才命令上传的文件存在了。8.2.2 测试二 & 运行下面的命令 & &$ bin/hadoop jar hadoop-examples-0.20.203.0.jar sleep 300 & &然后访问http://localhost:50030/,可以看到会有job在cluster里运行8.2.3 测试三 & 首先准备数据,下面两个命令是在hdfs上创建一个/test/input目录,然后从本地复制一下文件到此目录下 & &$ bin/hadoop fs -mkdir /test/input & &$ bin/hadoop fs -copyFromLocal /home/hadoop/data/hadoop-0.20.203.0/conf/*.xml /test/input & &运行测试来查找一些字符串 & &$ bin/hadoop jar hadoop-examples-*.jar grep /test/input /test/output 'dfs[a-z.]+' & &查看测试结果 & &$ bin/hadoop fs -ls /test/output/ & &$ bin/hadoop fs -cat /test/output/part-000008.3 停止hadoop后台daemon & $ bin/stop-all.sh================================================================================hadoop实战之动态添加节点-------------------------------------------------------------------------------- & &假定已经有了一个hadoop cluster环境,并且已经有了两个slave节点ubuntu-V02和ubuntu-V03,这里需要动态添加一个新的节点ubuntu-V04.1. 修改${HADOOP_HOME}/conf/slaves文件,在其中添加一个新的slave节点,比如 & ubuntu-V02 & &ubuntu-V03 & &ubuntu-V04(新节点)2. 登录到新添加的slave节点上,进入${HADOOP_HOME}目录并运行以下命令: & $ bin/hadoop-daemon.sh start datanode & & $ bin/hadoop-daemon.sh start tasktracker3. 验证添加是否成功 & 3.1 访问http://localhost:50070/可以看到&Live Nodes&的数量就从2变成了3; & &3.2 也可以通过以下命令行来验证是否成功 & &$ bin/hadoop dfsadmin -report================================================================================&&备注:进行分布式环境配置时,注意 /etc/hosts中ip与主机名的映射如ubuntu-01机器上:hadoop@ubuntu-V01:~$ cat /etc/hosts127.0.0.1 localhost192.168.1.109 ubuntu-V01192.168.1.110 ubuntu-V02192.168.1.111&ubuntu-V03192.168.1.112&ubuntu-V04&&参考:http://hadoop.apache.org/docs/r0.19.1/cn/index.html&http://hadoop.apache.org/docs/r1.0.4/cn/index.htmlhttp://blog.csdn.net/greatelite/article/details/&Hadoop 2.2.0 分布式集群搭建q.com/cn/articles/hadoop-intro &分布式计算开源框架Hadoop入门实践(一)分布式计算开源框架Hadoop介绍q.com/cn/articles/hadoop-config-tip &分布式计算开源框架Hadoop入门实践(二)Hadoop中的集群配置和使用技巧q.com/cn/articles/hadoop-process-develop &分布式计算开源框架Hadoop入门实践(三)Hadoop基本流程与应用开发&
来源:/huligong1234/p/3533382.html

我要回帖

更多关于 hadoop培训费用 的文章

 

随机推荐