Hive是基于Hadoop的,安装Hadoop可以参考这里:hadoop、zookeeper、hbase、spark集群环境搭建 ,除此之外,还需要安装mysql用来存储Hive的元数据,下面讲解mysql和hive的安装。
安装mysql5.6
1、安装依赖包和cmake
yum install gcc gcc-c++ ncurses-devel -y
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.tar.gz
tar zxvf cmake-2.8.12.tar.gz
cd cmake-2.8.12
./bootstrap
make && make install
- 1
- 2
- 3
- 4
- 5
- 6
2、创建mysql用户目录,一般安装mysql时已经创建了mysql用户,否则先创建用户
groupadd mysql
useradd -g mysql mysql
mkdir -p /data/mysql/
mkdir -p /data/mysql/data/
mkdir -p /data/mysql/log/
- 1
- 2
- 3
- 4
- 5
3、获取MySQL安装包并安装
wget http://dev.mysql.com/get/downloads/mysql/mysql-5.6.25.tar.gz
tar zxvf mysql-5.6.25.tar.gz
cd mysql-5.6.25
cmake \
-DCMAKE_INSTALL_PREFIX=/data/mysql \
-DMYSQL_UNIX_ADDR=/data/mysql/mysql.sock \
-DDEFAULT_CHARSET=utf8 \
-DDEFAULT_COLLATION=utf8_general_ci \
-DWITH_INNOBASE_STORAGE_ENGINE=1 \
-DWITH_ARCHIVE_STORAGE_ENGINE=1 \
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 \
-DMYSQL_DATADIR=/data/mysql/data \
-DMYSQL_TCP_PORT=3306 \
-DENABLE_DOWNLOADS=1
make && make install
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
4、修改目录权限
chmod +w /data/mysql/
chown -R mysql:mysql /data/mysql/
ln -s /data/mysql/lib/libmysqlclient.so.18 /usr/lib/libmysqlclient.so.18
ln -s /data/mysql/mysql.sock /tmp/mysql.sock
- 1
- 2
- 3
- 4
5、初始化数据库
cp /data/mysql/support-files/my-default.cnf /etc/my.cnf
cp /data/mysql/support-files/mysql.server /etc/init.d/mysqld
/data/mysql/scripts/mysql_install_db --user=mysql --defaults-file=/etc/my.cnf --basedir=/data/mysql --datadir=/data/mysql/data
- 1
- 2
- 3
6、启动MySQL服务
chmod +x /etc/init.d/mysqld
service mysqld start
ln -s /data/mysql/bin/mysql /usr/bin/
- 1
- 2
- 3
7、初始化密码
mysql -uroot -h127.0.0.1 -p
mysql> SET PASSWORD = PASSWORD('123456');
- 1
- 2
8、创建Hive用户
mysql>CREATE USER 'hive' IDENTIFIED BY 'hive';
mysql>GRANT ALL PRIVILEGES ON *.* TO 'hive'@'hxf' WITH GRANT OPTION;
mysql>flush privileges;
- 1
- 2
- 3
9、Hive用户登录
mysql -h hxf(这个是主机名) -uhive
mysql>set password = password('hive');
- 1
- 2
10、创建Hive数据库
mysql>create database hive;
- 1
安装Hive
1、到 https://hive.apache.org/downloads.html 下载解压Hive
wget http://apache.fayea.com/hive/hive-2.1.1/apache-hive-2.1.1-bin.tar.gz
tar -xzvf apache-hive-2.1.1-bin.tar.gz
- 1
- 2
2、设置环境变量
export HIVE_HOME=/data/install/apache-hive-2.1.1-bin
export PATH=$HIVE_HOME/bin:$PATH
- 1
- 2
3、在$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>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://172.16.0.107:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>
</configuration>
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
4、下载mysql连接的jar包,并且复制到$HIVE_HOME/lib目录下,下载地址: https://dev.mysql.com/downloads/connector/j/ ,这里我的是mysql-connector-java-5.1.34.jar
5、初始化schema
$HIVE_HOME/bin/schematool -initSchema -dbType mysql
- 1
6、启动Hive CLI
$HIVE_HOME/bin/hive