|
1 |
| ---- |
2 |
| -layout: post |
3 |
| -title: "链接hive数据库的正确方式" |
4 |
| -date: 2018-07-10 12:12:12 |
5 |
| -subtitle: 本文主要介绍了关于hive权限的配置文件,使用hive连接,使用hiveserver2后天启动,beeline和squi客户端链接hive |
6 |
| -mathjax: true |
7 |
| -author: "LSG" |
8 |
| -header-img: "img/lxy004.jpg" |
9 |
| -catalog: true |
10 |
| -tags: |
11 |
| - - hadoop |
12 |
| - - hive |
13 |
| - - nohup |
14 |
| ---- |
15 |
| -> 自建集群hiveserver2需要后台启动,客户端操作hive比直接链接hive会更方便 |
16 |
| -
|
17 |
| -*“hive: 数据仓库是olap分析中的一款利器”* |
18 |
| - |
19 |
| -### 1.获得账号密码: hive配置文件 hive-site.xml |
20 |
| - |
21 |
| -```xml |
22 |
| -<configuration> |
23 |
| - <property> |
24 |
| - <name>javax.jdo.option.ConnectionURL</name> |
25 |
| - <value>jdbc:mysql://140.143.67.105:3306/hive?createDatabaseIfNotExist=true&useSSL=false</value> |
26 |
| - <description>JDBC connect string for a JDBC metastore</description> |
27 |
| - </property> |
28 |
| - |
29 |
| - <property> |
30 |
| - <name>javax.jdo.option.ConnectionDriverName</name> |
31 |
| - <value>com.mysql.cj.jdbc.Driver</value> |
32 |
| - <description>Driver class name for a JDBC metastore</description> |
33 |
| - </property> |
34 |
| - |
35 |
| - <property> |
36 |
| - <name>javax.jdo.option.ConnectionUserName</name> |
37 |
| - <value>账号</value> |
38 |
| - <description>username to use against metastore database</description> |
39 |
| - </property> |
40 |
| - |
41 |
| - <property> |
42 |
| - <name>javax.jdo.option.ConnectionPassword</name> |
43 |
| - <value>密码</value> |
44 |
| - <description>password to use against metastore database</description> |
45 |
| - </property> |
46 |
| - |
47 |
| - <property> |
48 |
| - <name>hive.server2.thrift.port</name> |
49 |
| - <value>server2的端口号 默认10000</value> |
50 |
| - <description>password to use against metastore database</description> |
51 |
| - </property> |
52 |
| - |
53 |
| -</configuration> |
54 |
| - |
55 |
| -``` |
56 |
| - |
57 |
| -### 2.使用hive链接 |
58 |
| - |
59 |
| -```shell |
60 |
| -在bin目录下执行: |
61 |
| -./hive |
62 |
| -``` |
63 |
| - |
64 |
| -### 3.hiveserver2真正后台启动: |
65 |
| - |
66 |
| -``` |
67 |
| -nohup ./hiveserver2 & |
68 |
| -``` |
69 |
| - |
70 |
| -#### 3.1nohop简介: |
71 |
| - |
72 |
| -nohup 是 no hang up 的缩写,就是不挂断的意思。 |
73 |
| - |
74 |
| -此前使用./hiveserver2 >> hive.log & 依旧命令会出现在控制台,导致hiveserver2卡死,并非真正后台启动 |
75 |
| - |
76 |
| -在参考了如下文章后,使用了nohop不挂断命令: [Linux ——nohup和&的区别](https://blog.csdn.net/weixin_37490221/article/details/81539341) |
77 |
| - |
78 |
| -要想进程不受shell中Ctrl C和Shell窗口关闭的影响,就将nohup和&指令一起使用 |
79 |
| - |
80 |
| -#### 3.2nohup命令: |
81 |
| - |
82 |
| -如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令。该命令可以在你退出帐户/关闭终端之后继续运行相应的进程。 |
83 |
| - |
84 |
| -在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中。 |
85 |
| - |
86 |
| -#### 3.3nohop案例 |
87 |
| - |
88 |
| -```shell |
89 |
| -nohup command > myout.file 2>&1 & |
90 |
| -``` |
91 |
| - |
92 |
| -在上面的例子中,0 – stdin (standard input),1 – stdout (standard output),2 – stderr (standard error) ; |
93 |
| - |
94 |
| -2>&1是将标准错误(2)重定向到标准输出(&1),标准输出(&1)再被重定向输入到myout.file文件中。 |
95 |
| - |
96 |
| -```shell |
97 |
| -0 22 * * * /usr/bin/python /home/pu/download_pdf/download_dfcf_pdf_to_oss.py > /home/pu/download_pdf/download_dfcf_pdf_to_oss.log 2>&1 |
98 |
| -``` |
99 |
| - |
100 |
| -这是放在crontab中的定时任务,晚上22点时候怕这个任务,启动这个python的脚本,并把日志写在download_dfcf_pdf_to_oss.log文件中. |
101 |
| - |
102 |
| -### 4.hive客户端的使用 |
103 |
| - |
104 |
| -客户端链接hievserver2的端口,可以多个客户端同时使用hive |
105 |
| - |
106 |
| -命令行中:支持大数据hdfs操作如: |
107 |
| - |
108 |
| -`dfs -ls /` |
109 |
| - |
110 |
| -[hiveserver2:10002 图形化界面](http://hadoop02:10002/)可以查看hiveserver2是否链接 |
111 |
| - |
112 |
| -也可以使用:jps -m 查看是否开启 |
113 |
| - |
114 |
| -#### 4.1使用beeline |
115 |
| - |
116 |
| -* 执行命令开启客户端 |
117 |
| - |
118 |
| - |
119 |
| - |
120 |
| -```sql |
121 |
| -./beeline |
122 |
| -!connect jdbc:hive2://localhost:30030 |
123 |
| -``` |
124 |
| - |
125 |
| -按照要求输入客户端登陆,成功连接hive |
126 |
| - |
127 |
| -* 直接使用脚本 |
128 |
| - |
129 |
| -`2hiveserver2beeline.sh`脚本直接启动连接hive |
130 |
| - |
131 |
| -```sql |
132 |
| -beeline \ |
133 |
| --u jdbc:hive2://hadoop03:10000 \ |
134 |
| --n hdfs \ |
135 |
| ---autoCommit=false \ |
136 |
| ---color=true \ |
137 |
| ---autosave=true |
138 |
| -``` |
139 |
| - |
140 |
| -每一个客户端相当于一个session,里面的参数设置,添加jar包都要执行,和其他客户端不冲突不关联 |
141 |
| - |
142 |
| -#### 4.2使用squirrel客户端 |
143 |
| - |
144 |
| -##### 4.2.1使用beeline很不方便,原因是: |
145 |
| - |
146 |
| -* 不能记录以前的sql |
147 |
| -* 写长sql很不方便 |
148 |
| -* 不能看以前执行的sql |
149 |
| - |
150 |
| -那么可以使用有图形化界面的squirrel: [squirrel 的连接方式:官网](https://cwiki.apache.org/confluence/display/Hive) |
151 |
| - |
152 |
| -##### 4.2.2 主要操作是: |
153 |
| - |
154 |
| -1. 导入hadoop对应版本的hive jar包:可以在hivelib下面找 |
155 |
| -2. 建立驱动和别名 |
156 |
| -3. 链接客户端 |
157 |
| -4. 放一张我链接成功的图QAQ: |
158 |
| - |
159 |
| - |
160 |
| - |
161 |
| -#### 4.3 使用idea客户端 |
162 |
| - |
163 |
| -1. 下载对应的jar [hive-jdbc-3.1.1 - jar下载 - Maven Repository - IT猿网](https://maven.ityuan.com/maven2/org/apache/hive/hive-jdbc/3.1.1) |
164 |
| -2. 使用代理,让对应的datagrip跑在代理中 |
165 |
| -3. 链接集群中的hiveserver2 |
166 |
| - |
167 |
| - |
168 |
| - |
169 |
| -## References |
170 |
| - |
171 |
| -- [让进程在后台启动的方式](https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/index.html) |
172 |
| -- [beeline的使用](https://my.oschina.net/guol/blog/875875) |
173 |
| -- [Hive _ Hive2 新版连接工具 beeline 详解](https://blog.csdn.net/u010003835/article/details/80675767) |
| 1 | +--- |
| 2 | +layout: post |
| 3 | +title: "链接hive数据库的正确方式" |
| 4 | +date: 2018-07-10 12:12:12 |
| 5 | +subtitle: 本文主要介绍了关于hive权限的配置文件,使用hive连接,使用hiveserver2后天启动,beeline和squi客户端链接hive |
| 6 | +mathjax: true |
| 7 | +author: "LSG" |
| 8 | +header-img: "img/lxy004.jpg" |
| 9 | +catalog: true |
| 10 | +tags: |
| 11 | + - hadoop |
| 12 | + - hive |
| 13 | + - nohup |
| 14 | +--- |
| 15 | +> 自建集群hiveserver2需要后台启动,客户端操作hive比直接链接hive会更方便 |
| 16 | +
|
| 17 | +*“hive: 数据仓库是olap分析中的一款利器”* |
| 18 | + |
| 19 | +### 1.获得账号密码: hive配置文件 hive-site.xml |
| 20 | + |
| 21 | +```xml |
| 22 | +<configuration> |
| 23 | + <property> |
| 24 | + <name>javax.jdo.option.ConnectionURL</name> |
| 25 | + <value>jdbc:mysql://140.143.67.105:3306/hive?createDatabaseIfNotExist=true&useSSL=false</value> |
| 26 | + <description>JDBC connect string for a JDBC metastore</description> |
| 27 | + </property> |
| 28 | + |
| 29 | + <property> |
| 30 | + <name>javax.jdo.option.ConnectionDriverName</name> |
| 31 | + <value>com.mysql.cj.jdbc.Driver</value> |
| 32 | + <description>Driver class name for a JDBC metastore</description> |
| 33 | + </property> |
| 34 | + |
| 35 | + <property> |
| 36 | + <name>javax.jdo.option.ConnectionUserName</name> |
| 37 | + <value>账号</value> |
| 38 | + <description>username to use against metastore database</description> |
| 39 | + </property> |
| 40 | + |
| 41 | + <property> |
| 42 | + <name>javax.jdo.option.ConnectionPassword</name> |
| 43 | + <value>密码</value> |
| 44 | + <description>password to use against metastore database</description> |
| 45 | + </property> |
| 46 | + |
| 47 | + <property> |
| 48 | + <name>hive.server2.thrift.port</name> |
| 49 | + <value>server2的端口号 默认10000</value> |
| 50 | + <description>password to use against metastore database</description> |
| 51 | + </property> |
| 52 | + |
| 53 | +</configuration> |
| 54 | + |
| 55 | +``` |
| 56 | + |
| 57 | +### 2.使用hive链接 |
| 58 | + |
| 59 | +```shell |
| 60 | +在bin目录下执行: |
| 61 | +./hive |
| 62 | +``` |
| 63 | + |
| 64 | +### 3.hiveserver2真正后台启动: |
| 65 | + |
| 66 | +``` |
| 67 | +nohup ./hiveserver2 & |
| 68 | +``` |
| 69 | + |
| 70 | +#### 3.1nohop简介: |
| 71 | + |
| 72 | +nohup 是 no hang up 的缩写,就是不挂断的意思。 |
| 73 | + |
| 74 | +此前使用./hiveserver2 >> hive.log & 依旧命令会出现在控制台,导致hiveserver2卡死,并非真正后台启动 |
| 75 | + |
| 76 | +在参考了如下文章后,使用了nohop不挂断命令: [Linux ——nohup和&的区别](https://blog.csdn.net/weixin_37490221/article/details/81539341) |
| 77 | + |
| 78 | +要想进程不受shell中Ctrl C和Shell窗口关闭的影响,就将nohup和&指令一起使用 |
| 79 | + |
| 80 | +#### 3.2nohup命令: |
| 81 | + |
| 82 | +如果你正在运行一个进程,而且你觉得在退出帐户时该进程还不会结束,那么可以使用nohup命令。该命令可以在你退出帐户/关闭终端之后继续运行相应的进程。 |
| 83 | + |
| 84 | +在缺省情况下该作业的所有输出都被重定向到一个名为nohup.out的文件中。 |
| 85 | + |
| 86 | +#### 3.3nohop案例 |
| 87 | + |
| 88 | +```shell |
| 89 | +nohup command > myout.file 2>&1 & |
| 90 | +``` |
| 91 | + |
| 92 | +在上面的例子中,0 – stdin (standard input),1 – stdout (standard output),2 – stderr (standard error) ; |
| 93 | + |
| 94 | +2>&1是将标准错误(2)重定向到标准输出(&1),标准输出(&1)再被重定向输入到myout.file文件中。 |
| 95 | + |
| 96 | +```shell |
| 97 | +0 22 * * * /usr/bin/python /home/pu/download_pdf/download_dfcf_pdf_to_oss.py > /home/pu/download_pdf/download_dfcf_pdf_to_oss.log 2>&1 |
| 98 | +``` |
| 99 | + |
| 100 | +这是放在crontab中的定时任务,晚上22点时候怕这个任务,启动这个python的脚本,并把日志写在download_dfcf_pdf_to_oss.log文件中. |
| 101 | + |
| 102 | +### 4.hive客户端的使用 |
| 103 | + |
| 104 | +客户端链接hievserver2的端口,可以多个客户端同时使用hive |
| 105 | + |
| 106 | +命令行中:支持大数据hdfs操作如: |
| 107 | + |
| 108 | +`dfs -ls /` |
| 109 | + |
| 110 | +[hiveserver2:10002 图形化界面](http://hadoop02:10002/)可以查看hiveserver2是否链接 |
| 111 | + |
| 112 | +也可以使用:jps -m 查看是否开启 |
| 113 | + |
| 114 | +#### 4.1使用beeline |
| 115 | + |
| 116 | +* 执行命令开启客户端 |
| 117 | + |
| 118 | + |
| 119 | + |
| 120 | +```sql |
| 121 | +./beeline |
| 122 | +!connect jdbc:hive2://localhost:30030 |
| 123 | +``` |
| 124 | + |
| 125 | +按照要求输入客户端登陆,成功连接hive |
| 126 | + |
| 127 | +* 直接使用脚本 |
| 128 | + |
| 129 | +`2hiveserver2beeline.sh`脚本直接启动连接hive |
| 130 | + |
| 131 | +```sql |
| 132 | +beeline \ |
| 133 | +-u jdbc:hive2://hadoop03:10000 \ |
| 134 | +-n hdfs \ |
| 135 | +--autoCommit=false \ |
| 136 | +--color=true \ |
| 137 | +--autosave=true |
| 138 | +``` |
| 139 | + |
| 140 | +每一个客户端相当于一个session,里面的参数设置,添加jar包都要执行,和其他客户端不冲突不关联 |
| 141 | + |
| 142 | +#### 4.2使用squirrel客户端 |
| 143 | + |
| 144 | +##### 4.2.1使用beeline很不方便,原因是: |
| 145 | + |
| 146 | +* 不能记录以前的sql |
| 147 | +* 写长sql很不方便 |
| 148 | +* 不能看以前执行的sql |
| 149 | + |
| 150 | +那么可以使用有图形化界面的squirrel: [squirrel 的连接方式:官网](https://cwiki.apache.org/confluence/display/Hive) |
| 151 | + |
| 152 | +##### 4.2.2 主要操作是: |
| 153 | + |
| 154 | +1. 导入hadoop对应版本的hive jar包:可以在hivelib下面找 |
| 155 | +2. 建立驱动和别名 |
| 156 | +3. 链接客户端 |
| 157 | +4. 放一张我链接成功的图QAQ: |
| 158 | + |
| 159 | + |
| 160 | + |
| 161 | +#### 4.3 使用idea客户端 |
| 162 | + |
| 163 | +1. 下载对应的jar [hive-jdbc-3.1.1 - jar下载 - Maven Repository - IT猿网](https://maven.ityuan.com/maven2/org/apache/hive/hive-jdbc/3.1.1) |
| 164 | +2. 使用代理,让对应的datagrip跑在代理中 |
| 165 | +3. 链接集群中的hiveserver2 |
| 166 | + |
| 167 | + |
| 168 | + |
| 169 | +## References |
| 170 | + |
| 171 | +- [让进程在后台启动的方式](https://www.ibm.com/developerworks/cn/linux/l-cn-nohup/index.html) |
| 172 | +- [beeline的使用](https://my.oschina.net/guol/blog/875875) |
| 173 | +- [Hive _ Hive2 新版连接工具 beeline 详解](https://blog.csdn.net/u010003835/article/details/80675767) |
174 | 174 | - [jar驱动直接下载](https://maven.ityuan.com/maven2/org/apache/hive/hive-jdbc/3.1.1))
|
0 commit comments