[英]How to collect log from different servers to a central server(Elastic search and kibana)
I am assigned with task to create a central logging server.我被分配了创建中央日志服务器的任务。 In my case there are many web app servers spread across.
就我而言,分布着许多 Web 应用程序服务器。 My task is to get logs from these different servers and manage in central server where there will be
elastic-search
and kibana
.我的任务是从这些不同的服务器获取日志并在将有
elastic-search
和kibana
中央服务器中进行管理。
Question题
Things seen看到的东西
Looking for way to send logs over public IP to elastic-search.寻找通过公共 IP 将日志发送到弹性搜索的方法。
I would like to differ from the Ishara's Answer.我想与 Ishara 的回答不同。 You can ship logs directly from filebeat to elasticsearch without using logstash, If your logs are generic types(system logs, nginx logs, apache logs), Using this approach You don't need to go into incur extra cost and maintenance of logstash as filebeat provides inbuilt parsing processor.
您可以将日志直接从 filebeat 发送到 elasticsearch,而无需使用 logstash,如果您的日志是通用类型(系统日志、nginx 日志、apache 日志),则使用这种方法您不需要花费额外的成本和维护日志作为 filebeat提供内置的解析处理器。
If you have debian based OS on your server, I have prepared a shell script to install and configure filebeat.如果你的服务器上有基于 debian 的操作系统,我已经准备了一个 shell 脚本来安装和配置 filebeat。 You need to change elasticsearch server URL and modify second last line based on the modules that you want to configure.
您需要根据要配置的模块更改 elasticsearch 服务器 URL 并修改倒数第二行。
Regarding your first question, Yes, You can run filebeat agent on each server and send data to centralize Elasticsearch.关于您的第一个问题,是的,您可以在每个服务器上运行 filebeat 代理并发送数据以集中 Elasticsearch。 For your second question, It depends on the amount of logs elasticsearch server is going to process and store.
对于您的第二个问题,这取决于弹性搜索服务器将要处理和存储的日志量。 It also depends on the where kibana is hosted.
它还取决于 kibana 的托管位置。
sudo wget -qO - https://artifacts.elastic.co/GPG-KEY-elasticsearch | sudo apt-key add -
sudo echo "deb https://artifacts.elastic.co/packages/7.x/apt stable main" | sudo tee -a /etc/apt/sources.list.d/elastic-7.x.list
sudo apt-get update && sudo apt-get install -y filebeat
sudo systemctl enable filebeat
sudo bash -c "cat >/etc/filebeat/filebeat.yml" <<FBEOL
filebeat.inputs:
filebeat.config.modules:
path: ${path.config}/modules.d/*.yml
reload.enabled: false
setup.template.name: "filebeat-system"
setup.template.pattern: "filebeat-system-*"
setup.template.settings:
index.number_of_shards: 1
setup.ilm.enabled: false
setup.kibana:
output.elasticsearch:
hosts: ["10.32.66.55:9200", "10.32.67.152:9200", "10.32.66.243:9200"]
indices:
- index: "filebeat-system-%{+yyyy.MM.dd}"
when.equals:
event.module: system
processors:
- add_host_metadata: ~
- add_cloud_metadata: ~
- add_docker_metadata: ~
- add_kubernetes_metadata: ~
logging.level: warning
FBEOL
sudo filebeat modules enable system
sudo systemctl restart filebeat
Yes, it is possible to get logs from servers that are having different public IP.是的,可以从具有不同公共 IP 的服务器获取日志。 You need to setup an agent like filebeat (provided by elastic) to each server which produce logs.
您需要为每个生成日志的服务器设置一个像filebeat (由 elastic 提供)这样的代理。
It will listen to your log files in each machine and forward them to the logstash instance you would mention in filebeat.yml
configuration file like below:它会在每台机器上监听你的日志文件,并将它们转发到你在
filebeat.yml
配置文件中提到的 logstash 实例,如下所示:
#=========================== Filebeat inputs =============================
filebeat.inputs:
- type: log
# Change to true to enable this input configuration.
enabled: true
# Paths that should be crawled and fetched. Glob based paths.
paths:
- /path_to_your_log_1/ELK/your_log1.log
- /path_to_your_log_2/ELK/your_log2.log
#----------------------------- Logstash output --------------------------------
output.logstash:
# The Logstash hosts
hosts: ["private_ip_of_logstash_server:5044"]
Logstash server listens to port 5044 and stream all logs through logstash configuration files: Logstash 服务器侦听端口 5044 并通过 logstash 配置文件流式传输所有日志:
input { beats { port => 5044 } } filter { # your log filtering logic is here } output { elasticsearch { hosts => [ "elasticcsearch_server_private_ip:9200" ] index => "your_idex_name" } }
In logstash you can filter and split your logs into fields and send them to elasticsearch.在 logstash 中,您可以过滤日志并将其拆分为字段并将它们发送到 elasticsearch。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.