MySQL主從複製集羣部署

MySQL主從複製集羣部署

1. 在各個節點上安裝MySQL服務

wget http://repo.mysql.com/mysql57-community-release-el7-8.noarch.rpm

rpm -ivh mysql57-community-release-el7-8.noarch.rpm

2. 使用如下命令啓動MySQL服務

systemctl start mysqld

3. 安裝完成後使用命令查看root用戶默認隨機密碼

grep "password" /var/log/mysql.log

4. 以root用戶隨機密碼登錄登錄後修改root的密碼

降低密碼安全策略

set global validate_password_length=1;

set global validate_password_policy=0;

set password=password("root");

5. 爲MySQL創建用戶並授權遠程訪問

grant all privileges on *.* to 'root'@'%' identified by 'root' with grant option;

6. 配置主從同步

1). 創建同步用戶

set global validate_password_length=1;

set global validate_password_policy=0;

create user repl identified by 'repl';

grant replication slave on *.* to 'repl'@'%' identified by 'repl';

2). 修改Master上修改 /etc/my.cnf

mysql的數據文件和二進制文件: /var/lib/mysql/

mysql的配置文件: /etc/my.cnf

mysql的日誌文件: /var/log/mysql.log

[mysqld]

log-bin=mysql-bin

server-id=192_168_1_2

3). 重啓master的mysql服務

systemctl stop mysqld

systemctl start mysqld

4). 查看mysql的master狀態

show master status\G;

5). 在slave上修改 /etc/my.cnf

[mysqld]

server-id=192_168_1_3

relay-log=slave-relay-bin

relay-log-index=slave-relay-bin.index

read_only=1

6). 重啓slave的mysql服務

systemctl restart mysql

7). 配置數據庫主從同步

登錄mysql

change master to master_host='192.168.1.2',master_port=3306,master_user='repl',master_password='repl',master_log_file='mysql-bin.000001',master_log_pos=154;

start slave;

show slave status\G;

注:只要 Slave_IO_Running 和 Slave_SQL_Running都是yes,說明主從同步部署成功;

查看binlog的內容:

cd /var/lib/mysql

mysqlbinlog --base64-output=decode-rows -v mysql-bin.000001

binlog格式:

statement: 基於SQL語句模式;

row: 基於行模式; 記錄每一條記錄修改後變化的值;

mixed: 混合模式; 由mysql自動判斷處理;

查看binlog日誌:

show binlog events in 'mysql-bin.000001';

查看binlog當前日誌格式:

show variables like '%log%';

binlog_format 值即爲當前binlog格式

修改binlog格式:

set global binlog_format='mixed';

或通過修改 /etc/my.cnf

[mysqld]

binlog_format=ROW

binlog默認存儲在緩存binlog_cache中

會按照同步策略將binlog_cache中的數據刷新到磁盤;

sync_binlog=0 文件系統來調度把binlog_cache刷新到磁盤

sync_binlog=n 每執行n個事務就刷新一次到磁盤

延時監控

Nagios 做網絡監控

mk-heartbeat 監控(利用在master和slave中建表,在master插數據,查看兩條數據的時間差,太大會報警)

加Redis緩存,規避主從同步的時間差;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章