1、1. 介紹
nginx-ingress-controller的日志包括三個部分:
- controller日志:輸出到stdout,通過啟動引數中的–log_dir可已配置輸出到檔案,重定向到檔案后會自動輪轉,但不會自動清理
- accesslog:輸出到stdout,通過nginx-configuration中的欄位可以配置輸出到哪個檔案,輸出到檔案后不會自動輪轉或清理
- errorlog:輸出到stderr,配置方式與accesslog類似,
2、落盤
2.1、在ingress nginx所在的節點,創建落盤日志目錄,并賦予權限
mkdir /nfs/logs/nginx-ingress -p
chown -R 101.101 /nfs/logs/nginx-ingress/ # 在這里需要注意的是得跟自己nginx-ingress里的用戶一樣否則沒有權限
2.2、將controler日志輸出到檔案
修改一下nginx-ingress啟動選項
# 設定controller日志的輸出路徑和方式
- --log_dir=/var/log/nginx/
- --logtostderr=false

2.3、修改configmap設定access日志,error日志,以及logformat格式
data:
worker-processes: "4"
use-forwarded-headers: "true"
log-format-upstream: "[$host] [$remote_addr] [$http_x_forwarded_for]
[$remote_user] [$time_local] [$request] [$status] [$body_bytes_sent]
[$request_time] [$upstream_addr] [$upstream_response_time] [$connection]
[$connection_requests] [$msec] [$uri] [$body_bytes_sent] [$http_referer]
[$http_user_agent] [$request_length] [$http_session_id]"
access-log-path: "/var/log/nginx/access.log"
error-log-path: "/var/log/nginx/error.log"

2.4、掛載日志
volumeMounts:
- mountPath: /var/log/nginx
name: nginx-log
- mountPath: /etc/localtime
name: localtime
volumes:
- hostPath:
path: /nfs/logs/nginx-ingress/
name: nginx-log
- hostPath:
path: /etc/localtime
name: localtime

2.5、重啟一下Ingress查看一下效果
[root@k8s-m1 nginx-ingress]# ll /nfs/logs/nginx-ingress/
total 188
-rw-r--r-- 1 101 101 14229 Sep 11 17:30 access.log
-rw-r--r-- 1 101 101 539 Sep 12 14:01 error.log
lrwxrwxrwx 1 101 101 68 Sep 12 14:24 nginx-ingress-controller.ERROR -> nginx-ingress-controller.k8s-n3.www-data.log.ERROR.20210912-142434.6
lrwxrwxrwx 1 101 101 67 Sep 12 14:00 nginx-ingress-controller.INFO -> nginx-ingress-controller.k8s-n3.www-data.log.INFO.20210912-140059.6
-rw-r--r-- 1 101 101 8217 Sep 12 13:18 nginx-ingress-controller.k8s-n1.www-data.log.ERROR.20210911-135853.7
-rw-r--r-- 1 101 101 25589 Sep 12 13:18 nginx-ingress-controller.k8s-n1.www-data.log.INFO.20210911-134055.7
-rw-r--r-- 1 101 101 12091 Sep 12 13:18 nginx-ingress-controller.k8s-n1.www-data.log.WARNING.20210911-134055.7
-rw-r--r-- 1 101 101 5912 Sep 12 13:01 nginx-ingress-controller.k8s-n2.www-data.log.ERROR.20210911-135900.6
-rw-r--r-- 1 101 101 11022 Sep 12 13:01 nginx-ingress-controller.k8s-n2.www-data.log.INFO.20210911-133925.6
-rw-r--r-- 1 101 101 6190 Sep 12 13:01 nginx-ingress-controller.k8s-n2.www-data.log.WARNING.20210911-133925.6
-rw-r--r-- 1 101 101 7544 Sep 12 14:00 nginx-ingress-controller.k8s-n3.www-data.log.ERROR.20210911-135900.6
-rw-r--r-- 1 101 101 344 Sep 12 14:24 nginx-ingress-controller.k8s-n3.www-data.log.ERROR.20210912-142434.6
-rw-r--r-- 1 101 101 13627 Sep 12 14:00 nginx-ingress-controller.k8s-n3.www-data.log.INFO.20210911-134029.6
-rw-r--r-- 1 101 101 4120 Sep 12 14:24 nginx-ingress-controller.k8s-n3.www-data.log.INFO.20210912-140059.6
-rw-r--r-- 1 101 101 7822 Sep 12 14:00 nginx-ingress-controller.k8s-n3.www-data.log.WARNING.20210911-134029.6
-rw-r--r-- 1 101 101 622 Sep 12 14:24 nginx-ingress-controller.k8s-n3.www-data.log.WARNING.20210912-140059.6
-rw-r--r-- 1 101 101 7802 Sep 12 14:19 nginx-ingress-controller.k8s-n4.www-data.log.ERROR.20210911-140334.6
-rw-r--r-- 1 101 101 18859 Sep 12 14:19 nginx-ingress-controller.k8s-n4.www-data.log.INFO.20210911-133959.6
-rw-r--r-- 1 101 101 9427 Sep 12 14:19 nginx-ingress-controller.k8s-n4.www-data.log.WARNING.20210911-133959.6
lrwxrwxrwx 1 101 101 70 Sep 12 14:00 nginx-ingress-controller.WARNING -> nginx-ingress-controller.k8s-n3.www-data.log.WARNING.20210912-140059.6
3、帶域名訪問一下
apiVersion: networking.k8s.io/v1beta1
kind: Ingress
metadata:
name: lzulms-myapp
namespace: lzulms
spec:
rules:
- host: lzulmsconfig.chinaedu.net
http:
paths:
- backend:
serviceName: lzulms-myapp
servicePort: 80
path: /
cat /nfs/logs/nginx-ingress/access.log
[lzulmsconfig.chinaedu.net] [172.16.28.138] [-] [-] [11/Sep/2021:17:30:12 +0800] [GET /hostname.html HTTP/1.1] [200] [29] [0.003] [10.244.4.230:80] [0.002] [170314] [15] [1631352612.452] [/hostname.html] [29] [http://lzulmsconfig.chinaedu.net/] [Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36 Edg/93.0.961.38] [777] [-]
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/299642.html
標籤:其他
