尊龙凯时人生就是博

ÔõÑùÔÚLinuxÉÏÉèÖÃÈÕÖ¾ÖÎÀí

ÔõÑùÔÚlinuxÉÏÉèÖÃÈÕÖ¾ÖÎÀí

ÔÚLinuxϵͳÖУ¬ÈÕÖ¾ÊǼͼϵͳÔËÐÐ״̬¡¢Ó¦ÓóÌÐòÔËÐÐÐÅÏ¢ÒÔ¼°¹ýʧºÍÖÒÑÔµÈÖ÷ÒªÐÅÏ¢µÄÒªº¦×é³É²¿·Ö¡£ºÏÀíÉèÖúÍÖÎÀíÈÕÖ¾¹ØÓÚϵͳµÄ¼à¿ØºÍ¹ÊÕÏÅŲéÖÁ¹ØÖ÷Òª¡£±¾ÎĽ«ÏòÄúÏÈÈÝÔõÑùÔÚlinuxÉÏÉèÖÃÈÕÖ¾ÖÎÀí£¬²¢ÌṩһЩ´úÂëʾÀý×ÊÖúÄú¸üºÃµØÃ÷È·ºÍʵ¼ù¡£

Ò»¡¢ÏàʶÈÕÖ¾ÎļþµÄÀàÐͺÍλÖÃ

Ê×ÏÈ£¬ÎÒÃÇÐèÒªÏàʶϵͳÖг£¼ûµÄÈÕÖ¾ÎļþÀàÐͺÍλÖá£ÏÂÃæÊdz£¼ûµÄ¼¸ÖÖÈÕÖ¾ÎļþÀàÐͼ°ÆäλÖãº

ϵͳÈÕÖ¾£¨System Log£©£º¸ÃÀàÐ͵ÄÈÕÖ¾¼Í¼ÁËϵͳµÄÔËÐÐ״̬¡¢Æô¶¯ºÍ¹Ø±ÕÐÅÏ¢µÈ¡£Í¨³£ÓÉ rsyslog ÖÎÀí£¬²¢´æ´¢ÔÚ /var/log/syslog »ò /var/log/messages ÖС£

Ó¦ÓóÌÐòÈÕÖ¾£¨Application Log£©£º¸ÃÀàÐ͵ÄÈÕÖ¾ÓÉÖÖÖÖÓ¦ÓóÌÐòÌìÉú£¬¼Í¼ÁËÓ¦ÓóÌÐòµÄÔËÐÐÐÅÏ¢ºÍ¹ýʧÐÅÏ¢µÈ¡£ÕâЩÈÕ־ͨ³£´æ´¢ÔÚÓ¦ÓóÌÐòµÄÌض¨Ä¿Â¼Ï£¬ÀýÈç /var/log/nginx/access.log¡£

Çå¾²ÈÕÖ¾£¨Security Log£©£º¸ÃÀàÐ͵ÄÈÕÖ¾¼Í¼ÁËϵͳµÄÇå¾²ÊÂÎñ£¬ÈçµÇ¼ʵÑé¡¢ÊÚȨÇëÇóµÈ¡£Ôڴ󲿷ÖLinuxϵͳÖУ¬Çå¾²ÈÕÖ¾±»¼Í¼ÔÚ /var/log/secure »ò /var/log/auth.log ÖС£

¶þ¡¢ÉèÖÃÈÕÖ¾ÂÖת

ÈÕÖ¾ÂÖתÊÇÖ¸¶ÔÈÕÖ¾Îļþ¾ÙÐа´Æڵع鵵ºÍѹËõ£¬ÒÔ±ÜÃâÈÕÖ¾Îļþ¹ý´ó»òÕ¼Óùý¶àµÄ´æ´¢¿Õ¼ä¡£ÔÚLinuxϵͳÖУ¬logrotate Êdz£ÓõÄÈÕÖ¾ÂÖת¹¤¾ß¡£

×°Öà logrotate£º

$ sudo apt-get install logrotate

µÇ¼ºó¸´ÖÆ

ÉèÖà logrotate£º

½¨ÉèÒ»¸öеÄÉèÖÃÎļþ£¬ÒÔ±ãÎÒÃÇ¿ÉÒÔ¶¨ÖÆ»¯ logrotate µÄÐÐΪ¡£

$ sudo nano /etc/logrotate.d/myapp

µÇ¼ºó¸´ÖÆ

ÔÚÉèÖÃÎļþÖУ¬Äú¿ÉÒÔÖ¸¶¨ÒªÂÖתµÄÈÕÖ¾Îļþ¡¢ÂÖתµÄʱ¼ä¾àÀëºÍ±£´æµÄÂÖתÎļþÊýÄ¿µÈ²ÎÊý¡£ÀýÈ磺

/var/log/myapp/*.log {
    weekly
    rotate 4
    compress
    delaycompress
    missingok
    notifempty
    sharedscripts
}

µÇ¼ºó¸´ÖÆ

ÔÚÉÏÃæµÄʾÀýÖУ¬/var/log/myapp/*.log Ö¸¶¨ÁËÒªÂÖתµÄÈÕÖ¾Îļþ·¾¶£¬weekly ÌåÏÖ°´ÖÜÂÖת£¬rotate 4 ÌåÏÖ±£´æ×î½üËĸöÂÖתÎļþ£¬compress ÌåÏÖѹËõÂÖתÎļþ£¬delaycompress ÌåÏÖÑÓ³ÙѹËõ£¬missingok ÌåÏÖÈôÊÇÈÕÖ¾Îļþ²»±£´æÔòºöÂÔ£¬notifempty ÌåÏÖµ±ÈÕÖ¾ÎļþΪ¿Õʱ²»¾ÙÐÐÂÖת¡£

ÊÖ¶¯Ö´ÐÐÂÖת£º

¿ÉÒÔÊÖ¶¯Ö´ÐÐÂÖת£¬ÒÔÑéÖ¤ÉèÖÃÊÇ·ñ׼ȷ¡£

$ sudo logrotate -vf /etc/logrotate.d/myapp

µÇ¼ºó¸´ÖÆ

Èý¡¢ÉèÖÃÈÕÖ¾ÐýתºÍÕûÀíÕ½ÂÔ

³ýÁËÈÕÖ¾ÂÖתÍ⣬ÎÒÃÇ»¹¿ÉÒÔÔÚÉèÖÃÎļþÖÐÖ¸¶¨ÈÕÖ¾ÐýתºÍÕûÀíµÄÕ½ÂÔ¡£LinuxϵͳÖУ¬logrotate Ö§³ÖÒÔÏÂÕ½ÂÔ£º

postrotate£º¸ÃÑ¡ÏîÖ¸¶¨ÂÖתºóÖ´ÐеÄÏÂÁî¡£¿ÉÒÔÔÚ¸ÃÑ¡ÏîÏ£¬¾ÙÐÐÈÕÖ¾ÆÊÎö¡¢Êý¾Ý¿â±¸·ÝµÈ²Ù×÷¡£

/var/log/myapp/*.log {
    ...
    postrotate
        /usr/bin/analyze_logs /var/log/myapp/*.log > /dev/null
    endscript
}

µÇ¼ºó¸´ÖÆ

prerotate£º¸ÃÑ¡ÏîÖ¸¶¨ÂÖתǰִÐеÄÏÂÁî¡£¿ÉÒÔÔÚ¸ÃÑ¡ÏîÏ£¬Ö´ÐÐһЩԤ´¦Àí²Ù×÷¡£

/var/log/myapp/*.log {
    ...
    prerotate
        /usr/bin/sync_logs /var/log/myapp/*.log
    endscript
}

µÇ¼ºó¸´ÖÆ

size£º¸ÃÑ¡ÏîÖ¸¶¨ÈÕÖ¾ÎļþµÖ´ï¶à´óʱ´¥·¢ÂÖת²Ù×÷£¬µ¥Î»¿ÉÒÔÊÇk£¨Ç§×Ö½Ú£©»òM£¨Õ××Ö½Ú£©¡£

/var/log/myapp/*.log {
    ...
    size 10M
}

µÇ¼ºó¸´ÖÆ

maxage£º¸ÃÑ¡ÏîÖ¸¶¨ÈÕÖ¾Îļþ±£´æµÄ×î´óÌìÊý¡£

/var/log/myapp/*.log {
    ...
    maxage 30
}

µÇ¼ºó¸´ÖÆ

ËÄ¡¢ÉèÖÃÔ¶³ÌÈÕÖ¾ÍøÂç

ÓÐʱ¼ä£¬ÎÒÃÇÐèÒª½«ÈÕÖ¾ÎļþÖеÄÄÚÈÝ·¢Ë͵½Ô¶³ÌЧÀÍÆ÷¾ÙÐÐÖÐÑëÈÕÖ¾ÍøÂçºÍÆÊÎö¡£ÔÚLinuxϵͳÖУ¬rsyslog Êdz£ÓõÄÈÕÖ¾ÍøÂçºÍ´¦Àí¹¤¾ß¡£

×°Öà rsyslog£º

$ sudo apt-get install rsyslog

µÇ¼ºó¸´ÖÆ

ÉèÖà rsyslog£º

·­¿ª rsyslog µÄÖ÷ÉèÖÃÎļþ£¬²¢±à¼­ÒÔÏÂÄÚÈÝ£º

$ sudo nano /etc/rsyslog.conf

µÇ¼ºó¸´ÖÆ

×÷·ÏÒÔÏÂÐеÄ×¢ÊÍ£¨É¾³ýÐÐÊ×µÄ#£©£º

#$ModLoad imudp
#$UDPServerRun 514

µÇ¼ºó¸´ÖÆ

ÔÚÎļþµÄĩ⣬Ìí¼ÓÒÔÏÂÄÚÈÝ£º

*.* @192.168.0.100:514

µÇ¼ºó¸´ÖÆ

ÆäÖУ¬192.168.0.100 ÊÇÔ¶³ÌЧÀÍÆ÷µÄIPµØµã£¬514 ÊÇÍøÂçÈÕÖ¾µÄ¶Ë¿ÚºÅ¡£

ÖØÆô rsyslog£º

$ sudo systemctl restart rsyslog

µÇ¼ºó¸´ÖÆ

ͨ¹ýÒÔÉÏÉèÖã¬ÈÕÖ¾½«Í¨¹ýUDPЭÒé·¢Ë͵½Ô¶³ÌЧÀÍÆ÷µÄ514¶Ë¿Ú¡£

×ܽ᣺

±¾ÎÄÏÈÈÝÁËÔõÑùÔÚLinuxϵͳÉÏÉèÖÃÈÕÖ¾ÖÎÀí¡£´ÓÏàʶÈÕÖ¾ÎļþÀàÐͺÍλÖÃ×îÏÈ£¬µ½ÉèÖÃÈÕÖ¾ÂÖת¡¢ÉèÖÃÈÕÖ¾ÐýתºÍÕûÀíÕ½ÂÔÒÔ¼°ÉèÖÃÔ¶³ÌÈÕÖ¾ÍøÂ磬ÎÒÃÇÌṩÁËÏà¹ØµÄ´úÂëʾÀý×ÊÖúÄú¸üºÃµØÃ÷È·ºÍʵ¼ù¡£ºÏÀíÉèÖúÍÖÎÀíÈÕÖ¾¹ØÓÚϵͳ¼à¿ØºÍ¹ÊÕÏÅŲéÖÁ¹ØÖ÷Òª£¬Ï£ÍûÕâƪÎÄÕÂÄܶÔÄúÓÐËù×ÊÖú¡£

ÒÔÉϾÍÊÇÔõÑùÔÚLinuxÉÏÉèÖÃÈÕÖ¾ÖÎÀíµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡

ÃâÔð˵Ã÷£ºÒÔÉÏչʾÄÚÈÝȪԴÓÚÏàÖúýÌå¡¢ÆóÒµ»ú¹¹¡¢ÍøÓÑÌṩ»òÍøÂçÍøÂçÕûÀí£¬°æȨÕùÒéÓë±¾Õ¾Î޹أ¬ÎÄÕÂÉæ¼°¿´·¨Óë¿´·¨²»´ú±í尊龙凯时人生就是博ÂËÓÍ»úÍø¹Ù·½Ì¬¶È£¬Çë¶ÁÕß½ö×ö²Î¿¼¡£±¾ÎĽӴýתÔØ£¬×ªÔØÇë˵Ã÷À´ÓÉ¡£ÈôÄúÒÔΪ±¾ÎÄÇÖÕ¼ÁËÄúµÄ°æȨÐÅÏ¢£¬»òÄú·¢Ã÷¸ÃÄÚÈÝÓÐÈκÎÉæ¼°ÓÐÎ¥¹«µÂ¡¢Ã°·¸Ö´·¨µÈÎ¥·¨ÐÅÏ¢£¬ÇëÄúÁ¬Ã¦ÁªÏµ尊龙凯时人生就是博ʵʱÐÞÕý»òɾ³ý¡£

Ïà¹ØÐÂÎÅ

ÁªÏµ尊龙凯时人生就是博

13452372176

¿É΢ÐÅÔÚÏß×Éѯ

ÊÂÇéʱ¼ä£ºÖÜÒ»ÖÁÖÜÎ壬9:30-18:30£¬½ÚãåÈÕÐÝÏ¢

QR code
sitemap¡¢ÍøÕ¾µØͼ