设为首页 收藏本站
查看: 2307|回复: 0

[经验分享] ELK+Filebeat+Nginx集中式日志解决方案(二)——添加ElasticSear...

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2017-3-24 16:47:34 | 显示全部楼层 |阅读模式
ELK+Filebeat+Nginx集中式日志解决方案(二)——添加ElasticSearch集群
一、使用说明:

Elasticsearch插件:

Elasticsearch常用的几个插件为:
1
2
3
4
5
6
7
8
9
10
11
# head
# 地址  https://github.com/mobz/elasticsearch-head
mobz/elasticsearch-head

# kopf
# 地址  https://github.com/lmenezes/elasticsearch-kopf
lmenezes/elasticsearch-kopf

# bigdesk
# 地址 https://github.com/hlstudio/bigdesk
hlstudio/bigdesk



因为依照第一篇文章,笔者是用的elasticsearch-5.2.2安装的,版本比较新,所以安装方法也不一样,下面会以elasticsearch-head为例,构建与elasticsearch的交互。

   Elasticsearch 集群:
Elasticsearch 启动时会根据配置文件中设置的集群名字(cluster.name)自动查找并加入集群。Elasctisearch 节点默认使用 9300 端口寻找集群,所以必须开启这个端口。

一个 Elasticsearch 集群中一般拥有三种角色的节点,master、data 和 client。
  • master:master 节点负责一些轻量级的集群操作,比如创建、删除数据索引、跟踪记录集群中节点的状态、决定数据分片(shards)在 data 节点之间的分布;
  • data:data 节点上保存了数据分片。它负责数据相关操作,比如分片的 CRUD,以及搜索和整合操作。这些操作都比较消耗 CPU、内存和 I/O 资源;
  • client:client 节点起到路由请求的作用,实际上可以看做负载均衡器。


配置文件中有两个与集群相关的配置:
  • node.master:默认 true。True 表示该节点是 master 节点;
  • node.data:默认 true。True 表示该节点时 data 节点。如果两个值都为 false,表示是 client 节点。


一个集群中不一定有 client 节点,但是肯定有 master 和 data 节点。默认第一个启动的节点是 master。Master 节点也能起到路由请求和搜索结果整合的作用,所以在小规模的集群中,无需 client 节点。但是如果集群规模很大,则有必要设置专门的 client。

二、实验环境


架构图:
iyunv.com-2017-3-24105.png

6台服务器(centos 6.5 final版本):
1
2
3
4
5
6
192.168.1.194 (filebeat收集日志,nginx做为web服务器)
192.168.1.195 (filebeat收集日志,nginx做为web服务器)
192.168.1.196 (logstash)
192.168.1.198(elasticsearch master,kibana,nginx做方向代理)
192.168.1.200 (elasticsearch DataNode)
192.168.1.201 (elasticsearch DataNode)




使用版本:
1
2
3
4
5
6
java-1.8.0-openjdk
filebeat-5.2.2
logstash-5.2.2
elasticsearch-5.2.2
kibana-5.2.2
nginx-1.6.1





三、安装配置:

此次实验是在第一篇文章的基础上,不熟悉的可以先看一下第一篇文章《ELK+Filebeat+Nginx集中式日志解决方案(一)》。


安装插件:

先在192.168.1.198上安装elasticsearch-head插件,对于Elasticsearch 5.x不在支持head插件模式,只能已独立服务模式启动,具体方式如下:

1
2
3
4
5
6
7
cd /usr/local/
yum install -y git npm
git clone git://github.com/mobz/elasticsearch-head.git
cd elasticsearch-head
npm install
npm install -g grunt-cli
nohup grunt server &




通过浏览器访问http://192.168.1.198:9100/可以访问elasticsearch-head服务。可以看到head提供的页面,但是连接不上elasticsearch.需要在elasticsearch5.2.2的配置里增加一下参数:
1
2
http.cors.enabled: true
http.cors.allow-origin: "*"




重启elasticsearch后,刷新elasticsearch-head的页面(http://192.168.1.198:9100/),发现链接正常了。界面如下:
iyunv.com-2017-3-24106.png
ok,至此安装elasticsearch-head插件结束。


安装集群:

先在192.168.1.200和192.168.1.201上安装好elasticsearch环境,可以参照《ELK+Filebeat+Nginx集中式日志解决方案(一)》。


在192.168.1.198(master)上面配置elasticsearch.yml
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
#---------------------------------- Cluster -----------------------------------
# Use a descriptive name for your cluster:

cluster.name: myesdata

# ------------------------------------ Node ------------------------------------
node.name: server198
node.master: true
node.data: false

# ----------------------------------- Paths ------------------------------------
path.data: /home/data/elk      
path.logs: /var/log/elasticsearch/elasticsearchlog

# ----------------------------------- Memory -----------------------------------
#bootstrap.mlockall: true
indices.fielddata.cache.size: 50mb

#------------------------------------ Network And HTTP --------------------------
network.host: 0.0.0.0
http.port: 9200


# --------------------------------- Discovery ------------------------------------
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping_timeout: 200s
discovery.zen.fd.ping_timeout: 200s
discovery.zen.fd.ping_interval: 30s
discovery.zen.fd.ping_retries: 6
discovery.zen.ping.unicast.hosts: ["192.168.1.198:9300","192.168.1.200:9300","192.168.1.201:9300",]

# --------------------------------- merge ------------------------------------------
indices.store.throttle.max_bytes_per_sec: 100mb

bootstrap.system_call_filter: false
http.cors.enabled: true
http.cors.allow-origin: "*"




在192.168.1.200(DataNode)上面配置elasticsearch.yml
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
#---------------------------------- Cluster -----------------------------------
# Use a descriptive name for your cluster:

cluster.name: myesdata

# ------------------------------------ Node ------------------------------------
node.name: server200
node.master: false
node.data: true

# ----------------------------------- Paths ------------------------------------
path.data: /home/data/elk   
path.logs: /var/log/elasticsearch/elasticsearchlog

# ----------------------------------- Memory -----------------------------------
#bootstrap.mlockall: true
indices.fielddata.cache.size: 50mb

#------------------------------------ Network And HTTP --------------------------
network.host: 0.0.0.0
http.port: 9200

# ------------------------------------ Translog ----------------------------------
#index.translog.flush_threshold_ops: 50000

# --------------------------------- Discovery ------------------------------------
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping_timeout: 200s
discovery.zen.fd.ping_timeout: 200s
discovery.zen.fd.ping_interval: 30s
discovery.zen.fd.ping_retries: 6
discovery.zen.ping.unicast.hosts: ["192.168.1.198:9300",]
#discovery.zen.ping.multicast.enabled: false

# --------------------------------- merge ------------------------------------------
indices.store.throttle.max_bytes_per_sec: 100mb


bootstrap.system_call_filter: false





在192.168.1.201(DataNode)上面配置elasticsearch.yml
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
#---------------------------------- Cluster -----------------------------------
# Use a descriptive name for your cluster:

cluster.name: myesdata

# ------------------------------------ Node ------------------------------------
node.name: server201
node.master: false
node.data: true

# ----------------------------------- Paths ------------------------------------
path.data: /home/data/elk   
path.logs: /var/log/elasticsearch/elasticsearchlog

# ----------------------------------- Memory -----------------------------------
#bootstrap.mlockall: true
indices.fielddata.cache.size: 50mb

#------------------------------------ Network And HTTP --------------------------
network.host: 0.0.0.0
http.port: 9200

# ------------------------------------ Translog ----------------------------------
#index.translog.flush_threshold_ops: 50000

# --------------------------------- Discovery ------------------------------------
discovery.zen.minimum_master_nodes: 1
discovery.zen.ping_timeout: 200s
discovery.zen.fd.ping_timeout: 200s
discovery.zen.fd.ping_interval: 30s
discovery.zen.fd.ping_retries: 6
discovery.zen.ping.unicast.hosts: ["192.168.1.198:9300",]
#discovery.zen.ping.multicast.enabled: false

# --------------------------------- merge ------------------------------------------
indices.store.throttle.max_bytes_per_sec: 100mb


bootstrap.system_call_filter: false




在192.168.1.198,192.168.1.200,192.168.1.201上面分别执行
1
2
3
4
mkdir -p /home/data/elk/
mkdir -p /var/log/elasticsearch/elasticsearchlog/
chown elasticsearch. -R /home/data/elk/
chown elasticsearch. -R /var/log/elasticsearch/elasticsearchlog/




然后先启动master,在分别启动DataNode
1
service elasticsearch start





浏览器访问http://192.168.1.198:9100/ ,查看集群是否正常:
iyunv.com-2017-3-24107.png

ok,elasticsearch集群到这里就配置成功了,接下来需要做的就是修改logstash的配置:
1
2
3
4
5
6
7
8
output {
    elasticsearch {
        hosts => ["192.168.1.200:9200","192.168.1.201:9200"]
        index => "logstash-%{type}-%{+YYYY.MM.dd}"
        document_type => "%{type}"
    }
    #stdout { codec => rubydebug }
}




只需要把原来的
1
hosts => ["192.168.1.198:9200"]



这里改成
1
hosts => ["192.168.1.200:9200","192.168.1.201:9200"]



输出到elasticsearch集群的两个DataNode节点就ok了
然后启动logstash:
1
nohup logstash -r -f /etc/logstash/conf.d/nginx-test.conf --path.settings /etc/logstash &



加上-r选项比较好,可以自动观测logstash配置文件的变化,自动重载配置。

然后此时查看kibana就会有数据输出了。


然后浏览器再访问http://192.168.1.198:9100/ ,查看一下状态:
iyunv.com-2017-3-24108.png
会发现状态跟之前没数据时不一样了。

ok,到这里elasticsearch集群就加上去了。欢迎关注后续文章......


运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-354747-1-1.html 上篇帖子: elasticsearch-jdbc 例子 下篇帖子: ELK+Filebeat+Nginx集中式日志解决方案(一) 解决方案
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表