spark遠(yuǎn)程讀寫hive數(shù)據(jù)庫

實(shí)現(xiàn)spark遠(yuǎn)程連接hive數(shù)據(jù)庫赫冬,需要將服務(wù)端mysql數(shù)據(jù)庫里的hive數(shù)據(jù)表DBS和SDS里的localhost改為可以訪問到的IP地址或域名怠褐。


image.png

更改方式參考:hive修改localhost
本機(jī)spark訪問服務(wù)端應(yīng)采用域名的方式萝衩。

配置hostname

作者采用dbhive作為統(tǒng)一訪問hostname
服務(wù)端修改/etc/hosts:

nano /etc/hosts

# 10.211.55.2是服務(wù)端內(nèi)網(wǎng)地址
10.211.55.2     dbhive

本機(jī)修改/etc/hosts:

nano /etc/hosts

# 119.23.5.xx是服務(wù)端外網(wǎng)地址
119.23.5.xx     dbhive

服務(wù)端配置

hadoop下的core-site.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
<property>
        <name>fs.defaultFS</name>
        <value>hdfs://0.0.0.0:9000</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/Users/zhi/Documents/app/hadoopdata</value>
    </property>
    <property>
        <name>hadoop.proxyuser.root.hosts</name>
        <value>*</value>
    </property>
    <property>
        <name>hadoop.proxyuser.root.groups</name>
        <value>*</value>
    </property>
</configuration>
  • fs.defaultFS: 注意將ip設(shè)為0.0.0.0,允許外部訪問俱两。

hadoop下的hdfs-site.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
    <property>
        <name>dfs.datanode.hostname</name>
        <value>dbhive</value>
    </property>
    <property>
        <name>dfs.client.use.datanode.hostname</name>
        <value>true</value>
    </property>
    <property>
        <name>dfs.datanode.use.datanode.hostname</name>
        <value>true</value>
    </property>
</configuration>

hive下的hive-site.xml:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>hive.metastore.local</name>
        <value>false</value>
    </property>
    <property>  
        <name>hive.metastore.uris</name>  
        <value>thrift://0.0.0.0:9083</value>  
        <description>Thrift uri for the remote metastore. Used by metastore client to connect to remote metastore.</description>  
    </property>
    <property>
        <name>hive.server2.thrift.bind.host</name>
        <value>localhost</value>
    </property>
    <property>
        <name>hive.server2.thrift.port</name>
        <value>10000</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://localhost:3306/hivedata?characterEncoding=UTF-8</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionDriverName</name>
        <value>com.mysql.jdbc.Driver</value>
    </property>
    <property>
        <name>hive.server2.enable.doAs</name>
        <value>false</value> 
    </property>
    <property>
        <name>javax.jdo.option.ConnectionUserName</name>
        <value>hive</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionPassword</name>
        <value>228228</value>
    </property>
    <property>
        <name>hive.metastore.schema.verification</name>
        <value>false</value>
    </property>
    <property>
        <name>hive.server2.thrift.client.user</name>
        <value>hive</value>
        <description>Username to use against thrift client</description>
    </property>
    <property>
        <name>hive.server2.thrift.client.password</name>
        <value>hive228228</value>
        <description>Password to use against thrift client</description>
    </property> 
</configuration>

注意將hive.metastore.uris的ip段設(shè)為0.0.0.0赎线。

本機(jī)spark配置文件:

在spark/conf下有三個文件core-site.xml、hdfs-site.xml钥弯、hive-site.xml(從服務(wù)端拷貝過來)径荔。
core-site.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <property>
        <name>fs.defaultFS</name>
        <value>hdfs://dbhive:9000</value>
    </property>
    <property>
        <name>hadoop.tmp.dir</name>
        <value>/Users/zhi/Documents/app/hadoopdata</value>
    </property>
</configuration>
  • fs.defaultFS: 服務(wù)端的hdfs地址;
  • hadoop.tmp.dir: 和服務(wù)端保持一致脆霎。

hdfs-site.xml:

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<!--
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License. See accompanying LICENSE file.
-->

<!-- Put site-specific property overrides in this file. -->

<configuration>
    <property>
        <name>dfs.replication</name>
        <value>1</value>
    </property>
    <property>
        <name>dfs.datanode.hostname</name>
        <value>dbhive</value>
    </property>
    <property>
        <name>dfs.datanode.use.datanode.hostname</name>
        <value>true</value>
    </property>
    <property>
        <name>dfs.client.use.datanode.hostname</name>
        <value>true</value>
    </property>
</configuration>
  • dfs.datanode.hostname: 設(shè)置datanode的hostname总处;
  • dfs.datanode.use.datanode.hostname: datanode通訊采用域名方式;
  • dfs.client.use.datanode.hostname: 客戶端訪問datanode采用域名方式睛蛛。

hive-site.xml:

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
    <property>
        <name>hive.metastore.uris</name>
        <value>thrift://dbhive:9083</value>
    </property>
    <property>
        <name>javax.jdo.option.ConnectionURL</name>
        <value>jdbc:mysql://dbhive:3306/hivedata?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>123456</value>
    </property>
</configuration>
  • hive.metastore.uris: 訪問metastore采用域名方式鹦马;
  • javax.jdo.option.ConnectionURL: 服務(wù)器mysql地址;
  • javax.jdo.option.ConnectionUserName: 數(shù)據(jù)庫用戶忆肾;
  • javax.jdo.option.ConnectionPassword: 數(shù)據(jù)庫密碼荸频。

之后本機(jī)spark連接遠(yuǎn)程的metastore就可以讀寫了。

配置遠(yuǎn)程訪問最重要的是要配置hadoop下的hdfs-site.xml客冈,設(shè)置dfs.datanode.hostname域名旭从,以及開啟dfs.client.use.datanode.hostname和dfs.datanode.use.datanode.hostname開啟域名訪問。hdfs和metastore地址設(shè)為0.0.0.0.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個濱河市遇绞,隨后出現(xiàn)的幾起案子键袱,更是在濱河造成了極大的恐慌,老刑警劉巖摹闽,帶你破解...
    沈念sama閱讀 218,386評論 6 506
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蹄咖,死亡現(xiàn)場離奇詭異,居然都是意外死亡付鹿,警方通過查閱死者的電腦和手機(jī)澜汤,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 93,142評論 3 394
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來舵匾,“玉大人俊抵,你說我怎么就攤上這事∽荩” “怎么了徽诲?”我有些...
    開封第一講書人閱讀 164,704評論 0 353
  • 文/不壞的土叔 我叫張陵,是天一觀的道長吵血。 經(jīng)常有香客問我谎替,道長,這世上最難降的妖魔是什么蹋辅? 我笑而不...
    開封第一講書人閱讀 58,702評論 1 294
  • 正文 為了忘掉前任钱贯,我火速辦了婚禮,結(jié)果婚禮上侦另,老公的妹妹穿的比我還像新娘秩命。我一直安慰自己,他們只是感情好褒傅,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,716評論 6 392
  • 文/花漫 我一把揭開白布弃锐。 她就那樣靜靜地躺著,像睡著了一般殿托。 火紅的嫁衣襯著肌膚如雪拿愧。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,573評論 1 305
  • 那天碌尔,我揣著相機(jī)與錄音浇辜,去河邊找鬼。 笑死唾戚,一個胖子當(dāng)著我的面吹牛柳洋,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播叹坦,決...
    沈念sama閱讀 40,314評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼熊镣,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起绪囱,我...
    開封第一講書人閱讀 39,230評論 0 276
  • 序言:老撾萬榮一對情侶失蹤测蹲,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后鬼吵,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體扣甲,經(jīng)...
    沈念sama閱讀 45,680評論 1 314
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,873評論 3 336
  • 正文 我和宋清朗相戀三年齿椅,在試婚紗的時候發(fā)現(xiàn)自己被綠了琉挖。 大學(xué)時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,991評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡涣脚,死狀恐怖示辈,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情遣蚀,我是刑警寧澤矾麻,帶...
    沈念sama閱讀 35,706評論 5 346
  • 正文 年R本政府宣布,位于F島的核電站芭梯,受9級特大地震影響险耀,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜粥帚,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,329評論 3 330
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望限次。 院中可真熱鬧芒涡,春花似錦、人聲如沸卖漫。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,910評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽羊始。三九已至旱幼,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間突委,已是汗流浹背柏卤。 一陣腳步聲響...
    開封第一講書人閱讀 33,038評論 1 270
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留匀油,地道東北人缘缚。 一個月前我還...
    沈念sama閱讀 48,158評論 3 370
  • 正文 我出身青樓,卻偏偏與公主長得像敌蚜,于是被迫代替她去往敵國和親桥滨。 傳聞我的和親對象是個殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,941評論 2 355

推薦閱讀更多精彩內(nèi)容