本文主要是介绍RHEL7.X MySQL 5.7.X 数据库 标准建议 安装手册,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
MySQL Expert REVIEW
RHEL7.X
MySQL 5.7.X 数据库
安装手册
目 录
系统需求... 1
安装方式... 1
介质准备... 1
mysql 用户创建... 1
安装目录规划... 1
文件系统配置... 2
MySQL 安装... 3
OS 优化配置... 6
关闭不必要的服务... 6
优化IO调度设置... 6
配置系统参数... 6
调整相关的参数... 7
系统需求
安装方式
本文介绍的是在linux RHEL 7.x版本的操作系统上,安装 mysql 5.7 安装步骤。
安装方式:
- Mysql 2进制bin 包安装在服务器本地磁盘上。
- 数据文件都存放在本地磁盘中
介质准备
mysql-5.7.27-el7-x86_64.tar
下载链接:
https://cdn.mysql.com//Downloads/MySQL-5.7/mysql-5.7.27-el7-x86_64.tar
mysql 用户创建
groupadd mysql
useradd -g mysql mysql
安装目录规划
以下目录供参考:
目录 | 文件系统路径 | 备注 |
basedir | /mysql | Mysql 软件目录 |
datadir | /data | Mysql 数据文件目录 |
tmpdir | /data/tmp | Mysql 临时文件目录 |
文件系统配置
建议使用 xfs 文件系统:
1.初始化磁盘空间
pvcreate /dev/sdb
pvdisplay
vgcreate mysqlvg /dev/sdb
vgdisplay
lvcreate -L 3999G -n mysql /dev/mysqlvg
2.格式化成xfs文件系统:
mkfs.xfs /dev/mysqlvg/mysql
mount –o rw,noatime,nodiratime,nobarrier,logbufs=8,logbsize=32k /dev/mysqlvg/mysql /data
#vi /etc/fstab
/dev/mysqlvg/mysql /data ext4 defaults 1 2
文件系统属主设置:
chown mysql:mysql /mysql
chown -R mysql:mysql /data
MySQL 安装
解压mysql安装包:
tar xvf mysql-5.7.XXX.tar –C /mysql
初始化mysql:
使用-initialize-insecure 为 root@local 用户生成空密码,后续需要设置密码;
cd /mysql
./bin/mysqld --no-defaults --user=mysql --basedir=/mysql
--datadir=/data --initialize-insecure
配置mysql my.cnf 配置文件:
My.cnf 优化调整了部分参数,具体部分参数需要结合实际环境适当调整;
vi /etc/my.cnf
[client]
port = 3306
socket = /data/mysql.sock
[mysql]
prompt='mysql [\h] {\u} (\d) > '
[mysqld]
# basic settings #
user = mysql
port = 3306
socket = /data/mysql.sock
basedir = /mysql
datadir = /data/
character-set-server = utf8mb4
transaction_isolation = READ-COMMITTED
explicit_defaults_for_timestamp = 1
max_allowed_packet = 64M
event_scheduler = 1
query_cache_size = 0
query_cache_type = 0
open_files_limit = 65535
# connection #
interactive_timeout = 1800
wait_timeout = 1800
lock_wait_timeout = 1800
skip_name_resolve = 1
max_connections = 1024
max_connect_errors = 1000000
# table cache performance settings
table_open_cache = 4096
table_definition_cache = 4096
table_open_cache_instances = 64
# session memory settings #
read_buffer_size = 16M
read_rnd_buffer_size = 32M
sort_buffer_size = 32M
tmp_table_size = 64M
join_buffer_size = 128M
thread_cache_size = 64
# innodb settings #
#根据服务器实际内存配置 一般不要超过服务器总内存 80%
innodb_buffer_pool_size = 32G
# 8 default to buffer pool size / 2GB (so 16 for 32g pool) if concurrency is high
innodb_buffer_pool_instances = 16
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
innodb_lru_scan_depth = 4096
innodb_lock_wait_timeout = 5
# 根据您的服务器IOPS能力适当调整
# 一般配普通SSD盘的话,可以调整到 10000 - 20000
# 配置高端PCIe SSD卡的话,则可以调整的更高,比如 50000 - 80000
innodb_io_capacity = 4000
innodb_io_capacity_max = 8000
innodb_flush_method = O_DIRECT
innodb_log_file_size = 2G
innodb_log_files_in_group = 3
innodb_log_buffer_size = 64M
innodb_write_io_threads = 16
innodb_read_io_threads = 16
innodb_purge_threads = 4
innodb_large_prefix = 1
##>=5.6 打印死锁信息到error log
innodb_print_all_deadlocks = 1
innodb_strict_mode = 1
innodb_sort_buffer_size = 128M
innodb_file_per_table = 1
innodb_stats_persistent_sample_pages = 64
#auto-inc lock set:
innodb_autoinc_lock_mode = 2
innodb_online_alter_log_max_size= 4G
innodb_open_files=4000
# for SSD:if you have SSD storage
# Set to 0 data on SSDs, 1 for spinning disks. If mixed, 0 is probably best.
#innodb_flush_neighbors = 0
[mysqldump]
quick
max_allowed_packet = 32M
single-transaction
启动mysql:
cd /mysql/
bin/mysqld_safe &
修改mysql 超级用户密码:
/mysql/bin/mysql
set password for root@localhost=password("mysql");
OS 优化配置
关闭不必要的服务
vi /etc/selinux/config ==>SELINUX=disabled
#停止firewall
systemctl stop firewalld.service
#禁止firewall开机启动
systemctl disable firewalld.service
# systemctl stop avahi-daemon.socket avahi-daemon.service
# systemctl disable avahi-daemon.socket avahi-daemon.service
# systemctl stop postfix
# systemctl disable postfix
优化IO调度设置
vi /etc/grub.conf 添加elevator=deadline,需重启机器生效。
# grub.conf generated by anaconda
#
# Note that you do not have to rerun grub after making changes to this file
# NOTICE: You have a /boot partition. This means that
# all kernel and initrd paths are relative to /boot/, eg.
# root (hd0,1)
# kernel /vmlinuz-version ro root=/dev/mapper/VolGroup-LogVol01
# initrd /initrd-[generic-]version.img
#boot=/dev/sda1
device (hd0) HD(1,800,64000,e1fc1233-0f25-467e-9461-0739facbf83c)
default=0
timeout=5
splashimage=(hd0,1)/grub/splash.xpm.gz
hiddenmenu
title Red Hat Enterprise Linux (2.6.32-431.el6.x86_64)
root (hd0,1)
kernel /vmlinuz-2.6.32-431.el6.x86_64 ro root=/dev/mapper/VolGroup-LogVol01 rd_NO_LUKS LANG=en_US.UTF-8 rd_NO_MD rd_LVM_LV=VolGroup/LogVol01 SYSFONT=latarcyrheb-sun16 crashkernel=128M KEYBOARDTYPE=pc KEYTABLE=us rd_LVM_LV=VolGroup/LogVol00 rd_NO_DM rhgb quiet transparent_hugepage=never elevator=deadline
initrd /initramfs-2.6.32-431.el6.x86_64.img
配置系统参数
修改 /etc/sysctl.conf
vm.swappiness=1
修改之后使用sysctl –p命令使得修改生效
调整相关的参数
修改 /etc/security/limits.conf
mysql soft nofile 8192
mysql hard nofile 65536
这篇关于RHEL7.X MySQL 5.7.X 数据库 标准建议 安装手册的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!