惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
D
DataBreaches.Net
Microsoft Security Blog
Microsoft Security Blog
U
Unit 42
V
Visual Studio Blog
GbyAI
GbyAI
云风的 BLOG
云风的 BLOG
博客园 - Franky
C
CXSECURITY Database RSS Feed - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
P
Privacy & Cybersecurity Law Blog
T
The Exploit Database - CXSecurity.com
Simon Willison's Weblog
Simon Willison's Weblog
L
LangChain Blog
I
Intezer
V2EX - 技术
V2EX - 技术
Google DeepMind News
Google DeepMind News
T
Threat Research - Cisco Blogs
Apple Machine Learning Research
Apple Machine Learning Research
V
V2EX
腾讯CDC
博客园 - 【当耐特】
Know Your Adversary
Know Your Adversary
TaoSecurity Blog
TaoSecurity Blog
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
F
Fortinet All Blogs
Project Zero
Project Zero
Blog — PlanetScale
Blog — PlanetScale
S
Security @ Cisco Blogs
量子位
M
MIT News - Artificial intelligence
美团技术团队
C
Cisco Blogs
S
Schneier on Security
Recent Commits to openclaw:main
Recent Commits to openclaw:main
G
Google Developers Blog
N
News and Events Feed by Topic
MongoDB | Blog
MongoDB | Blog
The Hacker News
The Hacker News
H
Help Net Security
S
Secure Thoughts
Scott Helme
Scott Helme
SecWiki News
SecWiki News
T
Troy Hunt's Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
博客园 - 叶小钗
O
OpenAI News
Application and Cybersecurity Blog
Application and Cybersecurity Blog
博客园 - 司徒正美
T
Tenable Blog

博客园 - linwinfan

ZABBIX新功能系列2-通过Webhook调用虚拟化API重启故障主机 ZABBIX新功能系列1-使用Webhook将告警主动推送至第三方系统 xenserver添加静态路由 redmine常见问题 Opennms 问题整理 OpenERP 使用与开发笔记(一) KEEPALIVED 双机自动切换部署备忘 迁移 VMware 虚拟机到 KVM 安装设置squid3代理更新 iscsiadm基本用法 第4章.计算节点 第三章.可扩展性 第二章 云控制器设计 OpenStack实施管理手册-第一章 部署准备 VMware workstation to exsi openQRM在CENTOS64上的安装部署 在服务器上排除问题的头五分钟(转) u960s指令 某程序反向工程记录
使用flume-ng聚合双活Nginx日志
linwinfan · 2013-08-21 · via 博客园 - linwinfan

前不久使用Keepalived搭建了Nginx双活代理服务器,以达到一个公网IP后支持多个云主机的多个域名网站的目的。完成后又想在这双活的Nginx上有所有访问网站的日志,之前有了解过Google Analytics, 及一些日志分析系统。后来终于找到并部署了几个开源的分析系统,包括AWStats,JAWStats及Piwik。使用它发现有一个问题比较烦,就是如何将2个Nginx的日志发送到分析服务器后合并分析。

一、需求

     合并多台服务器同一域名网站的访问日志后,定时导入网站分析系统,生成网站分析数据。

二、技术方案

     前后想了很多方法,包括自已写脚本加入Cron定时发送到分析服务器,Fluentd日志收集系统等许多方法,最终选定使用flume-ng完成该了该任务,相对其它来说我觉得他应是安装配置最简单的一种方法。

     1.在分析服务器上安装flume-ng,用以日志收集。首先安装JDK(完成后记住配置JAVA_HOME等环境变量).下载flume-ng最新版后解压后即可使用。使用前添加收集服务器配置,示例如下:

collector1.sources = AvroIn
collector1.sources.AvroIn.type = avro
collector1.sources.AvroIn.bind = 0.0.0.0
collector1.sources.AvroIn.port = 4545
collector1.sources.AvroIn.channels = mc1

collector1.channels = mc1
collector1.channels.mc1.type = memory
collector1.channels.mc1.capacity = 100

collector1.sinks = LocalOut

collector1.sinks.LocalOut.type = file_roll
collector1.sinks.LocalOut.sink.directory = /var/log/flume/collector1
collector1.sinks.LocalOut.sink.rollInterval = 0
collector1.sinks.LocalOut.channel = mc1

View Code

    完成后运行:

bin/flume-ng agent -c conf  -f /etc/flume/conf/collector1.conf -n collector1

View Code

   完成后即系统即会在端口4545收集日志数据,写入指定的目录文件中。

    2.在Nginx服务器同1中安装好JDK并解压flume-ng后,同样新建一Nginx日志发送配置,示例如下:

agent1.sources = ngrinder
agent1.sources.ngrinder.type = exec 
agent1.sources.ngrinder.command = tail -F /var/log/nginx/otrs/access.log
agent1.sources.ngrinder.channels = mc1

agent1.channels = mc1
agent1.channels.mc1.type = memory
agent1.channels.mc1.capacity = 100

agent1.sinks = avro-sink

agent1.sinks.avro-sink.type = avro
agent1.sinks.avro-sink.channel = mc1
agent1.sinks.avro-sink.hostname = 172.22.2.203
agent1.sinks.avro-sink.port = 4545

View Code

    3.启动收集日志。

bin/flume-ng agent -c conf -f /etc/flume/conf/agent1.conf -n agent1

View Code

    完成后,访问你要收集网站访问日志的网站,然后到收集服务器上,到配置好的日志收集目录,您将可以看到相关日志。

     4.将收集到的日志定时给AWStats分析,以完成网站访问分析。运行:crontab -e添加:

0 1 * * * /usr/local/awstats/wwwroot/cgi-bin/awstats.pl -update -config=www.xxxxx.com

View Code

     使每天凌晨1点分析日志。