1.创建用户
useradd elasticsearch –M -s /sbin/nologin
2. 系统优化
1) vim /etc/sysctl.conf
vm.max_map_count=655360 #文件最后添加一行
sysctl –p
2)vim /etc/security/limits.conf
* soft nofile 65536 #文件最后添加
* hard nofile 65536 #文件最后添加
ulimit –n 65536
二、Elasticsearch部署
1. 解压elasticsearch-6.2.4.zip
2. 配置config/elasticsearch.yml
cluster.name: elasticsearch # 集群名称
node.name: local # 节点名称(节点之间名称不重复)
path.data: ${数据目录}
path.logs: ${日志目录}
network.host: 127.0.0.1
transport.tcp.port: 2810
http.port: 2811
discovery.zen.ping.unicast.hosts: ["127.0.0.1:2810"] # 默认写集群所有节点
discovery.zen.minimum_master_nodes: 1 #节点个数/2+1个节点
3. 配置config/jvm.options
-Xms2g
-Xmx2g
4. 启动elasticsearch
sudo –u elasticsearch bin/elasticsearch –d &
三、配置cerebro
1. 解压cerebro-0.8.1.zip
2. 配置conf/application.conf
#cerebro的账号密码
auth = {
type: basic
settings: {
username = "admin"
password = "admin"
}
}
# ES集群的http接口
hosts = [
{
host = "http://127.0.0.1:2811"
name = "elasticsearch"
}
]
3. 启动cerebro
bin/cerebro -Dhttp.port=1234 -Dhttp.address=127.0.0.1
四、使用
1. 创建索引test
PUT test
{
"settings" : {
"index" : {
# 指定生成多少个shard分片
"number_of_shards" : 1,
# 指定生成多少个副本
"number_of_replicas" : 0
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-create-index.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.0/_index_and_query_a_document.html
2. 创建type
PUT test/_mapping/_doc
{
"properties": {
"email": {
"type": "keyword"
},
"content":{
"type": "text"
}
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/indices-put-mapping.html
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/mapping-types.html
3. 写入doc
PUT test/_doc /1
{
"email" : "[email protected]",
"content": "大数据培训"
}
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/docs-index_.html
4. 数据查询
GET /test/_search
{
"query" : {
"match" : { "content" : "大数据" }
}
}
GET /first_index/_search
{
"query" : {
"term" : { "content" : "大数据" }
}
}
https://www.elastic.co/guide/en/elasticsearch/reference/6.2/search-request-body.html
四、Java API
RestHighLevelClient client = new RestHighLevelClient( RestClient.builder( new HttpHost("localhost", 2811, "http")));
https://www.elastic.co/guide/en/elasticsearch/client/java-rest/current/index.html
五、Python API
https://elasticsearch-py.readthedocs.io/en/master/api.html