生產搭建環境:
操做系統:CentOS7.5
內存大小:16GB
硬盤:500Gmysql
目錄:
一、環境準備與清理
二、參數調優
三、安裝部署linux
一、系統初始化
1.1.1. 關閉selinuxc++
#sed -i 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/selinux/config
#setenforce 0sql
1.1.2. 系統主機時間、時區、系統語言
修改時區
#ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
修改系統語言環境
#echo 'LANG="en_US.UTF-8"' >> /etc/profile && source /etc/profile數據庫
二、數據庫安裝
2.1 環境準備
2.1.1. 環境清理app
#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
.bakless
2.1.2. 依賴包安裝dom
#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-toolssocket
2.1.3. 建立用戶設置tcp
#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="\u@\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 root@localhost: #5+t+xYW+<t?
其中#5+t+xYW+<t?即爲root用戶的臨時密碼
#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
參數及部署過程有不足之處,還請多多指教!!