ElasticSearch安装SQL插件
ElasticSearch安装SQL插件下载地址(中国大佬开发的,膜拜ing):https://github.com/NLPchina/elasticsearch-sql
1、记得选择和自己Elasticsearch对应的版本哦!如果你的是集群默认,每个节点都要按照这个SQL插件的哦,由于我的是伪分布集群模式,我的安装操作如下所示:
注意:安装成功以后,是在/home/hadoop/soft/elasticsearch-5.4.3/plugins这个目录下面的。请注意进行查收。
1 [elsearch@slaver4 soft]$ ls 2 elasticsearch-5.4.3 elasticsearch-head-master el_slave node-v8.16.2-linux-x64 nohup.out 3 [elsearch@slaver4 soft]$ cd elasticsearch-5.4.3/ 4 [elsearch@slaver4 elasticsearch-5.4.3]$ ls 5 bin config data hs_err_pid11491.log lib LICENSE.txt logs modules NOTICE.txt plugins README.textile 6 [elsearch@slaver4 elasticsearch-5.4.3]$ ./bin/elasticsearch-plugin install https://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.3.0/elasticsearch-sql-5.4.3.0.zip 7 -> Downloading https://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.3.0/elasticsearch-sql-5.4.3.0.zip 8 [=================================================] 100% 9 -> Installed sql 10 [elsearch@slaver4 elasticsearch-5.4.3]$ ls 11 bin config data hs_err_pid11491.log lib LICENSE.txt logs modules NOTICE.txt plugins README.textile 12 [elsearch@slaver4 elasticsearch-5.4.3]$ cd plugins/ 13 [elsearch@slaver4 plugins]$ ls 14 elasticsearch-analysis-ik sql 15 [elsearch@slaver4 plugins]$ cd sql/ 16 [elsearch@slaver4 sql]$ ls 17 druid.jar elasticsearch-sql-5.4.3.0.jar guava.jar plugin-descriptor.properties 18 [elsearch@slaver4 sql]$
2、我在一个节点执行的,安装成功以后,然后将解压到plugins目录下sql目录拷贝到其他es的节点的plugins目录下面即可。如下所示:
1 [elsearch@slaver4 soft]$ ls 2 elasticsearch-5.4.3 elasticsearch-head-master el_slave node-v8.16.2-linux-x64 nohup.out 3 [elsearch@slaver4 soft]$ cd elasticsearch-5.4.3/plugins/ 4 [elsearch@slaver4 plugins]$ ls 5 elasticsearch-analysis-ik sql 6 [elsearch@slaver4 plugins]$ cp -r sql/ /home/hadoop/soft/el_slave/elasticsearch-5.4.3-slaver1/plugins/ 7 [elsearch@slaver4 plugins]$ cp -r sql/ /home/hadoop/soft/el_slave/elasticsearch-5.4.3-slaver2/plugins/ 8 [elsearch@slaver4 plugins]$ ls /home/hadoop/soft/el_slave/elasticsearch-5.4.3-slaver1/plugins/ 9 elasticsearch-analysis-ik sql 10 [elsearch@slaver4 plugins]$ ls /home/hadoop/soft/el_slave/elasticsearch-5.4.3-slaver2/plugins/ 11 elasticsearch-analysis-ik sql 12 [elsearch@slaver4 plugins]$
3、如果你的伪分布集群启动着呢,需要停止集群,然后重启集群,查看安装的SQL插件是否好使。
1 [elsearch@slaver4 soft]$ ls 2 elasticsearch-5.4.3 elasticsearch-head-master el_slave node-v8.16.2-linux-x64 nohup.out 3 [elsearch@slaver4 soft]$ jps 4 8048 Elasticsearch 5 9428 Jps 6 7928 Elasticsearch 7 7998 Elasticsearch 8 [elsearch@slaver4 soft]$ kill `ps -ef | grep Elasticsearch | grep -v grep | awk '{print $2}'` 9 [elsearch@slaver4 soft]$ jps 10 9480 Jps 11 [elsearch@slaver4 soft]$ cd elasticsearch-5.4.3/ 12 [elsearch@slaver4 elasticsearch-5.4.3]$ ls 13 bin config data hs_err_pid11491.log lib LICENSE.txt logs modules NOTICE.txt plugins README.textile 14 [elsearch@slaver4 elasticsearch-5.4.3]$ cd bin/ 15 [elsearch@slaver4 bin]$ ls 16 elasticsearch elasticsearch.in.sh elasticsearch-plugin elasticsearch-service-mgr.exe elasticsearch-systemd-pre-exec hs_err_pid9127.log 17 elasticsearch.bat elasticsearch-keystore elasticsearch-plugin.bat elasticsearch-service-x64.exe elasticsearch-translog 18 elasticsearch.in.bat elasticsearch-keystore.bat elasticsearch-service.bat elasticsearch-service-x86.exe elasticsearch-translog.bat 19 [elsearch@slaver4 bin]$ ./elasticsearch -d 20 [elsearch@slaver4 bin]$ cd ../../el_slave/ 21 [elsearch@slaver4 el_slave]$ ls 22 elasticsearch-5.4.3-slaver1 elasticsearch-5.4.3-slaver2 23 [elsearch@slaver4 el_slave]$ cd elasticsearch-5.4.3-slaver1/ 24 [elsearch@slaver4 elasticsearch-5.4.3-slaver1]$ ls 25 bin config data hs_err_pid11491.log lib LICENSE.txt logs modules NOTICE.txt plugins README.textile 26 [elsearch@slaver4 elasticsearch-5.4.3-slaver1]$ cd bin/ 27 [elsearch@slaver4 bin]$ ls 28 elasticsearch elasticsearch.in.sh elasticsearch-plugin elasticsearch-service-mgr.exe elasticsearch-systemd-pre-exec 29 elasticsearch.bat elasticsearch-keystore elasticsearch-plugin.bat elasticsearch-service-x64.exe elasticsearch-translog 30 elasticsearch.in.bat elasticsearch-keystore.bat elasticsearch-service.bat elasticsearch-service-x86.exe elasticsearch-translog.bat 31 [elsearch@slaver4 bin]$ ./elasticsearch -d 32 [elsearch@slaver4 bin]$ cd ../../elasticsearch-5.4.3-slaver2/ 33 [elsearch@slaver4 elasticsearch-5.4.3-slaver2]$ ls 34 bin config data hs_err_pid11491.log lib LICENSE.txt logs modules NOTICE.txt plugins README.textile 35 [elsearch@slaver4 elasticsearch-5.4.3-slaver2]$ cd bin/ 36 [elsearch@slaver4 bin]$ ls 37 elasticsearch elasticsearch.in.sh elasticsearch-plugin elasticsearch-service-mgr.exe elasticsearch-systemd-pre-exec 38 elasticsearch.bat elasticsearch-keystore elasticsearch-plugin.bat elasticsearch-service-x64.exe elasticsearch-translog 39 elasticsearch.in.bat elasticsearch-keystore.bat elasticsearch-service.bat elasticsearch-service-x86.exe elasticsearch-translog.bat 40 [elsearch@slaver4 bin]$ ./elasticsearch -d 41 [elsearch@slaver4 bin]$ jps 42 9520 Elasticsearch 43 9651 Jps 44 9637 Elasticsearch 45 9578 Elasticsearch 46 [elsearch@slaver4 bin]$
4、此时,你就可以使用浏览器进行测试,http://192.168.110.133:9200/_sql?sql=select * from player limit 10,我的测试如下所示:
注意:from后面跟的是你的索引Index哦!别查询错误了。
5、然后你可以使用界面的形式写SQL,感觉很喜欢这种方式哦!下载SQL的Server,方式如下所示:
注意:下面这个插件使用的是node编写的,所以需要node相关的依赖包,之前弄过,这里省略了。在一台节点安装即可哦!
1 [elsearch@slaver4 hadoop]$ wget http://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.1.0/es-sql-site-standalone.zip 2 --2019-10-21 22:05:36-- http://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.1.0/es-sql-site-standalone.zip 3 Resolving github.com (github.com)... 13.229.188.59 4 Connecting to github.com (github.com)|13.229.188.59|:80... connected. 5 HTTP request sent, awaiting response... 301 Moved Permanently 6 Location: https://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.1.0/es-sql-site-standalone.zip [following] 7 --2019-10-21 22:05:36-- https://github.com/NLPchina/elasticsearch-sql/releases/download/5.4.1.0/es-sql-site-standalone.zip 8 Connecting to github.com (github.com)|13.229.188.59|:443... connected. 9 HTTP request sent, awaiting response... 302 Found 10 Location: https://github-production-release-asset-2e65be.s3.amazonaws.com/23282991/0a751200-5085-11e7-9ec9-63ecd48186af?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20191021%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20191021T140536Z&X-Amz-Expires=300&X-Amz-Signature=5567d99816d092aa1f694ced016c9793776db7eef8d195bc50aa24cf14381b34&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Des-sql-site-standalone.zip&response-content-type=application%2Foctet-stream [following] 11 --2019-10-21 22:05:37-- https://github-production-release-asset-2e65be.s3.amazonaws.com/23282991/0a751200-5085-11e7-9ec9-63ecd48186af?X-Amz-Algorithm=AWS4-HMAC-SHA256&X-Amz-Credential=AKIAIWNJYAX4CSVEH53A%2F20191021%2Fus-east-1%2Fs3%2Faws4_request&X-Amz-Date=20191021T140536Z&X-Amz-Expires=300&X-Amz-Signature=5567d99816d092aa1f694ced016c9793776db7eef8d195bc50aa24cf14381b34&X-Amz-SignedHeaders=host&actor_id=0&response-content-disposition=attachment%3B%20filename%3Des-sql-site-standalone.zip&response-content-type=application%2Foctet-stream 12 Resolving github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)... 52.216.146.235 13 Connecting to github-production-release-asset-2e65be.s3.amazonaws.com (github-production-release-asset-2e65be.s3.amazonaws.com)|52.216.146.235|:443... connected. 14 HTTP request sent, awaiting response... 200 OK 15 Length: 1722956 (1.6M) [application/octet-stream] 16 Saving to: ‘es-sql-site-standalone.zip’ 17 18 100%[=======================================================================================================================================================================>] 1,722,956 81.5KB/s in 27s 19 20 2019-10-21 22:06:05 (63.4 KB/s) - ‘es-sql-site-standalone.zip’ saved [1722956/1722956]
开始执行解压缩操作,命令如下所示:
注意:由于unzip是解压缩到当前目录,你可以将.zip的包删除掉。
1 [elsearch@slaver4 hadoop]$ cd soft/ 2 [elsearch@slaver4 soft]$ ls 3 elasticsearch-5.4.3 elasticsearch-head-master el_slave node-v8.16.2-linux-x64 nohup.out 4 [elsearch@slaver4 soft]$ mkdir el_sql 5 [elsearch@slaver4 soft]$ cp ../es-sql-site-standalone.zip ./el_sql/ 6 [elsearch@slaver4 soft]$ ls 7 elasticsearch-5.4.3 elasticsearch-head-master el_slave el_sql node-v8.16.2-linux-x64 nohup.out 8 [elsearch@slaver4 soft]$ cd el_sql/ 9 [elsearch@slaver4 el_sql]$ ls 10 es-sql-site-standalone.zip 11 [elsearch@slaver4 el_sql]$ unzip es-sql-site-standalone.zip
6、开始安装你的图形化插件,如下所示:
1 [elsearch@slaver4 el_sql]$ cd site-server/ 2 [elsearch@slaver4 site-server]$ ls 3 node-server.js package.json site_configuration.json 4 [elsearch@slaver4 site-server]$ npm install express --save 5 npm notice created a lockfile as package-lock.json. You should commit this file. 6 npm WARN site-server No description 7 npm WARN site-server No repository field. 8 npm WARN site-server No license field. 9 10 + express@4.17.1 11 added 50 packages from 37 contributors and audited 126 packages in 19.057s 12 found 0 vulnerabilities 13 14 [elsearch@slaver4 site-server]$
7、修改SQL的Server的端口,vi site_configuration.json。默认端口号是8080,如果没有占用的话,可以直接使用的。操作如下所示:
1 [elsearch@slaver4 site-server]$ vim site_configuration.json
8、安装成功以后启动你的服务,如下所示:
前台启动方式如下所示:node node-server.js
后台启动方式如下所示:node node-server.js &
1 [elsearch@slaver4 site-server]$ node node-server.js
9、启动成功以后可以查看界面,如下所示:
10、图形化界面使用如下所示:
注意:记得修改右上角的地址哦!
更多案例,可以参考https://github.com/NLPchina/elasticsearch-sql
作者:别先生
博客园:https://www.cnblogs.com/biehongli/
如果您想及时得到个人撰写文章以及著作的消息推送,可以扫描上方二维码,关注个人公众号哦。