Chinaunix首页 | 论坛 | 博客

OPS

  • 博客访问: 490356
  • 博文数量: 117
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 1210
  • 用 户 组: 普通用户
  • 注册时间: 2015-05-05 14:50
个人简介

hellow 运维

文章分类

全部博文(117)

文章存档

2019年(1)

2018年(1)

2017年(45)

2016年(38)

2015年(32)

我的朋友

分类: 系统运维

2015-10-09 12:56:14

我的配置:
 [root@mysql ~]# rpm -qa keepalived
keepalived-1.2.13-5.el6_6.x86_64
[root@mysql ~]# cat /etc/issue
CentOS release 6.5 (Final)
Kernel \r on an \m
[root@test ~]# mysql -uroot -p123 -h192.168.31.132
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 53
Server version: 5.5.46-log MySQL Community Server (GPL) by Remi
[root@mysql ~]# mysql -u root -p123 -h192.168.31.136
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 124
Server version: 5.5.32-MariaDB-log MariaDB Server
mysql服务器ip地址 mysqlVIP mysql版本
192.168.31.132 192.168.31.131  5.5.46-log MySQL Community Server
192.168.31.136 192.168.31.131 5.5.32-MariaDB-log MariaDB Server
这里mysql的安装和配置主主复制就不提了:
mysql的安装:网上很多不一一复制了
mysql主主复制配置案例: http://blog.chinaunix.net/uid-30234663-id-5192230.html
 开始配置安装:  
 1:下载安装keepalived(所有节点都要安装):
      [root@mysql ~]# yum install -y keepalived
然后配置如下:
   192.168.31.136配置:
    [root@mysql ~]# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived
global_defs {
   notification_email {
        hz7726@163.com
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}
vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 60
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.31.131
    }
}
virtual_server 192.168.31.131 3306 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP
    real_server 192.168.31.136 3306 {
        weight 3
        notify_down /tmp/mysql.sh 
         TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
             connect_port 3306 
        }
    }
}
192.168.31.132的配置如下
  [root@test ~]# cat /etc/keepalived/keepalived.conf
! Configuration File for keepalived


global_defs {
   notification_email {
        hz7726@163.com
   }
   notification_email_from Alexandre.Cassen@firewall.loc
   smtp_server 127.0.0.1
   smtp_connect_timeout 30
   router_id LVS_DEVEL
}


vrrp_instance VI_1 {
    state BACKUP
    interface eth0
    virtual_router_id 60
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        192.168.31.131
    }
}


virtual_server 192.168.31.131 3306 {
    delay_loop 6
    lb_algo wrr
    lb_kind DR
    nat_mask 255.255.255.0
    persistence_timeout 50
    protocol TCP


    real_server 192.168.31.132 3306 {
        weight 3
        notify_down /tmp/mysql.sh 
         TCP_CHECK {
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
             connect_port 3306 
        }
    }
}
注意:要在两个服务器都要给其用户授权:不然报错如下
[root@test ~]# mysql -uroot -p123 -h192.168.31.131
ERROR 1045 (28000): Access denied for user 'root'@'192.168.31.131' (using password: YES)
解决办法:
mysql> grant all on *.* to root@'192.168.31.%' identified by '123';
Query OK, 0 rows affected (0.05 sec)


mysql>  flush privileges
    -> ;
Query OK, 0 rows affected (0.00 sec)
授权之后再在192.168.31.132和192。168.31.136上写mysql.sh检测脚本
如下:
#!/bin/sh 
pkill keepalived #检测资源放置脑裂
在测试随便一台服务器:
[root@mysql ~]# mysql -uroot -p123 -h 192.168.31.131
MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| han                |
| hanye              |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)
停掉一台服务器在测试:
        valid_lft forever preferred_lft forever
[root@mysql ~]# pkill keepalived

[root@mysql ~]# mysql -uroot -p123 -h 192.168.31.131
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 54
Server version: 5.5.46-log MySQL Community Server (GPL) by Remi


Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| blog_article02     |
| db1                |
| db2                |
| db3                |
| dbtest1            |
| dbtest2            |
| dbtest3            |
| mycat              |
| mysql              |
| performance_schema |
| syslog             |
+--------------------+
12 rows in set (0.07 sec)
注意:我这边两台服务器的数据是不一致的:更容易发现高可用成功与否!!!
[root@test ~]# ifconfig eth0 | awk -F'[: ]+' '/inet addr/{print $4}'
192.168.31.132
[root@test ~]# mysql -u root -p123
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 86
Server version: 5.5.46-log MySQL Community Server (GPL) by Remi


Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.


Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| blog_article02     |
| db1                |
| db2                |
| db3                |
| dbtest1            |
| dbtest2            |
| dbtest3            |
| mycat              |
| mysql              |
| performance_schema |
| syslog             |
+--------------------+
12 rows in set (0.00 sec
[root@mysql ~]# ifconfig eth0 | awk -F'[: ]+' '/inet addr/{print $4}'
192.168.31.136
[root@mysql ~]# mysql -uroot -p123
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 734
Server version: 5.5.32-MariaDB-log MariaDB Server


Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.


Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.


MariaDB [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| han                |
| hanye              |
| mysql              |
| performance_schema |
| test               |
+--------------------+
6 rows in set (0.00 sec)

ok了配置完成



 






阅读(1598) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~