一·
1.hive只需要安装在 hadoop主节点上
tar -zxvf hive-1.1.0-cdh5.5.2.tar.gz
2.
[root@h91 ~]# vi /etc/profile或者 .bash_profile
添加
export HIVE_HOME=/home/hadoop/hive-1.1.0-cdh5.5.2
export HADOOP_HOME=/home/hadoop/hadoop-2.6.0-cdh5.5.2
export PATH=$HIVE_HOME/bin:$PATH
3.hive配置文件
[hadoop@h91 ~]$ cd hive-0.9.0-bin/bin/
[hadoop@h91 bin]$ vi hive-config.sh
添加
export JAVA_HOME=/usr/jdk1.7.0_25
export HIVE_HOME=/home/hadoop/hive-1.1.0-cdh5.5.2
export HADOOP_HOME=/home/hadoop/hadoop-2.6.0-cdh5.5.2
[hadoop@h91 ~]$ cd hive-0.9.0-bin/conf/
[hadoop@h91 conf]$ cp hive-default.xml.template hive-default.xml
[hadoop@h91 conf]$ cp hive-default.xml.template hive-site.xml
(hive-default.xml用于保留默认配置,hive-site.xml用于个性化配置,可覆盖默认配置)
4.启动hive
[hadoop@h91 bin]$ ./hive
Logging initialized using configuration in jar:file:/home/hadoop/hive-0.9.0-bin/lib/hive-
common-0.9.0.jar!/hive-log4j.properties
Hive history file=/tmp/hadoop/hive_job_log_hadoop_201504261237_1850268663.txt
二·
默认情况下,hive元数据保存在derby数据库中,智能允许一个会话连接,只适合做测试。为了支持多用
户多会话,则需要一个独立的元数据库,配置mysql作为元数据库。
1.安装mysql
源码安装:或者 yum -y install mysql*
二、【必须依赖包】
rm -rf /etc/yum.repos.d/*
cat <<EOF > /etc/yum.repos.d/base.repo
[Base]
name=base
baseurl=file:///mnt/Server
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
EOF
mount /dev/cdrom /mnt
yum install -y make* gcc* ncurses-devel* gcc-c++*
三、
1.安装cmake
(mysql5.5以后是通过cmake来编译的)
下载解压cmake-2.8.5.tar.gz
wget http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
tar zxf /tmp/cmake-2.8.12.2.tar.gz -C /usr/local/src
cd /usr/local/src/cmake-2.8.12.2/
./configure --prefix=/usr/local/cmake
echo $?
make && make install
echo $?
export PATH=/usr/local/cmake/bin:$PATH
2.安装mysql
下载地址:http://cdn.mysql.com/Downloads/MySQL-5.6/mysql-5.6.17.tar.gz
groupadd mysql
useradd -s /sbin/nologin -g mysql mysql
cd /tmp
tar xf /tmp/mysql-5.6.17.tar.gz
cd /tmp/mysql-5.6.17
cmake
-DCMAKE_INSTALL_PREFIX=/app/mysql
-DMYSQL_DATADIR=/app/mysql/data
-DMYSQL_UNIX_ADDR=/app/mysql/data/mysql.sock
-DENABLED_LOCAL_INFILE=1
-DWITH_INNOBASE_STORAGE_ENGINE=1
-DWITH_ARCHIVE_STORAGE_ENGINE=1
-DWITH_BLACKHOLE_STORAGE_ENGINE=1
-DWITH_FEDERATED_STORAGE_ENGINE=1
-DWITH_EXAMPLE_STORAGE_ENGINE=1
-DWITH_PARTITION_STORAGE_ENGINE=1
-DWITH_MYISAM_STORAGE_ENGINE=1
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1
-DMYSQL_TCP_PORT=3306
-DEXTRA_CHARSETS=all
-DDEFAULT_CHARSET=utf8
-DDEFAULT_COLLATION=utf8_general_ci
-DMYSQL_USER=mysql
-DWITH_DEBUG=0
*********************z编译参数说明******************
cmake
-DCMAKE_INSTALL_PREFIX=/usr/local/mysql #安装的根目录
-DMYSQL_DATADIR=/usr/local/mysql/data #数据存放目录
-DMYSQL_UNIX_ADDR=/usr/local/mysql/data/mysql.sock #UNIX socket文件
-DENABLED_LOCAL_INFILE=1 #启用加载本地数据
-DWITH_INNOBASE_STORAGE_ENGINE=1 #支持InnoDB引擎
-DWITH_ARCHIVE_STORAGE_ENGINE=1 #支持ARCHIVE引擎
-DWITH_BLACKHOLE_STORAGE_ENGINE=1 #支持BLACKHOLE引擎
-DWITH_FEDERATED_STORAGE_ENGINE=1 #支持FEDERATED引擎
-DWITH_EXAMPLE_STORAGE_ENGINE=1 #支持EXAMPLE引擎
-DWITH_PARTITION_STORAGE_ENGINE=1 #支持PARTITION引擎
-DWITH_MYISAM_STORAGE_ENGINE=1 #支持MYISAM引擎
-DWITH_PERFSCHEMA_STORAGE_ENGINE=1 #支持PERFSCHEMA引擎
-DMYSQL_TCP_PORT=3306 #对外开放的默认端口
-DEXTRA_CHARSETS=all #支持所有扩展字符支持
-DDEFAULT_CHARSET=utf8 #默认字符集为utf8 latin
-DDEFAULT_COLLATION=utf8_general_ci #默认字符校对utf8
-DMYSQL_USER=mysql #指定mysql启动用户
-DWITH_DEBUG=0 #调试模式
**************************************************
# make && make install
# chown -R mysql.mysql /app/mysql
# cd /app/mysql/scripts/
# ./mysql_install_db --user=mysql --basedir=/app/mysql --datadir=/app/mysql/data #初始化mysql数据库,#指定mysql数据文件的存放位置
# cd ..
# cd support-files/
# cp mysql.server /etc/rc.d/init.d/mysql
# cp my-default.cnf /etc/my.cnf
# chkconfig --add mysql
# chkconfig mysql on
# service mysql start
# ln -s /app/mysql/bin/* /usr/bin/
mysqladmin -u root password 'mysql' #设置数据库root密码为mysql#
mysql -u root -pmysql
删除test和匿名帐户
mysql> DROP DATABASE test;
mysql> DELETE FROM mysql.user WHERE user = '';
mysql> FLUSH PRIVILEGES;
修改配置文件
vi /etc/my.cnf
[mysqld]
datadir=/app/mysql/data
socket =/app/mysql/data/mysql.sock
lower_case_table_names=1
character-set-server=utf8
collation-server=utf8_general_ci
[client]
default-character-set=utf8
socket =/app/mysql/data/mysql.sock
【 mysqladmin: connect to server at 'localhost' failed
error: 'Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)'
Check that mysqld is running and that the socket: '/var/lib/mysql/mysql.sock' exists!】
[mysql.server]
user=mysql
basedir=/app/mysql
default-character-set=utf8
[mysqld_safe]
err-log=/app/mysql/errlog/mysqld.log
service mysql restart
三·
2.为hive简历相应mysql用户
mysql> create user 'hive' identified by 'mysql';
mysql> grant all privileges on *.* to 'hive'@'%' with grant option;
mysql> grant all privileges on *.* to hive@h201 identified by 'mysql';
mysql> flush privileges;
3.建立hive专用的元数据库
[root@hadoop110 /]# mysql -h 192.168.121.132 -u hive -p
Enter password:
mysql> create database hive;
4.hive中配置
[hadoop@hadoop110 ~]$ cd hive-1.1.0-cdh5.5.2/conf/
[hadoop@hadoop110 conf]$ vi hive-site.xml
添加:
<property>
<name>hive.metastore.local</name>
<value>true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://192.168.121.132:3306/hive?characterEncoding=UTF-8</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>mysql</value>
</property>
5.把msql的JDBC复制到hive的lib下
[hadoop@hadoop110 ~]$ cp mysql-connector-java-5.1.5-bin.jar hive-1.1.0-cdh5.5.2/lib/
6.验证
hive> show tables;
hive> create table hehe(id int,name string)
row format delimited
fields terminated by ' '
stored as textfile;
[hadoop@hadoop110 ~]$ mysql -h 192.168.121.132 -u hive -p
mysql> use hive
mysql> show tables;
mysql> select * from TBLS;
(能看到新建的hehe表)