企业web高可用集群实战之lvs+keepalived+mysql双主

时间:2022-09-15 08:26:21

 

本文出自 “瑾于外者必盈于内” 博客,请务必保留此出处http://linuxops.blog.51cto.com/2238445/932673

 

前端用两台server做lvs+keepalived负载调度器,中间用apache+php作为web应用服务器,后端用两台做mysql高可用,用nfs、mfs或作为web文件共享服务器

  系统环境: LVS调度主服务器:192.168.8.11 LVS调度从服务器:192.168.8.12 LVS VIP:192.168.8.10 apache服务器:192.168.8.20 192.168.8.21 MySQL主服务器:192.168.8.31 MySQL从服务器:192.168.8.32 MySQL VIP:192.168.8.30 GFS:   由于工作时间比较紧,同时还要培训,架构图后期补上!!   用到软件准备: 所有服务器软件包都放在/opt 目录下,下面是下载地址:
  
 
 
  1. wget http://www.keepalived.org/software/keepalived-1.1.20.tar.gz
  2. wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.24-linux2.6-x86_64.tar.gz #64位
  3. wget http://downloads.mysql.com/archives/mysql-5.5/mysql-5.5.24-linux2.6-i686.tar.gz #32位
一、LVS+Keepalived 1.安装ipvsadm yum -y install ipvsadm kernel-devel ln -sv /usr/src/kernels/2.6.18-308.8.2.el5-x86_64/ /usr/src/linux   2.安装keepalived
  
 
 
  1. cd /opt/
  2. tar zxf keepalived-1.1.20.tar.gz
  3. cd keepalived-1.1.20
  4. ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.18-308.11.1.el5-x86_64/
  5. 出现如下信息内核加载成功:
  6. Keepalived configuration
  7. ------------------------
  8. Keepalived version : 1.2.0
  9. Compiler : gcc
  10. Compiler flags : -g -O2
  11. Extra Lib : -lpopt -lssl -lcrypto
  12. Use IPVS Framework : Yes
  13. IPVS sync daemon support : Yes
  14. Use VRRP Framework : Yes
  15. Use Debug flags : No
  16. make;make install
  17. cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d
  18. cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
  19. mkdir /etc/keepalived
  20. chkconfig keepalived on

3.创建配置文件
  
 
 
  1. cat /etc/keepalived/keepalived.conf
  2. ! Configuration File for keepalived
  3. global_defs {
  4. notification_email {
  5. 250621008@qq.com
  6. }
  7. notification_email_from 250621008@qq.com
  8. smtp_server smtp.163.com
  9. #smtp_connect_timeout 30
  10. router_id LVS_DEVEL
  11. }
  12. vrrp_instance VI_1 {
  13. state MASTER #备份服务器上将MASTER改为BACKUP
  14. interface eth0
  15. lvs_sync_daemon_inteface eth0
  16. virtual_router_id 51
  17. priority 100 #备份服务上将100改为低于100的数值
  18. advert_int 5
  19. authentication {
  20. auth_type PASS
  21. auth_pass 1111
  22. }
  23. virtual_ipaddress {
  24. 192.168.8.10
  25. }
  26. }
  27. virtual_server 192.168.8.10 80 {
  28. delay_loop 6 #(每隔10秒查询realserver状态)
  29. lb_algo wlc #(lvs 算法)
  30. lb_kind DR #(Direct Route)
  31. persistence_timeout 60 #(同一IP的连接60秒内被分配到同一台realserver)
  32. protocol TCP #(用TCP协议检查realserver状态)
  33. real_server 192.168.8.10 80 {
  34. weight 100 #(权重)
  35. TCP_CHECK {
  36. connect_timeout 10 #(10秒无响应超时)
  37. nb_get_retry 3
  38. delay_before_retry 3
  39. connect_port 80
  40. }
  41. }
  42. real_server 192.168.8.12 80 {
  43. weight 100
  44. TCP_CHECK {
  45. connect_timeout 10
  46. nb_get_retry 3
  47. delay_before_retry 3
  48. connect_port 80
  49. }
  50. }
  51. }
PS :从配置文件参考以上主的配置文件,不同的地方是红色标注两处!   二、WEB集群 1、这里可以选择lamp、lnmp、lanmp等web架构,至于搭建略! 2、在各web节点上创建realserver脚本
  
 
 
  1. cat /root/sh/lvs_real.sh
  2. #!/bin/bash
  3. #Description: Config realserver script
  4. #Written by : opsren----http://linuxops.blog.51cto.com
  5. SNS_VIP=192.168.8.10
  6. /etc/rc.d/init.d/functions
  7. case "$1" in
  8. start)
  9. /sbin/ifconfig lo:0 $SNS_VIP netmask 255.255.255.255 broadcast $SNS_VIP
  10. /sbin/route add -host $SNS_VIP dev lo:0
  11. echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
  12. echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
  13. echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
  14. echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
  15. sysctl -p >/dev/null 2>&1
  16. echo "RealServer Start OK"
  17. ;;
  18. stop)
  19. /sbin/ifconfig lo:0 down
  20. /sbin/route del $SNS_VIP >/dev/null 2>&1
  21. echo "0" >/proc/sys/net/ipv4/conf/lo/arp_ignore
  22. echo "0" >/proc/sys/net/ipv4/conf/lo/arp_announce
  23. echo "0" >/proc/sys/net/ipv4/conf/all/arp_ignore
  24. echo "0" >/proc/sys/net/ipv4/conf/all/arp_announce
  25. echo "RealServer Stoped"
  26. ;;
  27. *)
  28. echo "Usage: $0 {start|stop}"
  29. exit 1
  30. esac
  31. exit 0
  32. 给予可执行权限:
  33. chmod +755 /roo/sh/lvs_real.sh
  34. 启动脚本:
  35. /root/sh/lvs_real.sh start

三、MySQL高可用(双主)部署 1.MySQL安装与配置 这里采用mysql5.5.24二进制tar包 tar zxf mysql-5.5.24-linux2.6-x86_64.tar.gz -C /usr/local/mysql5.5 设置配置文件:
  
 
 
  1. cat >> /etc/my.cnf << EOF
  2. [client]
  3. port = 3306
  4. socket = /tmp/mysql.sock
  5. #character-set-server = utf8
  6. [mysqld]
  7. connect_timeout = 20
  8. basedir = /usr/local/mysql
  9. datadir = /data/mysql-5.5/data
  10. user = mysql
  11. port = 3306
  12. socket = /tmp/mysql.sock
  13. pid-file = /data/mysql-5.5/data/mysql.pid
  14. ##init_connect = 'SET AUTOCOMMIT=1'
  15. character-set-server = utf8
  16. open_files_limit = 10240
  17. table_open_cache = 6144
  18. table_definition_cache = 4096
  19. table_cache = 512
  20. max_connections = 1100
  21. max_connect_errors = 1000
  22. back_log = 500
  23. event_scheduler = ON
  24. external-locking = FALSE
  25. skip-name-resolve
  26. #default_table_type = MyISAM
  27. server-id = 10
  28. #master-host = 192.168.8.31
  29. #master-user = repl
  30. #master-password = repl
  31. #replicate-ignore-db=mysql
  32. slave-net-timeout=35
  33. #master-connect-retry=30
  34. #relay-log = relay-bin
  35. #max-relay-log-size = 128M
  36. #skip-slave-start
  37. #replicate-same-server-id=0
  38. #log_slave_update
  39. #replicate-do-db=WATCDB01
  40. #replicate-do-db=WATCDB02
  41. #replicate-do-db=WATCDB03
  42. #replicate-do-db=WATCDB04
  43. wait_timeout=100
  44. interactive_timeout = 100
  45. ##Add for debug,record all the sql
  46. ##log = /usr/local/mysql/fetiondata/data/g_log.log
  47. ##innodb_status_file = 1
  48. #
  49. #tmpdir = /tmp
  50. tmpdir = /data/mysql-5.5/tmp
  51. tmp_table_size = 32M
  52. max_heap_table_size = 64M
  53. thread_cache_size = 64
  54. thread_concurrency = 32
  55. thread_stack = 192K
  56. max_allowed_packet = 16M
  57. sort_buffer_size = 512k
  58. join_buffer_size = 512k
  59. query_cache_size = 0
  60. query_cache_limit = 2M
  61. key_buffer_size = 64M
  62. read_buffer_size = 512k
  63. read_rnd_buffer_size = 512k
  64. bulk_insert_buffer_size = 32M
  65. binlog_format = mixed
  66. #binlog_cache_size = 1M
  67. #log-bin = /data/mysql-5.5/logs/mysql-bin
  68. max_binlog_size = 128M
  69. #log_long_format
  70. slow-query-log
  71. slow-query-log-file = mysql.slow
  72. #log_queries_not_using_indexes = 0
  73. long_query_time = 1
  74. myisam_sort_buffer_size = 32M
  75. myisam_max_sort_file_size = 10G
  76. #myisam_max_extra_sort_file_size = 10G
  77. myisam_repair_threads = 1
  78. myisam_recover
  79. log_error = /data/mysql-5.5/logs/error.log
  80. # READ-UNCOMMITTED, READ-COMMITTED, REPEATABLE-READ, SERIALIZABLE
  81. #default#transaction_isolation = REPEATABLE-READ
  82. transaction_isolation = READ-COMMITTED
  83. #innodb_checksums = 0
  84. #innodb_doublewrite = 0
  85. innodb_flush_method = O_DIRECT
  86. #96G
  87. innodb_buffer_pool_size = 48G
  88. #innodb_buffer_pool_size = 60G
  89. #innodb_buffer_pool_instances = 10
  90. innodb_buffer_pool_instances = 4
  91. #innodb_buffer_pool_size = 33G
  92. innodb_additional_mem_pool_size = 16M
  93. innodb_data_home_dir =
  94. #innodb_data_file_path = ibdata1:20G;ibdata2:20G;ibdata3:20G;ibdata4:20G;ibdata5:20G;ibdata6:20G;ibdata7:20G;ibdata8:100M:autoextend
  95. innodb_data_file_path = ibdata1:2048M:autoextend
  96. innodb_log_group_home_dir = /data/mysql-5.5/logs
  97. innodb_log_buffer_size = 16M
  98. innodb_log_file_size = 1024M
  99. innodb_log_files_in_group = 3
  100. innodb_thread_concurrency = 288
  101. innodb_thread_sleep_delay = 500
  102. #innodb_file_io_threads = 8
  103. innodb_concurrency_tickets = 1000
  104. innodb_sync_spin_loops=40
  105. ##innodb_force_recovery is only used for recovery mode;
  106. ##innodb_force_recovery = 3
  107. innodb_flush_log_at_trx_commit = 0
  108. innodb_max_dirty_pages_pct = 90
  109. #innodb_lock_wait_timeout = 120
  110. innodb_lock_wait_timeout = 10
  111. innodb_support_xa = 0
  112. #Added to allow create function
  113. log_bin_trust_function_creators = 1
  114. innodb_file_per_table = 1
  115. #turn
  116. innodb_stats_on_metadata=0
  117. innodb_old_blocks_pct=20
  118. innodb_change_buffering=all
  119. #innodb_max_purge_lag
  120. innodb_purge_threads=1
  121. innodb_purge_batch_size = 32
  122. innodb_read_io_threads = 8
  123. innodb_write_io_threads = 8
  124. innodb_io_capacity = 2000
  125. innodb_file_format = Barracuda
  126. #manage
  127. performance_schema
  128. performance_schema_events_waits_history_size=100
  129. performance_schema_events_waits_history_long_size=30000
  130. #innodb_strict_mode=1
  131. [mysqldump]
  132. quick
  133. max_allowed_packet = 128M
  134. [mysql]
  135. no-auto-rehash
  136. [mysqlhotcopy]
  137. interactive-timeout
  138. [mysqld_safe]
  139. open-files-limit = 28192
  140. EOF

注意两点: 1).在两台MySQL服务器上开启bin-log日志,默认是开启的! 2).另外一台服务器节点的server-id设置为20,本来设置为10   2.将31服务器设置32的主服务器 在31服务器上建立授权用户!
  
 
 
  1. mysql> grant replication slave on *.* to 'rep'@'%' identified by "rep";
  2. Query OK, 0 rows affected (0.09 sec)
  3. mysql> flush privileges;
  4. Query OK, 0 rows affected (0.09 sec)
  5. mysql> show master status;
  6. +---------------+----------+--------------+------------------+
  7. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  8. +---------------+----------+--------------+------------------+
  9. | binlog.000004 | 138637 | | |
  10. +---------------+----------+--------------+------------------+
  11. 1 row in set (0.03 sec)
  12. 在32服务器上把31服务器设为自己的主服务器,mysql客户端连接到32服务器:
  13. mysql> change master to master_host='192.168.8.31',master_user='rep',master_password='rep',master_log_file='binlog.000004',master_log_pos=138637;
  14. Query OK, 0 rows affected (0.01 sec)
  15. mysql> start slave;
  16. Query OK, 0 rows affected (0.00 sec)
  17. mysql> show slave status\G
  18. *************************** 1. row ***************************
  19. Slave_IO_State: Waiting for master to send event
  20. Master_Host: 192.168.8.31
  21. Master_User: rep
  22. Master_Port: 3306
  23. Connect_Retry: 60
  24. Master_Log_File: binlog.000004
  25. Read_Master_Log_Pos: 138637
  26. Relay_Log_File: relaylog.000002
  27. Relay_Log_Pos: 250
  28. Relay_Master_Log_File: binlog.000004
  29. Slave_IO_Running: Yes
  30. Slave_SQL_Running: Yes
  31. Replicate_Do_DB:
  32. Replicate_Ignore_DB: mysql,test,information_schema
  33. Replicate_Do_Table:
  34. Replicate_Ignore_Table:
  35. Replicate_Wild_Do_Table:
  36. Replicate_Wild_Ignore_Table:
  37. Last_Errno: 0
  38. Last_Error:
  39. Skip_Counter: 0
  40. Exec_Master_Log_Pos: 138637
  41. Relay_Log_Space: 399
  42. Until_Condition: None
  43. Until_Log_File:
  44. Until_Log_Pos: 0
  45. Master_SSL_Allowed: No
  46. Master_SSL_CA_File:
  47. Master_SSL_CA_Path:
  48. Master_SSL_Cert:
  49. Master_SSL_Cipher:
  50. Master_SSL_Key:
  51. Seconds_Behind_Master: 0
  52. Master_SSL_Verify_Server_Cert: No
  53. Last_IO_Errno: 0
  54. Last_IO_Error:
  55. Last_SQL_Errno: 0
  56. Last_SQL_Error:
  57. Replicate_Ignore_Server_Ids:
  58. Master_Server_Id: 1
  59. 1 row in set (0.00 sec)

PS: Slave_IO_Running: Yes Slave_SQL_Running: Yes 两处都为YES,表示OK!   3.将32服务器设置31的主服务器 在32服务器上建立授权用户:  
  
 
 
  1. mysql> grant replication slave on *.* to 'rep'@'%' identified by "rep";
  2. Query OK, 0 rows affected (0.03 sec)
  3. mysql> flush privileges;
  4. Query OK, 0 rows affected (0.00 sec)
  5. mysql> show master status;
  6. +---------------+----------+--------------+------------------+
  7. | File | Position | Binlog_Do_DB | Binlog_Ignore_DB |
  8. +---------------+----------+--------------+------------------+
  9. | binlog.000004 | 320 | | |
  10. +---------------+----------+--------------+------------------+
  11. 1 row in set (0.00 sec)
  12. 在31服务器上把32服务器设为自己的主服务器,mysql客户端连接到31服务器:
  13. mysql> change master to master_host='192.168.8.32',master_user='rep',master_password='rep',master_log_file='binlog.000004',master_log_pos=320;
  14. ERROR 2006 (HY000): MySQL server has gone away
  15. No connection. Trying to reconnect...
  16. Connection id: 74
  17. Current database: *** NONE ***
  18. Query OK, 0 rows affected (0.07 sec)
  19. mysql> start slave;
  20. Query OK, 0 rows affected (0.03 sec)
  21. mysql> show slave status\G
  22. *************************** 1. row ***************************
  23. Slave_IO_State: Waiting for master to send event
  24. Master_Host: 192.168.8.32
  25. Master_User: rep
  26. Master_Port: 3306
  27. Connect_Retry: 60
  28. Master_Log_File: binlog.000004
  29. Read_Master_Log_Pos: 320
  30. Relay_Log_File: relaylog.000002
  31. Relay_Log_Pos: 250
  32. Relay_Master_Log_File: binlog.000004
  33. Slave_IO_Running: Yes
  34. Slave_SQL_Running: Yes
  35. Replicate_Do_DB:
  36. Replicate_Ignore_DB: mysql,test,information_schema
  37. Replicate_Do_Table:
  38. Replicate_Ignore_Table:
  39. Replicate_Wild_Do_Table:
  40. Replicate_Wild_Ignore_Table:
  41. Last_Errno: 0
  42. Last_Error:
  43. Skip_Counter: 0
  44. Exec_Master_Log_Pos: 320
  45. Relay_Log_Space: 399
  46. Until_Condition: None
  47. Until_Log_File:
  48. Until_Log_Pos: 0
  49. Master_SSL_Allowed: No
  50. Master_SSL_CA_File:
  51. Master_SSL_CA_Path:
  52. Master_SSL_Cert:
  53. Master_SSL_Cipher:
  54. Master_SSL_Key:
  55. Seconds_Behind_Master: 0
  56. Master_SSL_Verify_Server_Cert: No
  57. Last_IO_Errno: 0
  58. Last_IO_Error:
  59. Last_SQL_Errno: 0
  60. Last_SQL_Error:
  61. Replicate_Ignore_Server_Ids:
  62. Master_Server_Id: 2
  63. 1 row in set (0.00 sec)

4.主主同步测试 先在31服务器上建个库:
  
 
 
  1. mysql> create database t_test;
  2. Query OK, 1 row affected (0.03 sec)
  3. mysql> show databases;
  4. +--------------------+
  5. | Database |
  6. +--------------------+
  7. | information_schema |
  8. | mysql |
  9. | performance_schema |
  10. | t_test |
  11. | test |
  12. +--------------------+
  13. 5 rows in set (0.00 sec)
  14. 再到32服务器查询是否同步过来这个库:
  15. mysql> show databases;
  16. +--------------------+
  17. | Database |
  18. +--------------------+
  19. | information_schema |
  20. | bbs |
  21. | mysql |
  22. | performance_schema |
  23. | t_test |
  24. | test |
  25. +--------------------+
  26. 6 rows in set (0.00 sec)
  27. 可以看到同步过来了!
  28. 反过来一样!这步略!
  29. 5.keepalived安装配置
  30. yum -y install kernel-devel ipvsadm
  31. ln -sv /usr/src/kernels/2.6.18-308.8.2.el5-x86_64/ /usr/src/linux
  32. cd /opt
  33. tar zxf keepalived-1.1.20.tar.gz
  34. cd keepalived-1.1.20
  35. ./configure --prefix=/usr/local/keepalived --with-kernel-dir=/usr/src/kernels/2.6.18-308.11.1.el5-x86_64/
  36. make;make install
  37. cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/rc.d/init.d
  38. cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
  39. mkdir /etc/keepalived
  40. chkconfig keepalived on
  41. 创建配置文件:
  42. 主服务器:
  43. cat /etc/keepalived/keepalived.conf
  44. ! Configuration File for keepalived
  45. global_defs {
  46. notification_email {
  47. 250621008@qq.com
  48. }
  49. notification_email_from 250621008@qq.com
  50. smtp_server 127.0.0.1
  51. smtp_connect_timeout 30
  52. router_id mysql-ha
  53. }
  54. vrrp_instance VI_1 {
  55. state BACKUP
  56. interface eth0
  57. virtual_router_id 51
  58. priority 100
  59. advert_int 1
  60. nopreempt #不抢占,只在priority高的节点上设置
  61. authentication {
  62. auth_type PASS
  63. auth_pass 1111
  64. }
  65. virtual_ipaddress {
  66. 192.168.8.30
  67. }
  68. }
  69. virtual_server 192.168.8.30 3306 {
  70. delay_loop 2
  71. lb_algo wrr
  72. lb_kind DR
  73. persistence_timeout 60
  74. protocol TCP
  75. real_server 192.168.8.31 3306
  76. weight 3
  77. notify_down /root/sh/mysql.sh
  78. TCP_CHECK {
  79. connect_timeout 10
  80. nb_get_retry 3
  81. delay_before_retry 3
  82. connect_port 3306
  83. }
  84. }
  85. }
  86. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  87. 从服务器:
  88. cat /etc/keepalived/keepalived.conf
  89. ! Configuration File for keepalived
  90. global_defs {
  91. notification_email {
  92. 250621008@qq.com
  93. }
  94. notification_email_from 250621008@qq.com
  95. smtp_server 127.0.0.1
  96. smtp_connect_timeout 30
  97. router_id mysql-ha
  98. }
  99. vrrp_instance VI_1 {
  100. state BACKUP
  101. interface eth0
  102. virtual_router_id 51
  103. priority 90
  104. advert_int 1
  105. authentication {
  106. auth_type PASS
  107. auth_pass 1111
  108. }
  109. virtual_ipaddress {
  110. 192.168.8.30
  111. }
  112. }
  113. virtual_server 192.168.8.30 3306 {
  114. delay_loop 2
  115. lb_algo wrr
  116. lb_kind DR
  117. persistence_timeout 60
  118. protocol TCP
  119. real_server 192.168.8.32 3306
  120. weight 3
  121. notify_down /root/sh/mysql.sh
  122. TCP_CHECK {
  123. connect_timeout 10
  124. nb_get_retry 3
  125. delay_before_retry 3
  126. connect_port 3306
  127. }
  128. }
  129. }

主备配置文件注意几点: 1).router_id 两边必须相同 2).state 两边都为BACKUP 3).virtual_router_id 两边必须相同 4).priority 主节点的值必须大于从节点的值 5).nopreempt 不抢占,只在priority高的节点(即主节点)上设置 6).real_server 只需要本机的IP,不需要其它节点的! 7).notify_down 作用是监测到当mysql停止工作时自动关闭本机的keepalived的脚本,实现故障转移!   在主从上都创建当mysql停止工作时自动关闭本机的keepalived的脚本:
  
 
 
  1. cat /root/sh/mysql.sh
  2. #!/bin/bash
  3. MYSQL=/usr/local/mysql/bin/mysql
  4. MYSQL_HOST=localhost
  5. MYSQL_USER=root
  6. MYSQL_PASSWORD="admin"
  7. CHECK_TIME=3
  8. #mysql is working MYSQL_OK is 0 , mysql down MYSQL_OK is 1
  9. MYSQL_OK=1
  10. function check_mysql_helth (){
  11. $MYSQL -h $MYSQL_HOST -u $MYSQL_USER -p $MYSQL_PASSWORD -e "show status;" > /dev/null 2>&1
  12. if [ $? = 0 ] ;then
  13. MYSQL_OK=0
  14. else
  15. MYSQL_OK=1
  16. fi
  17. return $MYSQL_OK
  18. }
  19. while [ $CHECK_TIME -ne 0 ]
  20. do
  21. let "CHECK_TIME -= 1"
  22. check_mysql_helth
  23. if [ $MYSQL_OK = 0 ] ; then
  24. CHECK_TIME=0
  25. exit 0
  26. fi
  27. if [ $MYSQL_OK -eq 1 ] && [ $CHECK_TIME -eq 1 ]
  28. then
  29. /etc/init.d/keepalived stop
  30. exit 1
  31. fi
  32. sleep 1
  33. done

6.故障转移测试 分别启动主备节点的keepalived服务,然后在主节点查看VIP有没有启动:
  
 
 
  1. 31服务器:
  2. [root@mysql1 ~]# ip a |grep eth0
  3. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
  4. inet 192.168.8.31/24 brd 192.168.8.255 scope global eth0
  5. inet 192.168.8.30/32 scope global eth0
  6. 32服务器:
  7. [root@mysql2 keepalived-1.1.19]# ip a |grep eth0
  8. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
  9. inet 192.168.8.32/24 brd 192.168.8.255 scope global eth0
  10. 现在把31服务器的mysql服务停掉:
  11. [root@mysql1 keepalived]# ip a
  12. 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue
  13. link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  14. inet 127.0.0.1/8 scope host lo
  15. 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
  16. link/ether 00:0c:29:d4:fd:b3 brd ff:ff:ff:ff:ff:ff
  17. inet 192.168.8.31/24 brd 192.168.8.255 scope global eth0
  18. inet 192.168.8.30/32 scope global eth0
  19. [root@mysql1 keepalived]# service mysqld stop
  20. Shutting down MySQL. [ OK ]
  21. [root@mysql1 keepalived]# service keepalived status
  22. keepalived is stopped
  23. [root@mysql1 keepalived]#

可以看到mysql服务停掉后,keepalived服务也马上停掉了! 再到32节点上查看下VIP有没有接管: [root@mysql2 ~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:0c:29:e3:dd:5a brd ff:ff:ff:ff:ff:ff inet 192.168.8.32/24 brd 192.168.8.255 scope global eth0 inet 192.168.8.30/32 scope global eth0 可以看到接管过来了!   四、存储部分 请参考笔者的相关文章: http://linuxops.blog.51cto.com/2238445/895945 --mfs分布式存储 http://linuxops.blog.51cto.com/2238445/899652 --第五部分:NFS高可用web存储部署