五、hive的安装(不同版本的hadoop尽量找相对应hive版本) 

 1、下载hive安装包---apache-hive-1.1.1-bin.tar 



 2、解压安装到opt下面   

 tar -zxvf apache-hive-1.1.1-bin.tar -C ~/opt/ 



 3、配置环境变量 

 sudo gedit /etc/profile 



 在下面增加 

 export HIVE_HOME=/home/luffy/opt/apache-hive-1.1.1-bin 

 export PATH=$HADOOP_HOME/bin:$HIVE_HOME/bin:$PATH 



 4、刷新文件 

 soruce /etc/profile 



 5、在hive根目录新建一个加载目录iotmp 

 sudo mkdir iotmp 



 6、修改hive-site.xml(如果没有这个文件,可以根据模板cp一个出来hive-default.xml) 



 <property>  

    <name>javax.jdo.option.ConnectionURL</name>  

    <value>jdbc:mysql://localhost:3306/hive</value>  

 </property>  

   

 <property>  

    <name>javax.jdo.option.ConnectionDriverName</name>  

    <value>com.mysql.jdbc.Driver</value>  

 </property> 





 <property>  

    <name>javax.jdo.option.ConnectionPassword</name>  

    <value>hive</value>  

 </property>  

   

 <property>  

    <name>hive.hwi.listen.port</name> 

    <value>9999</value>  

    <description>This is the port the Hive Web Interface will listen on</descript ion>  

 </property>  





 <property>  

    <name>datanucleus.autoCreateSchema</name>  

    <value>true</value>  

 </property>  

   

 <property>  

    <name>datanucleus.fixedDatastore</name>  

    <value>false</value>  

 </property>  

 </property>  





   <property> 

     <name>javax.jdo.option.ConnectionUserName</name> 

     <value>hive</value> 

     <description>Username to use against metastore database</description> 

   </property> 





   <property> 

     <name>hive.exec.local.scratchdir</name> 

     <value>/home/luffy/opt/apache-hive-1.1.1-bin/iotmp</value> 

     <description>Local scratch space for Hive jobs</description> 

   </property> 

   <property> 

     <name>hive.downloaded.resources.dir</name> 

     <value>/home/luffy/opt/apache-hive-1.1.1-bin/iotmp</value> 

     <description>Temporary local directory for added resources in the remote file system.</description> 

   </property> 

   <property> 

     <name>hive.querylog.location</name> 

     <value>/home/luffy/opt/apache-hive-1.1.1-bin/iotmp</value> 

     <description>Location of Hive run time structured log file</description> 

   </property> 



 7、拷贝驱动包到hive的lib目录下面 

 mv mysql-connector-java-5.1.6-bin.jar /home/luffy/opt/apache-hive-1.1.1-bin/lib 



 8、把jline-2.12.jar包拷贝到hadoop相对应的目录下,替代jline-0.9.94.jar(替代之前最好先备份),否则会报错 

 cp /home/luffy/opt/apache-hive-1.1.1-bin/lib/jline-2.12.jar /home/luffy/hadoop-2.6.0/share/hadoop/yarn/lib/ 



 mv /home/luffy/hadoop-2.6.0/share/hadoop/yarn/lib/jline-0.9.94.jar /home/luffy/hadoop-2.6.0/share/hadoop/yarn/lib/jline-0.9.94.jar.bak / 



 9、启动测试hive 

 首先要确保hadoop一定在启动中 

 hive启动命令:hive 



 测试输入:show databases; 



 OK 

 default 

 Time taken: 0.345 seconds, Fetched: 1 row(s) 



 hive对utf-8支持不好。设置完编码latin1,发现table 字段描述无法显示中文。修改元数据库表的字符 

 (1)修改表字段注解和表注解 

 alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8 

 alter table TABLE_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8 

 (2) 修改分区字段注解: 

 alter table PARTITION_PARAMS  modify column PARAM_VALUE varchar(4000) character set utf8 ;  

 alter table PARTITION_KEYS  modify column PKEY_COMMENT varchar(4000) character set utf8;  

 (3)修改索引注解: 

 alter table INDEX_PARAMS  modify column PARAM_VALUE  varchar(4000) character set utf8; 



 启动元数据 

 bin/hive --service metastore & 





 hive安装完成------------- 



 Mysql 

 在ubuntu下并且同hive整合的安装 



 通过命令安装mysql(命令安装情况下需要连接外网,所以如果虚拟机无法连接外网的情况下需要自动获取IP地址 

 ,下载完之后再设置回来,不然会影响hadoop等软件的启动) 



 服务端 

 1.sudo apt-get install mysql-server 



 安装过程中会提示设置root用户密码(设置之后要记住) 



 客户端 

 2. sudo apt-get install mysql-client 



 不知道什么端 

 3.  sudo apt-get install libmysqlclient-dev 



 检查安装是否成功 

 sudo netstat -tap | grep mysql 



 tcp        0      0 localhost:mysql         *:*                     LISTEN      13193/mysqld     



 通过上述命令检查之后,如果看到有mysql 的socket处于 listen 状态则表示安装成功。 



 Mysql安装成功------------ 



 登陆mysql数据库 



 mysql -u root -p 



 输入上面命令之后就需要输入root用户密码 



 查看当前数据库 

 mysql> show databases; 

 +--------------------+ 

 | Database           | 

 +--------------------+ 

 | information_schema | 

 | mysql              | 

 | performance_schema | 

 +--------------------+ 

 3 rows in set (0.11 sec) 





 我们选择 mysql数据库就行下一步操作,使用use mysql 命令,显示当前数据库的表单:show tables  



 (安装完毕改回ip地址) 



 远程访问mysql(这里是物理机访问虚拟机的mysql) 



 1、修改localhost 

 进入虚拟机登陆mysql 

 mysql > use mysql; 



 mysql > update user set Host = "%" where User="root" 





 允许root用户在任何地方进行远程登录,并具有所有库任何操作权限,具体操作如下:  

  在本机先使用root用户登录mysql:  

 GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456';  



 重载授权表:  

  FLUSH PRIVILEGES; 



  退出mysql数据库: 

 exit  



 2、配置、/etc/mysql/my.cnf 

 找到bind-address 并且将其注释掉(如果找不到可能因为版本不对,放在包含在其他文件里面) 





 3、其它 



 然后启动MySQL服务,或者在启动服务的前提下重启服务 



 sudo /etc/init.d/mysql start (脚本启动)或者service mysqld start(命令启动)  



 sudo /etc/init.d/mysql restart(脚本重启)或者 service mysqld restart(命令重启 





 执行完上面的三步后,就可以通过远程机器连接了数据库了 





 注意:如果修改mysql之后遇到hive无法重启需要 

 异常:java.sql.SQLException: Access denied for user 'hive'@'localhost' (using password: YES) 



 执行以下命令 

 mysql > GRANT ALL PRIVILEGES ON*.* TO 'hive'@'%' Identified by 'hive';  

 mysql > GRANT ALL PRIVILEGES ON*.* TO 'hive'@'localhost' Identified by 'hive';  

 mysql > GRANT ALL PRIVILEGES ON*.* TO 'hive'@'127.0.0.1' Identified by 'hive'; 

 mysql > GRANT ALL PRIVILEGES ON*.* TO 'hive'@'hadoop1' Identified by 'hive'; 

 flush privileges; 

再次启动就成功了

-->>如需要搭建hadoop则需要看上一篇文章