搭建环境硬件资源:
服务器:centos7.2 服务器搭建环境时尽量全包安装。
数据库: mysql5.7以上
服务器的集群可以搭建一主一从,多主多从等,我今天搭建的是一主一从。
1:下载数据库安装包
MySQL-server-5.7.15-1.el6.x86_64.rpm
MySQL-devel-5.6.15-1.el6.x86_64.rpm
MySQL-client-5.6.15-1.el6.x86_64.rpm
2:按照rpm的安装方式安装完数据库
rpm -ivh MySQL-server-5.6.15-1.el6.x86_64.rpm
rpm -ivh MySQL-devel-5.6.15-1.el6.x86_64.rpm
rpm -ivh MySQL-client-5.6.15-1.el6.x86_64.rpm
3:启动数据库:service mysql start
cat /root/.mysql_secret #查看root账号密码
以root身份登录 :mysql -uroot –pqKTaFZnl
设置密码:SET PASSWORD = PASSWORD('123456'); #设置密码为123456
4:设置远程登录
update user set host='%' where user='root' and host='localhost';
5:按照这种安装方法在主从服务器上搭建环境,两台服务的配置及目录要保持一致。
6:配置主服务器的my.cnf文件
language = /usr/local/mysql/mysql-5.7.21-linux-glibc2.12-x86_64/share
port = 3306
character-set-server=utf8
default-storage-engine=InnoDB
max_connections=5000
open_files_limit=65536
event_scheduler=ON
group_concat_max_len=102400
sync_binlog=10
innodb_flush_log_at_trx_commit=2
max_allowed_packet=64M
sort_buffer_size=8M
binlog-format=MIXED
expire_logs_days=10
innodb_buffer_pool_size=40G
innodb_buffer_pool_instances=8
innodb_sort_buffer_size=16M
innodb_log_buffer_size=64M
innodb_read_io_threads=8
innodb_write_io_threads=8
innodb_flush_method=O_DIRECT
#主从复制的数据库名字
binlog-do-db=policeBusiness
binlog-ignore-db=mysql
log-bin=mysql-bin
server-id=132
slave-parallel-type=LOGICAL_CLOCK
slave-parallel-workers=16
master_info_repository=TABLE
relay_log_info_repository=TABLE
relay_log_recovery=ON
7:配置从服务器的my.cnf文件
language = /usr/local/mysql/mysql-5.7.21-linux-glibc2.12-x86_64/share
port = 3306
character-set-server=utf8
default-storage-engine=InnoDB
max_connections=5000
open_files_limit=65536
event_scheduler=ON
group_concat_max_len=102400
sync_binlog=10
innodb_flush_log_at_trx_commit=2
max_allowed_packet=64M
sort_buffer_size=8M
binlog-format=MIXED
expire_logs_days=10
innodb_buffer_pool_size=40G
innodb_buffer_pool_instances=8
innodb_sort_buffer_size=16M
innodb_log_buffer_size=64M
innodb_read_io_threads=8
innodb_write_io_threads=8
innodb_flush_method=O_DIRECT
innodb_file_per_table
slave_skip_errors=all
server-id=133