我正在尝试使用hadoop和hive创建一个docker容器.这是我的Dockerfile
FROM ubuntu:latest USER root RUN apt-get update #RUN apt-get -y install default-jre RUN apt-get install -y python-pip python-dev build-essential RUN apt-get install -y libMysqLclient-dev RUN apt-get install -y python-MysqLdb RUN apt-get update && \ apt-get upgrade -y && \ apt-get install -y git ENV HADOOP_HOME /opt/hadoop ENV JAVA_HOME /usr/lib/jvm/java-8-openjdk-amd64 # install packages RUN \ apt-get update && apt-get install -y \ ssh \ rsync \ vim \ openjdk-8-jdk # create ssh keys RUN \ ssh-keygen -t rsa -P '' -f ~/.ssh/id_rsa && \ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys && \ chmod 0600 ~/.ssh/authorized_keys RUN DEBIAN_FRONTEND=noninteractive apt install -y MysqL-client RUN DEBIAN_FRONTEND=noninteractive apt install -y MysqL-server RUN chown -R MysqL:MysqL /var/lib/MysqL /var/log/MysqL WORKDIR /opt # download and extract hadoop,set JAVA_HOME in hadoop-env.sh,update path RUN wget --no-check-certificate https://www-us.apache.org/dist/hadoop/common/hadoop-2.8.5/hadoop-2.8.5.tar.gz RUN tar -xzf hadoop-2.8.5.tar.gz RUN mv hadoop-2.8.5 $HADOOP_HOME RUN echo "export JAVA_HOME=$JAVA_HOME" >> $HADOOP_HOME/etc/hadoop/hadoop-env.sh RUN echo "PATH=$PATH:$HADOOP_HOME/bin" >> ~/.bashrc RUN rm hadoop-2.8.5.tar.gz ARG HIVE_VERSION # Set HIVE_VERSION from arg if provided at build,env if provided at run,or default # https://docs.docker.com/engine/reference/builder/#using-arg-variables # https://docs.docker.com/engine/reference/builder/#environment-replacement ENV HIVE_VERSION=${HIVE_VERSION:-2.3.2} ENV HIVE_HOME /opt/hive ENV PATH $HIVE_HOME/bin:$PATH RUN echo "PATH=$PATH:$HIVE_HOME/bin" >> ~/.bashrc #Install Hive and Postgresql JDBC RUN apt-get update && apt-get install -y wget procps && \ wget --no-check-certificate https://archive.apache.org/dist/hive/hive-$HIVE_VERSION/apache-hive-$HIVE_VERSION-bin.tar.gz && \ tar -xzvf apache-hive-$HIVE_VERSION-bin.tar.gz && \ mv apache-hive-$HIVE_VERSION-bin hive && \ rm apache-hive-$HIVE_VERSION-bin.tar.gz && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* ADD MysqL-connector-java-5.1.47.jar /opt/hive/lib ADD hive-site.xml /opt/hive/conf
@H_301_8@这是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://localhost:3306/Metastore?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false</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>password</value> </property> <property> <name>datanucleus.autoCreateSchema</name> <value>true</value> </property> <property> <name>datanucleus.fixedDatastore</name> <value>true</value> </property> <property> <name>datanucleus.autoCreateTables</name> <value>True</value> </property> </configuration>
@H_301_8@我能够构建和运行容器.当我执行到容器中时,我可以轻松地执行
root@c29fa91db6a2:/opt/hive/conf# MysqL -uroot -ppassword MysqL: [Warning] Using a password on the command line interface can be insecure. Welcome to the MysqL monitor. Commands end with ; or \g. Your MysqL connection id is 191 Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu) Copyright (c) 2000,2019,Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MysqL>
@H_301_8@但是当我尝试做蜂巢-服务元存储时,我得到了
Caused by: java.sql.sqlException: Unable to open a test connection to the given database. JDBC url = jdbc:MysqL://localhost:3306/Metastore?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false,username = root. Terminating connection pool (set lazyInit to true if you expect to start your database after your app). Original Exception: ------ com.MysqL.jdbc.exceptions.jdbc4.MysqLNonTransientConnectionException: Could not create connection to database server. Attempted reconnect 3 times. Giving up.
@H_301_8@在堆栈跟踪的更深处,我看到了
Caused by: java.sql.sqlException: Access denied for user 'root'@'localhost' at com.MysqL.jdbc.sqlError.createsqlException(sqlError.java:965) ~[MysqL-connector-java-5.1.47.jar:5.1.47]
@H_301_8@但是,这是root用户拥有的授予
root@c29fa91db6a2:/opt/hive/conf# MysqL -uroot -ppassword MysqL: [Warning] Using a password on the command line interface can be insecure. Welcome to the MysqL monitor. Commands end with ; or \g. Your MysqL connection id is 205 Server version: 5.7.25-0ubuntu0.18.04.2 (Ubuntu) Copyright (c) 2000,Oracle and/or its affiliates. All rights reserved. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MysqL> show grants; +---------------------------------------------------------------------+ | Grants for root@localhost | +---------------------------------------------------------------------+ | GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION | | GRANT PROXY ON ''@'' TO 'root'@'localhost' WITH GRANT OPTION | +---------------------------------------------------------------------+ 2 rows in set (0.00 sec) MysqL>
@H_301_8@我究竟做错了什么?为了在Docker容器内使用配置单元,我还需要做什么?
另外,我看到MysqL正在运行
root@7bfa781e1a2c:/opt/hive/conf# ps aux | grep MysqL MysqL 1931 0.0 0.0 4624 1768 ? S 20:19 0:00 /bin/sh /usr/bin/MysqLd_safe MysqL 2282 0.2 8.7 1416908 179700 ? Sl 20:19 0:00 /usr/sbin/MysqLd --basedir=/usr --datadir=/var/lib/MysqL --plugin-dir=/usr/lib/MysqL/plugin --log-error=/var/log/MysqL/error.log --pid-file=/var/run/MysqLd/MysqLd.pid --socket=/var/run/MysqLd/MysqLd.sock --port=3306 --log-syslog=1 --log-syslog-facility=daemon --log-syslog-tag= root 2594 0.0 0.0 11460 1084 pts/1 S+ 20:24 0:00 grep --color=auto MysqL root@7bfa781e1a2c:/opt/hive/conf#
@H_301_8@
最佳答案
有几个问题需要解决:
> MysqL安装随附的默认root用户使用auth_socket作为身份验证插件.这意味着它没有密码.尝试使用MysqL -uroot登录,它仍然会登录.
MysqL> select * from MysqL.user\G *************************** 1. row *************************** Host: localhost User: root Select_priv: Y Insert_priv: Y Update_priv: Y Delete_priv: Y Create_priv: Y Drop_priv: Y Reload_priv: Y Shutdown_priv: Y Process_priv: Y File_priv: Y Grant_priv: Y References_priv: Y Index_priv: Y Alter_priv: Y Show_db_priv: Y Super_priv: Y Create_tmp_table_priv: Y Lock_tables_priv: Y Execute_priv: Y Repl_slave_priv: Y Repl_client_priv: Y Create_view_priv: Y Show_view_priv: Y Create_routine_priv: Y Alter_routine_priv: Y Create_user_priv: Y Event_priv: Y Trigger_priv: Y Create_tablespace_priv: Y ssl_type: ssl_cipher: x509_issuer: x509_subject: max_questions: 0 max_updates: 0 max_connections: 0 max_user_connections: 0 plugin: auth_socket authentication_string: password_expired: N password_last_changed: 2019-04-03 07:43:20 password_lifetime: NULL account_locked: N
@H_301_8@>因此,在MysqL中进行任何更改之前,配置单元服务会引发以下错误:
由以下原因引起:java.sql.sqlException:用户’root’@’localhost’的访问被拒绝
>我们需要设置root @ localhost以使用MysqL_native_password身份验证,并设置@rajesh提到的密码:
MysqL> alter user root@localhost identified with MysqL_native_password by 'password'; Query OK,0 rows affected (0.00 sec) MysqL> flush privileges; Query OK,0 rows affected (0.00 sec) MysqL> \q Bye
@H_301_8@>仍然配置单元为我抛出错误,因为未更新加载的MysqL模式.所以不得不做Hive 2.1.1 MetaException(message:Version information not found in metastore. )中提到的一些步骤
cd $HIVE_HOME/scripts/Metastore/upgrade/MysqL/ MysqL -uroot -ppassword MysqL> use Metastore; Reading table information for completion of table and column names You can turn off this feature to get a quicker startup with -A Database changed MysqL> source hive-schema-2.3.0.MysqL.sql;
@H_301_8@>现在,配置单元开始正常.
2019-04-03T08:58:01,442 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - Starting hive Metastore on port 9083 2019-04-03T08:58:01,687 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - 0: opening raw store with implementation class:org.apache.hadoop.hive.Metastore.ObjectStore 2019-04-03T08:58:05,535 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - Added admin role in Metastore 2019-04-03T08:58:05,546 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - Added public role in Metastore 2019-04-03T08:58:05,594 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - No user is added in admin role,since config is empty 2019-04-03T08:58:05,804 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - Starting DB backed MetaStore Server with SetUGI enabled 2019-04-03T08:58:05,814 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - Started the new Metaserver on port [9083]... 2019-04-03T08:58:05,815 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - Options.minWorkerThreads = 200 2019-04-03T08:58:05,816 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - Options.maxWorkerThreads = 1000 2019-04-03T08:58:05,816 INFO [main] org.apache.hadoop.hive.Metastore.HiveMetaStore - TCP keepalive = true
@H_301_8@