一脸懵逼学习Hive的元数据库Mysql方式安装配置

1:要想学习Hive必须将Hadoop启动起来,因为Hive本身没有自己的数据管理功能,全是依赖外部系统,包括分析也是依赖MapReduce;

2:七个节点跑HA集群模式的:

第一步:必须先将Zookeeper启动起来(HA里面好多组件都依赖Zookeeper):

切换目录,启动Zookeeper(master节点,slaver1节点,slaver2节点):./zkServer.sh start

第二步:启动HDFS(千万不要格式化了,不然肯定报错给你):

直接在slaver3节点启动:start-dfs.sh

第三步:启动yarn:

直接在slaver4节点,slaver5节点启动:start-yarn.sh

第四步:使用hive:

切换目录使用(slaver3节点):./hive

这启动过程和上篇博客启动集群的模式完全吻合,所以一定注意启动节点,以及启动节点的进程的步骤和过程哦;

3:Hive配置Mysql方便对数据的管理(切换到hive目录下面的conf目录):

  注意:发现内置默认的metastore存在问题

    (1)换执行路径后,原来的表不存在了。

    (2)只能有一个用户访问同一个表。

    (3)配置mysql的metastore,上传两个mysql的rpm包

1)rpm -qa | grep mysql   rpm -e mysql-libs-5.1.66-2.el6_3.i686 --nodeps   rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm   rpm -ivh MySQL-client-5.1.73-1.glibc23.i386.rpm 2)配置mysql   /usr/bin/mysql_secure_installation 3)授权   GRANT ALL PRIVILEGES ON test.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;   //刷新授权命令   FLUSH PRIVILEGES; 4)安装hive和mysql完成后,将mysql的连接jar包拷贝到$HIVE_HOME/lib目录下       如果出现没有权限的问题,在mysql授权(在安装mysql的机器上执行)       mysql -uroot -p密码   注意:(执行下面的语句  *.*代表所有库下的所有表   %:任何IP地址或主机都可以连接)       GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '密码' WITH GRANT OPTION;       FLUSH PRIVILEGES;

然后将hive-default.xml.template复制一份为hive-site.xml:

[root@slaver3 conf]# cp hive-default.xml.template hive-site.xml

 要想使用Mysql对Hive的元数据进行管理,需要在hive-site.xml配置一下(由于要修改hive-site.xml,里面内容比较多,可以将复制的删除了,新建一个空白的文件):

[root@slaver3 conf]# vim hive-site.xml

然后对内容进行编辑,编辑内容就是Mysql的驱动,账号,密码,路径,如下所示:

如果数据库不存在自动创建:?createDatabaseIfNotExist=true

如果hive数据库不存在就创建一个:hive?createDatabaseIfNotExist=true

<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://slaver3:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>

 4:Centos安装mysql:

如果安装好了,直接登陆mysql -u账号 -p密码;   如果没安装先安装;   如果不知道是否安装可以whereis mysql查看一下mysql是否安装(查看路径的);   如果查找mysql路径登陆不了就先将mysql删除了,然后安装mysql;思路就是这个,百度方法也很多,我也是边学习边百度,大家都互相脑补吧。

 rpm方式安装mysql(包括安装mysql的客户端和服务器端),如下所示,首先将mysql的下载好客户端和服务器端上传到虚拟机上面:

使用rpm命令安装:   rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm 注意:命令解释:i:install v:显示详情 h:显示进度条

下面分别安装服务器端和客户端:

使用命令初始化mysql数据库(用户名和密码设置):

查看安装过程中提醒的信息,主要告诉我们如何初始化数据库:

[root@slaver3 hadoop]# rpm -ivh MySQL-server-5.1.73-1.glibc23.i386.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-server           ########################################### [100%]

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h slaver3 password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

Please report any problems with the /usr/bin/mysqlbug script!

Starting MySQL. SUCCESS! 
[root@slaver3 hadoop]# rpm -ivh MySQL-client-5.1.73-1.glibc23.i386.rpm 
Preparing...                ########################################### [100%]
   1:MySQL-client           ########################################### [100%]
[root@slaver3 hadoop]# 

输入如下命令初始化mysql:

Alternatively you can run:(翻译:或者你可以跑) /usr/bin/mysql_secure_installation

按照提示安装: Enter current password for root (enter for none):回车 Set root password? [Y/n]输入 Y New password:输入新的密码 Re-enter new password:再输一遍密码 Remove anonymous users? [Y/n] Y Disallow root login remotely? [Y/n] n Remove test database and access to it? [Y/n] y Reload privilege tables now? [Y/n] y

 我的操作如下所示:

[root@slaver3 hadoop]# /usr/bin/mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] n
 ... skipping.

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!


[root@slaver3 hadoop]# 

 下面使用客户端登录:

5:mysql安装成功以后就可以继续学习Hive了,是不是很开心,反正我挺开心的:

在hive.site.xml里面写如下内容:

<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://slaver3:3306/hive?createDatabaseIfNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name><!--自己mysql的密码哦-->
<value>123456</value>
</property>
</configuration>

然后运行一下hive,如下所示:

将mysql的驱动包加到hive的lib里面:

然后再试hive查看数据表是否成功:

FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.metastore.HiveMetaStoreClient

然后还报这个错误,可是我明明将mysql驱动包上传到hive的lib目录下面了:

 百度一下呗,瞄到可能是hive-site.xml的配置出错,想想自己刚才安装的mysql,看了一下,是自己讲密码123456写成了root了,修改即可:

 然后创建数据表,自己明明知道一些节点的进程没有启动,还去创建数据表,然后就卡着不动了,然后ctrl+c结束,然后启动节点的进程,然后再创建数据表:

启动节点的进程,根据自己那个节点没启动,来启动你节点的进程,注意启动顺序,如果你的nodeManager没有启动,先将yarn关闭,stop-yarn-sh,如果你的slaver3的namenode没有启动,先将dfs关闭了,stop-dfs.sh,然后再启动dfs进程,start-dfs.sh,然后启动yarn,start-yarn.sh,总之根据你的节点进程的启动情况来决定你如何启动你的节点的进程:

hive> create table tb_user(id int,name string);
FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Got exception: org.apache.hadoop.ipc.RemoteException org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /user/hive/warehouse/tb_user. Name node is in safe mode.
The reported blocks 0 needs additional 27 blocks to reach the threshold 0.9990 of total blocks 27.
The number of live datanodes 0 has reached the minimum number 0. Safe mode will be turned off automatically once the thresholds have been reached.
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkNameNodeSafeMode(FSNamesystem.java:1211)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.mkdirsInt(FSNamesystem.java:3590)
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.mkdirs(FSNamesystem.java:3566)
    at org.apache.hadoop.hdfs.server.namenode.NameNodeRpcServer.mkdirs(NameNodeRpcServer.java:754)
    at org.apache.hadoop.hdfs.protocolPB.ClientNamenodeProtocolServerSideTranslatorPB.mkdirs(ClientNamenodeProtocolServerSideTranslatorPB.java:558)
    at org.apache.hadoop.hdfs.protocol.proto.ClientNamenodeProtocolProtos$ClientNamenodeProtocol$2.callBlockingMethod(ClientNamenodeProtocolProtos.java)
    at org.apache.hadoop.ipc.ProtobufRpcEngine$Server$ProtoBufRpcInvoker.call(ProtobufRpcEngine.java:585)
    at org.apache.hadoop.ipc.RPC$Server.call(RPC.java:928)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2013)
    at org.apache.hadoop.ipc.Server$Handler$1.run(Server.java:2009)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:415)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1556)
    at org.apache.hadoop.ipc.Server$Handler.run(Server.java:2007)
Caused by: org.apache.hadoop.hdfs.server.namenode.SafeModeException: Cannot create directory /user/hive/warehouse/tb_user. Name node is in safe mode.
The reported blocks 0 needs additional 27 blocks to reach the threshold 0.9990 of total blocks 27.
The number of live datanodes 0 has reached the minimum number 0. Safe mode will be turned off automatically once the thresholds have been reached.
    at org.apache.hadoop.hdfs.server.namenode.FSNamesystem.checkNameNodeSafeMode(FSNamesystem.java:1207)
    ... 13 more
)
hive> 

然后一想,上篇博客自己记录过,哈哈哈哈,防火墙的原因,先关防火墙,先从这种解决问题的方向为入口,不然都是大问题了,然后七台机器的防火墙都关了:

防火墙一关闭,执行创建数据表命令一点也不卡了,哈哈哈哈,然后验证自己的mysql是否安装成功,退出hive,去其他目录运行hive,验证自己创建的数据表永久存在了:

OK,大功告成了;开森不开森,加油吧,骚年,努力的人还在努力。

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏北京马哥教育

MySQL存储日志并使用Loganalyzer作为前端展示

为什么要使用日志 在生产环境中我们可能需要一个较为完整的日志系统来查看运行中主机服务的状态和所作出的操作,我们可以在较大型的网络架构中使用ELK来实现对日志的收...

3009
来自专栏杨建荣的学习笔记

使用shell定制awr脚本(r3笔记第32天)

大家在做性能问题诊断的时候,awr是不可或缺的工具,使用?/rdbms/admin/awrrpt.sql可能大家使用的多了,可能有时候感觉输入参数还是有些太繁琐...

2524
来自专栏琯琯博客

docker-resources资源汇集相关项目博文

docker资源汇总。英文版本链接 资源汇集 书籍 第一本Docker书 (7.4分) Docker —— 从入门到实践 (内容一般) The Docker B...

3307
来自专栏刘望舒

Android PMS的创建过程

PMS的创建过程分为两个部分进行讲解,分别是SyetemServer处理部分和PMS构造方法。其中SyetemServer处理部分和AMS和WMS的创建过程是类...

723
来自专栏Hadoop实操

如何使用StreamSets实现MySQL中变化数据实时写入Kudu

温馨提示:要看高清无码套图,请使用手机打开并单击图片放大查看。 Fayson的github:https://github.com/fayson/cdhproje...

75210
来自专栏MYSQL轻松学

MYSQL数据闪回方式

MYSQL官方截止目前还没有出来数据闪回特性,也许后续版本会出现。社区有一些开源工具可以使用,沿用的基本都是彭立勋最早提出的思路,利用binlog对SQL进行反...

3478
来自专栏别先生

一脸懵逼学习Hive的安装(将sql语句翻译成MapReduce程序的一个工具)

Hive只在一个节点上安装即可: 1.上传tar包:这个上传就不贴图了,贴一下上传后的,看一下虚拟机吧: ? 2.解压操作: [root@slaver3...

2005
来自专栏散尽浮华

Centos下DNS+NamedManager高可用部署方案完整记录

之前说到了NamedManager单机版的配置,下面说下DNS+NamedManager双机高可用的配置方案:

1566
来自专栏bboysoul

Koadic的安装和使用

Koadic是DEFCON分型出来的一个后渗透工具,主要通过vbscript、jscript进行大部分操作 废话不多说开始演示

835
来自专栏乐沙弥的世界

Linux 下配置nginx到php的连接

安装Nginx:Linux 6 下安装编译安装Nginx 安装PHP : Linux 6 下编译安装 PHP 5.6

631

扫码关注云+社区