一、问题描述
使用fluentd的mongodb插件,将nginx的日志,存储到mongodb数据库中,配置如下:
<source> @type tail path /var/log/nginx/access.log pos_file /var/log/td-agent/nginx.access_log.pos <parse> @type nginx </parse> tag nginx.access </source> <filter nginx.access.**> @type stdout </filter> <match nginx.**> # plugin type @type mongo # mongodb db + collection database nginx collection access # mongodb host + port host 10.16.24.101 port 27017 user admin # 使用admin账户 password 密码 # admin账户的密码 # interval <buffer> flush_interval 10s </buffer> # make sure to include the time key <inject> time_key time </inject> </match>
发现,启动td-agent之后,并且生成了nginx的访问日志后,报错
2022-11-16 08:43:13 -0500 [warn]: #0 failed to flush the buffer. retry_times=14 next_retry_time=2022-11-16 13:25:18 -0500 chunk="5ed92ee044684576dfb8fafcfd50508a" error_class=Mongo::Auth::Unauthorized error="User admin (mechanism: scram) is not authorized to access nginx (auth source: nginx, used mechanism: SCRAM-SHA-1, used server: 10.16.224.101:27017 (STANDALONE)): [18:AuthenticationFailed]: Authentication failed." 2022-11-16 08:43:13 -0500 [warn]: #0 suppressed same stacktrace 2022-11-16 13:25:18 -0500 [warn]: #0 failed to flush the buffer. retry_times=15 next_retry_time=2022-11-16 22:38:48 -0500 chunk="5ed92ee044684576dfb8fafcfd50508a" error_class=Mongo::Auth::Unauthorized error="User admin (mechanism: scram) is not authorized to access nginx (auth source: nginx, used mechanism: SCRAM-SHA-1, used server: 10.16.224.101:27017 (STANDALONE)): [18:AuthenticationFailed]: Authentication failed." 2022-11-16 13:25:18 -0500 [warn]: #0 suppressed same stacktrace
二、问题分析
从上面的分析来看是用户认证的问题。
尝试以下的解决方案都没有解决:
- 修改admin账户对nginx库的权限
- 手动增加nginx库,和access 表
最终,通过下面的方法解决的问题
三、问题解决
1、使用admin账户登录到数据库
./mongo -u admin -p <password> admin
2、切换到nginx库,建立用户
use nginx db.createUser({user:"root",pwd:"password",roles:[{role:"dbOwner",db:"nginx"}]})
3、修改td-agent.conf,使用新的用户
user root # 修改为root,原来是admin password password
4、重启td-agent
5、重新生成nginx的访问日志
发现,在mongodb中nginx库中可以看到访问日志记录
OK,问题完美的解决!
关键点:就是用户和权限!
标签:fluentd,Mongo,16,admin,mongodb,access,nginx,报错,0500 From: https://www.cnblogs.com/chuanzhang053/p/16898635.html