机器地址
172.27.88.254:27107 MongoDB
172.27.88.3:9200 elasticsearch
172.27.88.3:5601 kibana:
分词插件:./bin/elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.0.0/elasticsearch-analysis-ik-6.0.0.zip
elasticsearch 安装启动
- 版本信息
elasticsearch 版本 elasticsearch-5.5.3.tar.gz
kibana 版本 kibana-5.5.3-darwin-x86_64.tar.gz
$: sudo vim /etc/sysctl.conf
fs.file-max=655360
vm.max_map_count=262144
$: sudo vim /etc/security/limits.conf
#* soft nofile 65536
#* hard nofile 131072
#* soft nproc 2048
#* hard nproc 4096
- 添加账号:elastic(启动账号不能是root)
groupadd elastic
useradd elastic -g elastic
- 给elastic用户赋予权限,这里的elasticsearch-6.0.0
chown -R elastic:elastic elasticsearch-6.0.0
- 修改配置文件,单节点启动
$: vim config/elasticsearch.yml
discovery.type: single-node
network.host: 192.168.4.71
http.port: 9200
- x-pack 插件安装(120多兆,可以使用离线安装)
./bin/elasticsearch-plugin install x-pack
- 离线安装(file://protocol)
bin/elasticsearch-plugin install file:///opt/x-pack-6.0.0.zip
- allow automatic index creation in elasticsearch.yml
action.auto_create_index: .security,.monitoring*,.watches,.triggered_watchers,.watcher-history*,.ml*
- Configure passwords ans SSL/TLS
kibana 安装启动
- 前提:安装 nodejs
wget https://nodejs.org/dist/v6.10.1/node-v6.10.1-linux-x64.tar.xz
安装 xz:
yum search xz
yum install xz.x86_64
xz -d node-v6.10.1-linux-x64.tar.xz
tar -xf node-v6.10.1-linux-x64.tar
建立软连接
ln -s /opt/node-v6.10.1-linux-x64/bin/node /usr/local/bin/node
ln -s /opt/node-v6.10.1-linux-x64/bin/npm /usr/local/bin/npm
查看版本
node --version
npm --version
- 如果在使用 bin/kibana 启动失败(有可能是下载的 kibana 版本不对),用如下方式启动
进入到 kibana 根目录执行 npm 运行命令:1. npm install 2. node /opt/kibana-6.0.0-darwin-x86_64/src/cli &
- x-pack 插件安装(120多兆,可以使用离线安装)
./bin/kibana-plugin install x-pack
- 离线安装(file://protocol)
bin/kibana-plugin install file:///opt/x-pack-6.0.0.zip
MongoDB 安装启动
Manipulating data with the REST API
- create a new document
如果需要执行版本号,可以在 url 后面加上 version 参数
curl -XPUT -H'Content-Type: application/json' http://172.27.88.3:9200/blog/article/1?version=123456 -d'
{
"title": "New version of Elasticsearch released!",
"content": "Version 1.0 released today!",
"tags": ["announce", "elasticsearch", "release"]
}
'
- retriveving documents
curl -XGET http://172.27.88.3:9200/blog/article/1
- updating documents
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/blog/article/1/_update -d '{
"script": "ctx._source.content = \"new content\""
}'
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/blog/article/1/_update -d '{
"script": "ctx._source.counter += 1",
"upsert": {
"counter" : 0
}
}'
- Deleting documents
An example of versioning
curl -XDELETE http://172.27.88.3:9200/blog/article/1?version=1
- 信息获取
- 获取集群信息
GET http://172.27.88.3:9200/_cluster/state/
- 获取集群所有节点信息
GET http://172.27.88.3:9200/_cluster/state/nodes/
- 添加 index, type
curl -XPOST 'http://172.27.88.3:9200/books/es/1' -H'Content-Type: application/json' -d '{"title":"Elasticsearch Server", "published": 2013}'
curl -XPOST 'http://172.27.88.3:9200/books/es/2' -H'Content-Type: application/json' -d '{"title":"Mastering Elasticsearch", "published": 2013}'
curl -XPOST 'http://172.27.88.3:9200/books/solr/1' -H'Content-Type: application/json' -d '{"title":"Apache Solr 4 Cookbook", "published": 2012}'
curl -XPUT 'http://172.27.88.3:9200/accounts/person/1' -H'Content-Type: application/json' -d '
{
"user": "张三",
"title": "工程师",
"desc": "数据库管理"
}'
curl -X POST -H 'Content-Type: application/json' 'http://192.168.4.71:9200/accounts/person' -d '
{
"user": "李四",
"title": "工程师",
"desc": "系统管理"
}'
- 查看当前节点所有 index
curl -X GET 'http://172.27.88.3:9200/_cat/indices?v'
curl 'http://172.27.88.3:9200/weather/_search'
curl 'http://172.27.88.3:9200/_mapping?pretty=true'
curl -X PUT -H 'Content-Type: application/json' -u elastic 'http://172.27.88.3:9200/_xpack/security/user/elastic/_password' -d '{
"password" : "123456"
}'
curl -XPUT http://172.27.88.3:9200/index;
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/index/fulltext/_mapping -d'
{
"properties": {
"content": {
"type": "text",
"analyzer": "ik_max_word",
"search_analyzer": "ik_max_word"
}
}
}';
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/index/fulltext/1 -d'
{"content":"美国留给伊拉克的是个烂摊子吗"}
';
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/index/fulltext/2 -d'
{"content":"公安部:各地校车将享最高路权"}
';
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/index/fulltext/3 -d'
{"content":"中韩渔警冲突调查:韩警平均每天扣1艘中国渔船"}
';
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/index/fulltext/4 -d'
{"content":"中国驻洛杉矶领事馆遭亚裔男子枪击 嫌犯已自首"}
';
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/index/fulltext/_search -d'
{
"query" : { "match" : { "content" : "中国" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}';
curl -XPOST -H'Content-Type: application/json' http://172.27.88.3:9200/index/fulltext/_search?pretty -d'{
"query" : { "match" : { "content" : "洛杉矶领事馆" }},
"highlight" : {
"pre_tags" : ["<tag1>", "<tag2>"],
"post_tags" : ["</tag1>", "</tag2>"],
"fields" : {
"content" : {}
}
}
}';
curl -H'Content-Type: application/json;charset=UTF-8' -XPOST 'http://172.27.88.3:9200/_analyze/' -d '{
"analyzer": "ik_max_word",
"text": "中华人民共和国"
}';
http://172.27.88.3:9200/_analyze/?analyzer=ik_max_word&text=洛杉矶领事馆