一、硬件部分
Linux环境检查
- 关闭numa
- 限制设置 /etc/security/limits.conf & 网络优化
- Swap
- IO调度
- 文件系统
- selinux & iptables
下面我们一个一个来讲
1.numa
numa
的关闭方法可以通过bios关闭,也可以在操作系统层面关闭,这里推荐在bios关闭。
查看是否开启numa
grep -i numa /var/log/dmesg
讲一下在操作系统怎么关闭
cat /boot/grub/grub.conf
在内核对应的位置添加numa=off或者numactl --interleave=all
2.限制设置&网络优化
查看系统设置
ulimit -a
主要注意
open files可以改成65535
max user processes可以改成65535
/etc/security/limits.d/xxx.conf
网络优化方面MySQL可以做的就比较少了,可以看博客:http://wubx.net/php-connect-mysql-hy000-2003/
3.Swap
对于swap把握两个原则:
(1)对于大内存的服务器(64G),可以完全关闭swap
(2)对于小内存的服务器,swap配置4-8G
4.IO调度
sas:deadline
ssd:noop
echo dealine >/sys/block/{DEV-NAME}/queue/scheduler
5.文件系统
数据目录:ext4或者XFS(推荐)
挂载XFS参数:
(rw, noatime,nodiratime,nobarrier)
mount -o rw,noatime,nodiratime,nobarrier /dev/sdb1 /storage
挂载ext4参数:
ext4 (rw,noatime,nodiratime,nobarrier,data=ordered)
6.selinux & iptables
selinux万年坑,直接关闭吧,骚年
iptables看实际情况,如果跑在内网环境下可以不开iptables,否则还是建议开启iptables为佳。
二、软件部分
yum -y install make gcc-c++ cmake bison-devel ncurses-devel
1.创建用户和用户组
groupadd mysql
useradd -s /sbin/nologin -g mysql -M mysql
2.创建mysql基目录
mkdir -p /usr/local/mysql
更改文件夹所属
chown -R mysql.mysql /usr/local/mysql
3.创建目录
mkdir -p /data/mysql/{data,logs,tmp}
更改文件夹所属
chown -R mysql.mysql /data/
4.上传安装包并解压到/usr/local/mysql
5.创建mysql配置文件my.cnf
vim my.cnf
#my.cnf
[client]
port = 3306
socket = /tmp/mysql3306.sock
[mysql]
prompt="\\u@\\h [\\d]>"
#pager="less -i -n -S"
#tee=/opt/mysql/query.log
no-auto-rehash #非自动补全
[mysqld]
#misc
user = mysql
basedir = /usr/local/mysql
datadir = /data/mysql/data
port = 3306
socket = /tmp/mysql3306.sock
event_scheduler = 0
tmpdir = /data/mysql/tmp
#timeout
interactive_timeout = 300
wait_timeout = 300
#character set
character-set-server = utf8
open_files_limit = 65535
max_connections = 100
max_connect_errors = 100000
lower_case_table_names =1
#file
#@secure-file-priv=/tmp
#symi replication
#rpl_semi_sync_master_enabled=1
#rpl_semi_sync_master_timeout=1000 # 1 second
#rpl_semi_sync_slave_enabled=1
#logs
log-output=file
slow_query_log = 1
slow_query_log_file = slow.log
log-error = error.log
log_warnings = 2
pid-file = mysql.pid
long_query_time = 1
#log-slow-admin-statements = 1
#log-queries-not-using-indexes = 1
log-slow-slave-statements = 1
#binlog
#binlog_format = STATEMENT
binlog_format = row
server-id = 1003306
log-bin = /data/mysql/logs/mysql-bin
max_binlog_size = 256M
sync_binlog = 0
expire_logs_days = 10
#procedure
log_bin_trust_function_creators=1
#file
secure_file_priv="/tmp"
#
gtid-mode = on
enforce-gtid-consistency=1
#relay log
skip_slave_start = 1
max_relay_log_size = 1024M
relay_log_purge = 1
relay_log_recovery = 1
relay-log=relay-bin
relay-log-index=relay-bin.index
log_slave_updates
#slave-skip-errors=1032,1053,1062
#skip-grant-tables
#buffers & cache
table_open_cache = 2048
table_definition_cache = 2048
table_open_cache = 2048
max_heap_table_size = 96M
sort_buffer_size = 128K
join_buffer_size = 128K
thread_cache_size = 200
query_cache_size = 0
query_cache_type = 0
query_cache_limit = 256K
query_cache_min_res_unit = 512
thread_stack = 192K
tmp_table_size = 96M
key_buffer_size = 8M
read_buffer_size = 2M
read_rnd_buffer_size = 16M
bulk_insert_buffer_size = 32M
#myisam
myisam_sort_buffer_size = 128M
myisam_max_sort_file_size = 10G
myisam_repair_threads = 1
#innodb
innodb_buffer_pool_size = 4G
innodb_buffer_pool_instances = 1
innodb_data_file_path = ibdata1:1024M:autoextend
innodb_flush_log_at_trx_commit = 2
innodb_log_buffer_size = 8M
innodb_log_file_size = 1024M
innodb_log_files_in_group = 3
innodb_max_dirty_pages_pct = 50
innodb_file_per_table = 1
innodb_rollback_on_timeout
innodb_io_capacity = 2000
transaction_isolation = READ-COMMITTED
innodb_flush_method = O_DIRECT
6.初始化数据库
mysql5.6:/usr/local/mysql/scripts/mysql_install_db --basedir=/usr/local/mysql/ --datadir=/data/mysql/data --defaults-file=/etc/my.cnf --user=mysql
mysql5.7:/usr/local/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize
若出现
(Can't locate Data/Dumper.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at scripts/mysql_install_db line 42.
BEGIN failed--compilation aborted at scripts/mysql_install_db line 42.)
执行下面命令
yum install 'perl(Data::Dumper)'
7.添加环境变量
vim /etc/profile
export PATH=$PATH:/usr/local/mysql/bin
8.环境变量生效
. /etc/profile
9.启动数据库服务
mysqld_safe --defaults-file=/etc/my.cnf 2>&1 > /dev/null &
10.更改系统变量
echo "export PATH=$PATH:/usr/local/mysql/bin" >>/etc/profile
source /etc/profile
网友评论