1. 鏡像中的日志
root@op-web-584664588b-629q2:/var/log/nginx# pwd
/var/log/nginx
root@op-web-584664588b-629q2:/var/log/nginx# ls -l
total 32
lrwxrwxrwx 1 root root 11 Jul 22 10:13 access.log -> /dev/stdout
lrwxrwxrwx 1 root root 11 Jul 22 10:13 error.log -> /dev/stderr
如上可見:
- 日志位置
/var/log/nginx
目錄下 - 日志輸出
是兩個軟連接炕舵,分別輸出到/dev/stdout
和/dev/stderr
兩個位置跋涣。
這實際是輸出到了容器的前臺日志肉渴。(我們在容器中讀這個文件是沒有輸出的)
2. 持久化
持久化存儲只需要將/var/log/nginx 目錄掛載出來归粉,兩個軟連接自然就沒有了雹顺,日志被保存在文件中野来。
但此時截汪,容器前臺日志也不會輸出這些信息了疾牲。
- 測試一下
nginx.conf 設置如下(當然k8s是通過configmap掛載出來的)
為了對比,我們保留兩個軟連接衙解,重新創(chuàng)建兩個日志文件
http {
error_log /var/log/nginx/error2.log info;
rewrite_log on;
access_log /var/log/nginx/access2.log;
......
結果
root@op-web-584664588b-629q2:/var/log/nginx# ls -l
total 44
lrwxrwxrwx 1 root root 11 Jul 22 10:13 access.log -> /dev/stdout
-rw-r--r-- 1 root root 35557 Sep 9 03:15 access2.log
lrwxrwxrwx 1 root root 11 Jul 22 10:13 error.log -> /dev/stderr
-rw-r--r-- 1 root root 3596 Sep 9 03:08 error2.log
root@op-web-584664588b-629q2:/var/log/nginx# tail -f error2.log
2021/09/09 03:17:20 [notice] 40#40: sched_setaffinity(): using cpu #10
2021/09/09 03:17:20 [notice] 1#1: start worker process 42
2021/09/09 03:17:20 [notice] 41#41: sched_setaffinity(): using cpu #11
2021/09/09 03:17:20 [notice] 1#1: start worker process 43
2021/09/09 03:17:20 [notice] 42#42: sched_setaffinity(): using cpu #12
2021/09/09 03:17:20 [notice] 1#1: start worker process 44
2021/09/09 03:17:20 [notice] 43#43: sched_setaffinity(): using cpu #13
2021/09/09 03:17:20 [notice] 44#44: sched_setaffinity(): using cpu #14
2021/09/09 03:17:20 [notice] 1#1: start worker process 45
2021/09/09 03:17:20 [notice] 45#45: sched_setaffinity(): using cpu #15