部署mysql高可用集群(第三方软件 + 主从同步)mysql-mmm


部署mysql高可用集群(第三方软件 + 主从同步)
mysql-mmm

集群:使用多台服务器提供相同的服务
根据多台服务器提供服务的方式,分为:
高可用集群:主 备(keepalived)
负载均衡集群:平均相应用户的连接请求(LVS haproxy

nginx)

配置主主结构(9/10)
9:
mysql> grant replication slave on *.* to plj@"%"

identified by "123456";
#vim /etc/my.cnf
server_id=9
log_bin=master9
binlog_format="mixed"
:wq
#systemctl stop mysqld
#systemctl start mysqld

10
mysql> grant replication slave on *.* to plj@"%"

identified by "123456";

#vim /etc/my.cnf
server_id=10
log_bin=master10
binlog_format="mixed"
log_slave_updates
:wq
#systemctl stop mysqld
#systemctl start mysqld
#mysql -uroot -p123456
mysql>mysql> change master to

master_host="192.168.4.9",master_user="plj",master_p

assword="123456",master_log_file="master9.000001",

master_log_pos=154;
mysql> start slave;
mysql>show slave status\G;

9
#mysql -uroot -p123456
mysql> change master to

master_host="192.168.4.10",master_user="plj",master_

password="123456",master_log_file="master10.000001

",master_log_pos=154;
mysql> start slave;
mysql>show slave status\G;

把数据库11 和 12 分别配置为10的从数据库服务器
11
vim /etc/my.cnf
[mysqld]
server_id=11
:wq
#systemctl stop mysqld
#systemctl start mysqld
#mysql -uroot -p12345
mysql>change master to

master_host="192.168.4.10",master_user="plj",master_

password="123456",master_log_file="master10.000001

",master_log_pos=154;
mysql> start slave;
mysql>show slave status\G;


12
vim /etc/my.cnf
[mysqld]
server_id=12
:wq
#systemctl stop mysqld
#systemctl start mysqld

#mysql -uroot -p12345
mysql>change master to

master_host="192.168.4.10",master_user="plj",master_

password="123456",master_log_file="master10.000001

",master_log_pos=154;
mysql> start slave;
mysql>show slave status\G;

MySQL主主复制管理器,监控、故障转移

监控服务 mmm-monitor 运行在监控服务器上,负责监控和故

障转移工作的进程

代理服务mmm-agent 运行在数据库服务器上,负责获取本

机数据库服务器的状态信息。

1 在所有主机上安装mysql-mmm软件
#yum -y install perl-*

#tar -zxvf mysql-mmm-2.2.1.tar.gz
#cd mysql-mmm-2.2.1
#make install

# ls /etc/mysql-mmm/
mmm_agent.conf mmm_agent服务主配置文件
mmm_common.conf 公共文件
mmm_mon.conf mmm_monitor服务主配置文件

2 修改配置
2.1 修改数据库服务器上 mmm_agent服务主配置文件
vim /etc/mysql-mmm/mmm_agent.conf
include mmm_common.conf
this 主机名
:wq

2.1 修改监控服务器上 mmm_monitor服务主配置文件
vim /etc/mysql-mmm/mmm_mon.conf
[root@localhost ~]# cat /etc/mysql-

mmm/mmm_mon.conf
include mmm_common.conf

<monitor>
ip 192.168.4.13
pid_path /var/run/mmm_mond.pid
bin_path /usr/lib/mysql-mmm/
status_path

/var/lib/misc/mmm_mond.status
ping_ips 192.168.4.9, 192.168.4.10,

192.168.4.11, 192.168.4.12
</monitor>

<host default>
monitor_user monitor
monitor_password 123456
</host>

debug 0
[root@localhost ~]#

2.3 修改公共配置文件
[root@localhost ~]# cat /etc/mysql-

mmm/mmm_common.conf
active_master_role writer


<host default>
cluster_interface eth0

pid_path

/var/run/mmm_agentd.pid
bin_path

/usr/lib/mysql-mmm/

replication_user plj
replication_password 123456

agent_user agent
agent_password 123456
</host>

<host masterdb9>
ip 192.168.4.9
mode master
peer masterdb10
</host>

<host masterdb10>
ip 192.168.4.10
mode master
peer masterdb9
</host>

<host slavedb11>
ip 192.168.4.11
mode slave
</host>

<host slavedb12>
ip 192.168.4.12
mode slave
</host>

<role writer>
hosts masterdb9, masterdb10
ips 192.168.4.100
mode exclusive
</role>

<role reader>
hosts slavedb11, slavedb12
ips 192.168.4.101,

192.168.4.102
mode balanced
</role>
[root@localhost ~]#

2.4 在数据库服务器根据上配置文件的设置添加对应的授权用户


mysql> grant replication client on *.* to

monitor@"%" identified by "123456";

mysql>grant replication client,process,super on *.* to

agent@"%" identified by "123456";

mysql> select user,host from mysql.user where user in

("monitor","agent");

3 启动服务
3.1 在所有主机安装服务运行是依赖的软件包
tar -zxvf Algorithm-Diff-1.1902.tar.gz
cd Algorithm-Diff-1.1902/
perl Makefile.PL
make
make install
cd ..
tar -zxvf Proc-Daemon-0.03.tar.gz
cd Proc-Daemon-0.03/
perl Makefile.PL
make
make install
cd ..
rpm -ivh perl-Log-Log4perl-1.26-1.el6.rf.noarch.rpm

3.2 启动数据数据库服务器上的代理服务9、10、11、12
a 安装获取虚拟ip地址的程序 arp-net
#yum -y install gcc gcc-c++
1 gunzip Net-ARP-1.0.8.tgz
2 tar -xvf Net-ARP-1.0.8.tar
3 cd Net-ARP-1.0.8/
4 ls
5 perl Makefile.PL
6 make
7 make install

b 启动代理服务
# /etc/init.d/mysql-mmm-agent start

[root@localhost ~]# netstat -utnalp | grep :9989
tcp 0 0 192.168.4.9:9989 0.0.0.0:*

LISTEN 20723/mmm_agentd
[root@localhost ~]#

错误日志文件
cat /var/log/mysql-mmm/mmm_agentd.log

3.3 启动监控服务器上的监控服务
]# /etc/init.d/mysql-mmm-monitor start

[root@localhost ~]# netstat -utnalp | grep :9988
tcp 0 0 192.168.4.13:9988 0.0.0.0:*

LISTEN 27642/mmm_mond
[root@localhost ~]#

日志文件
/var/log/mysql-mmm/mmm_mond.log
:wq

猜你喜欢

转载自www.cnblogs.com/fuzhongfaya/p/8952893.html