大数据hadoop学习总结
一、环境配置:
1、hadoop
2、zookeeper
3、hbase
4、phoenix
二、连接准备代码
hbase-site.xml
1 <?xml version="1.0"?> 2 <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> 3 <configuration> 4 <property> 5 <name>hbase.zookeeper.quorum</name> 6 <value>hadoop102,hadoop103,hadoop104</value> 7 </property> 8 </configuration>
PhoenixClient
1 package com.atguigu.hdfs; 2 3 import java.sql.*; 4 import java.util.Properties; 5 public class PhoenixClient { 6 public static void main(String[] args) throws SQLException { 7 // 标准的 JDBC 代码 8 // 1.添加链接 9 String url = "jdbc:phoenix:hadoop102,hadoop103,hadoop104:2181"; 10 // 2. 创建配置 11 // 没有需要添加的必要配置 因为 Phoenix 没有账号密码 12 Properties properties = new Properties(); 13 // 3. 获取连接 14 Connection connection = DriverManager.getConnection(url, properties); 15 // 5.编译 SQL 语句 16 PreparedStatement preparedStatement = connection.prepareStatement("select * from student"); 17 // 6.执行语句 18 ResultSet resultSet = preparedStatement.executeQuery(); 19 // 7.输出结果 20 while (resultSet.next()){ 21 String id = resultSet.getString("id"); 22 String name = resultSet.getString("name"); 23 int age = new Integer(resultSet.getString("age")); 24 25 System.out.println(id +" "+ name +" "+ age); 26 } 27 // 8.关闭资源 28 connection.close(); 29 // 由于 Phoenix 框架内部需要获取一个 HBase 连接,所以会延迟关闭 30 // 不影响后续的代码执行 31 System.out.println("hello"); 32 } 33 }
三、常用命令
(一)Hadoop
1、启动集群:myhadoop.sh start
2、启动metastore:nohup bin/hive --service metastore >> logs/metastore.log 2>&1 &
启动hiveservice2: nohup bin/hive --service hiveservice2>> logs/hiveservice2.log 2>&1 &
3、验证端口 :ps -ef|grep 4107
4、查看端口:netstat -anp|grep 10000
(二)集群分发
xsync xxx
source xxx
(三)从文件到hive
以‘/t’为分隔符 : row format delimited fields terminated by ‘/t’;
hdfs文件:load data inpath ‘地址’ into table 表名
(四)zookeeper
1、开启:bin/zkServer.sh start
2、脚本:zk.sh start / stop / status
(五)hbase
1、启动:bin/start-hbase.sh
2、启动phoenix:/otp/moudle/phoenix/bin/sqlline.py hadoop102,hadoop103,hadoop104:2181
3、退出:!quit !exit
4、phoenix查看表:!tables
5、建表加"student"为小写