共计 3517 个字符,预计需要花费 9 分钟才能阅读完成。
部署双节点双主数据库服务器 MySQL
分别在二台服务器上安装 mysql,要求同版本或主服务器比从服务器版本高。
主机 mysql 配置:
Vi /etc/my.cnf
[mysqld]
Log-bin=mysql-bin
Server-id=1
Service mysqld restart
Mysql –uroot –p
从 mysql 配置:
Vi /etc/my.cnf
[mysqld]
Log-bin=mysql-bin
Server-id=2
然后从主 mysql 导出数据,mysql –uroot –p dump –single-transaction *** > ***.sql
导入到从 mysql 数据库:mysql –uroot –p *** < ***.sql(*** 表示数据库名)
从服务器:
可能遇到的问题:log-bin 一定不是 log_bin,并且位置在 [mysqld] 的里面。否则日志不能正常开启。
主服务器:
测试:
以下为部署 keepalived 双主高可用:
二个服务器 IP10.16.37.101,10.16.37.94,一个 VIP10.16.37.200。
安装 keepalived:
下载 keepalived-1.2.23.tar.gz
tar –xvf keepalived-1.2.23.tar.gz –C /opt
cd /opt/keepalived-1.2.23/
./configure prefix=/usr/local/keepalived
make & make install
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
vi /etc/keepalived/keepalived.conf
主配置:(10.16.37.101)
! Configuration File for keepalived
global_defs {
notification_email {
linuxidc@linuxidc.com #通知邮箱
}
notification_email_from linuxidc@linuxidc.com
smtp_server 127.0.0.1 #表示发送 email 时使用的 smtp 服务器地址,这里可以用本地的 sendmail 来实现
smtp_connect_timeout 30 #连接 smtp 超时时间
router_id MySQL-ha #一般为主机名
}
vrrp_instance VI_1 {
state BACKUP #都为 BACKUP
interface eth0
virtual_router_id 51
priority 100 #权限 100
advert_int 1
nopreempt #不抢占
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.16.37.200 #虚拟 IP 地址,即 VIP
}
}
virtual_server 10.16.37.200 3306 {#监控端口及配置
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 10.16.37.101 3306 {#真实 IP 地址
weight 3
notify_down /usr/local/MySQL/bin/MySQL.sh #宕机脚本
TCP_CHECK {
connect_timeout 3
connect_port 3306
}
}
}
从配置:(10.16.37.94)
! Configuration File for keepalived
global_defs {
notification_email {
linuxidc@linuxidc.com #通知邮箱
}
notification_email_from linuxidc@linuxidc.com
smtp_server 127.0.0.1 #表示发送 email 时使用的 smtp 服务器地址,这里可以用本地的 sendmail 来实现
smtp_connect_timeout 30 #连接 smtp 超时时间
router_id Nginx-ha #一般为主机名
}
vrrp_instance VI_1 {
state BACKUP #都为 BACKUP
interface eth0
virtual_router_id 51
priority 90 #权限 90
advert_int 1
authentication {
auth_type PASS
auth_pass 1111
}
virtual_ipaddress {
10.16.37.200 #虚拟 IP 地址,即 VIP
}
}
virtual_server 10.16.37.200 3306 {#监控端口及配置
delay_loop 2
lb_algo wrr
lb_kind DR
persistence_timeout 60
protocol TCP
real_server 10.16.37.94 3306 {#真实 IP 地址
weight 3
notify_down /usr/local/MySQL/bin/MySQL.sh #宕机脚本
TCP_CHECK {
connect_timeout 3
connect_port 3306
}
}
}
vi /usr/local/MySQL/bin/MySQL.sh
#!/bin/bash
pkill keepalived
# chmod +x /usr/local/MySQL/bin/MySQL.sh
测试:关闭一台服务器 mysql,ps aux | grep keepalved 查看 keepalived 是否自动关闭。注意防火墙和 selinux 的关闭!!
Linux 下 HAProxy+Keepalived 双机高可用方案 http://www.linuxidc.com/Linux/2016-02/128566.htm
Haproxy+Keepalived 搭建 Weblogic 高可用负载均衡集群 http://www.linuxidc.com/Linux/2013-09/89732.htm
Keepalived+HAProxy 配置高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/56748.htm
CentOS 6.3 下 Haproxy+Keepalived+Apache 配置笔记 http://www.linuxidc.com/Linux/2013-06/85598.htm
Haproxy + KeepAlived 实现 WEB 群集 on CentOS 6 http://www.linuxidc.com/Linux/2012-03/55672.htm
Haproxy+Keepalived 构建高可用负载均衡 http://www.linuxidc.com/Linux/2012-03/55880.htm
《Keepalived 权威指南》下载见 http://www.linuxidc.com/Linux/2012-05/60951.htm
Nginx+Keepalived 实现站点高可用 http://www.linuxidc.com/Linux/2016-12/137883.htm
Nginx+Keepalived 实现站点高可用(负载均衡) http://www.linuxidc.com/Linux/2016-12/138221.htm
配置文件 keepalived.conf 详解 http://www.linuxidc.com/Linux/2016-08/134792.htm
轻量级 Keepalived 实现 Nginx 与 LVS 高可用 http://www.linuxidc.com/Linux/2016-06/132166.htm
本文永久更新链接地址:http://www.linuxidc.com/Linux/2016-12/138916.htm