$ sudo apt install logrotate
vi /etc/logrotate.conf
## 로그 파일을 순환시킬 기간에 대한 설정 (daily, weekly, monthly, yearly)
# see "man logrotate" for details
# rotate log files weekly
weekly
# use the adm group by default, since this is the owning group
# of /var/log/syslog.
su root adm
## 순환된 로그 파일을 보관할 기간에 대한 설정 (위에서 설정한 기간 단위 설정)
# keep 4 weeks worth of backlogs
rotate 4
## 로그 파일 순환 후 새로운 로그 파일 생성
# create new (empty) log files after rotating old ones
create
## 순환된 파일의 파일명 변경 옵션(YYYYMMDD)
# use date as a suffix of the rotated file
#dateext
## 순환된 파일을 압축하여 보관하는 옵션
# uncomment this if you want your log files compressed
#compress
## 로그 순환에 대한 추가 설정 파일이 저장된 디렉토리
# packages drop log rotation information into this directory
include /etc/logrotate.d
# system-specific logs may be also be configured here.
/etc/logrotate.d/ 경로에 testrotate 파일 생성
/logs/*.log {
rotate 10000
create
daily
missingok
dateext
dateformat -%Y-%m-%d_%H
maxage 14
maxsize 10M
}
vi /etc/logrotate.d/nginx
/var/log/nginx/*.log {
daily
rotate 1
size 1M
missingok
compress
delaycompress
notifempty
dateext
create 640 nginx adm
sharedscripts
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}
/var/log/nginx/*.log {
##일 단위로 rotate
daily
## 로그 파일 개수를 1개로 유지
rotate 1
## 지정된 용량이 되면 rotate (1M)
size 1M
## 로그 파일이 없는 경우에도 에러 없이 다음으로 넘어감
missingok
## gzip으로 압축
compress
## 최근파일 외 전부 압축
delaycompress
## 로그 파일이 비어있으면 rotate 하지 않음
notifempty
## rotate된 로그파일명에 1,2.. 등 numbering이 아닌 날짜를 붙여서 보관
dateext
## 새로 로그 파일 생성시 640 모드로 생성하고 소유자, 그룹은 nginx
create 640 nginx adm
## 로그파일이 여러개 있어도 스크립트를 공유하여 prerotate, postrotate 스크립트를 한번만 실행
sharedscripts
## 실행 후 스트립트 파일 실행
postrotate
if [ -f /var/run/nginx.pid ]; then
kill -USR1 `cat /var/run/nginx.pid`
fi
endscript
}
# 강제실행
logrotate -f /etc/logrotate.d/nginx
# 디버깅
logrotate -d /etc/logrotate.d/nginx
api/9c6fdb8c-172e-47f4-b8da-cfcb43eba42a:/var/vcap/sys/log/cloud_controller_ng# cat /dev/null > post-start.stderr.log
# Generated by bosh-agent
/var/vcap/data/sys/log/*.log /var/vcap/data/sys/log/.*.log /var/vcap/data/sys/log/*/*.log /var/vcap/data/sys/log/*/.*.log /var/vcap/data/sys/log/*/*/*.log /var/vcap/data/sys/log/*/*/.*.log {
daily
missingok
rotate 5
compress
copytruncate
size=5M
dateext
}
error: skipping "/var/log/alternatives.log" because parent directory has insecure permissions (It's world writable or writable by group which is not "root") Set "su" directive in config file to tell logrotate which user/group should be used for rotation.
error: destination /var/vcap/data/sys/log/bosh-dns/bosh_dns_health.stdout.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/bosh-dns/bosh_dns.stdout.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/cloud_controller_ng/nginx-access.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/cloud_controller_ng/nginx-error.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/loggregator_agent/loggregator_agent.stderr.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/metrics-discovery-registrar/bpm.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/metrics-discovery-registrar/metrics-discovery-registrar.stderr.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/route_registrar/bpm.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/route_registrar/route_registrar.stderr.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/route_registrar/route_registrar.stdout.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/routing-api/bpm.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/routing-api/routing-api.stderr.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/routing-api/routing-api.stdout.log-20221026.gz already exists, skipping rotation
error: destination /var/vcap/data/sys/log/cloud_controller_ng/drain/drain.log-20221026.gz already exists, skipping rotation
ta inception mysql garbd 작업
/var/vcap/data/sys/log/garbd/*.log {
daily
rotate 3
size=1M
missingok
compress
dateext
dateformat -%Y-%m-%d_%H_%M
copytruncate
}
arbitrator/aaf70783-b131-4514-b4a1-33cad7f2bed5:/var/vcap/data/sys/log/garbd# logrotate -f /etc/logrotate.d/vcap
arbitrator/aaf70783-b131-4514-b4a1-33cad7f2bed5:/var/vcap/data/sys/log/garbd# ll
total 48
drwxr-xr-x 2 root root 4096 Oct 27 16:26 ./
drwxr-x--- 9 root vcap 4096 Sep 25 03:19 ../
-rw-r--r-- 1 root root 540 Oct 27 16:26 garbd.stderr.log
-rw-r--r-- 1 root root 1267 Oct 27 16:23 garbd.stderr.log-2022-10-27_16_23.gz
-rw-r--r-- 1 root root 20 Oct 27 16:23 garbd.stderr.log-2022-10-27_16_24.gz
-rw-r--r-- 1 root root 1467 Oct 27 16:25 garbd.stderr.log-2022-10-27_16_26.gz
~# logrotate -d /etc/logrotate.d/pxc-mysql
rotating pattern: /var/vcap/sys/log/pxc-mysql/mysql_general.log 104857600 bytes (3 rotations)
empty log files are rotated, old logs are removed
considering log /var/vcap/sys/log/pxc-mysql/mysql_general.log
Creating new state
Now: 2022-10-28 06:25
Last rotated at 2022-10-28 06:00
log needs rotating
rotating log /var/vcap/sys/log/pxc-mysql/mysql_general.log, log->rotateCount is 3
Converted ' -%Y-%m-%d' -> '-%Y-%m-%d'
dateext suffix '-2022-10-28'
glob pattern '-[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]'
glob finding old rotated logs failed
copying /var/vcap/sys/log/pxc-mysql/mysql_general.log to /var/vcap/sys/log/pxc-mysql/mysql_general.log-2022-10-28
truncating /var/vcap/sys/log/pxc-mysql/mysql_general.log
compressing log with: /bin/gzip
database/eb411a1e-259c-4da0-83c5-916974333df6:/var/vcap/sys/log/pxc-mysql# logrotate -f /etc/logrotate.d/pxc-mysql
database/eb411a1e-259c-4da0-83c5-916974333df6:/var/vcap/sys/log/pxc-mysql# ll
total 44104
drwxrwx--- 2 vcap vcap 4096 Oct 28 06:30 ./
drwxr-x--- 22 root vcap 4096 Jan 25 2022 ../
-rw------- 1 vcap vcap 2319 Jan 25 2022 bpm.log
-rw-r--r-- 1 vcap vcap 0 Jan 25 2022 galera-init.log
-rw------- 1 vcap vcap 0 Jan 25 2022 galera-init.stderr.log
-rw------- 1 vcap vcap 12641 Jan 25 2022 galera-init.stdout.log
-rw-r----- 1 vcap vcap 305978 Oct 28 06:28 mysql.err.log
-rw-r----- 1 vcap vcap 91698 Oct 28 06:30 mysql_general.log
-rw-r----- 1 vcap vcap 44574384 Oct 28 06:25 mysql_general.log-2022-10-28.gz
-rw-r--r-- 1 vcap vcap 141148 Sep 5 06:27 mysql_slow_query.log
-rw-r----- 1 vcap vcap 0 Jan 25 2022 pre-start.stderr.log
-rw-r----- 1 vcap vcap 1832 Jan 25 2022 pre-start.stdout.log