Hive学习(一) 安装 环境:CentOS 7 + Hadoop3.2 + Hive3.1
软件环境: VMware:VMware® Workstation 15 Pro
CentOS7:CentOS-7-x86_64-DVD-1810.iso
JDK:jdk-8u211-linux-x64.tar.gz
Hadoop:hadoop-3.1.2.tar.gz
Hive:apache-hive-3.1.1-bin.tar.gz
Mysql:5.7.26
一、环境准备
1,CentOS 7 + Hadoop3.2 搭建集群
2,安装mysql
① 检测系统是否自带安装 MySQL
rpm -qa | grep mysql
② 添加Mysql5.7仓库
rpm -ivh https://dev.mysql.com/get/mysql57-community-release-el7-11.noarch.rpm
③ 安装Mysql5.7
yum -y install mysql-community-server
④ 启动 MySQL
systemctl start mysqld
⑤ 查看 MySQL 运行状态
systemctl status mysqld
⑥ 获取服务器状态
mysqladmin --version
Mysql的安全设置
CentOS上的root默认密码可以在文件 /var/log/mysqld.log 找到
cat /var/log/mysqld.log | grep -i 'temporary password'
设置密码
1.登录mysql
mysql -uroot -p
如果报错:
解决方案:
1、service mysqld stop停止mysql服务器
2、find / -name my.cnf 查找mysql配置文件的位置打开
3、在[mysqld]后添加skip-grant-tables
4、启动mysql :service mysqld start
2.修改密码
ALTER USER 'root'@'localhost' IDENTIFIED BY '******';
3.新建用户
CREATE USER 'hive'@'%' IDENTIFIED BY '******'; GRANT ALL ON *.* TO 'hive'@'%'; flush privileges;
设置数据库编码为utf8
1.打开配置文件
vim /etc/my.cnf
2.在[mysqld],[client],[mysql]节点下添加编码设置
[client] default-character-set=utf8 [mysql] default-character-set=utf8 [mysqld] collation-server = utf8_unicode_ci init-connect='SET NAMES utf8' character-set-server = utf8
3.重启Mysql
systemctl restart mysqld
二、Hive环境安装和配置
1.文件准备
tar -zxvf apache-hive-3.1.1-bin.tar.gz
2.环境配置
输入: vi /etc/profile
添加:
export HIVE_HOME=/root/hive export HIVE_CONF_DIR=${HIVE_HOME}/conf export PATH=.:${JAVA_HOME}/bin:${SCALA_HOME}/bin:${SPARK_HOME}/bin:${HADOOP_HOME}/bin:${ZK_HOME}/bin:${HBASE_HOME}/bin:${HIVE_HOME}/bin:$PATH
输入: source /etc/profile
3.更改配置
1/新建hive-site.xml
编辑:
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true&useSSL=false</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>******</value>
</property>
</configuration>
2/复制hive-env.sh.template hive-env.sh
cp hive-env.sh.template hive-env.sh
编辑:
export HADOOP_HOME=/root/hadoop-3.1.2 export HIVE_CONF_DIR=/root/hive/conf export HIVE_AUX_JARS_PATH=/root/hive/lib
3/添加数据驱动包
将mysql 的驱动包 mysql-connector-java-5.1.41-bin.jar 上传到 /root/hive/lib
4/初始化数据库 schematool -initSchema -dbType mysql
5/输入:
hive