1. 服务器设置
逻辑CPU个数:
最少8个,cat /proc/cpuinfo|grep "process"|wc -l
查看内存:
free -g 最少要求8G内存
操作系统版本:
lsb_release -a
系统空间:
df -h,安装MySQL软件最少要求2G,建议设置50G以上
Swap分区:
当物理内存小于16GB时,交换空间的大小与物理内存相等。
当物理内存大于16GB时,交换空间的大小需要大于16GB。
字符集:
vi /etc/sysconfig/i18n
LANG="en_US.UTF-8"
域名解析:
/etc/hosts 和/etc/sysconfig/network
防火墙:
service iptables status;
service iptables stop;
chkconfig --level 2345 iptables off;
Selinux:
vi/etc/selinux/config selinux=disabled
IO调度:
echo 'deadline'>/sys/block/sda/queue/scheduler(sda磁盘根据实际来)
或者/etc/grub.conf的kel那行的末尾加上elevator=deadline
Numa 关闭:
/etc/grub.confli的kel那行的末尾加上numa=off
卸载系统自带安装包:
rpm -e --nodeps
网卡:
Ifconfig -a
每台主机至少需要配置2张网卡,分别用作公共网卡和私网网卡
为了使系统具有高可用性,避免单点故障,建议将和MySQL数据库相关的公网和私网网卡都采用主备模式进行双网卡绑定。
网卡MTU缺省值为1500,对于私网(内联网)带宽配置为10000Mbps,建议将私网网卡的MTU值增加到9000,同时启用私网交换机的Jumbo Frame属性。
时区设置:
vi /etc/sysconfig/clock
ZONE="Asia/Shanghai"
时间同步:
Vi /etc/sysconfig/ntpd
OPTIONS="-x -u ntp:ntp -p /var/run/ntpd.pid -g"
系统文件选择:
在平均文件较小,并发较小的IO场景,ext4和xfs表现差不多,前者略微胜出。
当文件较大,并发较大时,xfs比ext4性能更好,同时更稳定。
实际使用上来说,一般数据库的文件系统推荐用xfs。
但是xfs的恢复比较麻烦,,这方面ext4的fschk修复成功率较高,而且ext4的社区支持比较完备
虚拟内存和系统参数:
vi /etc/sysctl.conf
vm.swappiness=0----------------------- cat /proc/sys/vm/swappiness
net.ipv4.tcp_max_syn_backlog = 65535
net.ipv4.tcp_max_tw_buckets = 8000
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 1
net.ipv4.tcp_fin_timeout = 10
验证:
cat /etc/sysctl.conf|egrep "net.ipv4.tcp_max_syn_backlog|net.ipv4.tcp_max_tw_buckets|net.ipv4.tcp_tw_reuse|net.ipv4.tcp_tw_recycle|net.ipv4.tcp_fin_timeout"
系统用户的shell配置:
vi /etc/security/limits.conf
mysql soft nofile 65535
mysql hard nofile 65535
mysql soft nproc 65535
mysql hard nproc 65535
修改open-file的参数:
vi /etc/profile
ulimit -HSn 65535
环境变量:
vi /root/.bash_profile
mysql_home=/usr/local/mysql
PATH=$PATH:$mysql_home/bin
2.数据库安装
下载数据包软件:
https://dev/mysql.com/doc
安装依赖包:(5.7的)
yum install cmake make gcc gcc-c++ bison libaio ncurses-devel perl perl-DBI perl-DBD-MySQL perl-Time-HiRes readline-devel numactl zlib-devel curldevel -y
如果没有yum,挂载本地yum:
mount -t iso9660 -o loop /data/software/rhel-server-6.5-x86_64-dvd.iso /media && echo "
[RHEL65]
name = Enterprise Linux 6.5 DVD
baseurl=file:///media/Server/
gpgcheck=0
enabled=1">/etc/yum.repos.d/public-yum-el6.repo && tail -5 /etc/yum.repos.d/public-yum-el6.repo
接下来
yum clean all;
yum makecache
解压:
tar -zxvf XXXX -C /usr/local
创建用户和组:
/usr/sbin/groupadd mysql
/usr/sbin/useradd -g mysql -r -s /sbin/nologin -M mysql
创建软连接:
ln -s XXXX mysql(/usr/local) ----------为了以后升级方便
创建目录和权限:
mkdir -p /data/mysql/data;
mkdir -p /data/tmp/mysql;
mkdir -p /data/mysql/log;
mkdir -p /data/mysql/binlog;
chown -R mysql:mysql /data/tmp;
chown -R mysql:mysql /data/mysql;
chown -R mysql:mysql /usr/local/mysql;
chmod 700 /data/tmp/mysql;
配置文件:
/etc/my.cnf
[root@racdg ~]# cat /etc/my.cnf
[mysqld_safe]
user = mysql
nice = 0
[client]
port = 3306 #根据客户要求
socket = /data/tmp/mysql/mysql.sock
[mysqld]
############# GENERAL #############
skip-external-locking = 1
autocommit = ON
character_set_server = utf8mb4
collation_server = utf8mb4_unicode_ci
explicit_defaults_for_timestamp = ON
lower_case_table_names = 1
port = 3306 #根据客户要求
read_only = OFF
transaction_isolation = READ-COMMITTED
open_files_limit = 65535
max_connections = 512
max_user_connections = 500
expire_logs_days = 7
default-time_zone = '+8:00'
####### CACHES AND LIMITS #########
interactive_timeout = 600
wait_timeout = 600
lock_wait_timeout = 300
max_connect_errors = 1000000
join_buffer_size = 2M
sort_buffer_size = 2M
read_rnd_buffer_size = 4M
table_definition_cache = 3000
table_open_cache = 3000
table_open_cache_instances = 32
thread_cache_size = 64
thread_stack = 256K
tmp_table_size = 64M
query_cache_size = 0
query_cache_type = 0
back_log = 1024
############# SAFETY ##############
local_infile = OFF #load data local infile不允许
skip_name_resolve = ON
skip_external_locking = ON
sql_mode = STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
############# LOGGING #############
binlog_format = ROW
general_log = 0
log_queries_not_using_indexes = ON
log_slow_admin_statements = ON
log_warnings = 2
long_query_time = 1 #1秒慢日志
slow_query_log = ON
############# REPLICATION #############
binlog_checksum = CRC32
binlog_format = ROW
binlog_rows_query_log_events = ON
enforce_gtid_consistency = ON
gtid_mode = ON
log_slave_updates = ON
master_info_repository = TABLE
master_verify_checksum = ON
max_binlog_size = 512M
relay_log_info_repository = TABLE
server_id = 8020 #ip+3位数字
skip_slave_start = ON
slave_net_timeout = 10
slave_sql_verify_checksum = ON
sync_binlog = 1
sync_master_info = 10000
sync_relay_log = 10000
sync_relay_log_info = 10000
loose-mysqlx = 0
loose_rpl_semi_sync_master_enabled = 1
loose_rpl_semi_sync_slave_enabled = 1
loose_rpl_semi_sync_master_timeout = 5000
loose_rpl_semi_sync_master_wait_point = AFTER_SYNC
loose_rpl_semi_sync_master_wait_for_slave_count = 1
plugin_load = rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so
############### PATH ##############
basedir = /usr/local/mysql
datadir = /data/mysql/data
socket = /data/tmp/mysql/mysql.sock
pid_file = /data/tmp/mysql/mysql.pid
innodb_data_home_dir = /data/mysql/data
tmpdir = /data/tmp/mysql
log_error = /data/mysql/log/error.log
general_log_file = /data/mysql/log/general.log
slow_query_log_file = /data/mysql/log/slow.log
log_bin = /data/mysql/binlog/mysql-bin
log_bin_index = /data/mysql/binlog/mysql-bin.index
relay_log = /data/mysql/binlog/relay-log
relay_log_index = /data/mysql/binlog/relay-log.index
############# INNODB #############
innodb_file_format = barracuda
innodb_flush_method = O_DIRECT
innodb_buffer_pool_instances = 4
innodb_buffer_pool_size = 10240M
innodb_log_file_size = 512M
innodb_log_files_in_group = 2
innodb_flush_log_at_trx_commit = 1
innodb_support_xa = ON
innodb_strict_mode = ON
innodb_data_file_path = ibdata1:512M:autoextend
innodb_checksum_algorithm = strict_crc32
innodb_lock_wait_timeout = 600
innodb_log_buffer_size = 32M
innodb_open_files = 65535
innodb_page_cleaners = 4
innodb_lru_scan_depth = 256
innodb_temp_data_file_path = ibtmp1:1G:autoextend:max:30G
innodb_file_per_table = 1
innodb_io_capacity = 600
innodb_io_capacity_max = 2000
[mysql]
############# CLIENT #############
max_allowed_packet = 64M
socket = /data/tmp/mysql/mysql.sock
no-auto-rehash
初始化:
./mysqld --defaults-file=/etc/my.cnf --basedir=/usr/local/mysql --datadir=/data/mysql/data --user=mysql --initialize
添加服务:
cp /usr/local/mysql/support-files/mysql.server /etc/init.d/mysqld;
chkconfig --add mysqld;
chkconfig --level 2345 mysqld on;
修改密码:
alter user user() identified by 'liu';
删除匿名用户:
mysql>delete from mysql.user where user = '';
mysql>delete from mysql.user where user = 'root' and host <> 'localhost';
mysql>delete from mysql.proxies_priv where user = 'root' and host <> 'localhost';
刷新权限:
Flush privileges
debug安装:
下载code版本
下载boost_1_59_0
cd mysql-5.7.28 cmake . \ -DCMAKE_INSTALL_PREFIX=/usr/local/mysql \ -DWITH_BOOST=/usr/local/src/boost \ -DMYSQL_DATADIR=/data/mysql/ \ -DMYSQL_USER=mysql \ -DWITH_INNOBASE_STORAGE_ENGINE=1 \ -DWITH_ARCHIVE_STORAGE_ENGINE=1 \ -DWITH_BLACKHOLE_STORAGE_ENGINE=1 \ -DWITH_PARTITION_STORAGE_ENGINE=1 \ -DWITHOUT_MROONGA_STORAGE_ENGINE=1 \ -DWITH_EXTRA_CHARSETS=all \ -DWITH_DEBUG=0 \ -DWITH_READLINE=1 \ -DWITH_SSL=system \ -DWITH_ZLIB=system \ -DWITH_LIBWRAP=0 \ -DENABLED_LOCAL_INFILE=1 \ -DMYSQL_UNIX_ADDR=/usr/local/mysql/tmp/mysql.sock \ -DDEFAULT_CHARSET=utf8mb4 \ -DDEFAULT_COLLATION=utf8mb4_general_ci
make -j `lscpu | grep -i '^cpu(s)'| tr -s ' ' '%' | cut -d% -f2` && make install
set password for root@localhost = password('123'); #修改密码
许多文章都是从书本获取