1 环境准备:
- 复制原有es文件,分别为三个文件夹:Node-8001,Node-8002,Node-8003
- 删除三个文件夹中的data文件,清除log文件
- 修改配置文件
1.1修改配置文件
配置文件路径es/config/elasticsearch.yml
Node-8001文件详情:
# 集群名称
cluster.name: my-application
# 节点名称
node.name: node-8001
# master节点
node.master: true
# 是否是数据节点
node.data: true
# 主机名称
network.host: localhost
# http端口
http.port: 8001
# tcp监听端口
transport.tcp.port: 9301
# 跨域配置
http.cors.enabled: true
http.cors.allow-origin: “*”
Node-8002文件详情:
# 集群名称
cluster.name: my-application
# 节点名称
node.name: node-8002
# master节点
node.master: true
# 是否是数据节点
node.data: true
# 主机名称
network.host: localhost
# http端口
http.port: 8002
# tcp监听端口
transport.tcp.port: 9302
#寻找master节点(不同于8001的地方)
discovery.seed_hosts: [“localhost:9301”]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
# 跨域配置
http.cors.enabled: true
http.cors.allow-origin: “*”
Node-8003文件详情:
# 集群名称
cluster.name: my-application
# 节点名称
node.name: node-8003
# master节点
node.master: true
# 是否是数据节点
node.data: true
# 主机名称
network.host: localhost
# http端口
http.port: 8003
# tcp监听端口
transport.tcp.port: 9303
#寻找master节点(不同于8002的地方)
discovery.seed_hosts: [“localhost:9301”,“localhost:9302”]
discovery.zen.fd.ping_timeout: 1m
discovery.zen.fd.ping_retries: 5
# 跨域配置
http.cors.enabled: true
http.cors.allow-origin: “*”
2 启动
文件配置好后,分别在bin目录下启动:./elasticsearch
查看节点启动情况:
方式 | 路径 |
---|---|
GET | http://localhost:8001/_cluster/health |
result:
{
"cluster_name":“my-application”,
"status":“green”,
"timed_out":false,
"number_of_nodes":3,
"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
}
3 常见启动报错
- 现象一
BindHttpException[Failed to bind to 127.0.0.1:1001]; nested: SocketException[Permission denied];
原因:
Linux不允许普通用户绑定到<= 1024 的端口,因为设置的端口号是1001,因此它失败了“权限被拒绝”。
mac的内核使用的是Linux,windows电脑不会有这个问题
解决:
最快和最安全的解决方案是使用大于1024的值配置端口,所以我改成了8001.
- 现象二
java.lang.IllegalStateException: failed to obtain node locks, tried [[/usr/local/opt/elasticsearch/data]] with lock id [0]; maybe these locations are not writable or multiple nodes were started without increasing [node.max_local_storage_nodes] (was [1])
原因:
后台已经存在相同的elasticsearch的进程端口号。
解决:
找到该进程 ps -ef | grep elasticsearch
杀掉该进程即可 kill -9 NNN