Elasticsearch配置与使用
host | ip |
---|---|
node1 | 192.168.79.103 |
node2 | 192.168.79.101 |
1、配置node1
-
修改配置文件/etc/elasticsearch/elasticsearch.yml
[root@localhost elasticsearch]# grep -Ev "#|^$" elasticsearch.yml
cluster.name: myes
node.name: node1
path.data: /data/es-data
bootstrap.memory_lock: true
network.host: 192.168.79.103
http.port: 9200
注意:修改data目录和log目录后,需要给相应目录授权。(yum安装user为elasticsearch)
-
配置目录权限
chown -R elasticsearch.elasticsearch /data/es-data
-
启动
systemctl start elasticsearch
[root@localhost elasticsearch]# netstat -tnlp | grep 9200
tcp6 0 0 192.168.79.103:9200 :::* LISTEN 11271/java
-
head插件安装
/usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head
访问:
http://192.168.79.103:9200/_plugin/head/
-
kopf插件安装
/usr/share/elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf
访问:
http://192.168.79.103:9200/_plugin/kopf/
2、配置node2
-
修改配置文件
[root@node1 elasticsearch]# grep -Ev "#|^$" elasticsearch.yml
cluster.name: myes
node.name: node2
path.data: /data/es-data
bootstrap.memory_lock: true
network.host: 192.168.79.101
http.port: 9200
-
启动
systemctl start elasticsearch
[root@localhost elasticsearch]# netstat -tnlp | grep 9200
tcp6 0 0 192.168.79.103:9200 :::* LISTEN 11271/java
3、监控api
[root@localhost plugins]# curl -XGET 'http://192.168.79.103:9200/_cluster/health?pretty=true'
{
"cluster_name" : "myes",
"status" : "green",
"timed_out" : false,
"number_of_nodes" : 2,
"number_of_data_nodes" : 2,
"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
}
可监控其中的字段