12 友盟專案--配置nginx的日誌滾動
阿新 • • 發佈:2018-11-04
配置nginx的日誌滾動
--------------------------
使用linux的crod排程器,週期性生成新檔案。
[編寫滾動指令碼 /usr/local/bin/umeng_roll_log.sh] chmod 777 修改可執行許可權
#!/bin/bash dateStr=`date '+%Y-%m-%d-%H-%M'` mv /usr/local/openresty/nginx/logs/access.log /usr/local/openresty/nginx/logs/access.log.${dateStr} touch access.log openresty -s reload
配置linux的crond服務,自動實現指令碼呼叫,實現日誌滾動
--------------------------------
1.編寫排程檔案
[/etc/crontab] 一分鐘滾動一次
SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4crontabs # Example of job definition: # .---------------- minute (0 - 59),分鐘 # | .------------- hour (0 - 23) # | | .---------- day of month (1 - 31) # | | | .------- month (1 - 12) OR jan,feb,mar,apr ... # | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat# | | | | | # * * * * * user-name command to be executed * * * * * root source /etc/profile;/usr/local/bin/umeng_roll_log.sh
2.啟動排程服務
$>su root
$>service crond status //檢視服務狀態
$>service crond start //啟動伺服器 3.設定crond服務開機自啟
$>chkconfig crond on //啟用開機自啟