Elasticsearch默认不像solr有console页面,可以执行查询,管理等工作。通过REST API直接操作真的好吗?我是非常烦REST API的。因此就有人写了一个plugin-head,用来查询或者管理ES。我使用的是ES6+版本,head插件可以单独部署,并远程连接ES服务器,通过REST API来处理交互。之前的版本可以直接通过安装plugin的方式来安装。
安装的整个步骤大致如下:
1. 修改ES配置,允许REST跨源操作ES服务器,添加以下2个配置,并重启ES。
http.cors.enabled: true #如果启用了 HTTP 端口,那么此属性会指定是否允许跨源 REST 请求
http.cors.allow-origin: "*" #如果 http.cors.enabled 的值为 true,那么该属性会指定允许 REST 请求来自何处。
2. 下载head插件
wget https://github.com/mobz/elasticsearch-head/archive/master.zip
3. 解压HEAD,并安装grunt
cd /root/elasticsearch-6.1.3/elasticsearch-head-master
npm install -g grunt-cli
确认一下版本
[root@10-10-192-88 elasticsearch-head-master]# grunt --version
grunt-cli v1.2.0
grunt v1.0.1
4. 修改HEAD监听的地址
1)默认HEAD监听 localhost, 不知道作者是否脑残,默认肯定应该监听所有网口,怎么会只监听localhost
修改Gruntfile.js,添加hostname:
connect: {
server: {
options: {
hostname: '10.10.192.88',
port: 9100,
base: '.',
keepalive: true
}
}
}
2) 既然是跨源访问ES,那么就要在HEAD里面指定ES服务器了,修改_site/app.js。
init: function(parent) {
this._super();
this.prefs = services.Preferences.instance();
this.base_uri = this.config.base_uri || this.prefs.get("app-base_uri") || "http://10.215.4.166:9200";
if( this.base_uri.charAt( this.base_uri.length - 1 ) !== "/" ) {
// XHR request fails if the URL is not ending with a "/"
this.base_uri += "/";
}
6. 进入HEAD目录,安装HEAD依赖包
npm install
[root@10-10-192-88 elasticsearch-head-master]# npm install
> phantomjs-prebuilt@2.1.16 install /root/elasticsearch-6.1.3/elasticsearch-head-master/node_modules/phantomjs-prebuilt
> node install.js
PhantomJS not found on PATH
Download already available at /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2
Verified checksum of previously downloaded file
Extracting tar contents (via spawned process)
Removing /root/elasticsearch-6.1.3/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
Copying extracted folder /tmp/phantomjs/phantomjs-2.1.1-linux-x86_64.tar.bz2-extract-1519453292391/phantomjs-2.1.1-linux-x86_64 -> /root/elasticsearch-6.1.3/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom
Writing location.js file
Done. Phantomjs binary available at /root/elasticsearch-6.1.3/elasticsearch-head-master/node_modules/phantomjs-prebuilt/lib/phantom/bin/phantomjs
elasticsearch-head@0.0.0 /root/elasticsearch-6.1.3/elasticsearch-head-master
└─┬ grunt-contrib-jasmine@1.0.3
├─┬ grunt-lib-phantomjs@1.1.0
│ ├─┬ phantomjs-prebuilt@2.1.16
│ │ ├── es6-promise@4.2.4
│ │ ├─┬ extract-zip@1.6.6
│ │ │ ├─┬ concat-stream@1.6.0
│ │ │ │ └── typedarray@0.0.6
│ │ │ ├─┬ mkdirp@0.5.0
│ │ │ │ └── minimist@0.0.8
│ │ │ └─┬ yauzl@2.4.1
│ │ │ └─┬ fd-slicer@1.0.1
│ │ │ └── pend@1.2.0
│ │ ├─┬ fs-extra@1.0.0
│ │ │ ├── jsonfile@2.4.0
│ │ │ └── klaw@1.3.1
│ │ ├─┬ hasha@2.2.0
│ │ │ └── is-stream@1.1.0
│ │ ├── kew@0.7.0
│ │ ├── progress@1.1.8
│ │ ├─┬ request@2.83.0
│ │ │ ├── aws-sign2@0.7.0
│ │ │ ├── aws4@1.6.0
│ │ │ ├── caseless@0.12.0
│ │ │ ├─┬ combined-stream@1.0.6
│ │ │ │ └── delayed-stream@1.0.0
│ │ │ ├── forever-agent@0.6.1
│ │ │ ├─┬ form-data@2.3.2
│ │ │ │ └── asynckit@0.4.0
│ │ │ ├─┬ har-validator@5.0.3
│ │ │ │ ├─┬ ajv@5.5.2
│ │ │ │ │ ├── co@4.6.0
│ │ │ │ │ ├── fast-deep-equal@1.0.0
│ │ │ │ │ ├── fast-json-stable-stringify@2.0.0
│ │ │ │ │ └── json-schema-traverse@0.3.1
│ │ │ │ └── har-schema@2.0.0
│ │ │ ├─┬ hawk@6.0.2
│ │ │ │ ├── boom@4.3.1
│ │ │ │ ├─┬ cryptiles@3.1.2
│ │ │ │ │ └── boom@5.2.0
│ │ │ │ ├── hoek@4.2.1
│ │ │ │ └── sntp@2.1.0
│ │ │ ├─┬ http-signature@1.2.0
│ │ │ │ ├── assert-plus@1.0.0
│ │ │ │ ├─┬ jsprim@1.4.1
│ │ │ │ │ ├── extsprintf@1.3.0
│ │ │ │ │ ├── json-schema@0.2.3
│ │ │ │ │ └── verror@1.10.0
│ │ │ │ └─┬ sshpk@1.13.1
│ │ │ │ ├── asn1@0.2.3
│ │ │ │ ├── bcrypt-pbkdf@1.0.1
│ │ │ │ ├── dashdash@1.14.1
│ │ │ │ ├── ecc-jsbn@0.1.1
│ │ │ │ ├── getpass@0.1.7
│ │ │ │ ├── jsbn@0.1.1
│ │ │ │ └── tweetnacl@0.14.5
│ │ │ ├── is-typedarray@1.0.0
│ │ │ ├── isstream@0.1.2
│ │ │ ├── json-stringify-safe@5.0.1
│ │ │ ├── oauth-sign@0.8.2
│ │ │ ├── performance-now@2.1.0
│ │ │ ├── qs@6.5.1
│ │ │ ├── stringstream@0.0.5
│ │ │ ├─┬ tough-cookie@2.3.3
│ │ │ │ └── punycode@1.4.1
│ │ │ ├── tunnel-agent@0.6.0
│ │ │ └── uuid@3.2.1
│ │ └─┬ request-progress@2.0.1
│ │ └── throttleit@1.0.0
│ └── rimraf@2.6.2
└── lodash@2.4.2
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@^1.0.0 (node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
5. 启动HEAD
grunt server
[root@10-10-192-88 elasticsearch-head-master]# pwd
/root/elasticsearch-6.1.3/elasticsearch-head-master
[root@10-10-192-88 elasticsearch-head-master]# grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://10.10.192.88:9100
6. 访问head地址: http://10.10.192.88:9100
npm安装过程需要连接网络,我的ES是不能通外网的,因此单独找了一台能通外网的机器来安装HEAD,现在基本查询都在这里面完成,方便。