fluent / fluent-plugin-mongo

MongoDB input and output plugin for Fluentd
https://docs.fluentd.org/output/mongo
173 stars 61 forks source link

connecting to mongo replicaset and using SSL as well #166

Open UnP1u9 opened 2 years ago

UnP1u9 commented 2 years ago

Hey Guys,

I am trying to connect to mongo_replset using SRV record but am unable to connect,

using below config.

@type mongo_replset
connection_string mongodb+srv://username:password@mongo-server-srv-example.com/log_db?tls=true&authSource=admin&replicaSet=mongo-rep
ssl true
ssl_ca_cert /tmp/tls

it does not work with this config, I am creating all this using code so don't have names of nodes behind the mongo replica set (hosted on DigitalOcean).

config works when I put node name in host entry like below. but this is not the best way in production.

@type mongo_replset
host mongo-server-node-example.com:27017
replica_set mongo-repl
database db
user user
password "password"
ssl true
ssl_ca_cert /tmp/tls

Please suggest. Thanks!

eindrawan commented 2 years ago

I have this similar problem yesterday, and its working using this config: in my case i was trying to connect to mongodb atlas

 @type mongo_replset
  connection_string mongodb+srv://user:pass@cluster.mongodb.net/yourdb
  replica_set atlas-xxxx-shard-0

  ssl true
  ssl_cert /tmp/tls/generated-cert.crt
akhilaj commented 2 years ago

@eindrawan Hi, Were you able to resolve this, we are also facing similar issue. Please help..

eindrawan commented 2 years ago

@akhilaj, yes, you must generate a certificate first, then try to follow my config above

akhilaj commented 2 years ago

Hi @eindrawan thanks for the response, one more question that I have is did you use a Self Signed Certificate (openSSL) or any specific Authority one.

eindrawan commented 2 years ago

@akhilaj , I just use openSSL to generate self signed certificate, and its working fine

akhilaj commented 2 years ago

Thanks @eindrawan for the help, it is working for me now -

@type mongo_replset

  collection fluentd

  connection_string mongodb+srv://abc:abc@dev-mongodb-sss-ss.xxxx.mongodb.net/Db

  replica_set atlas-xxxx-shard-0

  ssl true

  ssl_cert /opt/bitnami/fluentd/conf/generated-cert.crt
kush003 commented 2 years ago

Hi @eindrawan, Can you please help me to understand how can I create generated-cert.crt through yaml deployment file?

eindrawan commented 2 years ago

@kush003 , sorry I never tried before, but i guess you can search "generate self-signed certificates for Kubernetes"