返回顶部
首页 > 资讯 > 数据库 >keepalived+双主
  • 243
分享到

keepalived+双主

2024-04-02 19:04:59 243人浏览 泡泡鱼
摘要

[root@mini1 ~]# setenforce 0[root@mini1 ~]# systemctl stop firewalld.service [root@mini1 ~]# vim /

[root@mini1 ~]# setenforce 0

[root@mini1 ~]# systemctl stop firewalld.service 

[root@mini1 ~]# vim /etc/my.cnf 

server_id=1

log-bin=Mysql-bin

gtid-mode=on

enforce-gtid-consistency=1

log_slave_updates = 1

binlog-fORMat=mixed

auto-increment-increment=2          #自动增长步长,三台mysql这设置为3

auto-increment-offset=1              #自增长初始值

[root@mini1 ~]# service mysqld start

[root@mini2 ~]# setenforce 0

[root@mini2 ~]# systemctl stop firewalld.service 

[root@mini2 ~]# vim /etc/my.cnf 

server_id=2

log-bin=mysql-bin

gtid-mode=on

enforce-gtid-consistency=1

log_slave_updates = 1

binlog-format=mixed

auto-increment-increment=2  

auto-increment-offset=2

[root@mini2 ~]# service mysqld start

#设置双主同步

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

mysql> grant replication slave on *.* to rep@'192.168.1.%' identified by '123456';

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

mysql> change master to master_host='192.168.1.128',master_user='rep',master_passWord='123456',master_port=3306,master_auto_position=1;

mysql> start slave;

mysql> show slave status\G;

mysql>  grant replication slave on *.* to rep@'192.168.1.%' identified by '123456';

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

mysql> change master to master_host='192.168.1.128',master_user='rep',master_password='123456',master_port=3306,master_auto_position=1;

mysql> start slave;

mysql> show slave status\G;

#测试是否同步

mysql> create database test;

mysql> create table test.t1(id int primary key auto_increment,name varchar(10));

mysql> insert into test.t1(name) values('tom1');

#登录master2查看

mysql> select * from test.t1;

+----+------+

| id | name |

+----+------+

|  2 | tom1 |

|  4 | tom1 |

+----+------+

#在master1与master2上安装keepalived

#keepalived依赖包

[root@mini1 ~]# yum -y install kernel-devel openssl-devel popt-devel

[root@mini1 ~]# tar zxf keepalived-2.0.6.tar.gz 

[root@mini1 ~]# cd keepalived-2.0.6/

[root@mini1 keepalived-2.0.6]# ./configure --prefix=/ --with-kernel-dir= /usr/src/kernels/3.10.0-862.9.1.el7.x86_64/ &&make &&make install

[root@mini1 ~]# vim /etc/keepalived/keepalived.conf 

[root@mini1 ~]# vim /etc/keepalived/keepalived.conf 


! Configuration File for keepalived


global_defs {

   router_id mysql_1

}

    state BACKUP

    interface eno16777728

    virtual_router_id 51

        auth_type PASS

        auth_pass 1111

! Configuration File for keepalived


global_defs {

   router_id mysql_1

}


vrrp_instance VI_1 {

    state BACKUP

    interface eno16777728

    virtual_router_id 51

    priority 100

    advert_int 1

    nopreempt

    authentication {

        auth_type PASS

        auth_pass 1111

    }   

    virtual_ipaddress {

        192.168.1.100 

    }   

}   


virtual_server 192.168.1.100 3306 {

    delay_loop 6

    lb_alGo rr 

    lb_kind DR 

    persistence_timeout 50

    protocol tcp


    real_server 192.168.1.128 3306 {

        weight 1

        notify_down /etc/keepalived/bin/mysql.sh                  

        TCP_CHECK {

            connect_timeout 3

            retry 3

            delay_before_retry 3

            connect_port 3306

        }

    }

}

[root@mini1 ~]# mkdir /etc/keepalived/bin

[root@mini1 ~]# vim /etc/keepalived/bin/mysql.sh

#!/bin/bash

pkill keepalived

/sbin/ifdown eno16777728 && /sbin/ifup eno16777728

[root@mini1 ~]# chmod +x /etc/keepalived/bin/mysql.sh 

[root@mini1 ~]# systemctl start keepalived.service 

[root@mini1 ~]# ss -lanp |grep keepa

p_raw  UNCONN     0      0      rarp:*                      *                    users:(("keepalived",pid=17863,fd=7))

u_dgr  UNCONN     0      0         * 25852                 * 8724                users:(("keepalived",pid=17863,fd=3),("keepalived",pid=17862,fd=3),("keepalived",pid=17861,fd=3))

raw    UNCONN     0      0         *:112                   *:*                   users:(("keepalived",pid=17863,fd=9))

raw    UNCONN     0      0         *:112                   *:*                   users:(("keepalived",pid=17863,fd=8))

raw    UNCONN     0      0         *:255                   *:*                   users:(("keepalived",pid=17862,fd=5))

#master2给以上一样,只需修改配置文件几个地方和mysql.sh

[root@mini2 ~]# vim /etc/keepalived/keepalived.conf 


! Configuration File for keepalived


global_defs {

   router_id mysql_2

}


    state BACKUP

    interface eno16777736

    virtual_router_id 51

    priority 50

        auth_type PASS

        auth_pass 1111

    }   

    virtual_ipaddress {

        192.168.1.100 

    }   

}   


virtual_server 192.168.1.100 3306 {

    delay_loop 6

    lb_algo rr 

    lb_kind DR 

    persistence_timeout 50

    protocol TCP

    

    real_server 192.168.1.129 3306 {

        weight 1

        notify_down /etc/keepalived/bin/mysql.sh

        TCP_CHECK { 

            connect_timeout 3

            retry 3

            delay_before_retry 3

            connect_port 3306

        }   

    }   

}   

[root@mini2 ~]# vim /etc/keepalived/bin/mysql.sh 

#!/bin/bash

pkill keepalived

/sbin/ifdown eno16777736 && /sbin/ifup eno16777736

[root@mini1 ~]# chmod +x /etc/keepalived/bin/mysql.sh 

[root@mini1 ~]# ip addr

2: eno16777728: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:d8:de:a3 brd ff:ff:ff:ff:ff:ff

    inet 192.168.1.128/24 brd 192.168.1.255 scope global noprefixroute dynamic eno16777728

       valid_lft 5353953sec preferred_lft 5353953sec

    inet 192.168.1.100/32 scope global eno16777728

       valid_lft forever preferred_lft forever

[root@mini1 ~]# service mysqld stop

Shutting down MySQL............ SUCCESS! 

[root@mini1 ~]# ip addr

2: eno16777728: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:d8:de:a3 brd ff:ff:ff:ff:ff:ff

    inet 192.168.1.128/24 brd 192.168.1.255 scope global noprefixroute dynamic eno16777728

       valid_lft 5353814sec preferred_lft 5353814sec

    inet6 fe80::20c:29ff:fed8:dea3/64 scope link noprefixroute 

       valid_lft forever preferred_lft forever

[root@mini2 ~]# ip addr

2: eno16777736: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000

    link/ether 00:0c:29:da:f7:a1 brd ff:ff:ff:ff:ff:ff

    inet 192.168.1.129/24 brd 192.168.1.255 scope global noprefixroute dynamic eno16777736

       valid_lft 5353785sec preferred_lft 5353785sec

    inet 192.168.1.100/32 scope global eno16777736

       valid_lft forever preferred_lft forever

    inet6 fe80::20c:29ff:feda:f7a1/64 scope link noprefixroute 

       valid_lft forever preferred_lft forever


您可能感兴趣的文档:

--结束END--

本文标题: keepalived+双主

本文链接: https://lsjlt.com/news/38059.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

猜你喜欢
  • keepalived+双主
    [root@mini1 ~]# setenforce 0[root@mini1 ~]# systemctl stop firewalld.service [root@mini1 ~]# vim /...
    99+
    2024-04-02
  • mysql双主+keepalived
    环境 OS: centos7Mysql 版本: mysql 5.7Keepalived: keepalived-1.2.20Mysql-vip:192.168.41.100Mysql-master1:192...
    99+
    2024-04-02
  • keepalived+mysql双主
    keepalived+mysql双主原理:(1)主库1上的keepalived启动之后,会检查mysql服务是否活着,如果活着,keepalived进入master状态,获得VIP;(2)主库2上的keep...
    99+
    2024-04-02
  • Mysql8高可用之双主+keepalived
    1. 概述 利用keepalived实现Mysql数据库的高可用,Keepalived+Mysql双主来实现MYSQL-HA,我们必须保证两台Mysql数据库的数据完全一致,实现方法是两台Mysql互为主从关系,通过keepalived配...
    99+
    2023-10-08
    mysql 数据库 linux
  • mysql+keepalived 双主热备高可用
    理论介绍: 我们通常说的双机热备是指两台机器都在运行,但并不是两台机器都同时在提供服务。当提供服务的一台出现故障的时候,另外一台会马上自动接管并且提供服务,而且切换的时间非常短。MySQL双主复制,即互...
    99+
    2024-04-02
  • mysql双主配合keepalived可用简析
    一 版本。    mysql数据库版本:Preconna Server ,MariaDB还是MYSQL    1.mysql三种存储引擎 ...
    99+
    2024-04-02
  • linux上mysql MM(双主)及keepalived搭建
    一、主备机IP及VIP规划: master1 10.1.1.14 VIP 10.1.1.16 master2    10.1.1.15 VIP 10.1.1.16 二、mysq...
    99+
    2024-04-02
  • Mysql+Keepalived实现双主热备方式
    目录一、mysql安装、配置和安全启动二、 两台Mysql配置双主三、安装Keepalived四、配置Keepalived我们通常说的双机热备是指两台机器都在运行,但并不是两台机器都同时在提供服务。当提供服务的...
    99+
    2024-04-02
  • MySQL数据库如何配置Keepalived双主
    下面一起来了解下MySQL数据库如何配置Keepalived双主,相信大家看完肯定会受益匪浅,文字在精不在多,希望MySQL数据库如何配置Keepalived双主这篇短内容是你想要的。1、环境设置10.0....
    99+
    2024-04-02
  • Keepalived+MariaDB10配置+双主+高可用数据库
    Keepalived+MariaDB10配置双主高可用数据库  OSRS子网掩码路由网关Centos6.6MariaDB10Keepalived Eth0:192.168.26...
    99+
    2024-04-02
  • keepalived Mysql双主热备配置的示例分析
    这篇文章主要介绍keepalived Mysql双主热备配置的示例分析,文中介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们一定要看完! 基于keepalived双主热备:...
    99+
    2024-04-02
  • Ubuntu搭建Mysql+Keepalived高可用的实现(双主热备)
    Mysql5.5双机热备 实现方案 安装两台Mysql 安装Mysql5.5 sudo apt-get update apt-get install aptitud...
    99+
    2024-04-02
  • mysql主主+keepalived高可用
    mysql主主+keepalived高可用 1.两台主机 host: db1 外网:11.0.0.51 内网:172.16.1.51 db2 外网:11.0.0.52 内网:172.16.1.52 ...
    99+
    2024-04-02
  • 搭建MySQL双主MM+keepalived高可用架构的具体流程
    下文我给大家简单讲讲关于搭建MySQL双主MM+keepalived高可用架构的具体流程,大家之前了解过相关类似主题内容吗?感兴趣的话就一起来看看这篇文章吧,相信看完搭建MySQL双主MM+keepaliv...
    99+
    2024-04-02
  • Vmware部署Nginx+KeepAlived集群双主架构的问题及解决方法
    前言 用nginx做负载均衡,作为架构的最前端或中间层,随着日益增长的访问量,需要给负载均衡做高可用架构,利用keepalived解决单点风险,一旦 nginx宕机能快速切换到备份服...
    99+
    2024-04-02
  • centos7 mysql互为主从+keepalived
    一、互为主从配置1.1、资源情况192.168.11.177 server1192.168.11.180 server2192.168.11.210 VIP1.2、server1配置# vi /etc/my...
    99+
    2024-04-02
  • Keepalived+Mysql如何配置主主复制
    小编给大家分享一下Keepalived+Mysql如何配置主主复制,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!安装环境:Hos...
    99+
    2024-04-02
  • 如何搭建keepalived+nginx+httpd+dns高可用双主反向代理服务器
    如何搭建keepalived+nginx+httpd+dns高可用双主反向代理服务器,相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。rs服务器安装httpd,ip为:192.16...
    99+
    2023-06-05
  • keepalived配置虚拟ip(VRRP)实现双机热备以及自动切换主备
    需求 我有两个服务器,一台A是正常处理数据的,还有一台B是备用机器;A如果网络异常或者崩了,B开启采集技术 但是其他人访问的ip地址,如果从A变成B,地址改变了,会影响业务需求的;所以需要A与B共用一个Ip地址,A服务器崩了,B还在,不影...
    99+
    2023-10-06
    服务器
  • MySQL主从复制项目(MHA+双主Keepalived)_MySQL高可用复制与分布式集群架构04
    MySQL主从复制项目(MHA+双主Keepalived)_MySQL高可用复制与分布式集群架构04视频教程学习地址    http://edu.51cto.com/cours...
    99+
    2024-04-02
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作