syslog-ng+loganalyzer log system install guide

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
云数据库 RDS MySQL,高可用系列 2核4GB
简介:

 
 
  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日志并进行多维度分析。
相关文章
|
应用服务中间件 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 ...
323 2
|
8月前
|
人工智能 Ubuntu 机器人
【ubuntu】手把手教你解决ubuntu报错openssh-server E: Sub-process /usr/bin/dpkg returned an error code (1)
【ubuntu】手把手教你解决ubuntu报错openssh-server E: Sub-process /usr/bin/dpkg returned an error code (1)
833 0
|
JavaScript NoSQL MongoDB
mongodb踩坑- C:\Program Files\nodejs\node_cache\_logs\2019-01-08T08_49_25_665Z-debug.log
mongodb踩坑- C:\Program Files\nodejs\node_cache\_logs\2019-01-08T08_49_25_665Z-debug.log
68 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
179 0
linux篇-Parse error: syntax error, unexpected ‘new’ (T_NEW) in /usr/local/nginx/html/cacti/lib/adodb
|
Ruby
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.错误解决办法
ERROR: While executing gem ... (Gem::FilePermissionError) You don't have write permissions for the /usr/bin directory.错误解决办法
2683 0
|
关系型数据库 MySQL 数据安全/隐私保护

热门文章

最新文章