1,解压安装即可
2,运行
cd /elasticsearch-6.3.1/bin/
./elasticsearch
elasticsearch运行时的问题
NO1
在用root用户执行时,
[WARN ][o.e.b.ElasticsearchUncaughtExceptionHandler] [] uncaught exception in thread [main]
org.elasticsearch.bootstrap.StartupException: java.lang.RuntimeException: can not run elasticsearch as root
解决方案:新建一个用户
1,查看用户
cd /
2,home中保存的用户名
cd home
3,新建用户
adduser grace
4,添加密码
passwd grace
输入密码即可。
5,设置普通用户的访问权限
chown -R grace:grace /root
更多参见Linux chown命令
6,切换路径
su grace
7,运行 elasticsearch
8,查看运行是否成功,clone session,
curl http://127.0.0.1:9200
{
"name" : "0xybRKn",
"cluster_name" : "elasticsearch",
"cluster_uuid" : "juNds5tcTMaQOgk2f-n0qw",
"version" : {
"number" : "6.3.1",
"build_flavor" : "default",
"build_type" : "tar",
"build_hash" : "eb782d0",
"build_date" : "2018-06-29T21:59:26.107521Z",
"build_snapshot" : false,
"lucene_version" : "7.3.1",
"minimum_wire_compatibility_version" : "5.6.0",
"minimum_index_compatibility_version" : "5.0.0"
},
"tagline" : "You Know, for Search"
}
即为成功
更多参见Linux curl命令
更多参见 Linux chmod命令
NO2
[1]:max file descriptors [4096] for elasticsearch process is too low, increase to at least [65536]
[2]: max number of threads [3802] for user [grace] is too low, increase to at least [4096]
修改方法一:
sudo vi /etc/security/limits.conf
* soft nproc 4096
* hard nproc 4096
* soft nofile 65536
* hard nofile 65536
修改方法二:
vi /etc/security//limits.d/20-nproc.conf
* soft nproc 4096
* hard nproc 4096
root soft nproc unlimited
elasticsearch soft nofile 65536
elasticsearch hard nofile 65536
[3]: max virtual memory areas vm.max_map_count [65530] is too low, increase to at least [262144]
sudo vi /etc/sysctl.conf
vm.max_map_count=262144
最后重启虚拟机
reboot
问题解决。
配置文件
vi /elasticsearch-6.3.1/config/elasticsearch.yml
cluster.name: my-es
node.name: node-4
path.data: home/grace/essearch/data
path.logs: home/grace/essearch/logs
network.host: 192.168.150.154
http.port: 9200
运行成功,外网访问
新建文件夹:
mkdir 文件夹名
新建文件:
touch 文件名
elasticsearch的api(增删改查)
增Creat
数据一
curl -XPOST 'http://hdp-4:9200/search2/article2/1' -H 'Content-Type: application/json' -d '{
"title": "Test1",
"tags" : "test",
"summary" : "test",
"content" : "test1 content",
"pubtime":"0"
}'
返回结果:
{"_index":"search2","_type":"article2","_id":"1","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
数据二
curl -XPOST 'http://hdp-4:9200/search2/article2/2' -H 'Content-Type: application/json' -d '{
"title": "Test2",
"tags" : "test2",
"summary" : "test2",
"content" : "test2 content",
"pubtime":"2"
}'
返回结果:
{"_index":"search2","_type":"article2","_id":"2","_version":1,"result":"created","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":0,"_primary_term":1}
改Update
curl -XPOST 'http://hdp-4:9200/search2/article2/1' -H 'Content-Type: application/json' -d '{
"title": "Test1(updated)",
"tags" : "test",
"summary" : "test",
"content" : "test1 content",
"pubtime":"0"
}'
返回结果:
{"_index":"search2","_type":"article2","_id":"1","_version":2,"result":"updated","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":1,"_primary_term":1}
查Query
1,根据ID查询
curl -XGET 'http://hdp-4:9200/search2/article2/1'
返回结果:
{"_index":"search2","_type":"article2","_id":"1","_version":2,"found":true,"_source":{
"title": "Test1(updated)",
"tags" : "test",
"summary" : "test",
"content" : "test1 content",
"pubtime":"0"
}}
2,查询所有
curl -XGET 'http://hdp-4:9200/search2/article2/_search' -H 'Content-Type: application/json' -d '{
"query" : {
"match_all" : { }
}
}'
返回结果:
{"took":354,"timed_out":false,"_shards":{"total":5,"successful":5,"skipped":0,"failed":0},"hits":{"total":2,"max_score":1.0,"hits":[{"_index":"search2","_type":"article2","_id":"2","_score":1.0,"_source":{
"title": "Test2",
"tags" : "test2",
"summary" : "test2",
"content" : "test2 content",
"pubtime":"2"
}},{"_index":"search2","_type":"article2","_id":"1","_score":1.0,"_source":{
"title": "Test1(updated)",
"tags" : "test",
"summary" : "test",
"content" : "test1 content",
"pubtime":"0"
}}]}}
删Delete
curl -XDELETE 'http://hdp-4:9200/search2/article2/1'
返回结果:
{"_index":"search2","_type":"article2","_id":"1","_version":3,"result":"deleted","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":2,"_primary_term":1}
再次查询一下:
curl -XGET 'http://hdp-4:9200/search2/article2/1'
返回结果:
{"_index":"search2","_type":"article2","_id":"1","found":false}
表示删除成功。
集群搭建
配置文件
vi /elasticsearch-6.3.1/config/elasticsearch.yml
#集群的名字
cluster.name: my-es
#节点名字
node.name: node-1
#es保存数据的路径
path.data: /home/grace/essourch/data
#es生成log信息的路径
path.logs: /home/grace/essourch/log
#当前机器的ip地址
network.host: 192.168.150.151
#大集群时指定的leader的候选者
discovery.zen.ping.unicast.hosts: ["hdp-1", "hdp-2","hdp-4"]
验证集群的健康值:
http://hdp-1:9200/_cluster/health?pretty
网页结果:
{
"cluster_name" : "my-es",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 3,
"number_of_data_nodes" : 3,
"active_primary_shards" : 0,
"active_shards" : 0,
"relocating_shards" : 0,
"initializing_shards" : 0,
"unassigned_shards" : 0,
"delayed_unassigned_shards" : 0,
"number_of_pending_tasks" : 0,
"number_of_in_flight_fetch" : 0,
"task_max_waiting_in_queue_millis" : 0,
"active_shards_percent_as_number" : 100.0
}
//"status" : "green", 表示集群状态健康
//"number_of_nodes" : 3, "number_of_data_nodes" : 3, 表示集群节点有三台
安装IK插件
1,下载方式:
(1)源码
https://github.com/medcl/elasticsearch-analysis-ik
(2)releases
https://github.com/medcl/elasticsearch-analysis-ik/releases
(3)复制zip地址
https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v6.3.1/elasticsearch-analysis-ik-6.3.1.zip
2,选择与自己elasticsearch版本一致的压缩包,本文使用elasticsearch-analysis-ik-6.3.1.zip
linux没有zip,yum在线安装zip
yum install -y unzip zip
创建文件夹
cd /root/apps/elasticsearch-6.3.1/plugins/
mkdir ik
解压文件
unzip elasticsearch-analysis-ik-6.3.1.zip -d /root/apps/elasticsearch-6.3.1/plugins/ik/
scp复制到集群上的其它机器
scp -r /root/apps/elasticsearch-6.3.1/plugins hdp-1:/root/apps/elasticsearch-6.3.1/