您好,登錄后才能下訂單哦!
五臺虛擬機
雙網卡 第一塊內網,第二塊外網
80.100 主數據庫1
80.101 主數據庫2
80.102 從數據庫1
80.103 從數據庫2
80.104 監控端 monitor
搭建阿里云yum倉庫:
vi /etc/yum.repos.d/ali.repo
[Ali]
name=CentOS-$releasever - Base
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
scp /etc/yum.repos.d/ali.repo root@192.168.80.101:/etc/yum.repos.d/
scp /etc/yum.repos.d/ali.repo root@192.168.80.102:/etc/yum.repos.d/
scp /etc/yum.repos.d/ali.repo root@192.168.80.103:/etc/yum.repos.d/
scp /etc/yum.repos.d/ali.repo root@192.168.80.104:/etc/yum.repos.d/
vi /etc/sysconfig/network-scripts/ifcfg-ens32 //進入網卡配置文件
把圈中的命令刪掉在使用下一條命令
systemctl restart network //重啟網卡
四臺服務器安裝以下程序:
systemctl stop firewalld //關閉防火墻
setenforce 0 //關閉監控
[root@lq5 yum.repos.d]# ifconfig ens34 down //關閉ens34網卡
[root@lq5 yum.repos.d]# ifconfig ens34 up //開啟ens34網卡
yum install -y wget
wget -O /etc/yum.repos.d/ali.repo http://mirrors.aliyun.com/repo/Centos-7.repo
yum -y install epel-release
yum clean all && yum makecache
yum -y install mariadb-server mariadb
yum install mariadb-server -y
[root@NGINX ~]# systemctl start mariadb
[root@NGINX ~]# vi /etc/my.cnf
[mysqld]
log_error=/var/lib/mysql/mysql.err
log=/var/lib/mysql/mysql_log.log
log_slow_queries=/var/lib/mysql_slow_queris.log
binlog-ignore-db=mysql,information_schema
character_set_server=utf8
log_bin=mysql_bin
server_id=1
log_slave_updates
sync_binlog=1
auto_increment_increment=2
auto_increment_offset=1
[root@NGINX ~]# service mariadb restart
[root@NGINX ~]# netstat -anpt | grep 3306
-------沒有問題后,把配置文件復制到其它3臺數據庫服務器上并啟動服務器-----
[root@NGINX ~]# scp /etc/my.cnf root@192.168.80.101:/etc/
[root@NGINX ~]# scp /etc/my.cnf root@192.168.80.102:/etc/
[root@NGINX ~]# scp /etc/my.cnf root@192.168.80.103:/etc/
[root@NGINX ~]# mysql -u root
MariaDB [(none)]> grant replication slave on *.* to 'replication'@'192.168.80.%' identified by '123456';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> show master status \G
在從服務器上:
[root@test ~]# vi /etc/my.cnf
修改一下Server-id ,其他從服務器也要修改
[root@test ~]# service mariadb restart
[root@test ~]# mysql -u root
MariaDB [(none)]> grant replication slave on *.* to 'replication'@'192.168.80.%' identified by '123456';
MariaDB [(none)]> change master to master_host='192.168.80.100',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=490;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status \G
MariaDB [(none)]> show master status \G
MariaDB [(none)]> change master to master_host='192.168.80.101',master_user='replication',master_password='123456',master_log_file='mysql_bin.000003',master_log_pos=410;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status \G
vi /etc/my.cnf
[root@NGINX ~]# service mariadb restart
[root@NGINX ~]# netstat -anpt | grep 3306
mysql -u root
MariaDB [(none)]> change master to master_host='192.168.80.100',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=490;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status \G
[root@test ~]# vi /etc/my.cnf
修改一下Server-id ,其他從服務器也要修改
[root@NGINX ~]# service mariadb restart
[root@NGINX ~]# netstat -anpt | grep 3306
mysql -u root
MariaDB [(none)]> change master to master_host='192.168.80.100',master_user='replication',master_password='123456',master_log_file='mysql_bin.000001',master_log_pos=490;
MariaDB [(none)]> start slave;
MariaDB [(none)]> show slave status \G
測試:
在主備服務器上創建一個空庫:
MariaDB [(none)]> create database aa;
MariaDB [(none)]> show databases;
到此,主主備份主從同步成功
現在做對mmm進行配置
-------安裝MMM----在所有服務器上安裝-----注意,epel源要配置好
yum -y install mysql-mmm*
-------安裝結束后,對mmm進行配置------
[root@NGINX ~]# cd /etc/mysql-mmm/
[root@NGINX mysql-mmm]# ls
[root@NGINX mysql-mmm]# vi mmm_common.conf
修改以下圈住部分:
發送給其他數據庫服務器
scp mmm_common.conf root@192.168.80.101:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.80.102:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.80.103:/etc/mysql-mmm/
scp mmm_common.conf root@192.168.80.104:/etc/mysql-mmm/
[root@MYSQL ~]# cd /etc/mysql-mmm/
[root@MYSQL mysql-mmm]# vi mmm_mon.conf
在其它mysql服務器上:
[root@NGINX mysql-mmm]# vi /etc/mysql-mmm/mmm_agent.conf
主數據庫1:this db1
主數據庫2:this db2
從數據庫1:this db3
從數據庫2:this db4
monitor服務器:this db5
是在各自的配置文件修改,不是在一個虛擬機,每個虛擬機都要執行的操作。
在四臺數據庫中為mmm_agent授權
grant super, replication client, process on *.* to 'mmm_agent'@'192.168.80.%' identified by '123';
grant replication client on *.* to 'mmm_monitor'@'192.168.80.%' identified by '123';
systemctl start mysql-mmm-agent
在monitor服務器上配置:
[root@MYSQL mysql-mmm]# vi mmm_mon.conf
systemctl start mysql-mmm-monitor //啟動mysql-mmm-monitor
netstat -anp | grep 9988
mmm_control checks all
mmm_control show
查看是否有漂移地址
主數據庫1
從數據庫1
從數據庫2
模擬主數據庫1,從數據庫1故障,查看漂移地址是否從主數據庫1漂移到主數據庫2,和從數據庫1的地址漂移到從數據庫2上去
主數據庫1
systemctl stop mariadb
主數據庫2
從數據庫1
systemctl stop mariadb
從數據庫2
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。