首页 文章 精选 留言 我的

精选列表

搜索[elk],共1229篇文章
优秀的个人博客,低调大师

ELK-Logstash收集haproxy日志

场景需求 使用logstash收集haproxy的日志到Elasticsearch,并使用kibana对日志进行展示。由于 HAProxy的运行信息不写入日志文件,但它依赖于标准的系统日志协议将日志发送到远程服务器(通常位于同一系统上)。所以需要借助于使用rsyslog的方式来收集haproxy的日志. 环境说明 haproxy代理kibana的访问,使用logstash 收集kibana平台的访问信息。 node1: kibana Elasticsearch node2: haproxy logstash Elasticsearch 配置步骤 准备好node1和node2的环境,默认使用rpm包和yum安装。 在node2安装haproxy 在官网下载gz的压缩文件:http://www.haproxy.org/ 上传至服务器,解压编译: tar xf haproxy-1.8.1.tar.gz cd haproxy-1.8.1 安装依赖工具: [root@node2 haproxy-1.8.1]# yum install gcc pcre pcre-devel openssl openssl-devel -y 编译安装,需要在install的时候指定安装路径,否则会以默认路径安装: [root@node2 haproxy-1.8.1]# make TARGET=linux2628 USE_PCRE=1 USE_OPENSSL=1 USE_ZLIB=1 PREFIX=/usr/local/haproxy [root@node2 haproxy-1.8.1]# make install PREFIX=/usr/local/haproxy 确认安装版本: [root@node2 haproxy-1.8.1]# /usr/local/haproxy/sbin/haproxy -v HA-Proxy version 1.8.1 2017/12/03 Copyright 2000-2017 Willy Tarreau <willy@haproxy.org> 提示:使用haproxy 1.8.1版本编译时,不会生成haproxy-systemd-wrapper文件,而在1.7.9版本中可以生成,可以对1.7.9编译后拷贝出haproxy-systemd-wrapper添加到systemd文件中启动,使用haproxy命令作为systemd文件启动会报错。 使用systemd管理haproxy,编写systemd文件如下: [root@node2 haproxy-1.8.1]# cat /usr/lib/systemd/system/haproxy.service [Unit] Description=HAProxy Load Balancer After=syslog.target network.target [Service] EnvironmentFile=/etc/sysconfig/haproxy ExecStart=/usr/sbin/haproxy-systemd-wrapper -f /etc/haproxy/haproxy.cfg -p /run/haproxy.pid $OPTIONS ExecReload=/bin/kill -USR2 $MAINPID [Install] WantedBy=multi-user.target 将对应的命令复制到指定目录: [root@node2 ~]# cp /usr/local/haproxy/sbin/haproxy /usr/sbin/ 配置系统配置文件: [root@node2 ~]# vim /etc/sysconfig/haproxy # Add extra options to the haproxy daemon here. This can be useful for # specifying multiple configuration files with multiple -f options. # See haproxy(1) for a complete list of options. OPTIONS="" 创建主配置文件: [root@node2 ~]# mkdir /etc/haproxy [root@node2 ~]# vim /etc/haproxy/haproxy.cfg global maxconn 100000 chroot /usr/local/haproxy uid 1000 gid 1000 daemon nbproc 1 pidfile /usr/local/haproxy/run/haproxy.pid log 127.0.0.1 local6 info defaults option http-keep-alive option forwardfor maxconn 100000 mode http timeout connect 300000ms timeout client 300000ms timeout server 300000ms listen stats mode http bind 0.0.0.0:9999 stats enable log global stats uri /haproxy-status stats auth haadmin:123456 #frontend web_port frontend web_port bind 192.168.20.61:80 mode http log global default_backend kibana_web backend kibana_web mode http option httplog # balance source balance roundrobin server kibana-server 192.168.20.60:5601 check inter 2000 rise 3 fall 2 weight 1 创建用户: [root@node2 ~]# useradd haproxy.haproxy -M -s /sbin/nologin --gid 1000 --uid 1000 启动haproxy: [root@node2 ~]# systemctl daemon-reload [root@node2 ~]# systemctl start haproxy 配置rsyslog 记录haproxy日志 由于haproxy使用rsyslog记录日志,需要配置rsyslog将日志写到文件 对/etc/rsyslog.conf进行配置: vim /etc/rsyslog.conf # 打开15,16,19,20行注释 $ModLoad imudp $UDPServerRun 514 $ModLoad imtcp $InputTCPServerRun 514 文件末尾添加haproxy中配置的对应日志级别: local6.* /var/log/haproxy/haproxy.log # 日志记录文件 local6.* @@192.168.20.61:516 # 本地IP和监听端口 创建日志目录,并授权: [root@node2 ~]# mkdir /var/log/haproxy [root@node2 ~]# chown -R haproxy.haproxy /var/log/haproxy 重启rsyslog和haproxy: [root@node2 ~]# systemctl restart rsyslog [root@node2 ~]# systemctl restart haproxy 查看是否生成haproxy日志: [root@node2 ~]# tail -f /var/log/haproxy/haproxy.log Dec 18 19:12:12 localhost haproxy[6959]: Proxy stats started. Dec 18 19:12:12 localhost haproxy[6959]: Proxy web_port started. ... 查看使用haproxy是否能直接访问node1上的kibana. 提示: 使用haproxy不同主机代理Kibana需要将Kibana开启非本地监听状态。 配置logstash 在node2上安装好logstash,具体操作过程这里忽略。 配置logstash的conf文件: [root@node2 ~]# cat /etc/logstash/conf.d/haproxy_log.conf input { syslog{ type => "haproxy" port => "516" # 监听本地rsyslog端口 } } output{ stdout{ codec => "rubydebug" } } 测试文件,看是否能从rsyslog中直接接受日志到前台输出: [root@node2 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/haproxy_log.conf -t WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console Configuration OK 前台测试,访问haproxy: [root@node2 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/haproxy_log.conf -t WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console Configuration OK [root@node2 conf.d]# /usr/share/logstash/bin/logstash -f /etc/logstash/conf.d/haproxy_log.conf WARNING: Could not find logstash.yml which is typically located in $LS_HOME/config or /etc/logstash. You can specify the path using --path.settings. Continuing using the defaults Could not find log4j2 configuration at path /usr/share/logstash/config/log4j2.properties. Using default config which logs errors to the console { "severity" => 6, "pid" => "7271", "program" => "haproxy", "message" => "Connect from 192.168.20.3:54571 to 192.168.20.61:9999 (stats/HTTP)\n", "type" => "haproxy", "priority" => 182, "logsource" => "localhost", "@timestamp" => 2017-12-18T14:46:30.000Z, "@version" => "1", "host" => "192.168.20.61", "facility" => 22, "severity_label" => "Informational", "timestamp" => "Dec 18 22:46:30", "facility_label" => "local6" } { "severity" => 6, "pid" => "7271", "program" => "haproxy", "message" => "Connect from 192.168.20.3:54572 to 192.168.20.61:9999 (stats/HTTP)\n", "type" => "haproxy", "priority" => 182, "logsource" => "localhost", "@timestamp" => 2017-12-18T14:46:30.000Z, "@version" => "1", "host" => "192.168.20.61", "facility" => 22, "severity_label" => "Informational", "timestamp" => "Dec 18 22:46:30", "facility_label" => "local6" } 出现上面的日志,说明配置成功。 将输出到前台改为输出到Elaticsearch: [root@node2 ~]# cat /etc/logstash/conf.d/haproxy_log.conf input { syslog{ type => "haproxy" port => "6666" # 在使用后台启动logstash时,普通用户无法启动1024以内的端口,修改为大于1024的端口 } } output{ elasticsearch{ hosts => ["192.168.20.60:9200"] index => "haproxy-%{+YYYY.MM.dd}" } } 测试通过后重启logstash: [root@node2 conf.d]# systemctl restart logstash 修改rsyslog 日志输出端口也为6666: [root@node2 ~]# tail -2 /etc/rsyslog.conf local6.* /var/log/haproxy/haproxy.log local6.* @@192.168.20.61:6666 重启rsyslog: [root@node2 ~]# systemctl restart rsyslog 通过Elasticsearch的header插件,查看到日志已经写入: 在Kibana上添加haproxy日志 日志展示: 本文转自 酥心糖 51CTO博客,原文链接:http://blog.51cto.com/tryingstuff/2051930

优秀的个人博客,低调大师

ELK环境部署(已踩坑)

已踩的坑: 由于版本的不一致,安装marvel时会导致kibana界面报红, 还有启动kibana失败,提示端口在使用,(og [17:26:44.467] [fatal] Error: listen EADDRINUSE IP:5601) 然后 ps -ef|grep kibana ps -ef|grep 5601 netstat -antp|grep 5601, 找到或者找到杀不掉,最后 尝试 使用 fuser -n tcp 5601 kill -9 端口 成功!!! Logstash , Elasticsearch Kibana ,的下载地址统一为https://www.elastic.co/downloads/ 本次使用的软件版本分别为: 1. elasticsearch2.4.4.tar.gz 2. kibana-4.6.4-linux-x86_64.tar.gz 3. logstash-2.0.0.tar.gz 4. ik1.10.4 一:Logstash安装 第一步.解压到指定目录, 使用tar xvzf *.tar.gz -C “path” 第二步:进入到解压后的根目录,使用bin/plugin install “插件名” 安装对应插件, 常用插件如下: logstash-filter-date logstash-filter-grok logstash-input-file logstash-input-stdin logstash-output-elasticsearch logstash-output-redis logstash-output-stdout 安装失败可以多重试,(看人品..) 第三步:配置 *.conf 文件启动时使用,注意配置中的input的文件必须拥有足够的权限,不然就等着失败… 二:Elasticsearch的安装 第一步:同样解压, 第二步:进入解压后的根目录下的config文件中,修改配置elasticsearch.xml文件 主要修改一下几点: cluster.name:必须保持集群内的各个节点此名称的一致性。 node.name: 每个节点起一个(类似 node-1,node-2…..) network.host:(填写本机的ip即可,这样就可以在windows也可以访问) discovery.zen.ping.unicast.hosts:(将里面的hosts换成对应的集群中所有节点的ip) 第三步:在$ES_HOME/下执行 bin/plugin install mobz/elasticsearch-head (有了它,就可以访问对应的web界面) 网址类似:http://”Ip“:9200/_plugin/head/ 第三步:安装Marvel 分别在elasticsearch和kibana下安装 Step 1: Install Marvel into Elasticsearch: bin/plugin install license bin/plugin install marvel-agent Step 2: Install Marvel into Kibana bin/kibana plugin –install elasticsearch/marvel/latest Step 3: Start Elasticsearch and Kibana bin/elasticsearch bin/kibana 第四步:Kibana的安装 1.同样解压后,进入config目录,配置 kibana.yml文件 ,其中只需要修改elastic.url属性即可。 改成本机的ip。 访问网址:http://”IP“:5601/ 第五步:Ik分词器的安装: https://github.com/medcl/elasticsearch-analysis-ik下载 我们的版本 1.10.4。 下载后的压缩包解压后进去是pom工程 分别执行如下命令: mvn clean mvn compile mvn package 2.当然这里是用maven对此工程进行编译,前提要安装maven Maven安装也很简单,下载包以后解压缩,配置环境变量即可 3.前面编译了插件以后会在target/releases目录下出现一个zip包 4.然后在es的根目录下的plugins里面建一个ik目录,将上面的zip文件拷进去,并解压 5.重启es完成。

资源下载

更多资源
腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册