環境準備:java
hadoop環境搭建node
安裝mysqlmysql
hive環境搭建sql
hadoop環境搭建參考:http://my.oschina.net/u/2311010/blog/508139 數據庫
安裝mysqlapache
卸載自帶的mysql
bash
rpm -qa | grep mysql rpm -e mysql-libs-5.1.71-1.el6.x86_64 --nodeps
2.yum安裝mysqlapp
yum install -y mysql-server mysql mysql-devel
3.啓動mysql服務,添加mysql用戶
oop
service mysqld start /usr/bin/mysqladmin -u root password hadoop /usr/bin/mysqladmin -u root -h master password hadoop mysql -uroot -hmaster -phadoop 建立用戶hive@master(密碼hive)並分配權限 CREATE USER 'hive' IDENTIFIED BY 'hive'; GRANT ALL PRIVILEGES ON *.* TO 'hive'@'master' WITH GRANT OPTION; flush privileges; 用戶名hive登陸 mysql -h master -uhive set password = password('hive'); 創建 Hive 專用的元數據庫 create database hive; 查看MYSQL數據庫中全部用戶 SELECT DISTINCT CONCAT('User: ''',user,'''@''',host,''';') AS query FROM mysql.user; 查看用戶是否設置了密碼 select user,host,password from mysql.user;
4.hive環境搭建
spa
修改hive的配置文件,位置在hive/conf/hive-site.xml。幾個較爲重要的metastore配置屬性見下表:
hive.metastore.warehouse.dir | 相對於fs.default.name的目錄,託管表存儲在這裏 |
javax.jdo.option.ConnectionURL | metastore數據庫的JDBC URL |
javax.jdo.option.ConnectionDriverName | JDBC驅動器的類名 |
javax.jdo.option.ConnectionUserName | JDBC用戶名 |
javax.jdo.option.ConnectionConnectionPassword | JDBC密碼 |
進入到hive的配置文件目錄下,找到hive-default.xml.template,另存爲hive-site.xml並修改參數。Hive 系統會加載兩個配置文件一個默認配置文件「hive-default.xml」,另外一個就是用戶自定義文件「hive-site.xml」。當「hive-site.xml」中的配置參數的值與「hive-default.xml」文件中不一致時,以用戶自定義的爲準。因此可將不須要的參數都刪除掉,只留下下面所示的內容。
<?xml version=」1.0″?> <?xml-stylesheet type=」text/xsl」 href=」configuration.xsl」?> <configuration> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://master: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>hive</value> </property> <property> <name>hive.querylog.location</name> <value>/usr/local/hive/iotmp</value> <description>Location of Hive run time structured log file</description> </property> <property> <name>hive.exec.local.scratchdir</name> <value>/usr/local/hive/iotmp</value> <description>Local scratch space for Hive jobs</description> </property> <property> <name>hive.downloaded.resources.dir</name> <value>/usr/local/hive/iotmp</value> <description>Temporary local directory for added resources in the remote file system.</description> </property> </configuration>
5.拷貝jdbc驅動包
把MySQL的JDBC驅動包複製到Hive的lib目錄下(mysql-connector-java)
6.修改環境變量
vi ~/.bashrc export HIVE_HOME=/app/Servers/apache-hive-1.2.1-bin export PATH=$JAVA_HOME/bin:$HADOOP_HOME/bin:$HIVE_HOME/bin:$PATH
啓動hive
hive [hadoop@master conf]$ hive jar Logging initialized using configuration in jar:file:/app/Servers/apache-hive-1.2.1-bin/lib/hive-common-1.2.1.jar!/hive-log4j.properties hive> show databases; OK default Time taken: 1.458 seconds, Fetched: 1 row(s) hive>