mysql部署-主从搭建

一、安装数据库

yum -y install http://www.percona.com/downloads/percona-release/redhat/0.1-4/percona-release-0.1-4.noarch.rpm && yum -y install Percona-Server-server-56

二、建立主从:
1.修改my.cnf中server-id
修改为ip地址的第四位
2.在主库创建复制用户(注意网段)

GRANT REPLICATION SLAVE ON *.* TO 'repl'@'环境所属网段' IDENTIFIED BY 'repl';
flush privileges;

 

3.在从库执行(ip为主的ip)

CHANGE MASTER TO 
MASTER_HOST='master服务器IP',
MASTER_USER='repl',
MASTER_PASSWORD='repl',
MASTER_AUTO_POSITION=1;

 

4.在从库开启主从

start slave;

5.查看主从状态

show slave status\G;

出现Slave_SQL_Running_State: Slave has read all relay log; waiting for the slave I/O thread to update it 正常

 

 

6.mysql配置文件

# Generated by Percona Configuration Wizard (http://tools.percona.com/) version REL5-20120208

[mysql]

# CLIENT #
port                           = 3306
socket                         = /tmp/mysql.sock

[mysqld]

# GENERAL #
user                           = mysql
default-storage-engine         = InnoDB
socket                         = /tmp/mysql.sock
pid-file                       = /opt/mysql_data/mysql.pid
server-id               =102
# MyISAM #
key-buffer-size                = 32M
myisam-recover                 = FORCE,BACKUP

# SAFETY #
max-allowed-packet             = 16M
max-connect-errors             = 1000000
sql_mode               = 
# DATA STORAGE #
datadir                        = /opt/mysql_data/

# BINARY LOGGING #
log-bin                        = /opt/mysql_log/mysql-bin
expire-logs-days               = 7
sync-binlog                    = 1lower_case_table_names                 = 1
gtid_mode=ON
enforce_gtid_consistency=ON
master_info_repository=TABLE
relay_log_info_repository=TABLE
binlog_checksum=NONE
log_slave_updates=ON
binlog_format=ROW


# CACHES AND LIMITS #
tmp-table-size                 = 32M
max-heap-table-size            = 32M
query-cache-type               = 0
query-cache-size               = 0
max-connections                = 2000
thread-cache-size              = 100
open-files-limit               = 65535
table-definition-cache         = 4096
table-open-cache               = 4096

# INNODB #
innodb-flush-method            = O_DIRECT
innodb-log-files-in-group      = 2
innodb-log-file-size           = 512M
innodb-flush-log-at-trx-commit = 1
innodb-file-per-table          = 1
innodb-buffer-pool-size        =8G
# LOGGING #
log-error                      = /opt/mysql_log/mysql-error.log
log-queries-not-using-indexes  = 0
slow-query-log                 = 1
slow-query-log-file            = /opt/mysql_log/mysql-slow.log

 

posted @ 2018-01-16 20:30  dingkailinux  阅读(165)  评论(0编辑  收藏  举报