轩辕阁 发表于 2019-1-3 12:26:33

Atlas+keepalive+LVS+mysql主从

  web1            192.168.1.137    sh keninit.sh安装web
  

  vip             192.168.1.254    此ip是虚拟ip
  

  web2            192.168.1.138    sh keninit.sh安装web
  

  主mysqlA           192.168.1.140   主
  从mysqlB           192.168.1.141   从
  从mysqlC         192.168.1.145   从
  Atlas1          192.168.1.146    Atlas+keepalive+lvs
  Atlas2          192.168.1.144    Atlas+keepalive+lvs
  实验环境:六台机器全部是centos6.5的环境
  一、以下三台数据库机器140mysqlA,141mysqlB和145mysqlC操作一模一样
  yum install -ygcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libgcrypt* libtool*
  wget http://www.cmake.org/files/v2.8/cmake-2.8.4.tar.gz --no-check-certificate
  tar -zxvfcmake-2.8.4.tar.gz
  cdcmake-2.8.4.tar.gz
  ./configure&& make && make install
  mkdir /opt/mysql
  mkdir /opt/mysql/data
  groupadd mysql
  useradd -g mysql mysql
  chown mysql:mysql -R /opt/mysql/data
  wget http://downloads.mysql.com/archives/get/file/mysql-5.5.13.tar.gz
  tar -zxvfmysql-5.5.13.tar.gz
  cdmysql-5.5.13.tar.gz
  cmake -DCMAKE_INSTALL_PREFIX=/opt/mysql \
  -DSYSCONFDIR=/opt/mysql/etc \
  -DMYSQL_DATADIR=/opt/mysql/data \
  -DMYSQL_TCP_PORT=3306 \
  -DMYSQL_UNIX_ADDR=/tmp/mysqld.sock \
  -DMYSQL_USER=mysql \
  -DEXTRA_CHARSETS=all \
  -DWITH_READLINE=1 \
  -DWITH_SSL=system \
  -DWITH_EMBEDDED_SERVER=1 \
  -DENABLED_LOCAL_INFILE=1 \
  -DWITH_INNOBASE_STORAGE_ENGINE=1
  make && make install
  mkdir /opt/mysql/log
  mkdir /opt/mysql/etc
  cp support-files/my-medium.cnf /opt/mysql/etc/my.cnf
  chmod 755 scripts/mysql_install_db
  scripts/mysql_install_db --user=mysql --basedir=/opt/mysql/ --datadir=/opt/mysql/data/
  mkdir /opt/mysql/init.d
  cp support-files/mysql.server /opt/mysql/init.d/mysql
  chmod +x /opt/mysql/init.d/mysql
   /opt/mysql/init.d/mysql start
   find / -name mysqld.sock
   /tmp/mysqld.sock
   /opt/mysql/bin/mysql -S /tmp/mysqld.sock -P 3306
   /opt/mysql/bin/mysqladmin -u root password '123456'   #设置mysql数据库密码
   /opt/mysql/bin/mysql -uroot -p'123456'               #登陆mysql数据库
  # grep -Ev "^#|^$" /opt/mysql/etc/my.cnf
  
  port      = 3306
  socket      = /tmp/mysqld.sock
  
  port      = 3306
  socket      = /tmp/mysqld.sock
  basedir         = /opt/mysql/               ############报错的解决方法
  datadir         = /opt/mysql/data/             ###########报错的解决方法
  skip-external-locking
  key_buffer_size = 16M
  max_allowed_packet = 1M
  table_open_cache = 64
  sort_buffer_size = 512K
  net_buffer_length = 8K
  read_buffer_size = 256K
  read_rnd_buffer_size = 512K
  myisam_sort_buffer_size = 8M
  log-bin=mysql-bin
  binlog_format=mixed
  server-id    = 1
  
  quick
  max_allowed_packet = 16M
  
  no-auto-rehash
  
  key_buffer_size = 20M
  sort_buffer_size = 20M
  read_buffer = 2M
  write_buffer = 2M
  
  interactive-timeout
  
  
  1、在192.168.1.140主mysqlA里
  #   /opt/mysql/bin/mysql -uroot -p'123456'
  mysql>GRANT REPLICATION SLAVE ON *.* to 'rep1'@'192.168.1.141' identified by "123456";   #给mysqlB授权
  mysql>GRANT REPLICATION SLAVE ON *.* to 'rep1'@'192.168.1.145' identified by "123456";
  mysql>grant all on *.* to per1@'192.168.1.146' identified by '123456';   #所有主从都要给Atlas数据库授权,不然提示down的状态
  mysql> flushprivileges;
  mysql> show master status;
  +------------------+----------+--------------+------------------+
  | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  +------------------+----------+--------------+------------------+
  | mysql-bin.000003 |      699 |            |                  |
  +------------------+----------+--------------+------------------+
  ##记录下 FILE 及 Position 的值,在后面进行从服务器操作的时候需要用到。
  
  
  2、在192.168.1.141/145mysqlB/C从里
  #   /opt/mysql/bin/mysql -uroot -p'123456'
  mysql>grant all on *.* to per1@'192.168.1.146' identified by '123456';#所有主从都要给Atlas数据库授权,不然提示down的状态
  mysql> flushprivileges;
  # grepserver-id /opt/mysql/etc/my.cnf
  server-id    = 10          ###145的改为server-id =9                  
  #server-id       = 2
  # /opt/mysql/init.d/mysql restart
  Shutting down MySQL.                                       [确定]
  Starting MySQL..                                           [确定]
  # /opt/mysql/bin/mysql -uroot -p'123456'
  mysql> change master to master_host="192.168.1.140", master_user="rep1", master_password="123456", master_log_file="mysql-bin.000003", master_log_pos=699;
  mysql>start slave;
  Query OK, 0 rows affected (0.01 sec)                                                 ####注意防火墙和selinux都关掉或者开放相应的端口
  
  mysql> show slave status\G
                 Slave_IO_State: Waiting for master to send event
                    Master_Host: 192.168.1.140
                    Master_User: rep1
                    Master_Port: 3306
                  Connect_Retry: 60
              Master_Log_File: mysql-bin.000005
            Read_Master_Log_Pos: 107
                 Relay_Log_File: localhost-relay-bin.000005
                  Relay_Log_Pos: 253
        Relay_Master_Log_File: mysql-bin.000005
               Slave_IO_Running: Yes
              Slave_SQL_Running: Yes
              Replicate_Do_DB:
            Replicate_Ignore_DB:
           Replicate_Do_Table:
         Replicate_Ignore_Table:
        Replicate_Wild_Do_Table:
  Replicate_Wild_Ignore_Table:
                     Last_Errno: 0
                     Last_Error:
                 Skip_Counter: 0
            Exec_Master_Log_Pos: 107
              Relay_Log_Space: 413
              Until_Condition: None
                 Until_Log_File:
                  Until_Log_Pos: 0
           Master_SSL_Allowed: No
           Master_SSL_CA_File:
           Master_SSL_CA_Path:
              Master_SSL_Cert:
              Master_SSL_Cipher:
                 Master_SSL_Key:
        Seconds_Behind_Master: 0
  Master_SSL_Verify_Server_Cert: No
                  Last_IO_Errno: 0
                  Last_IO_Error:
                 Last_SQL_Errno: 0
                 Last_SQL_Error:
  Replicate_Ignore_Server_Ids:
               Master_Server_Id: 1
  1 row in set (0.00 sec)
  3、验证:在主192.168.1.140里
  #/opt/mysql/bin/mysql -uroot -p'123456'
  mysql>create database mydatabases;
  Query OK, 1 row affected (0.00 sec)
  
  mysql> show databases;
  +--------------------+
  | Database         |
  +--------------------+
  | information_schema |
  | first_db         |
  | mydatabases      |
  | mysql            |
  | performance_schema |
  | test               |
  +--------------------+
  6 rows in set (0.00 sec)
  
  在从数据库里192.168.1.141里查看
  
  #/opt/mysql/bin/mysql -uroot -p'123456'
  mysql> show databases;
  +--------------------+
  | Database         |
  +--------------------+
  | information_schema |
  | first_db         |
  | mydatabases      |
  | mysql            |
  | performance_schema |
  | test               |
  +--------------------+
  6 rows in set (0.00 sec)
  OK,至此主从同步完成。
  4、以下是常见的主从错误
  1.网络不通
  2.密码不对
  3.pos不正确
  4.ID问题
  5.防火墙开端口和selinux关掉
  补充:
  双方的机器防火墙是否策略有限制。
  ID的问题,在安装完mysql数据库的时候默认他们的server-id=1 但是在做主从同步的时候需要将ID 号码设置不一样才行。
  
  二、安装Atlas
  1、安装atlas
  yum install -y pkg-config libevent*glib lua
  wget ftp://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz && tar zxvfautoconf-2.69.tar.gz && cd autoconf-2.69 &&./configure && make && make install
  wget http://ftp.gnu.org/gnu/automake/automake-1.13.2.tar.gz&&tar zxvfautomake-1.13.2.tar.gz&& cd automake-1.13.2 &&./configure && make && make install
   yum install -y libffi-devel
  wget http://ftp.gnome.org/pub/gnome/sources/glib/2.36/glib-2.36.3.tar.xz && tar xvf glib-2.36.3.tar.xz && cd glib-2.36.3 && ./configure
  export PKG_CONFIG_PATH=/usr/bin/pkg-config
  make && make install
  将Atlas包下载到本地,再从本地上传到服务器里
  wget--no-check-certificatehttps://github.com/Qihoo360/Atlas/releases/download/2.2.1/Atlas-2.2.1.el6.x86_64.rpm
  2、修改test.cnf配置文件
  vim/usr/local/mysql-proxy/conf/test.cnf
  # /usr/local/mysql-proxy/bin/encrypt 123456   
  /iZxz+0GRoA=                            #生成密钥
  
  # cat test.cnf
  
  
  #带#号的为非必需的配置项目
  
  #管理接口的用户名
  admin-username = user
  
  #管理接口的密码
  admin-password = pwd
  
  #实现管理接口的Lua脚本所在路径
  admin-lua-script = /usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua
  
  #Atlas后端连接的MySQL主库的IP和端口,可设置多项,用逗号分隔
  proxy-backend-addresses = 192.168.1.140:3306
  
  #Atlas后端连接的MySQL从库的IP和端口,@后面的数字代表权重,用来作负载均衡,若省略则默认为1,可设置多项,用逗号分隔
  proxy-read-only-backend-addresses = 192.168.1.141:3306@1,192.168.1.145:3306@1
  
  #用户名与其对应的加密过的MySQL密码,密码使用PREFIX/bin目录下的加密程序encrypt加密
  pwds = root:/iZxz+0GRoA=                     ##和上面的密钥对应
  
  #设置Atlas的运行方式,设为true时为守护进程方式,设为false时为前台方式,一般开发调试时设为false,线上运行时设为true
  daemon = true
  
  #设置Atlas的运行方式,设为true时Atlas会启动两个进程,一个为monitor,一个为worker,monitor在worker意外退出后会自动将其重启,设为false时只有worker,没有monitor,一般开发调试时设为false,线上运行时设为true
  keepalive = true
  
  #工作线程数,推荐设置与系统的CPU核数相等
  event-threads = 4
  
  #日志级别,分为message、warning、critical、error、debug五个级别
  log-level = message
  
  #日志存放的路径
  log-path = /usr/local/mysql-proxy/log                   #日志查找的地方
  
  #SQL日志的开关,可设置为OFF、ON、REALTIME,OFF代表不记录SQL日志,ON代表记录SQL日志,REALTIME代表记录SQL日志且实时写入磁盘,默认为OFF
  #sql-log = OFF
  
  #实例名称,用于同一台机器上多个Atlas实例间的区分
  instance = test
  
  #Atlas监听的工作接口IP和端口
  proxy-address = 0.0.0.0:1234
  
  #Atlas监听的管理接口IP和端口
  admin-address = 0.0.0.0:2345
  
  #分表设置,此例中person为库名,mt为表名,id为分表字段,3为子表数量,可设置多项,以逗号分隔,若不分表则不需要设置该项
  #tables = person.mt.id.3
  
  #默认字符集,若不设置该项,则默认字符集为latin1
  charset = utf8
  
  #允许连接Atlas的客户端的IP,可以是精确IP,也可以是IP段,以逗号分隔,若不设置该项则允许所有IP连接,否则只允许列表中的IP连接
  #client-ips = 127.0.0.1, 192.168.1
  
  #Atlas前面挂接的LVS的物理网卡的IP(注意不是虚IP),若有LVS且设置了client-ips则此项必须设置,否则可以不设置
  #lvs-ips = 192.168.1.1
  3、启动Atlas
  /usr/local/mysql-proxy/bin/mysql-proxyd test start
  4、查看Atlas进程
  ps aux | grep mysql-proxy | grep -v grep
  5、在mysqlA、B、C主和从数据库里查看Atlas
   /opt/mysql/bin/mysql -uuser -ppwd-h192.168.1.144 -P2345   #查看Atlas2
  mysql> select * from backends;
  +-------------+--------------------+-------+------+
  | backend_ndx | address            | state | type |
  +-------------+--------------------+-------+------+
  |         1 | 192.168.1.140:3306 | up    | rw   |
  |         2 | 192.168.1.141:3306 | up    | ro   |
  |         3 | 192.168.1.145:3306 | up    | ro   |
  +-------------+--------------------+-------+------+
  3 rows in set (0.00 sec)
  
   /opt/mysql/bin/mysql -uuser -ppwd-h192.168.1.146 -P2345   #查看Atlas1
  mysql> select * from backends;
  +-------------+--------------------+-------+------+
  | backend_ndx | address            | state | type |
  +-------------+--------------------+-------+------+
  |         1 | 192.168.1.140:3306 | up    | rw   |
  |         2 | 192.168.1.141:3306 | up    | ro   |
  |         3 | 192.168.1.145:3306 | up    | ro   |
  +-------------+--------------------+-------+------+
  3 rows in set (0.00 sec)
  mysql> remove backend3;                               ###下线数据库
  Empty set (0.00 sec)
  
  mysql> select * from backends;
  +-------------+--------------------+-------+------+
  | backend_ndx | address            | state | type |
  +-------------+--------------------+-------+------+
  |         1 | 192.168.1.140:3306 | up    | rw   |
  |         2 | 192.168.1.141:3306 | up    | ro   |
  +-------------+--------------------+-------+------+
  2 rows in set (0.00 sec)
  
  mysql> add slave 192.168.1.145:3306                        ###上线数据库
      -> ;
  Empty set (0.00 sec)
  
  mysql> select * from backends;
  +-------------+--------------------+-------+------+
  | backend_ndx | address            | state | type |
  +-------------+--------------------+-------+------+
  |         1 | 192.168.1.140:3306 | up    | rw   |
  |         2 | 192.168.1.141:3306 | up    | ro   |
  |         3 | 192.168.1.145:3306 | up    | ro   |
  +-------------+--------------------+-------+------+
  3 rows in set (0.00 sec)
  
  mysql> set online 3;
  +-------------+--------------------+---------+------+
  | backend_ndx | address            | state   | type |
  +-------------+--------------------+---------+------+
  |         3 | 192.168.1.145:3306 | unknown | ro   |
  +-------------+--------------------+---------+------+
  1 row in set (0.00 sec)
  
  mysql> select * from backends;
  +-------------+--------------------+-------+------+
  | backend_ndx | address            | state | type |
  +-------------+--------------------+-------+------+
  |         1 | 192.168.1.140:3306 | up    | rw   |
  |         2 | 192.168.1.141:3306 | up    | ro   |
  |         3 | 192.168.1.145:3306 | up    | ro   |
  +-------------+--------------------+-------+------+
  3 rows in set (0.00 sec)
  6、在192.168.1.145从mysqlc机器上
  #模拟故障
  # netstat -utnalp | grep mysql
  tcp      0      0 0.0.0.0:3306                0.0.0.0:*                   LISTEN      4284/mysqld         
  tcp      0      0 192.168.1.145:54292         192.168.1.140:3306          ESTABLISHED 4284/mysqld         
  # kill 4284
  # netstat -utnalp | grep mysql
  # ps aux | grep mysql
  root      46910.00.1 103256   856 pts/0    S+   15:50   0:00 grep mysql
  # /opt/mysql/bin/mysql -uuser -ppwd-h192.168.1.144 -P2345
  mysql> select * from backends;
  +-------------+--------------------+-------+------+
  | backend_ndx | address            | state | type |
  +-------------+--------------------+-------+------+
  |         1 | 192.168.1.140:3306 | up    | rw   |
  |         2 | 192.168.1.141:3306 | up    | ro   |
  |         3 | 192.168.1.145:3306 | down| ro   |                     
  ###可以看到192.168.1.145已经down了,这个要把Atlas的配置文件
  vim/usr/local/mysql-proxy/conf/test.cnf里面的从数据库的优先级调成一样时看的更快。
  #proxy-read-only-backend-addresses = 192.168.1.141:3306@1,192.168.1.145:3306@1
  其中@1为优先级
  将192.168.1.145数据库启动
  # /opt/mysql/init.d/mysql restart         ###恢复故障
  Shutting down MySQL.                                       [确定]
  Starting MySQL..                                           [确定]
  # /opt/mysql/bin/mysql -uuser -ppwd-h192.168.1.144 -P2345
  mysql> select * from backends;
  +-------------+--------------------+-------+------+
  | backend_ndx | address            | state | type |
  +-------------+--------------------+-------+------+
  |         1 | 192.168.1.140:3306 | up    | rw   |
  |         2 | 192.168.1.141:3306 | up    | ro   |
  |         3 | 192.168.1.145:3306 | up    | ro   |
  +-------------+--------------------+-------+------+          ####可以看到已经OK.
  3 rows in set (0.00 sec)
  
  7、连接自己主从数据库的命令
  #   /opt/mysql/bin/mysql-uroot -p123456
  #   /opt/mysql/init.d/mysql restart/stop/start
  
  三、以下是架构的搭建
  Mysql主从:一主三从
  Atlas:2个节点做HA
  Keepalived:提供VIP防止Atlas单点故障
  
  1、安装keepalived
  wget http://www.keepalived.org/software/keepalived-1.2.13.tar.gz
  tar zxvf keepalived-1.2.13.tar.gz -C /opt/
  cd /opt/keepalived-1.2.13
  ./configure --prefix=/usr/local/keeplived
  make && makeinstall
  
  2、新建一个配置文件,默认情况下keepalived启动时会去/etc/keepalived
  # mkdir -p /etc/keepalived
  # cp -r /usr/local/keeplived/etc/keepalived/keepalived.conf/etc/keepalived/
  
  
  3、编辑配置文件
  #Atlas1(1.146)上
  
  # vim /etc/keepalived/keepalived.conf
  ! Configuration File for keepalived
  
  global_defs {
     notification_email {
     837337164@qq.com
     }
     notification_email_from 837337164@qq.com
     smtp_server 127.0.0.1
     smtp_connect_timeout 30
     router_id Atlas_ha
  }
  
  vrrp_instance Atlas_ha {
      state master
      interface eth0
      virtual_router_id 51
      priority 100
      advert_int 1
      authentication {
        auth_type PASS
        auth_pass 1111
      }
      virtual_ipaddress {
        192.168.1.254
      }
  }
  
  virtual_server 192.168.1.254 80 {
      delay_loop 6
      lb_algo rr
      lb_kind DR
      nat_mask 255.255.255.0
      persistence_timeout 50
      protocol TCP
  
      real_server 192.168.1.137 80 {
        weight 1
        notify_down /usr/local/mysql-proxy/bin/Atlas.sh
        TCP_CHECK {
              connect_timeout 10
              nb_get_retry 3
              delay_before_retry 3
              connect_port 80
              }
         }
      real_server 192.168.1.138 80 {
        weight 1
        notify_down /usr/local/mysql-proxy/bin/Atlas.sh
        TCP_CHECK {
              connect_timeout 10
              nb_get_retry 3
              delay_before_retry 3
              connect_port 80
        }
      }
  }
  
  
  
  #Atlas2(1.144)与atlas1几乎一致,如下:
  # vim /etc/keepalived/keepalived.conf
  ! Configuration File for keepalived
  
  global_defs {
     notification_email {
     837337164@qq.com
     }
     notification_email_from 837337164@qq.com
     smtp_server 127.0.0.1
     smtp_connect_timeout 30
     router_id Atlas_ha
  }
  
  vrrp_instance Atlas_ha {
      state BACKUP
      interface eth0
      virtual_router_id 51
      priority 50
      advert_int 1
      authentication {
        auth_type PASS
        auth_pass 1111
      }
      virtual_ipaddress {
        192.168.1.254
      }
  }
  
  virtual_server 192.168.1.254 80 {
      delay_loop 6
      lb_algo rr
      lb_kind DR
      nat_mask 255.255.255.0
      persistence_timeout 50
      protocol TCP
  
      real_server 192.168.1.137 80 {
        weight 1
        notify_down /usr/local/mysql-proxy/bin/Atlas.sh
        TCP_CHECK {
              connect_timeout 10
              nb_get_retry 3
              delay_before_retry 3
              connect_port 80
              }
        }
      real_server 192.168.1.138 80 {
        weight 1
        notify_down /usr/local/mysql-proxy/bin/Atlas.sh
        TCP_CHECK {
              connect_timeout 10
              nb_get_retry 3
              delay_before_retry 3
              connect_port 80
        }
      }
  }
  4、创建notify_down脚本
  # cat /usr/local/mysql-proxy/bin/Atlas.sh
  #!/bin/sh
  pkillkeepalived
  
  # chmod +x/usr/local/mysql-proxy/bin/Atlas.sh
  
  启动keepalived
  # /usr/local/keeplived/sbin/keepalived -D
  # ps aux | grep keepalived | grep -v grep
  root      51510.00.139980   776 ?      Ss   17:48   0:00 /usr/local/keeplived/sbin/keepalived -D
  root      51520.10.4420842068 ?      S    17:48   0:00 /usr/local/keeplived/sbin/keepalived -D
  root      51530.20.2420841296 ?      S    17:48   0:00 /usr/local/keeplived/sbin/keepalived -D
  停止keepalived
  # kill5151
  4、查看keepalived日志,解决问题思路
  tail -f/var/log/messages
  四、在192.168.1.146(Atlas1)和192.168.1.144(Atlas2)上分别安装LVS
  #yuminstall -yipvsadm
  # ipvsadm -L -n
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port         Forward Weight ActiveConn InActConn
  TCP192.168.1.254:80 rr persistent 50
  -> 192.168.1.137:80             Route   1      0          0         
  -> 192.168.1.138:80             Route   1      0          0   
  #ip addr list#用这个指令可以看到vip的192.168.1.254在那台Atlas上
  1: lo:mtu 16436 qdisc noqueue state UNKNOWN
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope host lo
      inet6 ::1/128 scope host
         valid_lft forever preferred_lft forever
  3: eth0:mtu 1500 qdisc pfifo_fast state UP qlen 1000
      link/ether 00:0c:29:ec:ff:f2 brd ff:ff:ff:ff:ff:ff
      inet 192.168.1.146/24 brd 192.168.1.255 scope global eth0
      inet 192.168.1.254/32 scope global eth0                     ###虚拟ip                           
      inet6 fe80::20c:29ff:feec:fff2/64 scope link
         valid_lft forever preferred_lft forever
  
  
  
  
  
  五、在192.168.1.137(web1)和192.168.1.138(web2)服务器里安装虚拟vip的ip脚本
  1、安装脚本
  # cat lvs-client.sh
  . /etc/rc.d/init.d/functions
  VIP=(
  192.168.1.254
  )
  function start(){
  for ((i=0;i/proc/sys/net/ipv4/conf/lo/arp_ignore
  echo "2">/proc/sys/net/ipv4/conf/lo/arp_announce
  echo "1">/proc/sys/net/ipv4/conf/all/arp_announce
  echo "2">/proc/sys/net/ipv4/conf/all/arp_announce
  }
  functionstop(){
  for ((i=0;i RemoteAddress:Port         Forward Weight ActiveConn InActConn
  TCP192.168.1.254:80 rr persistent 50
  -> 192.168.1.137:80             Route   1      0          1   
  3、测试,现在192.168.1.144Atlas2
  # curl http://192.168.1.254
  RS1
  4、重启192.168.1.138的http
  service httpdstart
  在看192.168.1.146Atlas1
  # ipvsadm -L -n
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port         Forward Weight ActiveConn InActConn
  TCP192.168.1.254:80 rr persistent 50
  -> 192.168.1.137:80             Route   1      0          0         
  -> 192.168.1.138:80             Route   1      0          0
  5、关闭192.168.1.146Atlas1上的keepalived
  # ps aux | grep keepalived | grep -v grep
  root      81730.00.139980   772 ?      Ss   14:14   0:00 /usr/local/keeplived/sbin/keepalived -D
  root      81740.00.4422082080 ?      S    14:14   0:00 /usr/local/keeplived/sbin/keepalived -D
  root      81750.00.2420841296 ?      S    14:14   0:00 /usr/local/keeplived/sbin/keepalived -D
  # kill 8173
  在192.168.1.144Atlas2上面查看
  # /usr/local/keeplived/sbin/keepalived -D
  # ipvsadm -L -n
  IP Virtual Server version 1.2.1 (size=4096)
  Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port         Forward Weight ActiveConn InActConn
  TCP192.168.1.254:80 rr persistent 50
  -> 192.168.1.137:80             Route   1      0          0         
  -> 192.168.1.138:80             Route   1      0          0      
  # ip addr list
  1: lo:mtu 16436 qdisc noqueue state UNKNOWN
      link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
      inet 127.0.0.1/8 scope host lo
      inet6 ::1/128 scope host
         valid_lft forever preferred_lft forever
  2: eth0:mtu 1500 qdisc pfifo_fast state UP qlen 1000
      link/ether 00:0c:29:bc:de:b4 brd ff:ff:ff:ff:ff:ff
      inet 192.168.1.144/24 brd 192.168.1.255 scope global eth0
      inet 192.168.1.254/32 scope global eth0                                    ###此时192.168.1.254VIP已经被Atlas2拿到了。
      inet6 fe80::20c:29ff:febc:deb4/64 scope link
         valid_lft forever preferred_lft forever
  在192.168.1.146Atlas1上
  #curl http://192.168.1.254
  RS2                                                    ###可以访问
  




页: [1]
查看完整版本: Atlas+keepalive+LVS+mysql主从