ubuntu安装hive
时间: 2024-05-19 16:09:30 浏览: 159
安装Hive需要先安装Hadoop,这里提供一个在Ubuntu上安装Hadoop和Hive的步骤:
1. 安装Java JDK和SSH服务
```
sudo apt-get update
sudo apt-get install default-jdk
sudo apt-get install ssh
```
2. 下载Hadoop和Hive
```
wget https://archive.apache.org/dist/hadoop/common/hadoop-2.7.7/hadoop-2.7.7.tar.gz
wget https://archive.apache.org/dist/hive/hive-2.3.6/apache-hive-2.3.6-bin.tar.gz
```
3. 解压文件并移动到/usr/local目录下
```
sudo tar -xzf hadoop-2.7.7.tar.gz -C /usr/local/
sudo mv /usr/local/hadoop-2.7.7 /usr/local/hadoop
sudo tar -xzf apache-hive-2.3.6-bin.tar.gz -C /usr/local/
sudo mv /usr/local/apache-hive-2.3.6-bin /usr/local/hive
```
4. 配置Hadoop和Hive环境变量
```
sudo nano ~/.bashrc
# 在最后添加以下内容:
export HADOOP_HOME=/usr/local/hadoop
export HIVE_HOME=/usr/local/hive
export PATH=$PATH:$HADOOP_HOME/bin:$HIVE_HOME/bin
source ~/.bashrc
```
5. 配置Hadoop和Hive的XML文件
```
cd /usr/local/hadoop/etc/hadoop/
sudo nano core-site.xml
# 添加以下内容:
<configuration>
<property>
<name>fs.defaultFS</name>
<value>hdfs://localhost:9000</value>
</property>
</configuration>
sudo nano hdfs-site.xml
# 添加以下内容:
<configuration>
<property>
<name>dfs.replication</name>
<value>1</value>
</property>
</configuration>
cd /usr/local/hive/conf/
sudo nano hive-site.xml
# 添加以下内容:
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost/metastore_db?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hiveuser</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>password</value>
</property>
<property>
<name>hive.metastore.uris</name>
<value>thrift://localhost:9083</value>
</property>
</configuration>
```
6. 配置MySQL数据库并启动服务
```
sudo apt-get install mysql-server
mysql -u root -p
# 创建hiveuser用户并赋予权限
CREATE USER 'hiveuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON *.* TO 'hiveuser'@'localhost' WITH GRANT OPTION;
# 创建metastore_db数据库
CREATE DATABASE metastore_db;
# 退出MySQL终端
exit;
```
7. 启动Hadoop和Hive服务
```
# 启动Hadoop服务
cd /usr/local/hadoop/sbin/
./start-dfs.sh
./start-yarn.sh
# 启动Hive服务
cd /usr/local/hive/bin/
./hive --service metastore &
./hive --service hiveserver2 &
```
现在,您已经成功安装了Hive。如果您需要进一步学习如何使用Hive,可以查看Apache Hive官方文档:http://hive.apache.org/
阅读全文