实验系统:CentOS 6.6_x86_64 实验前提:提前准备好编译环境,防火墙和selinux都关闭 实验说明:本实验共有2台主机,IP分配如拓扑
实验系统:CentOS 6.6_x86_64
实验前提:提前准备好编译环境,防火墙和selinux都关闭
实验说明:本实验共有2台主机,IP分配如拓扑
实验软件:mariadb-10.0.20
实验拓扑:
一、安装mysql
1.编译安装mariadb:
tar xf mariadb-10.0.20-linux-x86_64.tar.gz -C /usr/local/
cd /usr/local/
ln -sv mariadb-10.0.20-linux-x86_64 mysql
mkdir -pv /mydata/data
useradd -r mysql
chown -R mysql.mysql /mydata/data/
cd mysql/
chown -R root.mysql .
scripts/mysql_install_db --user=mysql --datadir=/mydata/data/
cp support-files/my-large.cnf /etc/my.cnf
cp support-files/mysql.server /etc/init.d/mysqld
chkconfig --add mysqld
chkconfig mysqld on
2.编辑配置文件:
vim /etc/my.cnf
--------------------------------
datadir = /mydata/data //增加此行
--------------------------------
service mysqld start
/usr/local/mysql/bin/mysql //连接测试
二、主从复制
实验中我先让19.43当主服务器,19.48为从服务器。
1.主服务器操作:
(1)编辑my.cnf,启用二进制日志(如果定义到其他路径,请给予其mysql权限):
log-bin=/mydata/data/mysql-bin
(2)定义server-id:
server-id = 1
(3)创建有复制权限的账号:
/usr/local/mysql/bin/mysql
-----------------------------------------
GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO slave@192.168.19.48 IDENTIFIED BY '123456'; //遵循最小权限原则
FLUSH PRIVILEGES;
(4)记录最后的二进制日志信息,CHANGE MASTER时会用到:
SHOW MASTER LOGS;
2.从服务器操作:
(1)启动中继日志(如果定义到其他路径,请给予其mysql权限):
relay_log=/mydata/data/relay-log
(2)从服务器用中继日志就足够了,关闭二进制日志,减少磁盘IO:
#log-bin=mysql-bin //将其注释
#binlog_format=mixed
(3)定义server-id:
server-id = 2 //不能与主服务器相同
(4)配置CHANGE MASTER:
/usr/local/mysql/bin/mysql
-----------------------------------------
CHANGE MASTER TO MASTER_HOST='192.168.19.43',MASTER_USER='slave',MASTER_PASSWORD='123456',MASTER_LOG_FILE='mysql-bin.000002',MASTER_LOG_POS=326;
SHOW SLAVE STATUS\G //查看状态
*************************** 1. row ***************************
Slave_IO_State:
Master_Host: 192.168.19.43
Master_User: slave
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: mysql-bin.000002
Read_Master_Log_Pos: 326
Relay_Log_File: relay-log.000001
Relay_Log_Pos: 4
Relay_Master_Log_File: mysql-bin.000002
Slave_IO_Running: No
Slave_SQL_Running: No
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 326
Relay_Log_Space: 248
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: NULL
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 0
Master_SSL_Crl:
Master_SSL_Crlpath:
Using_Gtid: No
Gtid_IO_Pos:
1 row in set (0.00 sec)
(5)启动io thread以及sql thread:
START SLAVE;
3.在主服务器创建数据库,从服务器查看:
CREATE DATABASE jason; //主服务器创建数据库
SHOW DATABASES; //从服务器查看
4.如果主数据库不是新建立的,而是使用过一段时间,且里面已经有不少数据的情况下,需要先把主服务器数据导出,再导入到从服务器,然后根据上面的步骤进行主从复制,这里将不再演示。
导出数据库命令参考:mysqldump --all-databases --lock-all-tables --master-data=2 > name.sql
三、半同步复制
1.什么是半同步复制?
已抢65168个
抢已抢28770个
抢已抢15676个
抢已抢7901个
抢已抢9900个
抢已抢20066个
抢