重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

部署数据库的高可用集群和性能调优

IP规划
角色                  IP地址       主机名
Master 数据库服务器         192.168.4.51      master51
备用 1 master 数据库服务器      192.168.4.52      master52
备用 2 master 数据库服务器      192.168.4.53      master53
第 1 台 slave 服务器         192.168.4.54      slave54
第 2 台 slave 服务器         192.168.4.55      slave55
Mha_manager 服务器         192.168.4.56       mgm56
VIP 地址 192.168.4.100

创新互联建站专注于木垒哈萨克企业网站建设,成都响应式网站建设公司,商城网站定制开发。木垒哈萨克网站建设公司,为木垒哈萨克等地区提供建站服务。全流程按需设计网站,专业设计,全程项目跟踪,创新互联建站专业和态度为您提供的服务

一、配置所有数据节点主机之间可以互相以ssh密钥对方式认证登陆
二、配置manager56主机 无密码ssh登录 所有数据节点主机
三、配置主从同步,要求如下:
51 主库 开半同步复制
52 从库(备用主库) 开半同步复制
53 从库(备用主库) 开半同步复制
54 从库 不做备用主库所以不用开半同步复制
55 从库 不做备用主库所以不用开半同步复制

3.1、master51配置:
vim /etc/my.cnf
[MySQLd]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1

server_id=51
log-bin=master51
binlog-format="mixed"
:wq

[root@host51~]# systemctl restart mysqld

[root@host51 ~]# ls /var/lib/mysql/master51.*
/var/lib/mysql/master51.000001 /var/lib/mysql/master51.index

[root@host51 ~]# mysql -uroot -p123456
mysql> grant replication slave on . to repluser@"%" identified by "123456";
Query OK, 0 rows affected, 1 warning (10.04 sec)

mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.15 sec)

mysql> show master status;
+-----------------+----------+--------------+------------------+-------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+-------------------+
| master51.000001 | 441 | | | |
+-----------------+----------+--------------+------------------+-------------------+
mysql> quit;

3.2、备用master52的配置
vim /etc/my.cnf
[mysqld]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1

server_id=52
log-bin=master52
binlog-format="mixed"

]# systemctl restart mysqld
[root@host52~]# ls /var/lib/mysql/master52.*
/var/lib/mysql/master52.000001 /var/lib/mysql/master52.index

[root@host52 ~]# mysql -uroot -p123456

mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.13 sec)

mysql> change master to
-> master_host="192.168.4.51",
-> master_user="repluser",
-> master_password="123456",
-> master_log_file="master51.000001",
-> master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.04 sec)

mysql> start slave;
Query OK, 0 rows affected (0.01 sec)

[root@host52 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i YES
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@host52 ~]#

3.3、备用master53的配置
]# vim /etc/my.cnf
[mysqld]
plugin-load = "rpl_semi_sync_master=semisync_master.so;rpl_semi_sync_slave=semisync_slave.so"
rpl-semi-sync-master-enabled = 1
rpl-semi-sync-slave-enabled = 1

server_id=53
log-bin=master53
binlog-format="mixed"
:wq

[root@host53 ~]# systemctl restart mysqld
[root@host53 ~]# ls /var/lib/mysql/master53.*
/var/lib/mysql/master53.000001 /var/lib/mysql/master53.index
[root@host53 ~]#

[root@host53 ~]# mysql -uroot -p123456
mysql> set global relay_log_purge=off;
Query OK, 0 rows affected (0.14 sec)

mysql> change master to master_host="192.168.36.51",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.05 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql>

[root@host53 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

3.4、配置从服务器54
[root@host54 ~]# vim /etc/my.cnf
[mysqld]
server_id=54
:wq

[root@host54~]# systemctl restart mysqld
[root@host54 ~]# mysql -uroot -p123456
mysql> change master to master_host="192.168.36.51",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.09 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye
[root@host54 ~]#
[root@host54 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes

3.5、配置从服务器55
[root@host55 ~]# vim /etc/my.cnf
[mysqld]
server_id=55
:wq

[root@db111 ~]# systemctl restart mysqld
[root@db111 ~]# mysql -uroot -p123456
mysql> change master to master_host="192.168.36.51",master_user="repluser",master_password="123456",master_log_file="master51.000001",master_log_pos=441;
Query OK, 0 rows affected, 2 warnings (0.09 sec)

mysql> start slave;
Query OK, 0 rows affected (0.00 sec)

mysql> quit;
Bye
[root@host55 ~]#
[root@host55 ~]# mysql -uroot -p123456 -e "show slave status\G" | grep -i yes
mysql: [Warning] Using a password on the command line interface can be insecure.
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
[root@host55~]#

3.6、在客户端测试主从同步配置
3.6.1 在主库51上添加访问数据的授权用户
[root@host51~]# mysql -uroot -p123456
mysql> grant all on gamedb.* to admin@"%" identified by "123456";

3.6.2 在客户端主机连接主库51 建库表记录
mysql> create database gamedb;
Query OK, 1 row affected (0.01 sec)

mysql> create table gamedb.t1 (id int);
Query OK, 0 rows affected (0.04 sec)

mysql> insert into gamedb.t1 values(999);
Query OK, 1 row affected (0.15 sec)

mysql> insert into gamedb.t1 values(999);
Query OK, 1 row affected (0.05 sec)

mysql> select * from gamedb.t1;
+------+
| id |
+------+
| 999 |
| 999 |
+------+
2 rows in set (0.00 sec)

mysql>

3.6.3 在客户端使用授权用户连接从库52-55,也能看到同样的库表及记录

#mysql -h从库IP地址 -uadmin -p123456
mysql> select * from gamedb.t1;
+------+
| id |
+------+
| 999 |
| 999 |
+------+
4.0.1下来我们配置代理服务器
配置MHA集群
安装软件包:
在所有主机上安装perl软件包 (51~56)
在所有主机上安装mha_node软件包 (51~56)
只在管理主机上安装mha_manager软件包(56)
检查配置环境
拷贝命令(56)
创建工作目录 和主配置文件 (56)
创建故障切换脚本(56)
编辑主配置文件 app1.cnf
验证配置
验证ssh 免密码登录 数据节点主机
验证 数据节点的主从同步配置

编辑管理主机主配置文件
]# cp mha4mysql-manager-0.56/bin/* /usr/local/bin/
]#mkdir /etc/mha_manager/
[root@host56 mha4mysql-manager-0.56]# cp samples/conf/app1.cnf /etc/mha_manager/
]#vim /etc/mha_manager/app1.cnf

[server default]
manager_workdir=/etc/mha_manager
manager_log=/etc/mha_manager/manager.log
master_ip_failover_script=/usr/local/bin/master_ip_failover


[root@host56 ~]# cd mha4mysql-manager-0.56/samples/scripts/
[root@host56 scripts]# ls
master_ip_failover master_ip_online_change power_manager send_report
[root@host56 scripts]# cp master_ip_failover /usr/local/bin/
]# vim /usr/local/bin/master_ip_failover
my $vip = '192.168.4.100/24'; # Virtual IP
my $key = "1";
my $ssh_start_vip = "/sbin/ifconfig eth0:$key $vip";
my $ssh_stop_vip = "/sbin/ifconfig eth0:$key down";
:wq
)             修改脚本文件

ssh_user=root
ssh_port=22

repl_user=repluser
repl_password=123456

user=root
password=123456

[server1]
hostname=192.168.36.51
port=3306
candidate_master=1

[server2]
hostname=192.168.36.52
port=3306
candidate_master=1

[server3]
hostname=192.168.36.53
port=3306
candidate_master=1

[server4]
hostname=192.168.36.54
port=3306
no_master=1

[server5]
hostname=192.168.36.55
port=3306
no_master=1
:wq

测试SSH

[root@host56 ~]# masterha_check_ssh --conf /etc/mha_manager/app1.cnf
All SSH connection tests passed successfully.

测试主从同步
[root@host56 mhasoft]# masterha_check_repl --conf /etc/mha_manager/app1.cnf

启动管理服务,并查看服务状态
]# masterha_manager --conf=/etc/mha_manager/app1.cnf --ignore_last_failover

另开终端 
在管理主机上查看服务状态
[root@host56 ~]# masterha_check_status --conf=/etc/mha_manager/app1.cnf

把51 宕掉后  看看 是不是52 是不是主库 
但是 51 好了需手动配置成 52 的从


文章名称:部署数据库的高可用集群和性能调优
文章地址:http://cqcxhl.cn/article/pcgdhj.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP