我一直在关注这些教程,存储库,文档和所有内容:
- https://medium.com/@anjlab/how-to-set-up-eelk-for-rails-lails-lag-management-using-docker-and-docker-and-docker-compose-a6edc290669f
- https://github.com/orthodex/docker-elk-rails
- http://ericlondon.com/2017/01/26/integrate-rails-lails-lags-with-elasticsearch-logstash-kibana-kibana-in-docker-compose.html
- https://manas.tech/blog/2015/12/15/logging-for-rails-apps-inps-in-docker.html
- https://logz.io/blog/docker-logging/
- https://www.youtube.com/watch?v=Kr2fziqu57i
- https://dzone.com/articles/docker-logging-with-the-the-lk-stack-part-i
- Docker容器无法将日志发送到Docker Elk Stack
好吧,你明白了。我还有几个由于简洁而省略的
不幸的是,要么过时,要么不显示整个图片,要么我的配置不好(我认为这是后者(。
老实说,我不知道我是否缺少任何东西。
我目前正在使用docker-compose
版本3。我当前正在使用此图像(SEBP/Elk(。我能够启动所有内容,并访问Kibana,但是我无法将日志发送到LogStash,因此它被处理并发送到Elasticsearch。
我尝试了这些方法是无济于事的:
内部应用程序.rb
1(使用lograge并将其发送到端口5044(显然是logstash正在听(
config.lograge.enabled = true
config.lograge.logger = LogStashLogger.new(type: :udp, host: 'localhost', port: 5044)
2(将其设置为stdout,让Docker作为gelf进行处理,然后将其发送到Logstash:
logger = ActiveSupport::Logger.new(STDOUT)
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
并将其映射回撰写文件:
rails_app:
logging:
driver: gelf
options:
gelf-address: "tcp://localhost:5044"
3(我尝试了
我遇到的其他错误:
每当我尝试使用config.lograge.logger = LogStashLogger.new(type: :udp, host: 'localhost', port: 5044)
时,我会得到: -errno :: eaddrnotavail-无法分配请求的地址 - " Localhost端口5044"的连接(2(。有趣的是,这个错误可能会不时消失。
另一个问题是,每当我尝试创建一个虚拟日志条目时,我都会收到Elasticsearch Unreachable: [http://localhost:9200...]
这是在容器内...我不知道它是否无法连接,因为URL在外面暴露了...或还有另一个错误。我可以卷曲到Localhost:9200并获得积极的响应。
我正在检查SEBP/ELK图像,我发现它正在使用FileBeat。这可能就是我无法发送日志的原因吗?
我感谢任何帮助!
以防万一,这是我的docker-compose.yml文件:
version: '3'
services:
db:
image: mariadb:10.3.5
restart: always
environment:
MYSQL_ROOT_PASSWORD: "rootPassword"
MYSQL_USER: "ruby"
MYSQL_PASSWORD: "userPassword"
MYSQL_DATABASE: "dev"
ports:
- "3306:3306"
volumes:
- db-data:/var/lib/mysql/data
- ./db/rails_cprint.sql:/docker-entrypoint-initdb.d/rails_cprint.sql
elk:
image: sebp/elk:623
ports:
- 5601:5601
- 9200:9200
- 5044:5044
- 2020:2020
volumes:
- elasticsearch:/var/lib/elasticsearch
app:
build: .
depends_on:
- db
- elk
environment:
RAILS_ENV: development
LOGSTASH_HOST: localhost
SECRET_MYSQL_HOST: 'db'
SECRET_MYSQL_DATABASE: 'dev'
SECRET_MYSQL_USERNAME: 'ruby'
SECRET_MYSQL_PASSWORD: 'userPassword'
command: bash -c "rm -f tmp/pids/server.pid && bundle exec rails s -p 3001 -b '0.0.0.0'"
stdin_open: true
tty: true
logging:
driver: gelf
options:
gelf-address: "tcp://localhost:5044"
links:
- db
volumes:
- "./:/var/www/cprint"
ports:
- "3001:3001"
expose:
- "3001"
volumes:
db-data:
driver: local
elasticsearch:
driver: local
不要在配置中使用" localhost"。在Docker网络中,服务名称是主机名。例如,使用"麋鹿",例如:
config.lograge.logger = LogStashLogger.new(type: :udp, host: 'elk', port: 5044)