CentOS7搭建elasticsearch集群

时间:2024-08-27 18:34:56

准备三个节点,系统版本为CentOS7.3。

11.0.10.18 		es01
11.0.10.19 es02
11.0.10.20 es03

1、安装java环境

# yum install -y java java-1.8.0-openjdk-devel
# vim /etc/profile.d/java.sh
export JAVA_HOME=/usr
# source /etc/profile.d/java.sh

2、下载程序包

# wget https://download.elasticsearch.org/elasticsearch/release/org/elasticsearch/distribution/rpm/elasticsearch/2.0.0/elasticsearch-2.0.0.rpm

3、安装elasticsearch

# yum install -y ./elasticsearch-2.0.0.rpm

4、修改配置文件

# vim /etc/elasticsearch/elasticsearch.yml
cluster.name: che001-es
node.name: es03
network.host: 11.0.10.20
discovery.zen.ping.unicast.hosts: ["11.0.10.18", "11.0.10.19","11.0.10.20"]

5、启动服务

# systemctl start elasticsearch && systemctl enable elasticsearch
# netstat -tnlp # jps
41408 Jps
41328 Elasticsearch # jps -v
41328 Elasticsearch -Xms256m -Xmx1g -Djava.awt.headless=true -XX:+UseParNewGC -XX:+UseConcMarkSweepGC -XX:CMSInitiatingOccupancyFraction=75 -XX:+UseCMSInitiatingOccupancyOnly -XX:+HeapDumpOnOutOfMemoryError -XX:+DisableExplicitGC -Dfile.encoding=UTF-8 -Djna.nosys=true -Des.path.home=/usr/share/elasticsearch
41420 Jps -Dapplication.home=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.121-0.b13.el7_3.x86_64 -Xms8m

6、查看集群状态

# curl -XGET 'http://11.0.10.18:9200/_cluster/health?pretty=true'
{
"cluster_name" : "che001-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
}