CentOS7下Elasticsearch集群部署记录

Elasticsearch是一个分布式搜索服务,提供Restful API,底层基于Lucene,采用多shard的方式保证数据安全,并且提供自动resharding的功能,github等大型的站点也都采用Elasticsearch作为其搜索服务。废话在此就不多赘述了,下面记录下CentOS7下Elasticsearch集群部署过程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
之前在三台服务器部署Elasticsearch集群:
qd-vpc- op -es01    101.119.92.247
qd-vpc- op -es02    101.119.92.249
qd-vpc- op -es03    101.119.92.254
 
下面再追加一台es04机器到集群中,操作如下:
qd-vpc- op -es04    101.119.92.16
 
1)安装jdk和elasticsearch
jdk-8u5-linux-x64.rpm下载地址:
https: //pan .baidu.com /s/1bpxtX5X       (提取密码:df6s)
 
elasticsearch-5.5.0.rpm下载地址:
https: //pan .baidu.com /s/1mibwWeG      (提取密码:vtm2)
 
[root@qd-vpc- op -es04 ~] # cd tools/
[root@qd-vpc- op -es04 tools] # ls
elasticsearch-5.5.0.rpm  jdk-8u5-linux-x64.rpm
[root@qd-vpc- op -es04 tools] # rpm -ivh elasticsearch-5.5.0.rpm
[root@qd-vpc- op -es04 tools] # rpm -ivh jdk-8u5-linux-x64.rpm
[root@qd-vpc- op -es04 tools] # java -version
java version  "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
 
2)配置elasticsearch
[root@qd-vpc- op -es04 ~] # cd /etc/elasticsearch/
[root@qd-vpc- op -es04 elasticsearch] # ls
elasticsearch.yml  elasticsearch.yml.bak  jvm.options  log4j2.properties   nohup .out  scripts
 
[root@qd-vpc- op -es04 elasticsearch] # cat elasticsearch.yml|grep -v "#"           //集群中每个节点的配置内容都基本一致
 
cluster.name: image_search                                                        // 集群名称
node.name: image_search_node_4                                                    // 集群中本节点的节点名称,这里定义即可
path.data:  /data/es/data                                                          // 服务目录路径
path.logs:  /data/es/logs                                                          // 服务日志路径
discovery.zen. ping .unicast.hosts: [ "101.119.92.247" , "101.119.92.249" , "101.119.92.254" , "10.111.233.16" ]      // 这里是各节点的ip地址
network.host: 0.0.0.0                                                             // 服务绑定的网络地址
 
默认elasticsearch服务端口时9200
[root@qd-vpc- op -es04 elasticsearch] # cat elasticsearch.yml|grep 9200
#http.port: 9200
 
[root@qd-vpc- op -es04 elasticsearch] # systemctl start elasticsearch.service
[root@qd-vpc- op -es04 elasticsearch] # systemctl restart elasticsearch.service
[root@qd-vpc- op -es04 elasticsearch] # systemctl status elasticsearch.service
 
[root@qd-vpc- op -es04 elasticsearch] # ps -ef|grep elasticsearch
[root@qd-vpc- op -es04 elasticsearch] # lsof -i:9200
COMMAND   PID          USER   FD   TYPE DEVICE SIZE /OFF  NODE NAME
java    10998 elasticsearch  320u  IPv4  39255      0t0  TCP *:wap-wsp (LISTEN)
 
检查elasticsearch的健康状态
[root@qd-vpc- op -es04 elasticsearch] # curl 'localhost:9200/_cat/indices?v'
health status index                   uuid                   pri rep docs.count docs.deleted store.size pri.store.size
green   open    video_filter            Bx7He6ZtTEWuRBqXYC6gRw   5   1     458013            0      4.1gb            2gb
green   open    recommend_history_image svYo_Do4SM6wUiv6taUWug   5   1    2865902            0     24.9gb         12.4gb
green   open    recommend_history_gif   rhN3MDN2TbuYILqEDksQSg   5   1     265731            0      2.4gb          1.2gb
green   open    post_images             TMsMsMEoR5Sdb7UEQJsR5Q   5   1   48724932            0    407.3gb        203.9gb
green   open    review_images_v2        qzqnknpgTniU4rCsvXzs0w   5   1   50375955            0     61.6gb         30.9gb
green   open    review_images           rWC4WlfMS8aGe-GOkTauZg   5   1   51810877            0    439.3gb        219.7gb
green   open    sensitive_images        KxSrjvXdSz-y8YcqwBMsZA   5   1      13393            0    128.1mb           64mb
green   open    post_images_v2          FDphBV4-QuKVoD4_G3vRtA   5   1   49340491            0     55.8gb         27.8gb
 
从上面的命令结果中可以看出,本节点已经成功加入到名为image_search的elasticsearch集群中了,green表示节点状态很健康,数据也已经在同步中了。
 
3)在代码中更新elasticsearch的配置
通知开发同事,在代码中增加新增elasticsearch节点的配置,上线更新后,到新节点上查看elasticsearch日志是否有信息写入:
[root@qd-vpc- op -es04 ~] # cd /data/es/logs/
[root@qd-vpc- op -es04 ~] # chown -R elasticsearch.elasticsearch /data/es
[root@qd-vpc- op -es04 logs] # ls
image_search_deprecation.log  image_search_index_indexing_slowlog.log  image_search_index_search_slowlog.log  image_search.log
 
----------------------------------------------------------------------------------------------------------------
注意:
如果往elasticsearch集群中新增一个节点,做法如下:
1)在新节点上安装jdk和elasticsearch服务,配置elasticsearch.yml文件了,启动elasticsearch服务
2)在集群中其他节点上配置elasticsearch.yml文件,不需要启动elasticsearch服务
3)在新节点上执行curl  'localhost:9200/_cat/indices?v' 命令,查看健康状态以及数据同步情况
4)在代码中增加新增elasticsearch节点的配置,上线更新后,查看新增节点的elasticsearch日志是否有信息写入
----------------------------------------------------------------------------------------------------------------
最后顺便贴一下其他三个节点的elasticsearch.yml文件配置:
[root@qd-vpc- op -es01 ~] # cat /etc/elasticsearch/elasticsearch.yml |grep -v "#"
 
cluster.name: image_search
node.name: image_search_node_1
path.data:  /data/es/data
path.logs:  /data/es/logs
discovery.zen. ping .unicast.hosts: [ "10.111.233.16" , "101.119.92.247" , "101.119.92.249" , "101.119.92.254" ]
network.host: 0.0.0.0
 
[root@qd-vpc- op -es02 ~] # cat /etc/elasticsearch/elasticsearch.yml |grep -v "#"
cluster.name: image_search
node.name: image_search_node_2
path.data:  /data/es/data
path.logs:  /data/es/logs
discovery.zen. ping .unicast.hosts: [ "10.111.233.16" , "101.119.92.247" , "101.119.92.249" , "101.119.92.254" ]
network.host: 0.0.0.0
 
[root@qd-vpc- op -es03 ~] # cat /etc/elasticsearch/elasticsearch.yml|grep -v "#"
 
cluster.name: image_search
node.name: image_search_node_3
path.data:  /data/es/data
path.logs:  /data/es/logs
discovery.zen. ping .unicast.hosts: [ "101.119.92.247" , "101.119.92.249" , "101.119.92.254" , "10.111.233.16" ]
network.host: 0.0.0.0
----------------------------------------------------------------------------------------------------------------
 
如果关闭某个节点或将其从集群中提出来,需要提前通知该节点停止同步数据(迁移的时候会用到):
# curl -XPUT 'localhost:9200/_cluster/settings' -d '{"transient" : {"cluster.routing.allocation.enable" : "none”}}’
***************当你发现自己的才华撑不起野心时,就请安静下来学习吧***************

本文转自散尽浮华博客园博客,原文链接:http://www.cnblogs.com/kevingrace/p/7693422.html,如需转载请自行联系原作者


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值