博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
keepalived mariadb 主主
阅读量:5102 次
发布时间:2019-06-13

本文共 3972 字,大约阅读时间需要 13 分钟。

场景描述

#安装数据库mariadb 主主模式 keepalived 调度

#mysql1 192.168.30.99
#mysql2 192.168.30.100
#vip 192.168.30.101

yum install mariadb-server keepalived -y 

配置keepalived

global_defs {   router_id mysql-ha}vrrp_instance VI_1 {    state BACKUP # 两个节点都为BACKUP状态,根据优先级大小判断谁为MASTER    interface eth0    virtual_router_id 51    priority 100    advert_int 1    nopreempt # 非抢占模式    authentication {        auth_type PASS        auth_pass 1111    }    # 虚拟IP池    virtual_ipaddress {        192.168.30.101    }}virtual_server 192.168.30.101 3306 {     delay_loop 2     lb_algo wrr #如果调度失败 可以注释这两行     lb_kind DR #     persistence_timeout 60     protocol TCP     real_server 192.168.1.99 3306 {         weight 3         notify_down /etc/keepalived/mysql.sh  # 当mysql服务down了之后,执行的脚本         TCP_CHECK {             connect_timeout 10   # mysql连接超时时长(秒)             nb_get_retry 3       # mysql服务连接失败,重试次数             delay_before_retry 3 #每隔3秒检测一次mysql服务是否可用             connect_port 3306         }     }}#节点二配置global_defs {   router_id mysql-ha}vrrp_instance VI_1 {    state BACKUP    interface eth0    virtual_router_id 51    priority 90    advert_int 1    nopreempt    authentication {        auth_type PASS        auth_pass 1111    }    virtual_ipaddress {        192.168.30.101    }}virtual_server 192.168.30.101 3306 {     delay_loop 2     lb_algo wrr #如果调度不成功,可以将这两行注释     lb_kind DR #     persistence_timeout 60     protocol TCP     real_server 192.168.30.100 3306 {         weight 3         notify_down /etc/keepalived/mysql.sh         TCP_CHECK {             connect_timeout 10             nb_get_retry 3             delay_before_retry 3             connect_port 3306         }     }}

  配置数据库

#配置mysql主主模式#mysql1 192.168.30.99 配置[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socklog-bin=mysql-binserver-id=1symbolic-links=0character-set-server=utf8[mysqld_safe]log-error=/var/log/mariadb/mariadb.logpid-file=/var/run/mariadb/mariadb.pid!includedir /etc/my.cnf.dservice mariadb start #创建账号用户同步mysql -uroot -p grant replication slave on *.* to 'backup'@'192.168.30.100' identified by 'backup'; flush privileges;show master status;MariaDB [(none)]> show master status;+------------------+----------+--------------+------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000007 |    40989 |              |                  |+------------------+----------+--------------+------------------+1 row in set (0.00 sec)#在100上配置vi /etc/my.cnf[mysqld]datadir=/var/lib/mysqlsocket=/var/lib/mysql/mysql.socklog-bin=mysql-binserver-id=2symbolic-links=0character-set-server=utf8[mysqld_safe]log-error=/var/log/mariadb/mariadb.logpid-file=/var/run/mariadb/mariadb.pid!includedir /etc/my.cnf.dservice mariadb start mysql -uroot -p change master to master_host='192.168.30.99',master_user='backup',master_password='backup',master_log_file='mysql-bin.000007',master_log_pos=40989;show slave status \G;#查看到Slave_IO_Running :yes 和Slave_SQL_Running yes 则说明同步成功,如果没有可以关闭防火墙和SELinux 然后重启服务器setenforce 0iptables -F service mariadb restart #设置99和100互为主从关系#100上操作mysql -uroot -pgrant replication slave on *.* to 'backup'@'192.168.30.99' identified by 'backup'; flush privileges;show master status;MariaDB [(none)]> show master status ;+------------------+----------+--------------+------------------+| File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |+------------------+----------+--------------+------------------+| mysql-bin.000009 |      245 |              |                  |+------------------+----------+--------------+------------------+1 row in set (0.00 sec) change master to master_host='192.168.30.100',master_user='backup',master_password='backup',master_log_file='mysql-bin.000009',master_log_pos=245; show slave status \G;

 如果同步不成功 可以重启mariadb试试

然后在99 上面创建数据表 测试 

 

重启服务

service mariadb restart 

service keepalived restart 

转载于:https://www.cnblogs.com/pdjun/p/5977338.html

你可能感兴趣的文章
Zookeeper常用命令 (转)
查看>>
Bootstrap栅格学习
查看>>
程序员的数学
查看>>
聚合与组合
查看>>
洛谷 P2089 烤鸡【DFS递归/10重枚举】
查看>>
我眼中的技术地图
查看>>
lc 145. Binary Tree Postorder Traversal
查看>>
在centos上开关tomcat
查看>>
android dialog使用自定义布局 设置窗体大小位置
查看>>
ionic2+ 基础
查看>>
[leetcode]Minimum Path Sum
查看>>
Aizu - 1378 Secret of Chocolate Poles (DP)
查看>>
IO流写出到本地 D盘demoIO.txt 文本中
查看>>
Screening technology proved cost effective deal
查看>>
mysql8.0.13下载与安装图文教程
查看>>
Thrift Expected protocol id ffffff82 but got 0
查看>>
【2.2】创建博客文章模型
查看>>
Kotlin动态图
查看>>
从零开始系列之vue全家桶(1)安装前期准备nodejs+cnpm+webpack+vue-cli+vue-router
查看>>
Jsp抓取页面内容
查看>>