(на которую будут приходить логи с нод-машин)
https://gist.github.com/elvisgiv/cf83570c79da80bec326d2bdd454980d
https://gist.github.com/elvisgiv/e32d1c043df4e38594c6bbd10044548d
(from: http://itc-life.ru/fluentd-bystryj-poisk-logov-s-elasticsearch-kibana-and-fluentd
)
(from: http://www.fluentd.org/guides/recipes/elasticsearch-and-s3
)
$ `curl -L http://toolbelt.treasuredata.com/sh/install-ubuntu-precise-td-agent2.sh | sh`
Next, install the Elasticsearch plugin (to store data into Elasticsearch) and the secure-forward plugin (for secure communication with the node server)
$ `sudo /usr/sbin/td-agent-gem install fluent-plugin-secure-forward`
$ `sudo /usr/sbin/td-agent-gem install fluent-plugin-elasticsearch`
$ `sudo nano /etc/td-agent/td-agent.conf`
```ruby
# Listen to incoming data over SSL
<source>
type forward
shared_key 911
self_hostname 51.1.0.15
cert_auto_generate yes
</source>
# Store Data in Elasticsearch
<match *.**>
type copy
<store>
type elasticsearch
host localhost
port 9200
include_tag_key true
tag_key @log_name
logstash_format true
flush_interval 10s
</store>
</match>
```
$ `sudo service td-agent restart`
$ `systemctl status td-agent.service`
$ `journalctl -xe`
$ `sudo apt-get install iptables-persistent -y`
$ `sudo /sbin/iptables -A INPUT -i eth0 -p tcp --destination-port 42185 -j ACCEPT`
$ `sudo /sbin/iptables -A INPUT -i eth0 -p udp --destination-port 42185 -j ACCEPT`
`eth0` в коде выше заменяем на `enp3s0` (в моем случае) - это `network_interface`
для того, чтобы понять на что заменять надо ввести команду
$ `ifconfig`
вывод: ```ruby
enp3s0 Link encap:Ethernet HWaddr fc:aa:14:0d:9f:d6
...
RX bytes:837639863 (837.6 MB) TX bytes:79243706 (79.2 MB)
```
либо:
$ route |grep default |awk ' {print $8} '
вывод:
enp3s0
либо мы можем писать команды так:
$ `sudo /sbin/iptables -A INPUT -i $(route |grep default |awk ' {print $8} ') -p tcp --destination-port 42185 -j ACCEPT`
$ `sudo /sbin/iptables -A INPUT -i $(route |grep default |awk ' {print $8} ') -p udp --destination-port 42185 -j ACCEPT`
для этого заходим под суперюзером
$ `su -` или $ `sudo su -`
далее:
$ `iptables-save > /etc/iptables/rules.v4`
$ `sudo apt-get install rsyslog curl -y`
$ `sudo nano /etc/rsyslog.conf`
Добавим строку, она означает, что rsyslog будет отправлять данные на порт 42185, его будет слушать td-agent(fluentd)
`*.* @127.0.0.1:42185`
$ `sudo systemctl unmask rsyslog.service`
$ `sudo service rsyslog restart`
$ `curl -L http://toolbelt.treasuredata.com/sh/install-ubuntu-precise-td-agent2.sh | sh`
$ `sudo nano /etc/td-agent/td-agent.conf`
```ruby
# Listen to Syslog
<source>
type syslog
port 42185
tag system
</source>
# Ship data to the aggregator
<match *.**>
type forward
shared_key 911
self_hostname 51.0.15.1 (ip нода)
<server>
host 51.1.0.15
</server>
</match>
```
$ `sudo service td-agent restart`
$ `sudo service td-agent restart`
$ `sudo service elasticsearch restart`
$ `sudo service kibana restart`
`http://localhost:5601`
и выбираем там во вкладке Settings
-> Indices
index name of pattern logstash-*
или что-то другое, я еще не разобрался с индексами, передаваемыми в elasticsearch
# Listen to Syslog
<source>
type syslog
port 42185
tag system
# @type tail
# path /vagrant/temp/log/development.log
# pos_file /vagrant/temp/log/development.log.pos
# tag elvis
# format multiline
# format1 /^Started/ format1 /Started (?<method>[^ ]+) "(?<path>[^"]+)" for (?<host>[^ ]+) at (?<time>[^ ]+ [^ ]+ [^ ]+)\n/
# format2 /Processing by (?<controller>[^\u0023]+)\u0023(?<controller_method>[^ ]+) as (?<format>[^ ]+?)\n/
# format3 /( Parameters: (?<parameters>[^ ]+)\n)?/
# format4 / Rendered (?<template>[^ ]+) within (?<layout>.+) \([\d\.]+ms\)\n/
# format5 /Completed (?<code>[^ ]+) [^ ]+ in (?<runtime>[\d\.]+)ms \(Views: (?<view_runtime>[\d\.]+)ms \| ActiveRecord: (?<ar_runtime>[\d\.]+)ms\)/
</source>
# Ship data to the aggregator
<match *.**>
type forward
shared_key 911
self_hostname 51.0.15.1
<server>
host 51.1.0.15
</server>
#@type elasticsearch
#logstash_format true
#host 51.1.0.15 #(optional; default="localhost")
#port 9200 #(optional; default=9200)
#index_name elvis_log #(optional; default=fluentd)
#type_name elvis_tag #(optional; default=fluentd)
</match>