1. 程式人生 > 實用技巧 >【筆記】Archlinux下配置rsyslog寫日誌到mysql

【筆記】Archlinux下配置rsyslog寫日誌到mysql

  1、archlinux的rsyslog不在官方包裡面 需要用yay在社群下載

  2、先配置資料庫

CREATE DATABASE Syslog;
USE Syslog;
CREATE TABLE SystemEvents
(
        ID int unsigned not null auto_increment primary key,
        CustomerID bigint,
        ReceivedAt datetime NULL,
        DeviceReportedTime datetime NULL,
        Facility smallint
NULL, Priority smallint NULL, FromHost varchar(60) NULL, Message text, NTSeverity int NULL, Importance int NULL, EventSource varchar(60), EventUser varchar(60) NULL, EventCategory int NULL, EventID int NULL, EventBinaryData
text NULL, MaxAvailable int NULL, CurrUsage int NULL, MinUsage int NULL, MaxUsage int NULL, InfoUnitID int NULL , SysLogTag varchar(60), EventLogType varchar(60), GenericFileName VarChar(60), SystemID int NULL ); CREATE TABLE SystemEventsProperties ( ID
int unsigned not null auto_increment primary key, SystemEventID int NULL , ParamName varchar(255) NULL , ParamValue text NULL );

資料庫名和下面的配置一致就好 但是表明和表結構是定死的 不能改

  3、建立使用者並賦予許可權

create user sys_使用者名稱@'localhost' identified by '使用者密碼';
grant all privileges on Syslog.* to 使用者名稱@'localhost';

  4、編輯/etc/rsyslog.conf 在最上面加上兩行

$Modload ommysql
*.* :ommysql:資料庫地址,資料庫名稱,使用者名稱,密碼

  5、重啟rsyslog服務 檢視服務狀態 如果報錯action 'action-0-ommysql' (module 'ommysql') message lost, could not be processed

    重新整理資料庫許可權 flush privileges