linux上Hive-2.3.2的安裝和部署__linux

來源:互聯網
上載者:User

參考官網:https://cwiki.apache.org/confluence/display/Hive/GettingStarted 1. 伺服器要求:

Java1.7或以上,建議java1.8 Hadoop2.x 2. 擷取安裝包

官網地址:https://mirrors.tuna.tsinghua.edu.cn/apache/hive/  可以選擇合適的版本下載

下載地址:https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.2/apache-hive-2.3.2-bin.tar.gz

可以直接使用wget命令直接下載到linux伺服器上。

wget https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.2/apache-hive-2.3.2-bin.tar.gz
3. 解壓安裝包即安裝
tar xvf apache-hive-2.3.2-bin.tar.gz
4. 啟動hdfs,為hive建立檔案夾並授權,用於資料存放區
$HADOOP_HOME/sbin/start-dfs.sh$HADOOP_HOME/bin/hadoop fs -mkdir tmp$HADOOP_HOME/bin/hadoop fs -mkdir /user/hive/warehouse$HADOOP_HOME/bin/hadoop fs -chmod g+w /tmp$HADOOP_HOME/bin/hadoop fs -chmod g+w /user/hive/warehouse

通過hive儲存的資料實際存在hdfs上。 5. 初始化

hive的中繼資料(如表定義)儲存在derby資料庫或mysql資料庫裡。 5.1 使用derby資料庫

$HIVE_HOME/bin/schematool -dbType "derby" -initSchema

好處:不需要額外安裝

缺點:derby只允許單串連,無法兩個用戶端串連到hive;

初始化的時候會在當前路徑產生一個metastore檔案,當切換路徑去啟動hive時,會找不到該檔案,報錯。

不建議使用derby資料庫。 5.2 使用mysql資料庫

(1)配置hive-site.xml檔案

vim $HIVE_HOME/conf/hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="configuration.xsl"?><configuration>    <property>         <name>hive.metastore.warehouse.dir</name>         <value>/user/hive/warehouse</value><!-- 實際資料在hdfs上儲存路徑 -->    </property>    <property>            <name>hive.metastore.local</name>            <value>true</value><!-- 中繼資料存放區在本地 -->    </property>     <property>            <name>javax.jdo.option.ConnectionURL</name>            <value>jdbc:mysql://127.0.0.1:3306/hive?createDatabaseIfNotExist=true&useSSL=false</value>    </property>    <property>            <name>javax.jdo.option.ConnectionDriverName</name>            <value>com.mysql.jdbc.Driver</value><!-- jdbc驅動 -->    </property>    <property>            <name>javax.jdo.option.ConnectionUserName</name>            <value>root</value><!-- mysql帳號 -->    </property>    <property>            <name>javax.jdo.option.ConnectionPassword</name>            <value>rootpassword</value><!-- mysql密碼 -->    </property></configuration>

(2)需要將mysql jdbc驅動包拷至$HIVE_HOME/lib/下

官網地址:https://dev.mysql.com/downloads/connector/j/ 選擇JDBC

下載地址:https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-5.1.46.tar.gz

可以使用wget下載,並使用tar xvf命令解壓,拷貝其中的mysql-connector-java-5.1.46.jar

(3)初始化mysql資料庫

$HIVE_HOME/bin/schematool -dbType mysql -initSchema
6. 運行Hive
$HIVE_HOME/bin/hive

7. 簡單的表操作,資料操作

show databases;show tables;create table test (id int ,name string ) row format delimited fields terminated by ' ';load data local inpath'/root/lbl/file/hivetest' overwrite into table test;select * from test;

第三行是建立表,表資料會存在hdfs的檔案中,表的一行資料在檔案中也是一行,列與列之間以‘ ’間隔。

第四行是將本地檔案讀取到表中,檔案內容如下:

1 a2 b3 c


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.