CentOS7.5生产环境MySQL5.7.27数据库RPM包部署


生产搭建环境:
操作系统:CentOS7.5
内存大小:16GB
硬盘:500G

目录:
1、环境准备与清理
2、参数调优
3、安装部署


1、系统初始化
1.1.1. 关闭selinux


#sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
#setenforce 0


1.1.2. 系统主机时间、时区、系统语言
? 修改时区
#ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
? 修改系统语言环境
#echo 'LANG="en_US.UTF-8"' >> /etc/profile && source /etc/profile

2、数据库安装
2.1 环境准备
2.1.1. 环境清理


#yum list installed | grep mariadb
#yum list installed | grep mysql
#yum -y remove mariadb

#yum -y remove mysql*
#mv /etc/my.cnf /etc/my.cnf.date +%Y%m%d%H%M%S.bak


2.1.2. 依赖包安装


#yum -y install bzr zlib-devel gcc-c++ ncurses-devel libev make gcc autoconf automake zlib libxml libgcrypt libtool bison perl perl-devel libaio libaio-devel perl-Time-HiRes perl-DBD-MySQL perl-Digest-MD5 rsync perl-Data-Dumper net-tools


2.1.3. 创建用户设置


#groupadd mysql
#useradd mysql -g mysql -s /sbin/nologin -M


2.1.4. 配置系统内核参数


#vi /etc/sysctl.conf
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_fin_timeout = 10
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_keepalive_time = 120
net.ipv4.tcp_keepalive_intvl = 30
net.ipv4.tcp_keepalive_probes = 3
vm.swappiness = 0
net.ipv4.ip_forward=1
net.bridge.bridge-nf-call-iptables=1
net.ipv4.neigh.default.gc_thresh1=4096
net.ipv4.neigh.default.gc_thresh2=6144
net.ipv4.neigh.default.gc_thresh3=8192
kernel.shmmax = 8589934592
kernel.shmmni = 4096
kernel.shmall = 2097152
kernel.sem = 1010 129280 1010 128
net.ipv4.ip_local_port_range = 9000 65500
net.core.rmem_default = 4194304
net.core.rmem_max = 4194304
net.core.wmem_default = 262144
net.core.wmem_max = 1048576
fs.aio-max-nr = 1048576
fs.file-max = 6815744
#/sbin/sysctl -p


2.1.5. 修改系统资源限制


#vi /etc/security/limits.conf
mysql soft nproc 65535
mysql hard nproc 65535
mysql soft nofile 65535
mysql hard nofile 65535
mysql soft stack 10240


2.1.6. 修改环境变量


#vi /etc/profile
if [ $USER = "mysql" ]; then
if [ $SHELL = "/bin/ksh" ]; then
ulimit -p 16384
ulimit -n 65536
else
ulimit -u 16384 -n 65536
fi
fi
#source /etc/profile


2.2 单机环境安装mysql
2.2.1. 创建软件安装目录


#mkdir -p /data/mysql/{logs,data,binlog}
#mkdir /var/lib/mysql
#chown -R mysql:mysql /data/
#chown -R mysql:mysql /var/lib/mysql


2.2.2. 安装部署
? 下载MySQL Yum Repository源

#yum -y install numactl wget
#wget http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
#rpm -ivh mysql57-community-release-el7-9.noarch.rpm


? 安装MySQL


#cd /opt/software
#yum install -y mysql-community-client-5.7.27-1.el7.x86_64.rpm mysql-community-devel-5.7.27-1.el7.x86_64.rpm mysql-community-libs-5.7.27-1.el7.x86_64.rpm mysql-community-libs-compat-5.7.27-1.el7.x86_64.rpm mysql-community-common-5.7.27-1.el7.x86_64.rpm mysql-community-server-5.7.27-1.el7.x86_64.rpm


2.2.3. 配置数据库启动参数


$ vi /etc/my.cnf
[client]
port = 3306

[mysql]
auto-rehash
prompt="\[email?protected]\h [\d]>"
#pager="less -i -n -S"
#tee=/opt/mysql/query.log

[mysqld]
####: for global
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/data
server_id = 83
port = 3306
character_set_server = utf8
explicit_defaults_for_timestamp = off
log_timestamps = system
socket = /var/lib/mysql/mysql.sock
read_only = 0
skip_name_resolve = 1
auto_increment_increment = 1
auto_increment_offset = 1
#lower_case_table_names = 1
secure_file_priv =
open_files_limit = 65536
max_connections = 1000
thread_cache_size = 64
table_open_cache = 81920
table_definition_cache = 4096
table_open_cache_instances = 64
max_prepared_stmt_count = 1048576

####: for binlog
binlog_format = row
log_bin = /data/mysql/binlog/mysql-bin
binlog_rows_query_log_events =on
log_slave_updates = on
expire_logs_days = 7
binlog_cache_size = 65536
log_bin_trust_function_creators = 1
#binlog_checksum = none
sync_binlog = 1
slave-preserve-commit-order = ON

####: for error-log
log_error = /data/mysql/logs/error.log

general_log = off
general_log_file = /data/mysql/logs/general.log

####: for slow query log
slow_query_log = on
slow_query_log_file = /data/mysql/logs/slow.log
#log_queries_not_using_indexes = on
long_query_time = 1.000000

####: for gtid
#gtid_executed_compression_period = 1000
gtid_mode = on
enforce_gtid_consistency = on

####: for replication
skip_slave_start = 1
#master_info_repository = table
#relay_log_info_repository = table
slave_parallel_type = logical_clock
slave_parallel_workers = 4
#rpl_semi_sync_master_enabled = 1
#rpl_semi_sync_slave_enabled = 1
#rpl_semi_sync_master_timeout = 1000
#plugin_load_add = semisync_master.so
#plugin_load_add = semisync_slave.so
binlog_group_commit_sync_delay = 100
binlog_group_commit_sync_no_delay_count = 10

####: for innodb
default_storage_engine = innodb
default_tmp_storage_engine = innodb
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_temp_data_file_path = ibtmp1:12M:autoextend
innodb_buffer_pool_filename = ib_buffer_pool
innodb_log_group_home_dir = /data/mysql/data
innodb_log_files_in_group = 3
innodb_log_file_size = 1024M
innodb_file_per_table = on
innodb_online_alter_log_max_size = 128M
innodb_open_files = 65535
innodb_page_size = 16k
innodb_thread_concurrency = 0
innodb_read_io_threads = 4
innodb_write_io_threads = 4
innodb_purge_threads = 4
innodb_page_cleaners = 4
#4(刷新lru脏页)
innodb_print_all_deadlocks = on
innodb_deadlock_detect = on
innodb_lock_wait_timeout = 20
innodb_spin_wait_delay = 128
innodb_autoinc_lock_mode = 2
innodb_io_capacity = 200
innodb_io_capacity_max = 2000
#--------Persistent Optimizer Statistics
innodb_stats_auto_recalc =on
innodb_stats_persistent = on
innodb_stats_persistent_sample_pages = 20
innodb_adaptive_hash_index=on
innodb_change_buffering = all
innodb_change_buffer_max_size = 25
innodb_flush_neighbors = 1
#innodb_flush_method =
innodb_doublewrite = on
innodb_log_buffer_size = 128M
innodb_flush_log_at_timeout = 1
innodb_flush_log_at_trx_commit = 1
innodb_buffer_pool_size = 1024M
innodb_buffer_pool_instances = 4
autocommit = 1
#--------innodb scan resistant
innodb_old_blocks_pct = 37
innodb_old_blocks_time = 1000
#--------innodb read ahead
innodb_read_ahead_threshold = 56
innodb_random_read_ahead = OFF
#--------innodb buffer pool state
innodb_buffer_pool_dump_pct = 25
innodb_buffer_pool_dump_at_shutdown = ON
innodb_buffer_pool_load_at_startup = ON


2.2.4. 启动数据库,配置服务自启动


#systemctl start mysqld
#systemctl enable mysqld


? 查看数据库是否已经启动,配置服务是否添加自启动成功


#ps -ef|grep mysqld #查看运行进程
#systemctl status mysqld #查看运行状态
#systemctl list-unit-files |grep mysqld #查看是否自启动


2.2.5. 修改MySQL数据库root用户密码
? 获取MySQL数据库root用户的临时密码


#cat /data/mysql/logs/error.log | grep 'A temporary password'
[Note] A temporary password is generated for [email?protected]: #5+t+xYW+<>
? 其中#5+t+xYW+<>
#mysql -uroot -p
Enter password:
mysql> alter user 'root'@'localhost' identified by '密码';
mysql> flush privileges;


2.2.6. 防火墙开放端口
? 根据实际要求,添加开放端口
#firewall-cmd --permanent --zone=public --add-port=3306/tcp
? 重新载入
#firewall-cmd --reload


2.2.7. 数据导入


#mysql -uroot -p
Enter password:
mysql> create database sidname default character set utf8 collate utf8_bin;
mysql> grant select,insert,update,delete,create,execute on sidname.* to 'username'@'%' identified by '密码';
mysql> flush privileges;
还原数据库
#mysql -uroot -p'passwd' sidname < /tmp/XXX.sql


参数及部署过程有不足之处,还请多多指教!!

猜你喜欢

转载自blog.51cto.com/8355320/2438744