syslog-ng+loganalyzer log system install guide

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
日志服务 SLS,月写入数据量 50GB 1个月
简介:

 
 
  1. 一,创建Syslog数据库 
  2. mysql> CREATE DATABASE Syslog character set utf8; 
  3. mysql> USE Syslog; 
  4. mysql> CREATE TABLE SystemEvents 
  5.         ID int unsigned not null auto_increment primary key, 
  6.         CustomerID bigint, 
  7.         ReceivedAt datetime NULL, 
  8.         DeviceReportedTime datetime NULL, 
  9.         Facility smallint NULL, 
  10.         Priority smallint NULL, 
  11.         FromHost varchar(60) NULL, 
  12.         Message text, 
  13.         NTSeverity int NULL, 
  14.         Importance int NULL, 
  15.         EventSource varchar(60), 
  16.         EventUser varchar(60) NULL, 
  17.         EventCategory int NULL, 
  18.         EventID int NULL, 
  19.         EventBinaryData text NULL, 
  20.         MaxAvailable int NULL, 
  21.         CurrUsage int NULL, 
  22.         MinUsage int NULL, 
  23.         MaxUsage int NULL, 
  24.         InfoUnitID int NULL , 
  25.         SysLogTag varchar(60), 
  26.         EventLogType varchar(60), 
  27.         GenericFileName VarChar(60), 
  28.         SystemID int NULL 
  29. ); 
  30.  
  31.  
  32.  
  33. mysql> CREATE TABLE SystemEventsProperties 
  34.  ( 
  35.          ID int unsigned not null auto_increment primary key, 
  36.          SystemEventID int NULL , 
  37.          ParamName varchar(255) NULL , 
  38.          ParamValue text NULL 
  39.  ); 
  40.  
  41. 二,设置数据库权限 
  42. mysql> GRANT ALL ON Syslog.* TO syslog_ng@localhost IDENTIFIED BY 'syslog_ngpass';            
  43. mysql> FLUSH PRIVILEGES; 
  44.  
  45. 三,配置syslog-ng服务端 
  46. rpm -ivh libnet-1.1.5-1.el6.x86_64.rpm 
  47. rpm -ivh eventlog-0.2.12-1.el6.x86_64.rpm  
  48. rpm -ivh syslog-ng-3.2.5-3.el6.x86_64.rpm 
  49. rpm -ivh libdbi-0.8.3-3.1.el6.x86_64.rpm 
  50. rpm -ivh syslog-ng-libdbi-3.2.5-3.el6.x86_64.rpm 
  51.  
  52. vim /etc/syslog-ng/syslog-ng.conf  
  53. ======================================================================================================================== 
  54. source s_src { 
  55.                unix-stream("/dev/log"); 
  56.                udp(ip("192.168.122.200") port(514)); 
  57. }; 
  58. destination d_mysql { 
  59. sql(type(mysql) 
  60. host("localhost") username("syslog_ng") password("syslog_ngpass"
  61. database("Syslog") table("SystemEvents"
  62.  
  63. columns("ID int unsigned not null auto_increment primary key","ReceivedAt datetime NULL""DeviceReportedTime datetime NULL"
  64. "Facility smallint NULL","Priority smallint NULL","FromHost varchar(60) NULL"
  65. "Message text","InfoUnitID int NULL","SysLogTag varchar(60)"
  66. "CustomerID bigint","NTSeverity int NULL","Importance int NULL","EventSource varchar(60)","EventUser varchar(60) NULL"
  67. "EventCategory int NULL","EventID int NULL","EventBinaryData text NULL","MaxAvailable int NULL","CurrUsage int NULL","MinUsage int NULL"
  68. "MaxUsage int NULL","EventLogType varchar(60)","GenericFileName VarChar(60)","SystemID int NULL"
  69. values("","$R_ISODATE", "$S_ISODATE","$FACILITY_NUM","$LEVEL_NUM","$HOST", 
  70. "$MSGONLY","1","$MSGHDR","","","","","","","","","","","","","","","") 
  71. indexes("ID","ReceivedAt","Facility","Priority","FromHost","SysLogTag",)); 
  72. }; 
  73. log { source(s_src); destination(d_mysql); }; 
  74. ========================================================================================================================== 
  75. 四。配置loganalyzer日志web页面 
  76. wget http://download.adiscon.com/loganalyzer/loganalyzer-3.6.1.tar.gz 
  77. tar xf loganalyzer-3.6.1.tar.gz 
  78. cd  loganalyzer-3.6.1 
  79. mkdir /var/www/html/loganalyzer 
  80. mv ./src/*  /var/www/html/loganalyzer 
  81. cp contrib/* /var/www/html/loganalyzer 
  82. cd /var/www/html/loganalyzersh 
  83. sh  configure.sh  
  84.  
  85. cat >/etc/cron.daily/syslog-clean.sh <<EOF 
  86. #!/bin/bash 
  87. MYSQL_USER="syslog_ng" 
  88. MYSQL_PASS="syslog_ngpass" 
  89. MYSQL_DB="Syslog" 
  90. mysql  -u\${MYSQL_USER} -p\${MYSQL_PASS} \${MYSQL_DB} -e "DELETE FROM SystemEvents WHERE ReceivedAt < DATE_SUB(CURDATE(),INTERVAL 30 DAY)" 
  91. EOF 
  92. chmod 700 /etc/cron.daily/syslog-clean.sh 
  93. http://192.168.122.200/loganalyzer/install.php 
  94.  
  95.  
  96. 五,配置客户端syslog-ng 
  97. rpm -ivh libnet-1.1.5-1.el6.x86_64.rpm 
  98. rpm -ivh eventlog-0.2.12-1.el6.x86_64.rpm  
  99. rpm -ivh syslog-ng-3.2.5-3.el6.x86_64.rpm 
  100. rpm -ivh libdbi-0.8.3-3.1.el6.x86_64.rpm 
  101. rpm -ivh syslog-ng-libdbi-3.2.5-3.el6.x86_64.rpm 
  102.  
  103.  
  104. vim /etc/syslog-ng/syslog-ng.conf  
  105. =================================================================================== 
  106. destination d_euid { file("/var/log/user"); }; 
  107. filter f_euid   { match("euid" value("euid")) or facility(authpriv); }; 
  108. log { source(s_sys); filter(f_euid);destination(d_euid); }; 
  109. log { source(s_sys);filter(f_euid); destination(d_udp);}; 
  110. log { source(s_sys); destination(d_udp);}; 
  111. ================================================================================== 
  112.  
  113. cat >>/etc/bashrc <<EOF 
  114. export PROMPT_COMMAND='{ msg=$(history 1 | { read x y; echo $y; });logger "[hostname- $(hostname)]": "[euid=$(whoami)]":$(who am i):[`pwd`]:"$msg"; }' 
  115. EOF 
  116.  
  117. #rsyslog 
  118. #sed -i "s/SYSLOGD_OPTIONS=\"-c 5\"/SYSLOGD_OPTIONS=\"-c 2 -r -m 0\"/g"  /etc/sysconfig/rsyslog 
  119. #echo "*.* @192.168.122.200"  >> /etc/rsyslog.conf 

 


本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/1176492,如需转载请自行联系原作者

相关实践学习
日志服务之使用Nginx模式采集日志
本文介绍如何通过日志服务控制台创建Nginx模式的Logtail配置快速采集Nginx日志并进行多维度分析。
相关文章
configure: error: Could not find cups!
configure: error: Could not find cups!
478 0
|
应用服务中间件 nginx
Mac Nginx nginx: [emerg] mkdir() “/usr/local/var/run/nginx/client_body_temp“ failed ...
Mac Nginx nginx: [emerg] mkdir() “/usr/local/var/run/nginx/client_body_temp“ failed ...
307 2
|
关系型数据库 MySQL Linux
【Linux环境】centos安装mysql5.7.26报 ./mysqld: error while loading shared libraries: libaio.so.1: cannot op
【Linux环境】centos安装mysql5.7.26报 ./mysqld: error while loading shared libraries: libaio.so.1: cannot op
282 0
E: flAbsPath on /var/lib/dpkg/status failed - realpath (2: 没有那个文件或目录)
E: flAbsPath on /var/lib/dpkg/status failed - realpath (2: 没有那个文件或目录)
281 0
|
应用服务中间件 nginx
【已解决】nginx: [warn] conflicting server name “www.xxx.com“ on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name “www.xxx.com“ on 0.0.0.0:443, ignored
830 0
|
关系型数据库 MySQL 应用服务中间件
linux篇-Parse error: syntax error, unexpected ‘new’ (T_NEW) in /usr/local/nginx/html/cacti/lib/adodb
linux篇-Parse error: syntax error, unexpected ‘new’ (T_NEW) in /usr/local/nginx/html/cacti/lib/adodb
170 0
linux篇-Parse error: syntax error, unexpected ‘new’ (T_NEW) in /usr/local/nginx/html/cacti/lib/adodb
|
消息中间件 Linux
Linux - error: cannot open Packages database in /var/lib/rpm
Linux - error: cannot open Packages database in /var/lib/rpm
372 0
|
Ubuntu
WARNING: The scripts f2py, f2py3 and f2py3.9 are installed in ‘/home/ubuntu/.local/bin‘ which is no
WARNING: The scripts f2py, f2py3 and f2py3.9 are installed in ‘/home/ubuntu/.local/bin‘ which is no
598 0
WARNING: The scripts f2py, f2py3 and f2py3.9 are installed in ‘/home/ubuntu/.local/bin‘ which is no