准备三个节点,系统版本为CentOS7.3。
11.0.10.18 es0111.0.10.19 es0211.0.10.20 es03
1、安装java环境
# yum install -y java java-1.8.0-openjdk-devel# vim /etc/profile.d/java.shexport 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.ymlcluster.name: che001-esnode.name: es03network.host: 11.0.10.20discovery.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# jps41408 Jps41328 Elasticsearch# jps -v41328 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/elasticsearch41420 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}
CentOS 7 安装 Elasticsearch5.2.2 的 Head 插件
一、安装nodejs
curl -sL -o /etc/yum.repos.d/khara-nodejs.repo https://copr.fedoraproject.org/coprs/khara/nodejs/repo/epel-7/khara-nodejs-epel-7.repo
yum install -y nodejs nodejs-npm
二、安装grunt
npm install grunt-cli
npm install grunt -g
grunt -version
三、安装head
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
vim _site/app.js
# 修改 『http://localhost:9200』字段到本机ES端口与IP
grunt server
# 打开浏览器 http://localhost:9100
在浏览器访问haed
默认地址:http://127.0.0.1:9100/
到这里haed就已经启动成功了
但是现在发现:集群健康值: 未连接
因为elasticsearch5之后对对其安全性进行了加强
这里需要修改elasticsearch-5.2.0\config\elasticsearch.yml文件
在文件elasticsearch.yml中添加配置如下:
#避免出现跨域问题
http.cors.enabled: true
http.cors.allow-origin: "*"
注意:配置中冒号后面需要有一个空格!!
然后重启elasticsearch
再次访问:http://127.0.0.1:9100/
这里head就已经连上elasticsearch了
淘宝源
npm install -g cnpm --registry=https://registry.npm.taobao.org
后台启动
进入到插件目录启动
grunt server &
三、基于5.4的多机集群配置
ELasticsearch 5.4要求JDK版本最低为1.8,由于服务器上的JDK版本为1.7并且Java环境变量写在/etc/profile里面,改JDK会影响其他程序,这次基于5.4在我的mac和另外一台Ubuntu 做测试。
mac上的本机ip为192.168.1.111,设为master节点,配置如下:
cluster.name: my-applicationnode.name: node-111network.host: 192.168.1.111http.port: 9200http.cors.enabled: truehttp.cors.allow-origin: "*"node.master: truenode.data: truediscovery.zen.ping.unicast.hosts: ["192.168.1.111"]
Ubuntu机器的ip位192.168.1.102,配置如下:
cluster.name: my-applicationnode.name: node-102network.host: 192.168.1.102http.port: 9200http.cors.enabled: truehttp.cors.allow-origin: "*"node.master: falsenode.data: truediscovery.zen.ping.unicast.hosts: ["192.168.1.111"]
先启动mac上的master,再启动Ubuntu上的slave节点,观察输出,会有一个node-102探测到master节点的提示:
2017-06-07T11:33:39,369][INFO ][o.e.c.s.ClusterService ] [node-102] detected_master {node-111}{3dQd1RRVTMiKdTckM68nPQ}{H6Zu7PAQRWewUBcllsQWTQ}{192.168.1.111}{192.168.1.111:9300}, added {{node-111}{3dQd1RRVTMiKdTckM68nPQ}{H6Zu7PAQRWewUBcllsQWTQ}{192.168.1.111}{192.168.1.111:9300},}, reason: zen-disco-receive(from master [master {node-111}{3dQd1RRVTMiKdTckM68nPQ}{H6Zu7PAQRWewUBcllsQWTQ}{192.168.1.111}{192.168.1.111:9300} committed version [8]])'
访问head,一个master一个slave组成集群,界面如下:
四、基于5.4的单机多节点集群配置
如果想要在一台机器上启动多个节点,步骤如下:
建议或者问题欢迎留言。
配置文件:
cluster.name: my-application
node.name: node-82
network.host: 172.1.1.82
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["172.1.1.83"]
cluster.name: my-application
node.name: node-83
配置文件
network.host: 172.1.1.83
http.port: 9200
http.cors.enabled: true
http.cors.allow-origin: "*"
node.master: true
node.data: true
discovery.zen.ping.unicast.hosts: ["172.1.1.82"]