CentOS7+Rsyslog+MySQL 搭建 Rsyslog 日志服务器

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

1、主机环境

rsyslog-server   10.11.66.218
rsyslog-client   10.11.66.225
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.7.1908 (Core)
[root@localhost ~]# uname -r
3.10.0-1062.el7.x86_64
[root@localhost ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           2.9G        140M        2.7G        8.9M        103M        2.7G
Swap:          3.0G          0B        3.0G
[root@localhost ~]# hostnamectl --static set-hostname rsyslog-server

2、rsyslog搭建

2.1、rsyslog-server搭建

[root@rsyslog-server ~]# cp /etc/rsyslog.conf{,.bak}
[root@rsyslog-server ~]# vim /etc/rsyslog.conf
$ModLoad imudp        # 使用udp协议,也可以使用tcp协议
$UDPServerRun 514     # 开启514端口
[root@rsyslog-server ~]# systemctl restart rsyslog.service
[root@rsyslog-server ~]# systemctl enable rsyslog.service

2.2、rsyslog-client

[root@localhost ~]# hostnamectl --static set-hostname rsyslog-client
[root@rsyslog-client ~]# yum -y install nginx
[root@rsyslog-client ~]# cp /etc/rsyslog.conf{,.bak}   # 良好的习惯,从备份配置文件开始
[root@rsyslog-client ~]# vim /etc/rsyslog.conf
[root@rsyslog-client ~]# egrep -v "^$|#" /etc/rsyslog.conf
$ModLoad imudp        # 使用udp协议,也可以使用tcp协议
$UDPServerRun 514     # 开启514端口
$WorkDirectory /var/lib/rsyslog
$ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
$IncludeConfig /etc/rsyslog.d/*.conf
$OmitLocalLogging on
$IMJournalStateFile imjournal.state
*.info;mail.none;authpriv.none;cron.none                @10.11.66.218  # 将日志存到远端rsyslog-server上
authpriv.*                                              /var/log/secure
mail.*                                                  -/var/log/maillog
cron.*                                                  /var/log/cron
*.emerg                                                 :omusrmsg:*
uucp,news.crit                                          /var/log/spooler
local7.*                                                /var/log/boot.log
[root@rsyslog-client ~]# systemctl restart rsyslog.service
[root@rsyslog-client ~]# systemctl enable rsyslog.service   # 以防万一
2.2.1、测试
[root@rsyslog-client ~]# systemctl restart nginx.service
[root@rsyslog-server ~]# tail /var/log/messages
Jul 18 17:17:47 rsyslog-server systemd: Stopped System Logging Service.
Jul 18 17:17:47 rsyslog-server systemd: Starting System Logging Service...
Jul 18 17:17:47 rsyslog-server rsyslogd: [origin software="rsyslogd" swVersion="8.24.0-52.el7_8.2" x-pid="2419" x-info="http://www.rsyslog.com"] start
Jul 18 17:17:47 rsyslog-server systemd: Started System Logging Service.
Jul 18 17:17:52 rsyslog-server systemd: Reloading.
Jul 18 17:18:15 rsyslog-client systemd: Starting The nginx HTTP and reverse proxy server...
Jul 18 17:18:15 rsyslog-client nginx: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jul 18 17:18:15 rsyslog-client nginx: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jul 18 17:18:15 rsyslog-client systemd: Failed to parse PID from file /run/nginx.pid: Success
Jul 18 17:18:15 rsyslog-client systemd: Started The nginx HTTP and reverse proxy server.
# rsyslog-server成功获取到rsyslog-client的日志

2.3、rsyslog日志分类

# 只需要在rsyslog-server上操作即可
[root@rsyslog-server ~]# vim /etc/rsyslog.d/default.conf
尽量避免修改主配置文件,我们在 '/etc/rsyslog.d/'中新建'default.conf',追加如下模板:
#### GLOBAL DIRECTIVES ####
# Use default timestamp format  # 使用自定义的格式
  $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat
  $template myFormat,"%timestamp% %fromhost-ip% %syslogtag% %msg%\n"
  $ActionFileDefaultTemplate myFormat
# 根据客户端的IP单独存放主机日志在不同目录,rsyslog需要手动创建
  $template RemoteLogs,"/var/log/rsyslog/%fromhost-ip%/%syslogtag%_%$YEAR%-%$MONTH%-%$DAY%-%$hour%:%$minute%.log"
# 排除本地主机IP日志记录,只记录远程主机日志
  :fromhost-ip, !isequal, "127.0.0.1" ?RemoteLogs
# 忽略之前所有的日志,远程主机日志记录完之后不再继续往下记录
  & ~
[root@rsyslog-server ~]# egrep -v "^$|#" /etc/sysconfig/rsyslog
SYSLOGD_OPTIONS="-r -m 0 -c 2"
[root@rsyslog-server ~]# mkdir /var/log/rsyslog
[root@rsyslog-server ~]# chmod a+w /var/log/rsyslog/
[root@rsyslog-server ~]# systemctl restart rsyslog.service
2.3.1、测试
[root@rsyslog-client ~]# systemctl restart nginx.service
[root@rsyslog-server ~]# cd /var/log/rsyslog/
[root@rsyslog-server rsyslog]# ls
10.11.66.225
[root@rsyslog-server rsyslog]# cd 10.11.66.225/
[root@rsyslog-server 10.11.66.225]# ls
nginx:_2020-07-18-17:24.log  systemd:_2020-07-18-17:24.log
[root@rsyslog-server 10.11.66.225]# cat nginx\:_2020-07-18-17\:24.log  # nginx没有操作,所以没有日志内容
[root@rsyslog-server 10.11.66.225]# cat systemd\:_2020-07-18-17\:24.log   # systemctl的操作日志,被记录在systemd日志下
Jul 18 17:24:54 10.11.66.225 systemd:  Starting The nginx HTTP and reverse proxy server...
Jul 18 17:24:54 10.11.66.225 systemd:  Failed to parse PID from file /run/nginx.pid: Success
Jul 18 17:24:54 10.11.66.225 systemd:  Started The nginx HTTP and reverse proxy server.

3、基于mysql存储日志信息

3.1、安装mariadb

# 注意主机名
[root@rsyslog-server ~]# yum -y install mariadb mariadb-server
[root@rsyslog-client ~]# yum -y install rsyslog-mysql mariadb-server

3.2、配置mariadb数据库

[root@rsyslog-server ~]# systemctl enable mariadb.service --now  # rsyslog-server和rsyslog-client都需要启动,方便测试
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

3.3、配置rsyslog-server

[root@rsyslog-server ~]# mysql_secure_installation   # 数据库初始化
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.
Set root password? [Y/n] y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
 ... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove anonymous users? [Y/n] y
 ... Success!
Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] n
 ... skipping.
By default, MariaDB comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
 ... Success!
Cleaning up...
All done!  If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
[root@rsyslog-server ~]# mysql -uroot -p  # 不要在终端明文输入密码
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 11
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> create database rsyslog;   # 创一个rsyslog库
Query OK, 1 row affected (0.01 sec)
MariaDB [(none)]> show databases;    # 查看是否创建成功
+--------------------+  
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| rsyslog            |
+--------------------+
4 rows in set (0.01 sec)
MariaDB [(none)]> grant all on rsyslog.* to "rsyslog"@"10.11.66.%" identified by "1234.com";   # 创建一个rsyslog的用户
Query OK, 0 rows affected (0.00 sec)
MariaDB [(none)]> flush privileges;   # 刷新授权
Query OK, 0 rows affected (0.00 sec)
[root@rsyslog-server ~]# cp /etc/my.cnf{,.bak}
[root@rsyslog-server ~]# vim /etc/my.cnf
skip_name_resolve=on        # 这个参数是禁止域名解析
innodb_file_per_table=on    # 共享表空间转化为独立表空间
[root@rsyslog-server ~]# systemctl restart mariadb.service

3.4、配置rsyslog-client

[root@rsyslog-client ~]# cat /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
USE rsyslog;
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
);
[root@rsyslog-client ~]# mysql -ursyslog -h 10.11.66.218 -p  # 测试远程连接没有问题
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 12
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
[root@rsyslog-client ~]# mysql -ursyslog -h 10.11.66.218 -p < /usr/share/doc/rsyslog-8.24.0/mysql-createDB.sql
Enter password:

3.5、测试

[root@rsyslog-client ~]# vim /etc/rsyslog.conf
#### MODULES ####
$ModLoad ommysql
#### RULES ####
#*.info;mail.none;authpriv.none;cron.none                @10.11.66.218
*.info;mail.none;authpriv.none;cron.none               :ommysql:10.11.66.218,rsyslog,rsyslog,1234.com
[root@rsyslog-client ~]# systemctl restart rsyslog.service
[root@rsyslog-client ~]# systemctl restart nginx.service
[root@rsyslog-client ~]# mysql -ursyslog -h 10.11.66.218 -p
Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 7
Server version: 5.5.65-MariaDB MariaDB Server
Copyright (c) 2000, 2018, 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 |
| rsyslog            |
+--------------------+
2 rows in set (0.00 sec)
MariaDB [(none)]> use rsyslog;
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 [rsyslog]> show tables;
+------------------------+
| Tables_in_rsyslog      |
+------------------------+
| SystemEvents           |
| SystemEventsProperties |
+------------------------+
2 rows in set (0.00 sec)
MariaDB [rsyslog]> select * from SystemEvents;
+----+------------+---------------------+---------------------+----------+----------+----------------+---------------------------------------------------------------------------------------------------------------------------------+------------+------------+-------------+-----------+---------------+---------+-----------------+--------------+-----------+----------+----------+------------+-----------+--------------+-----------------+----------+
| ID | CustomerID | ReceivedAt          | DeviceReportedTime  | Facility | Priority | FromHost       | Message                                                                                                                         | NTSeverity | Importance | EventSource | EventUser | EventCategory | EventID | EventBinaryData | MaxAvailable | CurrUsage | MinUsage | MaxUsage | InfoUnitID | SysLogTag | EventLogType | GenericFileName | SystemID |
+----+------------+---------------------+---------------------+----------+----------+----------------+---------------------------------------------------------------------------------------------------------------------------------+------------+------------+-------------+-----------+---------------+---------+-----------------+--------------+-----------+----------+----------+------------+-----------+--------------+-----------------+----------+
|  1 |       NULL | 2020-07-18 18:00:12 | 2020-07-18 18:00:12 |        3 |        6 | rsyslog-client | Stopping System Logging Service...                                                                                              |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | systemd:  | NULL         | NULL            |     NULL |
|  2 |       NULL | 2020-07-18 18:00:12 | 2020-07-18 18:00:12 |        5 |        6 | rsyslog-client |  [origin software="rsyslogd" swVersion="8.24.0-52.el7_8.2" x-pid="17500" x-info="http://www.rsyslog.com"] exiting on signal 15. |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | rsyslogd: | NULL         | NULL            |     NULL |
|  3 |       NULL | 2020-07-18 18:00:12 | 2020-07-18 18:00:12 |        3 |        6 | rsyslog-client | Stopped System Logging Service.                                                                                                 |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | systemd:  | NULL         | NULL            |     NULL |
|  4 |       NULL | 2020-07-18 18:00:12 | 2020-07-18 18:00:12 |        3 |        6 | rsyslog-client | Starting System Logging Service...                                                                                              |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | systemd:  | NULL         | NULL            |     NULL |
|  5 |       NULL | 2020-07-18 18:00:17 | 2020-07-18 18:00:17 |        5 |        6 | rsyslog-client |  [origin software="rsyslogd" swVersion="8.24.0-52.el7_8.2" x-pid="18007" x-info="http://www.rsyslog.com"] start                 |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | rsyslogd: | NULL         | NULL            |     NULL |
|  6 |       NULL | 2020-07-18 18:00:17 | 2020-07-18 18:00:17 |        3 |        6 | rsyslog-client | Started System Logging Service.                                                                                                 |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | systemd:  | NULL         | NULL            |     NULL |
|  7 |       NULL | 2020-07-18 18:01:01 | 2020-07-18 18:01:01 |        3 |        6 | rsyslog-client | Started Session 78 of user root.                                                                                                |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | systemd:  | NULL         | NULL            |     NULL |
|  8 |       NULL | 2020-07-18 18:02:35 | 2020-07-18 18:02:35 |        3 |        6 | rsyslog-client | Starting The nginx HTTP and reverse proxy server...                                                                             |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | systemd:  | NULL         | NULL            |     NULL |
|  9 |       NULL | 2020-07-18 18:02:35 | 2020-07-18 18:02:35 |        3 |        6 | rsyslog-client | nginx: the configuration file /etc/nginx/nginx.conf syntax is ok                                                                |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | nginx:    | NULL         | NULL            |     NULL |
| 10 |       NULL | 2020-07-18 18:02:35 | 2020-07-18 18:02:35 |        3 |        6 | rsyslog-client | nginx: configuration file /etc/nginx/nginx.conf test is successful                                                              |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | nginx:    | NULL         | NULL            |     NULL |
| 11 |       NULL | 2020-07-18 18:02:35 | 2020-07-18 18:02:35 |        3 |        6 | rsyslog-client | Failed to parse PID from file /run/nginx.pid: Success                                                                           |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | systemd:  | NULL         | NULL            |     NULL |
| 12 |       NULL | 2020-07-18 18:02:35 | 2020-07-18 18:02:35 |        3 |        6 | rsyslog-client | Started The nginx HTTP and reverse proxy server.                                                                                |       NULL |       NULL | NULL        | NULL      |          NULL |    NULL | NULL            |         NULL |      NULL |     NULL |     NULL |          1 | systemd:  | NULL         | NULL            |     NULL |
+----+------------+---------------------+---------------------+----------+----------+----------------+---------------------------------------------------------------------------------------------------------------------------------+------------+------------+-------------+-----------+---------------+---------+-----------------+--------------+-----------+----------+----------+------------+-----------+--------------+-----------------+----------+
12 rows in set (0.00 sec)


相关实践学习
如何快速连接云数据库RDS MySQL
本场景介绍如何通过阿里云数据管理服务DMS快速连接云数据库RDS MySQL,然后进行数据表的CRUD操作。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
1天前
|
SQL 关系型数据库 MySQL
MySQL事务日志-Undo Log工作原理分析
事务的持久性是交由Redo Log来保证,原子性则是交由Undo Log来保证。如果事务中的SQL执行到一半出现错误,需要把前面已经执行过的SQL撤销以达到原子性的目的,这个过程也叫做"回滚",所以Undo Log也叫回滚日志。
MySQL事务日志-Undo Log工作原理分析
|
11天前
|
SQL 存储 关系型数据库
MySQL/SqlServer跨服务器增删改查(CRUD)的一种方法
通过上述方法,MySQL和SQL Server均能够实现跨服务器的增删改查操作。MySQL通过联邦存储引擎提供了直接的跨服务器表访问,而SQL Server通过链接服务器和分布式查询实现了灵活的跨服务器数据操作。这些技术为分布式数据库管理提供了强大的支持,能够满足复杂的数据操作需求。
55 12
|
17天前
|
SQL 存储 关系型数据库
Mysql并发控制和日志
通过深入理解和应用 MySQL 的并发控制和日志管理技术,您可以显著提升数据库系统的效率和稳定性。
73 10
|
13天前
|
安全 关系型数据库 MySQL
MySQL崩溃保险箱:探秘Redo/Undo日志确保数据库安全无忧!
《MySQL崩溃保险箱:探秘Redo/Undo日志确保数据库安全无忧!》介绍了MySQL中的三种关键日志:二进制日志(Binary Log)、重做日志(Redo Log)和撤销日志(Undo Log)。这些日志确保了数据库的ACID特性,即原子性、一致性、隔离性和持久性。Redo Log记录数据页的物理修改,保证事务持久性;Undo Log记录事务的逆操作,支持回滚和多版本并发控制(MVCC)。文章还详细对比了InnoDB和MyISAM存储引擎在事务支持、锁定机制、并发性等方面的差异,强调了InnoDB在高并发和事务处理中的优势。通过这些机制,MySQL能够在事务执行、崩溃和恢复过程中保持
42 3
|
2月前
|
存储 Oracle 关系型数据库
【赵渝强老师】MySQL InnoDB的数据文件与重做日志文件
本文介绍了MySQL InnoDB存储引擎中的数据文件和重做日志文件。数据文件包括`.ibd`和`ibdata`文件,用于存放InnoDB数据和索引。重做日志文件(redo log)确保数据的可靠性和事务的持久性,其大小和路径可由相关参数配置。文章还提供了视频讲解和示例代码。
160 11
【赵渝强老师】MySQL InnoDB的数据文件与重做日志文件
|
29天前
|
SQL 存储 缓存
MySQL进阶突击系列(02)一条更新SQL执行过程 | 讲透undoLog、redoLog、binLog日志三宝
本文详细介绍了MySQL中update SQL执行过程涉及的undoLog、redoLog和binLog三种日志的作用及其工作原理,包括它们如何确保数据的一致性和完整性,以及在事务提交过程中各自的角色。同时,文章还探讨了这些日志在故障恢复中的重要性,强调了合理配置相关参数对于提高系统稳定性的必要性。
|
2月前
|
SQL 关系型数据库 MySQL
【赵渝强老师】MySQL的全量日志文件
MySQL全量日志记录所有操作的SQL语句,默认禁用。启用后,可通过`show variables like %general_log%检查状态,使用`set global general_log=ON`临时开启,执行查询并查看日志文件以追踪SQL执行详情。
|
2月前
|
关系型数据库 MySQL 数据库
【赵渝强老师】MySQL的binlog日志文件
MySQL的binlog日志记录了所有对数据库的更改操作(不包括SELECT和SHOW),主要用于主从复制和数据恢复。binlog有三种模式,可通过设置binlog_format参数选择。示例展示了如何启用binlog、设置格式、查看日志文件及记录的信息。
172 6
|
2月前
|
SQL 关系型数据库 MySQL
【赵渝强老师】MySQL的慢查询日志
MySQL的慢查询日志用于记录执行时间超过设定阈值的SQL语句,帮助数据库管理员识别并优化性能问题。通过`mysqldumpslow`工具可查看日志。本文介绍了如何检查、启用及配置慢查询日志,并通过实例演示了慢查询的记录与分析过程。
185 3
|
2月前
|
存储 Oracle 关系型数据库
【赵渝强老师】MySQL的撤销日志文件和错误日志文件
本文介绍了MySQL的物理存储结构,重点讲解了InnoDB存储引擎中的撤销日志文件(undo log)和错误日志文件。从MySQL 8.0开始,默认生成两个10MB的undo表空间文件,并支持动态扩容和收缩。错误日志文件记录了MySQL启动、运行、关闭过程中的问题,通过示例展示了如何查看和使用这些日志。