MySQLmaster-master如何配置
发表于:2024-10-21 作者:千家信息网编辑
千家信息网最后更新 2024年10月21日,本篇内容介绍了"MySQLmaster-master如何配置"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有
千家信息网最后更新 2024年10月21日MySQLmaster-master如何配置
本篇内容介绍了"MySQLmaster-master如何配置"的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!
MySQLmaster-master怎么配置
1、修改MySQL配置文件 两台MySQL均如要开启binlog日志功能,开启方法:在MySQL配置文件[MySQLd]段中加上log-bin=MySQL-bin选项 两台MySQL的server-ID不能一样,默认情况下两台MySQL的serverID都是1,需将其中一台修改为2即可 2、将192.168.1.201设为192.168.1.202的主服务器 在192.168.1.201上新建授权用户 MySQL>grantreplicationslaveon*.*to'replication'@'%'identifiedby'replication';QueryOK,0rowsaffected(0.00sec)MySQL>showmasterstatus;+------------------+----------+--------------+------------------+|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|+------------------+----------+--------------+------------------+|MySQL-bin.000003|374|||+------------------+----------+--------------+------------------+1rowinset(0.00sec) 在192.168.1.202上将192.168.1.201设为自己的主服务器 MySQL>changemastertomaster_host='192.168.1.201',master_user='replication',master_password='replication',master_log_file='MySQL-bin.000003',master_log_pos=374;QueryOK,0rowsaffected(0.05sec)MySQL>startslave;QueryOK,0rowsaffected(0.00sec)MySQL>showslavestatus\G***************************1.row***************************Slave_IO_State:WaitingformastertosendeventMaster_Host:192.168.1.201Master_User:replicationMaster_Port:3306Connect_Retry:60Master_Log_File:MySQL-bin.000003Read_Master_Log_Pos:374Relay_Log_File:MySQL-master2-relay-bin.000002Relay_Log_Pos:235Relay_Master_Log_File:MySQL-bin.000003Slave_IO_Running:YesSlave_SQL_Running:YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:0Last_Error:Skip_Counter:0Exec_Master_Log_Pos:374Relay_Log_Space:235Until_Condition:NoneUntil_Log_File:Until_Log_Pos:0Master_SSL_Allowed:NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master:01rowinset(0.00sec) 3、将192.168.1.202设为192.168.1.201的主服务器 在192.168.1.202上新建授权用户 MySQL>grantreplicationslaveon*.*to'replication'@'%'identifiedby'replication';QueryOK,0rowsaffected(0.00sec)MySQL>showmasterstatus;+------------------+----------+--------------+------------------+|File|Position|Binlog_Do_DB|Binlog_Ignore_DB|+------------------+----------+--------------+------------------+|MySQL-bin.000003|374|||+------------------+----------+--------------+------------------+1rowinset(0.00sec) 在192.168.1.201上,将192.168.1.202设为自己的主服务器 MySQL>changemastertomaster_host='192.168.1.202',master_user='replication',master_password='replication',master_log_file='MySQL-bin.000003',master_log_pos=374;QueryOK,0rowsaffected(0.05sec)MySQL>startslave;QueryOK,0rowsaffected(0.00sec)MySQL>showslavestatus\G***************************1.row***************************Slave_IO_State:WaitingformastertosendeventMaster_Host:192.168.1.202Master_User:replicationMaster_Port:3306Connect_Retry:60Master_Log_File:MySQL-bin.000003Read_Master_Log_Pos:374Relay_Log_File:MySQL-master1-relay-bin.000002Relay_Log_Pos:235Relay_Master_Log_File:MySQL-bin.000003Slave_IO_Running:YesSlave_SQL_Running:YesReplicate_Do_DB:Replicate_Ignore_DB:Replicate_Do_Table:Replicate_Ignore_Table:Replicate_Wild_Do_Table:Replicate_Wild_Ignore_Table:Last_Errno:0Last_Error:Skip_Counter:0Exec_Master_Log_Pos:374Relay_Log_Space:235Until_Condition:NoneUntil_Log_File:Until_Log_Pos:0Master_SSL_Allowed:NoMaster_SSL_CA_File:Master_SSL_CA_Path:Master_SSL_Cert:Master_SSL_Cipher:Master_SSL_Key:Seconds_Behind_Master:01rowinset(0.00sec) 4、MySQL同步测试 如上述均正确配置,现在任何一台MySQL上更新数据都会同步到另一台MySQL,MySQL同步在此不再演示。 keepalived怎么安装及配置 1、192.168.1.201服务器上keepalived安装及配置 安装keepalived #tarzxvfkeepalived-1.1.20.tar.gz#cdkeepalived-1.1.20#./configure--prefix=/usr/local/keepalived--with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686#make&&makeinstall 配置keepalived 我们自己在新建一个配置文件,默认情况下keepalived启动时会去/etc/keepalived目录下找配置文件 #mkdir/etc/keepalived#vi/etc/keepalived/keepalived.conf!ConfigurationFileforkeepalivedglobal_defs{notification_email{luwenju@live.cn}notification_email_fromluwenju@live.cnsmtp_server127.0.0.1smtp_connect_timeout30router_idMySQL-ha}vrrp_instanceVI_1{stateBACKUP#两台配置此处均是BACKUPinterfaceeth0virtual_router_id51priority100#优先级,另一台改为90advert_int1nopreempt#不抢占,只在优先级高的机器上设置即可,优先级低的机器不设置authentication{auth_typePASSauth_pass1111}virtual_ipaddress{192.168.1.200}}virtual_server192.168.1.2003306{delay_loop2#每个2秒检查一次real_server状态lb_algowrr#LVS算法lb_kindDR#LVS模式persistence_timeout60#会话保持时间protocolTCPreal_server192.168.1.2013306{weight3notify_down/usr/local/MySQL/bin/MySQL.sh#检测到服务down后执行的脚本TCP_CHECK{connect_timeout10#连接超时时间nb_get_retry3#重连次数delay_before_retry3#重连间隔时间connect_port3306#健康检查端口}} 编写检测服务down后所要执行的脚本 #vi/usr/local/MySQL/bin/MySQL.sh#!/bin/shpkillkeepalived#chmod+x/usr/local/MySQL/bin/MySQL.sh 注:此脚本是上面配置文件notify_down选项所用到的,keepalived使用notify_down选项来检查real_server的服务状态,当发现real_server服务故障时,便触发此脚本;我们看到的是,脚本就一个命令,通过pkillkeepalived强制杀死keepalived进程,从而实现了MySQL故障自动转移。另外,我们不用担心两个MySQL会同时提供数据更新操作,因为每台MySQL上的keepalived的配置里面只有本机MySQL的IP+VIP,而不是两台MySQL的IP+VIP 启动keepalived #/usr/local/keepalived/sbin/keepalived-D#ps-aux|grepkeepalived 测试 找一台局域网PC,然后去pingMySQL的VIP,这时候MySQL的VIP是可以ping的通的 停止MySQL服务,看keepalived健康检查程序是否会触发我们编写的脚本 2、192.168.1.202上keepalived安装及配置 安装keepalived #tarzxvfkeepalived-1.1.20.tar.gz#cdkeepalived-1.1.20#./configure--prefix=/usr/local/keepalived--with-kernel-dir=/usr/src/kernels/2.6.18-164.el5-i686#make&&makeinstall 配置keepalived 这台配置和上面基本一样,但有三个地方不同:优先级为90、无抢占设置、real_server为本机IP #mkdir/etc/keepalived#vi/etc/keepalived/keepalived.conf!ConfigurationFileforkeepalivedglobal_defs{notification_email{luwenju@live.cn}notification_email_fromluwenju@live.cnsmtp_server127.0.0.1smtp_connect_timeout30router_idMySQL-ha}vrrp_instanceVI_1{stateBACKUPinterfaceeth0virtual_router_id51priority90advert_int1authentication{auth_typePASSauth_pass1111}virtual_ipaddress{192.168.1.200}}virtual_server192.168.1.2003306{delay_loop2lb_algowrrlb_kindDRpersistence_timeout60protocolTCPreal_server192.168.1.2023306{weight3notify_down/usr/local/MySQL/bin/MySQL.shTCP_CHECK{connect_timeout10nb_get_retry3delay_before_retry3connect_port3306}} 编写检测服务down后所要执行的脚本 #vi/usr/local/MySQL/bin/MySQL.sh#!/bin/shpkillkeepalived#chmod+x/usr/local/MySQL/bin/MySQL.sh启动keepalived#/usr/local/keepalived/sbin/keepalived-D#ps-aux|grepkeepalived 测试 停止MySQL服务,看keepalived健康检查程序是否会触发我们编写的脚本 三、测试 MySQL远程登录测试 我们找一台安装有MySQL客户端的windows,然后登录VIP,看是否能登录,在登录之两台MySQL服务器都要授权允许从远程登录 MySQL>grantallprivilegeson*.*to'root'@'%'identifiedby'123456';QueryOK,0rowsaffected(0.00sec)MySQL>flushprivileges;QueryOK,0rowsaffected(0.00sec) 使用客户端登录VIP测试 C:\MySQL\bin>MySQL.exe-uroot-p123456-h292.168.1.200-P3306WelcometotheMySQLmonitor.Commandsendwith;or\g.YourMySQLconnectionidis224Serverversion:5.0.89-logSourcedistributionType'help;'or'\h'forhelp.Type'\c'toclearthecurrentinputstatement.MySQL> ●keepalived故障转移测试 ※在windows客户端一直去pingVIP,然后关闭192.168.1.201上的keepalived,正常情况下VIP就会切换到192.168.1.202上面去 ※开启192.168.1.201上的keepalived,关闭192.168.1.202上的keepalived,看是否能自动切换,正常情况下VIP又会属于192.168.1.201 注:keepalived切换速度还是非常块的,整个切换过程只需1-3秒 ●MySQL故障转移测试 ※在192.168.1.201上关闭MySQL服务,看VIP是否会切换到192.168.1.202上 ※开启192.168.1.201上的MySQL和keepalived,然后关闭192.168.1.202上的MySQL,看VIP是否会切换到192.168.1.201上 下面是用windows客户端连接的MySQL的VIP,在切换时我执行了一个MySQL查询命令,从执行showdatabases到显示出结果时间为3-5秒(大家看到的是上面有个错误提示,不过不用担心,因为我们的keepalived切换大概为3秒左右,这3秒左右VIP是谁都不属于的) MySQL>showdatabases;ERROR2006(HY000):MySQLserverhasgoneawayNoconnection.Tryingtoreconnect...Connectionid:592Currentdatabase:***NONE***+--------------------+|Database|+--------------------+|information_schema||MySQL||test|+--------------------+3rowsinset(9.01sec)
"MySQLmaster-master如何配置"的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!
配置
服务
脚本
切换
测试
服务器
情况
文件
检查
登录
优先级
客户
故障
时间
健康
客户端
检测
不用
内容
命令
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
单片机软件开发怎么调试
热血传奇手游换服务器
建数据库工具
个人地理数据库gdb和mdb
慧运营网络技术有限公司
网络安全进学校教师学习活动总结
英特尔多核软件开发
数据库工具汉化
厦门橙市网络技术有限公司
两台数据库服务不能启动
传奇架设服务器装什么系统
php数据库推荐
福州企业软件开发平台
ecshop 数据库文件
查找联系不到服务器
河南服务器机柜配件云服务器
河南107区有哪些服务器
定制服务器机柜
如何建立测量地形数据库
电子图书数据库有
护苗网络安全教育课计划
高并发服务器开发
网络安全意识论文
淘宝上的服务器在哪
软件开发行业竞争强度
放心的财务软件开发商
设备在线状态是否存储在数据库
数据库 平滑升级
至强D是服务器
软件开发简历突出特点