首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何禁用k8s部署nginx映像,配置为使用符号链接到/dev/stdout和/dev/stdin,并将日志转发到另一个荚

如何禁用k8s部署nginx映像,配置为使用符号链接到/dev/stdout和/dev/stdin,并将日志转发到另一个荚
EN

Stack Overflow用户
提问于 2022-11-11 16:56:33
回答 1查看 13关注 0票数 0

nginx映像正在捕获日志,这些日志正在使用符号链接转发到/dev/stdout和/dev/stderror,这将呈现给Rancher UI日志控制台,用于此部署。

我需要转发到一个圆角舱,它已经成功地从其他豆荚中收集了日志。

任何给予的帮助都将不胜感激。

######################## nginx和location ########################

/var/log/nginx # ls -hal共计0 drwxr-xr-x2根41,2016年10月18日。2016年10月19日.access.log -> /dev/stdout lrwxrwxrwx 1根,2016年10月11日error.log -> /dev/stderr

######################## nginx conf ########################

代码语言:javascript
复制
user  nginx;                                                                                                                                                                                                                                                                                                                  
worker_processes  1;                                                                                                                                                                                                                                                                                                          
                                                                                                                                                                                                                                                                                                                              
error_log  /var/log/nginx/error.log warn;                                                                                                                                                                                                                                                                                     
pid        /var/run/nginx.pid;                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                              
events {                                                                                                                                                                                                                                                                                                                      
    worker_connections  1024;                                                                                                                                                                                                                                                                                                 
}                                                                                                                                                                                                                                                                                                                             
                                                                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                              
http {                                                                                                                                                                                                                                                                                                                        
    include       /etc/nginx/mime.types;                                                                                                                                                                                                                                                                                      
    default_type  application/octet-stream;                                                                                                                                                                                                                                                                                   
                                                                                                                                                                                                                                                                                                                              
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '                                                                                                                                                                                                                                                 
                      '$status $body_bytes_sent "$http_referer" '                                                                                                                                                                                                                                                             
                      '"$http_user_agent" "$http_x_forwarded_for"';                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                              
    access_log  /var/log/nginx/access.log  main;                                                                                                                                                                                                                                                                              
                                                                                                                                                                                                                                                                                                                              
    sendfile        on;                                                                                                                                                                                                                                                                                                       
    #tcp_nopush     on;                                                                                                                                                                                                                                                                                                       
                                                                                                                                                                                                                                                                                                                              
    keepalive_timeout  65;                                                                                                                                                                                                                                                                                                    
                                                                                                                                                                                                                                                                                                                              
    #gzip  on;                                                                                                                                                                                                                                                                                                                
                                                                                                                                                                                                                                                                                                                              
    include /etc/nginx/conf.d/*.conf;                                                                                                                                                                                                                                                                                         
}     

尝试了对配置文件进行不同的更改,但无法找到将日志转发到流畅荚的方法,后者已经在从同一个命名空间中的其他部署中收集日志。

EN

回答 1

Stack Overflow用户

发布于 2022-11-13 09:24:49

尝试使用不同的nginx.conf,但仍然看不到将日志转发给fluentd/mongodb

其他的豆荚没有问题,可以看到它们收藏的日志,只有这个nginx荚不是转发的,其他的不是nginx代理。

任何提供的帮助都将非常感谢,如下面的nginx和fluentd配置文件所示

我可以在nginx.namespace.svc和fluentd.namespace.svc之间切换

代码语言:javascript
复制
<pre><code>
user nginx; 
worker_processes 1;

error_log /var/log/nginx/error.log warn; 
pid /var/run/nginx.pid; 

events { 
worker_connections 1024; 
} 

http { 
include /etc/nginx/mime.types; 
default_type application/octet-stream; 
log_format main escape=json
  '{'
    '"time_local":"$time_local",'
    '"remote_addr":"$remote_addr",'
    '"remote_user":"$remote_user",'
    '"request":"$request",'
    '"status": "$status",'
    '"body_bytes_sent":"$body_bytes_sent",'
    '"http_referrer":"$http_referer",'
    '"http_user_agent":"$http_user_agent",'
    '"request_time":"$request_time"'
  '}'; 

access_log syslog:server=fluentd.namespace.svc:24224 main;

sendfile on;
#tcp_nopush on; 

keepalive_timeout 65; 

#gzip on; 

include /etc/nginx/conf.d/*.conf; 
}
</code></pre>

<pre><code>
<source>
  @type  forward
  @id    inputDocker
  @label @DOCKER
  port  24224
  bind  0.0.0.0
</source>

<label @DOCKER>
   <match **>
        # plugin type
        @type mongo

        # mongo db connection string
        connection_string mongodb://logging:password@mongodb.namespace.svc:27017/logs

        # mongodb db + collection
        collection docker

        # interval
        <buffer>
            flush_interval 10s
        </buffer>

        # make sure to include the time key
        <inject>
           time_key time
        </inject>
   </match>
</label>
</code></pre>
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/74405808

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档