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.git
cd elasticsearch-head
npm install
grunt server
open
http://localhost:9100/https://github.com/mobz/elasticsearch-head#running-with-built-in-serverphp
一、windows下的NodeJS安裝是比較方便的(v0.6.0版本以後,支持windows native),只須要登錄官網(http://nodejs.org/),即可以看到首頁的「INSTALL」按鈕,直接點擊就會自動下載安裝了。html
步驟3:前端
MINGW64 /e/elasticsearch-head (master)
$ npm install
npm WARN deprecated node-uuid@1.4.7: use uuid module insteadhtml5
> phantomjs-prebuilt@2.1.13 install E:\workspace-demo\elasticsearch-head\node_modules\phantomjs-prebuilt
> node install.jsjava
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...node
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.2mysql
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 expressiongit
是一套前端自動化工具,一個基於nodeJs的命令行工具,通常用於:
① 壓縮文件
② 合併文件
③ 簡單語法檢查es6
對於其餘用法,我還不太清楚,咱們這裏簡單介紹下grunt的壓縮、合併文件,初學,有誤請包涵github
由於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進行查看。
最關鍵的:若是文章內容有誤,請指出!!!
http://www.cnblogs.com/chyingp/p/npm.html