当前位置: 首页 > news >正文

MySQL 基线核查实录:标准化配置与命令验证全解析

在数据库系统交付、迁移或上线前,执行基线核查对于保障环境稳定、安全和高效至关重要。本文基于mysql标准化实践,从操作系统层与数据库层两个维度,详尽梳理了 MySQL 的关键基线项配置方法及对应命令与预期输出,适用于运维工程师、DBA、交付工程师等技术人员作为参考与操作手册。

一、操作系统层基线核查(Linux)

1. 磁盘空间

检查命令:

df -hP
df -i

预期输出:

数据库数据目录所在磁盘及 / 根目录的 Use% 小于 85%,inode 使用率合理,避免空间瓶颈。

2. NetworkManager 状态

CentOS 6 检查与禁用命令:

chkconfig --list NetworkManager
service NetworkManager stop
chkconfig NetworkManager off

CentOS 7 检查与禁用命令:

systemctl status NetworkManager.service
systemctl stop NetworkManager.service
systemctl disable NetworkManager.service

预期输出示例:

CentOS 6:

NetworkManager 0:关闭 1:关闭 2:关闭 3:关闭 4:关闭 5:关闭 6:关闭

CentOS 7:

Active: inactive (dead)

3. 防火墙状态

CentOS 6 命令:

chkconfig --list iptables
chkconfig --list ip6tables
service iptables stop
chkconfig iptables off
chkconfig ip6tables off

CentOS 7 命令:

systemctl status firewalld.service
systemctl stop firewalld.service
systemctl disable firewalld.service

预期输出示例:

firewalld.service - dynamic firewall daemon
Active: inactive (dead)

4. Selinux 配置

检查与禁用命令:

more /etc/selinux/config
getenforce
sed -i "s/SELINUX=.*/SELINUX=disabled/g" /etc/selinux/config
setenforce 0

预期输出:

配置文件中的 SELINUX=disabled,当前状态为 PermissiveDisabled

5. 系统资源限制

配置文件路径:

/etc/security/limits.conf

推荐配置内容:

* soft nofile 65536
* hard nofile 65536
* soft nproc 16384
* hard nproc 16384

6. PAM 模块配置

修改文件:

/etc/pam.d/login

添加内容:

session required pam_limits.so

7. 系统与数据库时区一致性

命令:

date -R
mysql> show global variables like 'system_time_zone';

预期输出:

操作系统与 MySQL 的时区设置保持一致,例如均为 CST+08:00

设置方法:

set time_zone = '+08:00';

8. 安装数据库依赖包

命令:

yum -y install gcc* gcc-c++ libaio-devel* libgcrypt

预期输出:

安装无报错,依赖包完整。

9. NUMA 禁用

检查命令:

grep -i numa /var/log/dmesg

预期输出示例:

NUMA turned off
numa=off

禁用命令:

grubby --args="numa=off" --update-kernel $(grubby --default-kernel)
reboot

二、数据库层基线核查(MySQL)

1. 定时备份任务配置

检查命令(Linux):

crontab -l

预期输出:

存在定时调用 mysqldump 等逻辑备份脚本的计划任务。

2. 会话连接参数

检查命令:

show global variables where variable_name in ('max_connections','max_user_connections','wait_timeout','interactive_timeout','connect_timeout');
show global status where variable_name in ('Max_used_connections');

预期输出示例:

max_connections = 5000
Max_used_connections = 600

推荐设置命令:

set global max_connections=5000;
set global max_user_connections=4000;
set global max_connect_errors=50000;
set global wait_timeout=7200;
set global interactive_timeout=7200;
set global connect_timeout=10;

3. Binlog 与 GTID 配置

检查命令:

show global variables where variable_name in ('log_bin','binlog_format','gtid_mode','enforce_gtid_consistency','expire_logs_days');

预期输出:

log_bin = ON
binlog_format = ROW
gtid_mode = ON
enforce_gtid_consistency = ON

设置命令(需已开启 binlog):

set global binlog_format='ROW';
set global gtid_mode=ON;
set global enforce_gtid_consistency=ON;
set global expire_logs_days=7;

4. 强一致性模式(双一模式)

检查命令:

show global variables where variable_name in ('sync_binlog','innodb_flush_log_at_trx_commit');

预期输出:

sync_binlog = 1
innodb_flush_log_at_trx_commit = 1

设置命令:

set global sync_binlog=1;
set global innodb_flush_log_at_trx_commit=1;

5. Redo 日志文件参数

检查命令:

show global variables where variable_name in ('innodb_log_file_size','innodb_log_files_in_group');

推荐配置(需重启生效):

innodb_log_file_size = 1048576000
innodb_log_files_in_group = 3

6. 缓存参数优化

命令:

show global variables where variable_name in ('sort_buffer_size','join_buffer_size','max_allowed_packet');

推荐设置:

set global sort_buffer_size=720896;
set global join_buffer_size=360448;
set global max_allowed_packet=1073741824;

7. 临时表缓存参数

命令:

show global variables where variable_name in ('max_heap_table_size','tmp_table_size');

推荐设置:

set global max_heap_table_size=16777216;
set global tmp_table_size=16777216;

8. InnoDB 缓冲池大小

命令:

show global variables where variable_name='innodb_buffer_pool_size';
free -h

推荐配置:

缓冲池大小为物理内存的 50% 至 80%,例如:

set global innodb_buffer_pool_size=134217728;

9. 事务隔离级别

检查命令:

show global variables where variable_name='transaction-isolation';

推荐配置:

set global transaction-isolation='READ-COMMITTED';

10. 字符集设置

检查命令:

show global variables where variable_name='character_set_server';

推荐配置:

set global character_set_server='utf8mb4';

11. 表名大小写敏感控制(需重启)

检查命令:

show global variables where variable_name='lower_case_table_names';

推荐配置:

在配置文件 my.cnf 中设置:

lower_case_table_names=1

12. 用户安全性核查

命令:

select user,host from mysql.user where authentication_string=password(user);

预期输出:

无用户名密码一致的账户。若存在,需及时修改用户密码。

总结

本基线核查清单涵盖 MySQL 在交付部署过程中需要重点关注的系统与数据库参数配置,确保环境符合最佳实践与安全要求。建议将核查内容固化为标准化流程,纳入 CMDB 自动化扫描或数据库上线前检查清单中。

IMG_6768 2.jpg
hhh6.jpg

相关文章:

  • (LeetCode 面试经典 150 题 ) 238. 除自身以外数组的乘积 (前缀和)
  • 考取华为HCIE-AI有什么用?
  • 机器学习3——参数估计之极大似然估计
  • vscode 使用教程
  • 麒麟系统使用-运用VSCode运行.NET工程
  • C++day04(大容量数据、科学记数法、浮点数的格式化)
  • LangChain4j(20)——调用百度地图MCP服务
  • 车载诊断架构--- 车载诊断中的引导式诊断
  • Node.js到底是什么
  • opi是什么
  • 面向大语言模型幻觉的关键数据集:系统性综述与分类法_DEEPSEEK
  • virtual box 配置ubuntu 22.04网络与SSH服务
  • 大模型在急性重型肝炎风险预测与治疗方案制定中的应用研究
  • 力扣刷题(第七十天)
  • 云计算与人工智能的融合:从弹性算力到智能云的IT新革命
  • CentOS 7 编译ClickHouse 24.8完整指南
  • 七天学会SpringCloud分布式微服务——04——Nacos配置中心
  • AI助力游戏设计——从灵感到行动-靠岸篇
  • 蓝牙工作频段与跳频扩频技术(FHSS)详解:面试高频考点与真题解析
  • 【开发杂谈】Auto Caption:使用 Electron 和 Python 开发实时字幕显示软件