First, prepare the production environment
1, the network environment
CentOS7: Temporarily turn off the firewall: [root @ localhost home] # systemctl stop firewalld Turn off the firewall boot from Kai: [root @ localhost home] # systemctl disable firewalld selinux temporarily turn off: [Home the root @ localhost] # the setenforce 0 selinux permanently closed: [Home the root @ localhost] # Sed -i ' . S / the SELINUX = * / the SELINUX = Disabled / G ' / etc / sysconfig / selinux CentOs6: Temporarily turn off the firewall: [root @ localhost home] # service iptables stop Turn off the firewall boot from Kai: [root @ localhost home] # chkconfig iptables off selinux temporarily turn off: [Home the root @ localhost] # the setenforce 0 selinux permanently closed: [Home the root @ localhost] # Sed -i ' . S / the SELINUX = * / = disbales the SELINUX / G ' / etc / sysconfig / selinux
2, CPU IO scheduling model (for the efficiency of disk read and write IO)
IO model mode Description Reference: https://www.cnblogs.com/cobbliu/p/5389556.html
IO Scheduler :( mechanical disc set are recommended: deadline, SSDs recommended noop)
View current IO scheduling modes: [root@localhost home]# cat /sys/block/sda/queue/scheduler Set IO scheduling mode: Centos7: [root@localhost home]# grubby --update-kernel=ALL --args="elevator=deadline"
3, SWAP setting
View current distribution ratio [root@localhost home]#cat /proc/sys/vm/swappiness Modify the proportion of precedence Current modification: [Home the root @ localhost] # echo 10 > / proc / SYS / VM / the swappiness Power call: [root @ localhost Home] # echo -e " echo 10> / proc / SYS / vm / swappiness " >> /etc/rc.d/rc.local
4, file system settings
mysql is a B + Tree structure, and XFS is the storage format, combined with mysql better, and the file system type is more stable.
Cenos7 default filesystem: XFS Centos6 default file system ext4.
Set Centos6 XFS file system
. 1, [the root @ localhost Home] # yum the install xfsprogs xfsdump -Y
2, the file system format: [root @ localhost home] # mkfs.xfs / dev / sdb
5, the system parameters
Mysql itself provide services to applications, so there will be a lot of connection to the Mysql production, and file data concurrently read, while Linux itself in order to prevent too many concurrent processes cause a system crash, has been restricted to the parameters, we can be modified directly
1 , View: the ulimit - A 1 . Open the file handle number: open files (to prevent too many open files error) 2 for subscriber number limit: max user processes (to prevent the single multi-instance, too many connections rejecting new connection). 2 , modify: [root@localhost home]# echo -e "* soft nproc 65535\n* hard nproc 65535\n* soft nofile 65535\n* hard nofile 65535\n" >> /etc/security/limits.conf
Two, mysql5.6 installation
1 , Environmental ready 1 Create a directory: [root@localhost home]# mkdir -p data/{mysql,software} [Home the root @ localhost] # mkdir -p Data / MySQL / {Data, tmp, log} 2 . Create User: [root@localhost home]# useradd mysql 3 . Install dependencies: [root@localhost home]# yum install perl perl-devel perl-Data-Dumper libaio-devel -y 3 , installation 1 . Download the package files [root@localhost home]# cd /data/software [root@localhost home]# wget https://cdn.mysql.com/archives/mysql-5.6/mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz [root@localhost home]# tar -zxvf mysql-5.6.34-linux-glibc2.5-x86_64.tar.gz [root@localhost home]# mv mysql-5.6.34-linux-glibc2.5-x86_64 /usr/local/mysql
2.权限赋值:
[root@localhost home]# chown -R mysql:mysql /usr/local/mysql /data/mysql/*
Three, my.cnf configuration file
[client] port = 3306 socket = /data/mysql/tmp/mysql.sock [mysql] prompt="\u@db \R:\m:\s [\d]> " no-auto-rehash [mysqld] user = mysql port = 3306 basedir = /usr/local/mysql datadir = /data/mysql/data socket = /data/mysql/tmp/mysql.sock pid-file = /data/mysql/tmp/mysql.pid character-set-server=utf8 collation-server = utf8_general_ci #skip-character-set-client-handshake=true #init_connect='insert into auditlog.accesslog(ConnectionID,ConnUserName,PrivMatchName,LoginTime) values(connection_id(),user(),current_user(),now());' skip_name_resolve=1 event_scheduler = on sql_mode='NO_UNSIGNED_SUBTRACTION,NO_ENGINE_SUBSTITUTION' open_files_limit = 65535 innodb_open_files = 65535 back_log=1024 max_connections = 512 max_connect_errors=1000000 interactive_timeout=300 wait_timeout=300 max_allowed_packet = 1024M table_open_cache=2048 table_definition_cache=2048 table_open_cache_instances = 32 thread_cache_size = 128 thread_stack = 512K external-locking = FALSE max_tmp_tables=200 tmp_table_size=100M max_heap_table_size=100G explicit_defaults_for_timestamp = 1 lock_wait_timeout = 3600 auto_increment_increment = 1 auto_increment_offset = 1 autocommit = ON secure_file_priv='' read_only = OFF lower_case_table_names=1 innodb_fast_shutdown = 0 innodb_force_recovery=0 innodb_buffer_pool_dump_at_shutdown = 1 innodb_buffer_pool_load_at_startup = 1 log-error=/data/mysql/log/error.log slow_query_log=ON slow_query_log_file=/data/mysql/log/slow_mysql.log long_query_time=2 innodb_flush_log_at_trx_commit=1 innodb_log_file_size =1G innodb_log_files_in_group=3 innodb_log_group_home_dir=./ sync_binlog = 1 binlog_cache_size = 16M max_binlog_cache_size = 1G max_binlog_size=1G expire_logs_days = 30 default-storage-engine = INNODB #internal_tmp_disk_storage_engine = INNODB transaction_isolation=REPEATABLE-READ innodb_max_dirty_pages_pct = 50 innodb_adaptive_flushing = ON innodb_flush_method = O_DIRECT sort_buffer_size=8M join_buffer_size=8M query_cache_size=0 query_cache_type=0 read_buffer_size = 8M optimizer_switch="index_condition_pushdown=on,mrr=on,mrr_cost_based=on,batched_key_access=off,block_nested_loop=on" read_rnd_buffer_size = 8M innodb_old_blocks_pct=35 #innodb_additional_mem_pool_size= 128M innodb_buffer_pool_size= 1G innodb_buffer_pool_instances = 16 innodb_log_buffer_size =32M bulk_insert_buffer_size=128M innodb_change_buffer_max_size = 50 innodb_doublewrite=on innodb_adaptive_hash_index = on innodb_file_per_table =1 innodb_data_file_path = ibdata1:1024M:autoextend innodb_page_size = 16k #innodb_checksum_algorithm =crc32 innodb_lock_wait_timeout = 35 innodb_rollback_on_timeout = on innodb_sync_spin_loops = 100 innodb_spin_wait_delay = 30 innodb_lru_scan_depth = 4000 innodb_thread_concurrency = 0 innodb_write_io_threads = 2 innodb_read_io_threads = 2 innodb_purge_threads = 2 innodb_io_capacity = 800 innodb_io_capacity_max = 1600 server-id = 3306110 log-bin= /data/mysql/log/binlog-mysql binlog_format=row
Fourth, mysql initialization
1 View initialized with help: / usr / local / MySQL / scripts / mysql_install_db - Help 2 initialize the current Mysql:. / Usr / local / mysql / scripts / mysql_install_db --basedir = / usr / local / mysql --datadir = / the Data / MySQL / --defaults the Data-File = / etc / my.cnf --user = MySQL 3 . Upon completion of initialization will prompt you to change the password: / usr / local / MySQL / bin / mysqladmin -u root password ' 123456 ' 4 Reviewing initialize the database file:. ls / data / mysql / data / If including mysql, information_schema, test directory that is deemed to be successful initialization