日志:历史日志

  历史事件:

    时间记录,事件的关键性程度,loglevel  

  系统日志服务:

    syslogd,守护进程

      syslogd:system

      klogd:kernel

     rsyslog:

      syslogd

      klogd

      多线程:

      UDP,TCP,SSL,TLS,

      Mysql,PGSQL

      强大的过滤器,可实现过滤日志信息中的任何部分;

      自定义输出格式;

  日志收集方:

 priority:

  debug,info,notice,warn(warning),err(error),crit(critical),alert,emerg(panic)

  调试-信息级别-引起注意-警告-产生错误-蓝色警报-橙色警报-要挂了。

  指定级别:

    *:表示所以级别

    none:没用级别

    priority:此级别及更高级别的日志信息;

  [root@localhost ~]# rpm -ql rsyslog    

    /etc/rsyslog.conf   主配置文件

    rsyslogd      主程序;

    /etc/rc.d/init.d/rsyslog  服务脚本;

root@localhost ~]# vim /etc/rsyslog.conf  

# rsyslog v5 configuration file

# For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html
# If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html

#### MODULES ####

$ModLoad imuxsock # provides support for local system logging (e.g. via logger command) //支持本地日志收集的模块
$ModLoad imklog   # provides kernel logging support (previously done by rklogd) //支持本地内核日志收集的模块
#$ModLoad immark  # provides --MARK-- message capability

# Provides UDP syslog reception
#$ModLoad imudp
#$UDPServerRun 514

# Provides TCP syslog reception
#$ModLoad imtcp
#$InputTCPServerRun 514

#### GLOBAL DIRECTIVES #### 全局参数指定

# Use default timestamp format
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat

# File syncing capability is disabled by default. This feature is usually not required,
# not useful and an extreme performance hit
#$ActionFileEnableSync on

# Include all config files in /etc/rsyslog.d/
$IncludeConfig /etc/rsyslog.d/*.conf

#### RULES ####

# Log all kernel messages to the console.
# Logging much else clutters up the screen.
#kern.*                                                 /dev/console  //

# Log anything (except mail) of level info or higher.
# Don't log private authentication messages!
*.info;mail.none;authpriv.none;cron.none                /var/log/messages   //

# The authpriv file has restricted access.
authpriv.*                                              /var/log/secure

# Log all the mail messages in one place.
mail.*                                                  -/var/log/maillog    //-号表示异步写入;

# Log cron stuff
cron.*                                                  /var/log/cron

# Everybody gets emergency messages
*.emerg                                                 *  //通知所有用户在线的用户系统要挂了

# Save news errors of level crit and higher in a special file.
uucp,news.crit                                          /var/log/spooler

# Save boot messages also to boot.log
local7.*                                                /var/log/boot.log  //自定义日志

# ### begin forwarding rule ###
# The statement between the begin ... end define a SINGLE forwarding
# rule. They belong together, do NOT split them. If you create multiple
# forwarding rules, duplicate the whole block!
# Remote Logging (we use TCP for reliable delivery)
#
# An on-disk queue is created for this action. If the remote host is
# down, messages are spooled to disk and sent when it is up again.
#$WorkDirectory /var/lib/rsyslog # where to place spool files
#$ActionQueueFileName fwdRule1 # unique name prefix for spool files
#$ActionQueueMaxDiskSpace 1g   # 1gb space limit (use as much as possible)
#$ActionQueueSaveOnShutdown on # save messages to disk on shutdown
#$ActionQueueType LinkedList   # run asynchronously
#$ActionResumeRetryCount -1    # infinite retries if host is down
# remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional
#*.* @@remote-host:514
# ### end of the forwarding rule ###

# A template to for higher precision timestamps + severity logging
$template SpiceTmpl,"%TIMESTAMP%.%TIMESTAMP:::date-subseconds% %syslogtag% %syslogseverity-text%:%msg:::sp-if-no-1st-sp%%msg:::drop-last-lf%\n"

:programname, startswith, "spice-vdagent"       /var/log/spice-vdagent.log;SpiceTmpl
(END)

主服务器测试:

root@localhost ~]# vim /etc/ssh/sshd_config  

    添加:SyslogFacility local2

      service sshd reload

root@localhost ~]# vim /etc/rsyslog.conf

   local7.*  /var/log/boot.log 下添加如下:

   local2.*  /var/log/sshd.log

   重启服务:servicee rsyslog restart

  测试:只要复制下当前xshell会话即可,然后查看日志;

总结:

  文件记录的日志的格式:

    时间产生记录的日期时间      主机     进程(PID) :事件内容

  有些日志记录二进制格式:/var/log/wtmp,/var/logbtmp  

    /var/log/wtmp :当前系统上成功登陆的日志;

      last 查看

    /var/log/btmp:当前系统上失败的登陆尝试;

      lastb

    lastlog   查看哪些用户登陆过系统,

      mail                                       **Never logged in** 表示从来没用登陆过系统;

--------------------------------------------------------------------------------------------------

一:rsyslog服务器:

1,主服务器:root@localhost ~]# vim /etc/rsyslog.conf

  # Provides UDP syslog reception
  $ModLoad imudp  去掉#号
  $UDPServerRun 514   去掉#号

  # Provides TCP syslog reception
  $ModLoad imtcp    去掉#号
  $InputTCPServerRun 514    去掉#号

  service rsyslog restart

  netstat -tunl

3:主服务器查看日志:

  tail /var/log/messages

2,从服务器:

  主服务器:root@localhost ~]# vim /etc/rsyslog.conf

  *.info;mail.none;authpriv.none;cron.none  @172.16.100.6  //把从服务器的日志传输给主日志服务器;

  service rsyslog restart

  yum -y install vsftpd

二:  配置下rsyslog如何记录到mysql服务中;

 1:从服务安装mysql;

 查看包:   rpm -q mariadb

安装: [root@localhost ~]# yum -y install mariadb-server

 启动: [root@localhost ~]# systemctl start mariadb.service

 查看监听:ss -tnlp

 进入mysql数据库: [root@localhost ~]# mysql -uroot -p  直接回车,默认密码为空;

      mariaDB [(none)]> use mysql;

      MariaDB [mysql]> update user set password=password('password') where user='root';

     MariaDB [(none)]> GRANT ALL ON Syslog.* TO 'syslog'@'192.168.%.%' IDENTIFIED BY 'syslogpass';

     MariaDB [mysql]> flush privileges;

   MariaDB [mysql]> quit

  root@localhost ~]# vim /etc/my.cnf

    [mysqld]

     skip_name_resolve = on
     innodb_file_per_table = on

   [root@localhost ~]# systemctl restart mariadb.service

   [root@localhost ~]# ss -tnl

  测试:

  [root@localhost ~]# mysql -usyslog -psyslogpass -h 192.168.214.140
  Welcome to the MariaDB monitor.  Commands end with ; or \g.
  Your MariaDB connection id is 3
  Server version: 5.5.56-MariaDB MariaDB Server

  Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

  MariaDB [(none)]> show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | test               |
  +--------------------+
  2 rows in set (0.00 sec)

  MariaDB [(none)]>

4:验证

  [root@localhost ~]# mysql -usyslog -psyslogpass -h 192.168.214.140
  Welcome to the MariaDB monitor.  Commands end with ; or \g.
  Your MariaDB connection id is 5
  Server version: 5.5.56-MariaDB MariaDB Server

  Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

  Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.  MariaDB [(none)]> show databases;
  +--------------------+
  | Database           |
  +--------------------+
  | information_schema |
  | Syslog             |
  | test                 |
  +--------------------+
  3 rows in set (0.00 sec)
  MariaDB [(none)]> use Syslog
  Reading table information for completion of table and column names
  You can turn off this feature to get a quicker startup with -A

  Database changed
  MariaDB [Syslog]> show tables;
  +------------------------+
  | Tables_in_Syslog       |
  +------------------------+
  | SystemEvents           |
  | SystemEventsProperties |
  +------------------------+
  2 rows in set (0.00 sec)

6:查看日志

  MariaDB [Syslog]> show tables;
  
+------------------------+
  | Tables_in_Syslog       |
  +------------------------+
  | SystemEvents           |
  | SystemEventsProperties |
  +------------------------+
  2 rows in set (0.00 sec)

  MariaDB [Syslog]>
  MariaDB [Syslog]> show tables;
  +------------------------+
  | Tables_in_Syslog       |
  +------------------------+
  | SystemEvents           |
  | SystemEventsProperties |
  +------------------------+
  2 rows in set (0.00 sec)

  MariaDB [Syslog]> select * from SystemEvents\G;

  

2:主服务器端想要rsyslog日志存储到mysql服务器中,使用 yum list all rsyslog*,有一个rsyslog-mysql的程序包,安装即可。

  yum -y install rsyslog-mysql

  [root@localhost log]# rpm -ql rsyslog-mysql

    /lib64/rsyslog/ommysql.so
    /usr/share/doc/rsyslog-mysql-5.8.10
    /usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql

 3:[root@localhost log]# mysql -usyslog -h192.168.214.140 -p < /usr/share/doc/rsyslog-mysql-5.8.10/createDB.sql
  Enter password: syslogpass  //192.168.214.140是从服务器的IP地址
 5:[root@localhost log]# vim /etc/rsyslog.conf
     #### MODULES ####

      $ModLoad ommysql  手动添加;

     #### RULES ####

      *.info;mail.none;authpriv.none;cron.none                :ommysql:192.168.214.140,Syslog,syslog,syslogpass

    service rsyslog restart

  记录日志:yum -y install vsftp

---------------------------------------------

主服务器:

  yum install httpd php php-mysql

  vim /var/www/html/index.php

    <?php
            $conn = mysql_connect('192.168.214.140','syslog','syslogpass');
          if  ($conn)
                  echo "OK";
          else
                  echo "Failure";
         ?>

  service httpd start

  网页测试:192.168.214.146  是否显示OK

下载loganalyzer-3.6.5.tar.gz

tar xf alyzer-3.6.5.tar.gz

mv alyzer-3.6.5 /var/www/html/log

cd /var/www/html/log

ls

cd ..

ls

mv log/src loganalyzer

ls

cd loganalyzer

cd ..

cd log

ls

ls contrib/

cp conrtib/*  ../loganalyzer/

cd ../loganalyzer/

chmod +x *.sh

./configure.sh

./secure.sh

chmod 666 config.php

访问:192.168.214.145/loganalyzer/install.php
~     

    yum -y install php-gd

    service httpd restart

 

 

      

//支持本地日志收集的模块

转载于:https://www.cnblogs.com/Juvenile/p/8046362.html

rsyslog及loganalyzer相关推荐

  1. rsyslog+mysql+loganalyzer 环境搭建日志服务器

    环境:CentOS6.6 rsyslog+mysql+loganalyzer 环境搭建日志服务器 Client端:    192.168.2.10 MySQL服务器:  192.168.2.11 # ...

  2. rsyslog与mysql可以是同一台_关于rsyslog和loganalyzer使用

    系统日志太多太分散的话就需要整合,并且分析,所以就有了这样一套东西,这样就大大的减轻了系统管理员的压力,不过现在这篇只是小试牛刀,很多应用功能还是没有用到,例如自定义日志收集过滤, 日志分析图表,等等 ...

  3. sylog mysql_syslog-ng+loganalyzer搭建日志集中监控平台

    这里还是承接同事的需求,想要将所有网络设备的日志汇总后在一个平台上进行展示.在上一篇syslog-ng日志应用详解中提到了,通过syslog-ng创建日志集中服务器.可以通过syslog-ng+log ...

  4. mysql 搭建日志服务器_rsyslog+mysql+loganalyzer 环境搭建日志服务器

    环境:CentOS6.6 rsyslog+mysql+loganalyzer 环境搭建日志服务器 Client端:192.168.2.10 MySQL服务器:192.168.2.11 # Client ...

  5. Syslog日志服务器配置 For CentOS 7.8(Syslog+LogAnalyzer+LAMP)

    声明:本教程仅供学习.研究.测试使用,本文作者不承担任何法律责任! 本次中央日志服务器采用rsyslog提供日志接收服务,Mariadb作为后端数据库提供日志存储服务, 一.安装CentOS 7操作系 ...

  6. android日志收集存入mysql_rsyslog+analyzer+mysql实现日志收集展示

    why->what->where->when->who->how 1.为什么要进行日志收集?为什么要用到rsyslog? 日志是我们对系统和应用程序的运行状况分析的根本依 ...

  7. python视频人脸检测_OpenCV + python 实现人脸检测(基于照片和视频进行检测)

    OpenCV + python 实现人脸检测(基于照片和视频进行检测) Haar-like 通俗的来讲,就是作为人脸特征即可. Haar特征值反映了图像的灰度变化情况.例如:脸部的一些特征能由矩形特征 ...

  8. html中单引号与双引号区别,JS 和 HTML 中的单引号与双引号

    JS中的单引号与双引号 HTML中的单引号与双引号很简单,就是两个字符实体: 显示 描述 实体名称 实体编号 " 双引号.引号 " " ' 单引号.撇号 ' ' x 1 ...

  9. linux点滴yan

    运维学习 进程被杀死的几种命令 https://blog.csdn.net/whdxjbw/article/details/80681191 lsof -i:{端口号} netstat -tunlp| ...

  10. rsync工具介绍(资料)

    2019独角兽企业重金招聘Python工程师标准>>> 1. rsync工具介绍(非常重要) 备份的几种形式 1.正常备份(Normal): 也叫完全备份.正常备份是最普遍的一种备份 ...

最新文章

  1. FD.io/VPP — 流量追踪
  2. dynamic change date type to sap.ca.ui.model.type.Date in Debugger
  3. activiti表单设计器_基于Vue,ElementUI开发的一款表单设计器
  4. python之使用numpy实现从二维数组中找出行(子数组)为特定值的索引
  5. 彼得林奇:赚钱密码(1990年一次演讲)
  6. EV录屏怎么实现选区录屏
  7. 用几行代码恶搞别人的电脑
  8. 【labelme】制作标签数据的完整流程
  9. matlab解一元三次方程组,如何用matlab求解一元高次方程
  10. 使用this.$refs.XXX修改某个元素样式并添加点击事件
  11. android nfc 启动流程,android-NFC-如何使用NDEF_DISCOVERED启动应用程序
  12. 中华人民共和国民法典
  13. 国产操作系统Deepin的安装
  14. 以太坊白皮书(中文版)
  15. 搭建智能语音助手思路整理
  16. root 红米note5_红米Note5 root教程_红米Note5卡刷root包来获取root权限
  17. 警告 1 warning C4996: 'scanf': This function or variable may be unsafe. Consider using scanf_s instead
  18. 寒假训练赛复盘2.9
  19. python全栈s3视频教程笔记 Day1
  20. html课堂笔记2.24

热门文章

  1. linux查看app路径下文件卡死
  2. prism.js让页面代码变漂亮
  3. csdn 博客添加目录方法
  4. JavaWeb之Cookie与Session
  5. java 二进制转十进制的算法_java中位运算与整数的十进制转二进制
  6. html5标签对js影响,浅谈JS对html标签的属性的干预以及对CSS样式表属性的干预
  7. eclipse-Tomcat运行项目笔记
  8. 列车控制matlab仿真,基于matlab的列车纵向碰撞建模仿真研究
  9. 怎么高速旋转_洗衣机怎么选比较好,滚筒洗衣机和波轮洗衣机哪种更好?
  10. python与pycharm的作用_JSON 在pycharm 与python 三者有什么关系?JSON有什么作用?