标签:roc 2.0 shell 童鞋 instead 方法 jar tsp async
http.cors.enabled: true in elasticsearch configuration. Don’t forget to also set http.cors.allow-origin because no origin allowed by default. http.cors.allow-origin: "*" is valid value, however it’s considered as a security risk as your cluster is open to cross origin from anywhere. Check Elasticsearch documentation on this parameter:https://www.elastic.co/guide/en/elasticsearch/reference/current/modules-http.html#modules-httpgit clone git://github.com/mobz/elasticsearch-head.gitcd elasticsearch-headnpm installgrunt serveropen http://localhost:9100/https://github.com/mobz/elasticsearch-head#running-with-built-in-server
1、windows下的NodeJS安装是比较方便的(v0.6.0版本之后,支持windows native),只需要登陆官网(http://nodejs.org/),便可以看到首页的“INSTALL”按钮,直接点击就会自动下载安装了。



步骤3:
 MINGW64 /e/elasticsearch-head (master)
$ npm install
npm WARN deprecated node-uuid@1.4.7: use uuid module instead
> phantomjs-prebuilt@2.1.13 install E:\workspace-demo\elasticsearch-head\node_modules\phantomjs-prebuilt
> node install.js
PhantomJS not found on PATH
Downloading https://github.com/Medium/phantomjs/releases/download/v2.1.1/phantomjs-2.1.1-windows.zip
Saving to C:\Users\TANG~1.CHE\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip
Receiving...
Received 17767K total.
Extracting zip contents
Removing E:\workspace-demo\elasticsearch-head\node_modules\phantomjs-prebuilt\lib\phantom
Copying extracted folder C:\Users\TANG~1.CHE\AppData\Local\Temp\phantomjs\phantomjs-2.1.1-windows.zip-extract-1479521265399\phantomjs-2.1.1-windows -> E:\workspace-demo\elasticsearch-head\node_modules\phantomjs-prebuilt\lib\phantom
Writing location.js file
Done. Phantomjs binary available at E:\workspace-demo\elasticsearch-head\node_modules\phantomjs-prebuilt\lib\phantom\bin\phantomjs.exe
elasticsearch-head@0.0.0 E:\workspace-demo\elasticsearch-head
`-- grunt-contrib-jasmine@1.0.3
  +-- grunt-lib-phantomjs@1.1.0
  | +-- phantomjs-prebuilt@2.1.13
  | | +-- es6-promise@4.0.5
  | | +-- extract-zip@1.5.0
  | | | +-- concat-stream@1.5.0
  | | | | `-- typedarray@0.0.6
  | | | +-- debug@0.7.4
  | | | +-- mkdirp@0.5.0
  | | | | `-- minimist@0.0.8
  | | | `-- yauzl@2.4.1
  | | |   `-- fd-slicer@1.0.1
  | | |     `-- pend@1.2.0
  | | +-- fs-extra@0.30.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.74.0
  | | | +-- aws-sign2@0.6.0
  | | | +-- aws4@1.5.0
  | | | +-- bl@1.1.2
  | | | +-- caseless@0.11.0
  | | | +-- combined-stream@1.0.5
  | | | | `-- delayed-stream@1.0.0
  | | | +-- forever-agent@0.6.1
  | | | +-- form-data@1.0.1
  | | | | `-- async@2.1.2
  | | | |   `-- lodash@4.17.2
  | | | +-- har-validator@2.0.6
  | | | | +-- commander@2.9.0
  | | | | | `-- graceful-readlink@1.0.1
  | | | | `-- is-my-json-valid@2.15.0
  | | | |   +-- generate-function@2.0.0
  | | | |   +-- generate-object-property@1.2.0
  | | | |   | `-- is-property@1.0.2
  | | | |   +-- jsonpointer@4.0.0
  | | | |   `-- xtend@4.0.1
  | | | +-- hawk@3.1.3
  | | | | +-- boom@2.10.1
  | | | | +-- cryptiles@2.0.5
  | | | | +-- hoek@2.16.3
  | | | | `-- sntp@1.0.9
  | | | +-- http-signature@1.1.1
  | | | | +-- assert-plus@0.2.0
  | | | | +-- jsprim@1.3.1
  | | | | | +-- extsprintf@1.0.2
  | | | | | +-- json-schema@0.2.3
  | | | | | `-- verror@1.3.6
  | | | | `-- sshpk@1.10.1
  | | | |   +-- asn1@0.2.3
  | | | |   +-- assert-plus@1.0.0
  | | | |   +-- bcrypt-pbkdf@1.0.0
  | | | |   +-- dashdash@1.14.0
  | | | |   | `-- assert-plus@1.0.0
  | | | |   +-- ecc-jsbn@0.1.1
  | | | |   +-- getpass@0.1.6
  | | | |   | `-- assert-plus@1.0.0
  | | | |   +-- jodid25519@1.0.2
  | | | |   +-- jsbn@0.1.0
  | | | |   `-- tweetnacl@0.14.3
  | | | +-- is-typedarray@1.0.0
  | | | +-- isstream@0.1.2
  | | | +-- json-stringify-safe@5.0.1
  | | | +-- node-uuid@1.4.7
  | | | +-- oauth-sign@0.8.2
  | | | +-- qs@6.2.1
  | | | +-- stringstream@0.0.5
  | | | +-- tough-cookie@2.3.2
  | | | | `-- punycode@1.4.1
  | | | `-- tunnel-agent@0.4.3
  | | `-- request-progress@2.0.1
  | |   `-- throttleit@1.0.0
  | `-- rimraf@2.5.4
  `-- 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.0.15: wanted {"os":"darwin","arch":"any"} (current: {"os":"win32","arch":"x64"})
npm WARN elasticsearch-head@0.0.0 license should be a valid SPDX license expression
是一套前端自动化工具,一个基于nodeJs的命令行工具,一般用于:
① 压缩文件
② 合并文件
③ 简单语法检查
对于其他用法,我还不太清楚,我们这里简单介绍下grunt的压缩、合并文件,初学,有误请包涵
因为grunt是基于nodeJs的,所以首先各位需要安装nodeJS环境,这块我们便不管了
http://www.cnblogs.com/yexiaochai/p/3527418.html
有了nodeJs环境后,我们便可以开始搞grunt了,因为我们可能在任何目录下运行打包程序,所以我们需要安装CLI
官方推荐在全局安装CLI(grunt的命令行接口)
npm install -g grunt-cli
这条命令将会把grunt命令植入系统路径,这样就能在任意目录运行他,原因是
每次运行grunt时,它都会使用node的require查找本地是否安装grunt,如果找到CLI便加载这个本地grunt库
然后应用我们项目中的GruntFile配置,并执行任务
步骤4:
/e/elasticsearch-head (master)
$ npm install -g grunt-cli
C:\Users\admin\AppData\Roaming\npm\grunt -> C:\Users\admin\AppData\Roaming\npm\node_modules\grunt-cli\bin\grunt
C:\Users\admin\AppData\Roaming\npm
`-- grunt-cli@1.2.0
  +-- findup-sync@0.3.0
  | `-- glob@5.0.15
  |   +-- inflight@1.0.6
  |   | `-- wrappy@1.0.2
  |   +-- inherits@2.0.3
  |   +-- minimatch@3.0.3
  |   | `-- brace-expansion@1.1.6
  |   |   +-- balanced-match@0.4.2
  |   |   `-- concat-map@0.0.1
  |   +-- once@1.4.0
  |   `-- path-is-absolute@1.0.1
  +-- grunt-known-options@1.1.0
  +-- nopt@3.0.6
  | `-- abbrev@1.0.9
  `-- resolve@1.1.7
ANTS-SH-0063 MINGW64 /e/elasticsearch-head (master)
$ grunt server
Running "connect:server" (connect) task
Waiting forever...
Started connect web server on http://localhost:9100
The IK Analysis plugin integrates Lucene IK analyzer (http://code.google.com/p/ik-analyzer/) into elasticsearch, support customized dictionary.
Analyzer: ik_smart , ik_max_word , Tokenizer: ik_smart , ik_max_word
| IK version | ES version | 
|---|---|
| master | 5.x -> master | 
| 5.0.1 | 5.0.1 | 
| 1.10.1 | 2.4.1 | 
| 1.9.5 | 2.3.5 | 
| 1.8.1 | 2.2.1 | 
| 1.7.0 | 2.1.1 | 
| 1.5.0 | 2.0.0 | 
| 1.2.6 | 1.0.0 | 
| 1.2.5 | 0.90.x | 
| 1.1.3 | 0.20.x | 
| 1.0.0 | 0.16.2 -> 0.19.0 | 
1.compile
checkout ik version respective to your elasticsearch version
git checkout tags/{version}
mvn package
copy and unzip target/releases/elasticsearch-analysis-ik-{version}.zip to your-es-root/plugins/ik
2.restart elasticsearch
Tips:
ik_max_word: 会将文本做最细粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,中华人民,中华,华人,人民共和国,人民,人,民,共和国,共和,和,国国,国歌”,会穷尽各种可能的组合;
ik_smart: 会做最粗粒度的拆分,比如会将“中华人民共和国国歌”拆分为“中华人民共和国,国歌”。
1.create a index
curl -XPUT http://localhost:9200/index
2.create a mapping
curl -XPOST http://localhost:9200/index/fulltext/_mapping -d‘
{
    "fulltext": {
             "_all": {
            "analyzer": "ik_max_word",
            "search_analyzer": "ik_max_word",
            "term_vector": "no",
            "store": "false"
        },
        "properties": {
            "content": {
                "type": "text",
                "analyzer": "ik_max_word",
                "search_analyzer": "ik_max_word",
                "include_in_all": "true",
                "boost": 8
            }
        }
    }
}‘
3.index some docs
curl -XPOST http://localhost:9200/index/fulltext/1 -d‘
{"content":"美国留给伊拉克的是个烂摊子吗"}
‘
curl -XPOST http://localhost:9200/index/fulltext/2 -d‘
{"content":"公安部:各地校车将享最高路权"}
‘
curl -XPOST http://localhost:9200/index/fulltext/3 -d‘
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
‘
curl -XPOST http://localhost:9200/index/fulltext/4 -d‘
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
‘
4.query with highlighting
curl -XPOST http://localhost:9200/index/fulltext/_search  -d‘
{
    "query" : { "match" : { "content" : "中国" }},
    "highlight" : {
        "pre_tags" : ["<tag1>", "<tag2>"],
        "post_tags" : ["</tag1>", "</tag2>"],
        "fields" : {
            "content" : {}
        }
    }
}
‘
Result
{
    "took": 14,
    "timed_out": false,
    "_shards": {
        "total": 5,
        "successful": 5,
        "failed": 0
    },
    "hits": {
        "total": 2,
        "max_score": 2,
        "hits": [
            {
                "_index": "index",
                "_type": "fulltext",
                "_id": "4",
                "_score": 2,
                "_source": {
                    "content": "中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"
                },
                "highlight": {
                    "content": [
                        "<tag1>中国</tag1>驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首 "
                    ]
                }
            },
            {
                "_index": "index",
                "_type": "fulltext",
                "_id": "3",
                "_score": 2,
                "_source": {
                    "content": "中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"
                },
                "highlight": {
                    "content": [
                        "均每天扣1艘<tag1>中国</tag1>渔船 "
                    ]
                }
            }
        ]
    }
}
https://github.com/medcl/elasticsearch-analysis-ik
配置 JDBC 数据源
1. 安装 openjdk(本人用的ubuntu)
sudo apt-get install openjdk-7-jre
2.下载安装 elasticsearch
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.4.deb
sudo dpkg -i elasticsearch-1.4.4.deb
/etc/init.d/elasticsearch start
3.安装JDBC 插件
1
./bin/plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.4.0.10/elasticsearch-river-jdbc-1.4.0.10.zip
4.安装MySQL JDBC 驱动
curl -o mysql-connector-java-5.1.33.zip -L ‘http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.33.zip/from/http://cdn.mysql.com/‘
unzip mysql-connector-java-5.1.33.zip
cp mysql-connector-java-5.1.33-bin.jar $ES_HOME/plugins/jdbc/
chmod 644 $ES_HOME/plugins/jdbc/*
/etc/init.d/elasticsearch restart
http://localhost:9200/_nodes?settings=true&pretty=true  配置信息(安装路径、插件...)
更多参数见:https://github.com/jprante/elasticsearch-river-jdbc
5.测试mysql (用户root 密码passwd 库jdbctest 表名posts)
curl -XPUT ‘localhost:9200/_river/my_jdbc_river/_meta‘ -d ‘{
    "type" : "jdbc",
    "jdbc" : {
        "url" : "jdbc:mysql://localhost:3306/jdbctest",
        "user" : "root",
        "password" : "passwd",
        "sql" : "select * from posts"
    }
}‘
curl ‘localhost:9200/jdbc/_search‘
运行如下命令,就会在当前目录下安装grunt-cli(grunt命令行工具)
npm install grunt-cli
安装结束后,当前目录下回多出一个node_modules目录,grunt-cli就安装在里面。同时注意控制台输出的信息:
grunt-cli@0.1.9 node_modules/grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.4)
└── findup-sync@0.1.2 (lodash@1.0.1, glob@3.1.21)
简单说明一下:
上面已经安装了grunt-cli,然后你跑到其他目录下面运行如下命令
grunt
果断提示你grunt命令不存在,为什么呢?因为上面只是进行了本地安装,grunt命令只能在对应安装目录下使用。
-bash: grunt: command not found
如果为了使用grunt命令,每到一个目录下都得重新安装一次,那不抓狂才怪。肿么办呢?
很简单,采用全局安装就行了,很简单,加上参数-g就可以了
npm install -g grunt-cli
于是,在所有目录下都可以无压力使用grunt命令了。这个时候,你会注意到控制台输入的信息有点不同。主要的区别在于安装目录,现在变成了/usr/local/lib/node_modules/grunt-cli,/usr/local/lib/node_modules/也就是之前所说的全局安装目录啦。
grunt-cli@0.1.9 /usr/local/lib/node_modules/grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.4)
└── findup-sync@0.1.2 (lodash@1.0.1, glob@3.1.21)
npm的包管理命令是使用频率最高的,所以也是我们需要牢牢记住并熟练使用的。其实无非也就是几个动作:安装、卸载、更新、查看、搜索、发布等。
npm install grunt-cli
npm install grunt-cli@"0.1.9"
如果我们的项目依赖了很多package,一个一个地安装那将是个体力活。我们可以将项目依赖的包都在package.json这个文件里声明,然后一行命令搞定
npm install
运行如下命令,列出所有npm install可能的参数形式
npm install --help
输出如下,有兴趣的童鞋可以了解下
npm install <tarball file>
npm install <tarball url>
npm install <folder>
npm install <pkg>
npm install <pkg>@<tag>
npm install <pkg>@<version>
npm install <pkg>@<version range>
比如卸载grunt-cli
npm uninstall grunt-cli
npm uninstall grunt-cli@"0.1.9"
运行如下命令,就可以查看当前目录安装了哪些package
npm ls
输出如下
/private/tmp/npm
└─┬ grunt-cli@0.1.9
  ├─┬ findup-sync@0.1.2
  │ ├─┬ glob@3.1.21
  │ │ ├── graceful-fs@1.2.3
  │ │ ├── inherits@1.0.0
  │ │ └─┬ minimatch@0.2.12
  │ │   ├── lru-cache@2.3.0
  │ │   └── sigmund@1.0.0
  │ └── lodash@1.0.1
  ├─┬ nopt@1.0.10
  │ └── abbrev@1.0.4
  └── resolve@0.3.1
输出如下,同样,如果是要查看package的全局安装信息,加上-g就可以
运行如下命令,输出grunt-cli的信息
npm ls grunt-cli
输出的信息比较有限,只有安装目录、版本,如下:
/private/tmp/npm
└── grunt-cli@0.1.9 
如果要查看更详细信息,可以通过npm info pkg,输出的信息非常详尽,包括作者、版本、依赖等。
npm info grunt-cli
npm update grunt-cli
输入如下命令
npm search grunt-cli
返回结果如下
npm http GET http://registry.npmjs.org/-/all/since?stale=update_after&startkey=1375519407838
npm http 200 http://registry.npmjs.org/-/all/since?stale=update_after&startkey=1375519407838
NAME                  DESCRIPTION                                        AUTHOR            DATE              KEYWORDS
grunt-cli             The grunt command line interface.                  =cowboy =tkellen  2013-07-27 02:24
grunt-cli-dev-exitprocess The grunt command line interface.              =dnevnik          2013-03-11 16:19
grunt-client-compiler Grunt wrapper for client-compiler.                 =rubenv           2013-03-26 09:15  gruntplugin
grunt-clientside      Generate clientside js code from CommonJS modules  =jga              2012-11-07 01:20  gruntplugin
这个命令我自己也还没实际用过,不误导大家,语法如下,也可参考官方对于package发布的说明https://npmjs.org/doc/developers.html:
npm publish <tarball>
npm publish <folder>
npm的配置工作主要是通过npm config命令,主要包含增、删、改、查几个步骤,下面就以最为常用的proxy配置为例。
内网使用npm很头痛的一个问题就是代理,假设我们的代理是 http://proxy.example.com:8080,那么命令如下:
npm config set proxy http://proxy.example.com:8080
由于npm config set命令比较常用,于是可以如下简写
npm set proxy http://proxy.example.com:8080    
设置完,我们查看下当前代理设置
npm config get proxy
输出如下:
同样可如下简写:
npm get proxy
代理不需要用到了,那删了吧
npm delete proxy
npm config list
有时候觉得一条配置一条配置地修改有些麻烦,就直接进配置文件修改了
npm config edit
这货在官网似乎没有详细的描述,其实就是包的描述信息啦。假设当我们下载了node应用,这个node应用依赖于A、B、C三个包,如果没有package.json,我们需要人肉安装这个三个包(如果对版本有特定要求就更悲剧了):
npm install A
npm install B
npm install C
有了package.json,一行命令安装所有依赖。
npm install
字段相当多,但最重要的的是下面几个
在package.json里,你经常会在包名后看到类似"~0.1.0"这样的字符串,这就是包的版本啦。下面会列举最常见的版本声明形式,以及版本书写的要求:
a、"~1.2.3" 是神马意思呢,看下面领悟
"~1.2.3" = ">=1.2.3 <1.3.0"
"~1.2" = ">=1.2.0 <1.3.0"
"~1" = ">=1.0.0 <1.1.0"
b、"1.x.x"是什么意思呢,继续自行领悟
"1.2.x" = ">=1.2.0 <1.3.0"
"1.x.x" = ">=1.0.0 <2.0.0"
"1.2" = "1.2.x"
"1.x" = "1.x.x"
"1" = "1.x.x"
内容只是简单地把最常见的命令,以及一些需要了解的内容列了出来。如要进一步了解,可参考官网说明。此外,npm help是我们最好的朋友,如果忘了有哪些命令,命令下有哪些参数,可通过help进行查看。
最关键的:如果文章内容有误,请指出!!!
Install elasticsearch-head: – for Elasticsearch 5.x
标签:roc 2.0 shell 童鞋 instead 方法 jar tsp async
原文地址:http://www.cnblogs.com/softidea/p/6079980.html