常见的日志分析手段


________________________________________
1、sed:处理缓冲区中的字符串,然后输出的标准输出。
(1)行单位增删 sed ‘2,7d’ 但是删除,2起始行,7结尾行($代表最后一行)
(2)行单位替换 sed ‘2,5c xxxxxxx’,把2到5行替换成xxxxx
(3)行单位显示 sed -n ‘3,13p’ p显示
(4)数据搜索 sed ‘/root/p’ 搜索root 并显示
(5)数据替换 sed ’s/要被取代的字串/新的字串/g'
________________________________________
2、sort:排序。
-b 忽略每行前面开始出的空格字符
-c 检查文件是否已经按照顺序排序
-d 排序时,处理英文字母、数字及空格字符外,忽略其他的字符
-f 排序时,将小写字母视为大写字母
-i 排序时,除了040至176之间的ASCII字符外,忽略其他的字符
-M 将前面3个字母依照月份的缩写进行排序
-n 依照数值的大小排序
-o<输出文件> 将排序后的结果存入指定的文件
-r 以相反的顺序来排序
________________________________________
3、uniq:去重类作用。
-c或–count 在每列旁边显示该行重复出现的次数
-d或–repeated 仅显示重复出现的行列
-u或–unique 仅显示出一次的行列
________________________________________
4、awk:文本分析作用。
(1)awk [选项参数] ‘script’ var=value file
(2)输出文本1 4 行 awk ‘{print 1,1,4}’ log.txt
(3)正则 awk ‘/re/ ’ log.txt ~ 表示模式开始 /中间是模式/
________________________________________
1、日志分类:
1.1操作系统日志
1.1.1UNIX/LINUX系统日志
@1登录时间日志 /var/log/wtmp && /var/run/utmp
@2进程统计日志
@3错误记录日志/var/log/message/…
@4lastlog 二进制 maillog略
1.1.2Windows系统日志
@1windows_server_8 ^ && windows_7 ^ path=%SystemRoot%System32WinevtLogs
1Applacation: pathApplication.evtx
2Security: pathSecurity.evtx
3System: pathSystem.evtx
4FW: %SystemRoot%System32LogFilesFirewallpfirewall.evtx
1.2网络设备日志
@1locallog
@2syslog
@3maillog
1.3应用系统日志
找不到日志文件的可以先查询/var/log/message @1 WEB 1 Apache (1)Config_File : /etc/apachex/apachex.conf or httpd.conf (2)Access_Log : /var/log/apachex/access_log(Ubuntu)
(3)Access_Log : /usr/local/apachex/logs or /usr/local/apachex/logs
(4)Error_Log : the same as access log
(5)format:
|remote_ip|-|-|time|timezone|method|URL|protocol|response_code|size
(6)other linux or unixlike system’s position of it’s logs:
please use find or locate command to find
2 Nginx
(1)Config_file : nginx.conf
(2)Access_Log : /usr/local/nginx/logs/access.log
(3)Error_Log : /usr/local/nginx/logs/error.log
3 Tomcat
(1)Config_File : /etc/tomcat7/server.xml
(2)Access_Log : /var/log/tomcat7/
(3)the format is the same as Apache’s
@2 FTP
1 log’s position
(1)Config_File : /etc/vsftp/vsftp.conf
(2)Log : /var/log/vsftp/ vsftpd.log && xferlog
2 vsftpd.log
|time|pid|command|context|
3 xferlog
|time|transport_time|remote_ip|file_size|file_path|transport_mode|-|transport_direction|connect_mode|username|ftp|Auth_way|ID|transport_state
@3 Squid
1 Config_File : 、/etc/squid/squid.conf
2 Log_File : /var/log/squid (1)access.log
(2)cache.log
(3)store.log
3 Access Log Format
|unix_time|time_to_last|ip|squid_state_code|size|method|url|-|code_level|http_header|
@4 NFS
1 Config_File : /etc/nfs/nfslog.conf
2 Log : /var/log/nfs
3 Format |time|time_to_last|ip_or_host|file_size|path|data_type|_|cmd|connect_mode|ID|service_type|auth|-|
@5 IPTABLES
1 Config_File : /var/log/iptables.log
2 Log_File : /var/log/iptables/……
@6 Samba
1 Config_File : smb.conf
2 logfile = /var/log/samba/
@7 DNS
1 /var/log/messages
@8 DHCP
1 /var/log/messages
2 /var/lib/dhcp/db/dhcpd.leases
@9 Mail
1 Sendmail /var/log/maillog
*2 Postfix /var/log/maillog

原文地址:https://www.cnblogs.com/mutudou/p/13749863.html