os: centos 7.4
db: mysql 5.7
# yum install make cmake *gcc* libaio libaio-devel automake autoconf bz bison libtool ncurses wget perl-DBI perl-DBD-MySQL perl-JSON perl-Time-HiRes perl-devel numactl* bzip2 git openssl openssl-devel
修改 NOZEROCONF
# vi /etc/sysconfig/network
NOZEROCONF=YES
修改IO调度器设置
elevator=deadline
关闭 NUMA 特性
numa=off
禁用透明大页
transparent_hugepage=never
# vi /etc/default/grub
# grub2-mkconfig -o /boot/grub2/grub.cfg
修改os内核参数
# vi /etc/sysctl.conf
vm.swappiness = 1
调整资源限制
# vi /etc/security/limits.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
禁止selinux
vi /etc/sysconfig/selinux
SELINUX=DISABLED
或者
vi /etc/selinux/config
SELINUX=disabled
sshd中关闭UseDNS
vi /etc/ssh/sshd_config
修改为
UseDNS no
systemctl restart sshd
确认安装sysstat
rpm -qa | grep sysstat
安装mysql 软件
添加一个mysql组及用户,默认存在mysql用户(MariaDB Server)
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
# groupadd mysql
# useradd -r -g mysql mysql
# mkdir -p /usr/local/mysql
# chown -R mysql:mysql /usr/local/mysql/
basedir=/usr/local/mysql/
datadir=/var/lib/mysql
# cd /tmp
# tar -xvf ./mysql-5.7.21-el7-x86_64.tar
mysql-5.7.21-el7-x86_64.tar.gz
mysql-test-5.7.21-el7-x86_64.tar.gz
# tar -zxvf ./mysql-5.7.21-el7-x86_64.tar.gz
# cd mysql-5.7.21-el7-x86_64
# mv ./* /usr/local/mysql/
# cd /usr/local/mysql
# chown -R mysql:mysql ./*
初始化数据库
# cd /usr/local/mysql/bin
# ./mysqld --initialize --user=mysql --basedir=/usr/local/mysql/ --datadir=/var/lib/mysql/
2018-03-26T08:31:53.761393Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2018-03-26T08:31:55.234236Z 0 [Warning] InnoDB: New log files created, LSN=45790
2018-03-26T08:31:55.304877Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2018-03-26T08:31:55.423472Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 243eec6c-30d0-11e8-adff-0800273d32a4.
2018-03-26T08:31:55.427992Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2018-03-26T08:31:55.429849Z 1 [Note] A temporary password is generated for [email protected]: )kyYcrsc=7r%
# ls -l /var/lib/mysql/
total 110628
-rw-r----- 1 mysql mysql 56 Mar 26 16:31 auto.cnf
-rw-r----- 1 mysql mysql 420 Mar 26 16:31 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Mar 26 16:31 ibdata1
-rw-r----- 1 mysql mysql 50331648 Mar 26 16:31 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Mar 26 16:31 ib_logfile1
drwxr-x--- 2 mysql mysql 4096 Mar 26 16:31 mysql
drwxr-x--- 2 mysql mysql 8192 Mar 26 16:31 performance_schema
drwxr-x--- 2 mysql mysql 8192 Mar 26 16:31 sys
ssl
# ./mysql_ssl_rsa_setup --datadir=/var/lib/mysql/
Generating a 2048 bit RSA private key
......................+++
.....................................................+++
writing new private key to 'ca-key.pem'
-----
Generating a 2048 bit RSA private key
.....................................................................+++
...................................+++
writing new private key to 'server-key.pem'
-----
Generating a 2048 bit RSA private key
...+++
..................................................................+++
writing new private key to 'client-key.pem'
-----
# ls -l /var/lib/mysql/
total 110660
-rw-r----- 1 mysql mysql 56 Mar 26 16:31 auto.cnf
-rw------- 1 root root 1675 Mar 26 16:33 ca-key.pem
-rw-r--r-- 1 root root 1107 Mar 26 16:33 ca.pem
-rw-r--r-- 1 root root 1107 Mar 26 16:33 client-cert.pem
-rw------- 1 root root 1679 Mar 26 16:33 client-key.pem
-rw-r----- 1 mysql mysql 420 Mar 26 16:31 ib_buffer_pool
-rw-r----- 1 mysql mysql 12582912 Mar 26 16:31 ibdata1
-rw-r----- 1 mysql mysql 50331648 Mar 26 16:31 ib_logfile0
-rw-r----- 1 mysql mysql 50331648 Mar 26 16:31 ib_logfile1
drwxr-x--- 2 mysql mysql 4096 Mar 26 16:31 mysql
drwxr-x--- 2 mysql mysql 8192 Mar 26 16:31 performance_schema
-rw------- 1 root root 1675 Mar 26 16:33 private_key.pem
-rw-r--r-- 1 root root 451 Mar 26 16:33 public_key.pem
-rw-r--r-- 1 root root 1107 Mar 26 16:33 server-cert.pem
-rw------- 1 root root 1679 Mar 26 16:33 server-key.pem
drwxr-x--- 2 mysql mysql 8192 Mar 26 16:31 sys
一些额外工作
# cd /usr/local/mysql/support-files
# cp ./mysql.server /etc/init.d/mysql.server
# vi /etc/my.cnf
# /etc/init.d/mysql.server status
# /etc/init.d/mysql.server start
# /etc/init.d/mysql.server stop
如果密码过期或者没记住通过skip-grant-tables可以解决
# vi /etc/my.cnf
[mysqld]
skip-grant-tables
validate_password_length=4
validate_password_mixed_case_count=0
validate_password_number_count=0
validate_password_policy=0
validate_password_special_char_count=0
update mysql.user
use mysql;
update mysql.user
set authentication_string = password('rootroot')
where host='localhost' and user='root'
;
flush privileges;
select host,user,authentication_string
from mysql.user
where 1=1
order by user,host
;
如果出现密码过期的错误,可以启用skip-grant-tables再次update
ERROR 1862 (HY000): Your password has expired. To log in you must change it using a client that supports expired passwords.
update mysql.user
set password_expired='N'
where host='localhost' and user='root';
flush privileges;
原创文章,作者:Maggie-Hunter,如若转载,请注明出处:https://blog.ytso.com/3896.html