系统:centos7
mysql 端口3306 Percona-XtraDB-Cluster 主节点
mysql端口3307 Percona-XtraDB-Cluster+haproxy+keepalived
MySQL端口3307 Percona-XtraDB-Cluster+haproxy+keepalived
/21 vip ip
软件版本:Percona-XtraDB-Cluster-- percona-xtrabackup-
haproxy- keepalived-
一、linux 系统限制配置
1、关闭系统防火墙
systemctl stop 关闭防火墙 systemctl disable 禁用防火墙
2、关闭SElinux sed -i 's/SELINUX=.*/SELINUX=disabled/g' /etc/selinux/config setenforce 0 selinux 立即生效
二、系统安装约定
源码包编译安装位置:/usr/local/软件名字
数据目录 /apps/data
三、下在源码安装包
下载 Percona-XtraDB-Cluster--
wget -P /usr/local/src /downloads/Percona-XtraDB-Cluster-57/Percona-XtraDB-Cluster--/rel-/source/tarball/Percona-XtraDB-Cluster--
下载percona-xtrabackup-
wget -P /usr/local/src /downloads/XtraBackup/Percona-XtraBackup-/source/tarball/percona-xtrabackup-
下载boost_1_59_0
mkdir -p /usr/local/boost wget -P /usr/local/boost /project/boost/boost//boost_1_59_
下载haproxy-
wget -P /usr/local/src /download//src/haproxy-
下载keepalived-
wget -P /usr/local/src /software/keepalived-
下载automake-
wget -P /usr/local/src ftp:///gnu/automake/automake-
四、安装编译环境及编译依赖
1、yum -y install epel-release 2、卸载旧版mysql或mariadb yum -y remove mariadb* mysql* 3、安装编译环境 yum -y install libtool ncurses-devel libgcrypt-devel libev-devel \ git scons gcc gcc-c++ openssl check cmake bison boost-devel \ asio-devel libaio-devel ncurses-devel readline-devel pam-devel socat \ libaio automake autoconf vim redhat-lsb check-devel curl curl-devel xinetd 4、安装keepalived 依赖 ( ) yum -y install libnl-devel openssl-devel libnfnetlink-devel ipvsadm \ popt-devel libnfnetlink kernel-devel popt-static iptraf
五、编译安装 Percona-XtraDB-Cluster-- percona-xtrabackup-
1、解压percona-xtrabackup-
tar -xvf /usr/local/src/percona-xtrabackup- -C /usr/local/src/
2、解压Percona-XtraDB-Cluster--
tar -xvf /usr/local/src/Percona-XtraDB-Cluster-- -C /usr/local/src/
3、编译percona-xtrabackup-
cd /usr/local/src/percona-xtrabackup-/ cmake ./ -DBUILD_CONFIG=xtrabackup_release \ -DWITH_MAN_PAGES=OFF \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST="/usr/local/boost" make -j4 && make install ln -sf /usr/local/xtrabackup/bin/* /usr/sbin/
4、编译安装Percona-XtraDB-Cluster--
、创建mysql用户名及文件夹
mkdir /apps/{run,log}/mysqld -p useradd mysql -s /sbin/nologin -M chown -R mysql:mysql /apps
、编译garbd,libgalera_
cd /usr/local/src/Percona-XtraDB-Cluster-- cd "percona-xtradb-cluster-galera" revno值 cat GALERA-REVISION scons -j4 psi=1 --config=force revno="b98f92f" boost_pool=0 libgalera_ scons -j4 --config=force revno="b98f92f" garb/garbd 创建pxc安装目录 mkdir -p /usr/local/Percona-XtraDB-Cluster/{bin,lib} 拷贝编译结果文件到pxc安装目录 cp garb/garbd /usr/local/Percona-XtraDB-Cluster/bin cp libgalera_ /usr/local/Percona-XtraDB-Cluster/lib
、编译 Percona-XtraDB-Cluster--
-DMYSQL_SERVER_SUFFIX 值得获取 cd /usr/local/src/Percona-XtraDB-Cluster-- WSREP_VERSION="$(grep WSREP_INTERFACE_VERSION wsrep/wsrep_ | cut -d '"' -f2).$(grep 'SET(WSREP_PATCH_VERSION' "cmake/" | cut -d '"' -f2)" echo $WSREP_VERSION -DCOMPILATION_COMMENT 值获取 cd /usr/local/src/Percona-XtraDB-Cluster-- source VERSION MYSQL_VERSION="$MYSQL_VERSION_MAJOR.$MYSQL_VERSION_MINOR.$MYSQL_VERSION_PATCH" echo $MYSQL_VERSION REVISION="$(cd "$SOURCEDIR"; grep '^short: ' Docs/INFO_SRC |sed -e 's/short: //')" -DCOMPILATION_COMMENT 值 Percona XtraDB Cluster binary (GPL) $MYSQL_VERSION-$WSREP_VERSION Revision $REVISION 编译Percona-XtraDB-Cluster-- cd /usr/local/src/Percona-XtraDB-Cluster-- cmake ./ -DBUILD_CONFIG=mysql_release \ -DCMAKE_BUILD_TYPE=RelWithDebInfo\ -DWITH_EMBEDDED_SERVER=OFF \ -DFEATURE_SET=community \ -DENABLE_DTRACE=OFF \ -DWITH_SSL=system -DWITH_ZLIB=system \ -DCMAKE_INSTALL_PREFIX="/usr/local/Percona-XtraDB-Cluster" \ -DMYSQL_DATADIR="/apps/data" \ -DMYSQL_SERVER_SUFFIX="" \ -DWITH_INNODB_DISALLOW_WRITES=ON \ -DWITH_WSREP=ON \ -DWITH_UNIT_TESTS=0 \ -DWITH_READLINE=system \ -DWITHOUT_TOKUDB=ON \ -DCOMPILATION_COMMENT="Percona XtraDB Cluster binary (GPL) -, Revision bec0879" \ -DWITH_PAM=ON \ -DWITH_INNODB_MEMCACHED=ON \ -DDOWNLOAD_BOOST=1 \ -DWITH_BOOST="/usr/local/boost" \ -DWITH_SCALABILITY_METRICS=ON make -j4 && make install 拷贝文件到安装目录 cp -R /usr/local/src/Percona-XtraDB-Cluster--/percona-xtradb-cluster-tests /usr/local/Percona-XtraDB-Cluster/ 创建软连接 mysql 系统环境 ln -sf /usr/local/Percona-XtraDB-Cluster/bin/* /usr/sbin/ 拷贝启动文件到系统启动目录 cp -R /usr/local/Percona-XtraDB-Cluster/support-files/ /etc//mysqld 拷贝监控文件到xinetd管理目录 cp -R /usr/local/Percona-XtraDB-Cluster//mysqlchk /etc// 加入动态库 echo "/usr/local/Percona-XtraDB-Cluster/lib" >> /etc/ ldconfig
配置MySQL健康检查
vim /etc//mysqlchk server = /usr/bin/clustercheck 修改为如果不修过可以cp /usr/local/Percona-XtraDB-Cluster/bin/clustercheck 到 /usr/bin/ server = /usr/sbin/clustercheck vim /etc/services 添加 mysqlchk 9200/tcp # mysqlchk
配置
vim /etc/ # Template for PXC # Edit to your requirements. [client] socket=/apps/data/ port=3306 [mysqld] user=mysql server-id=10055 datadir=/apps/data socket=/apps/data/ log-error=/apps/log/mysqld/ pid-file=/apps/run/mysqld/ log-bin log_slave_updates expire_logs_days=7 port=3306 character_set_server = utf8 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Path to Galera library wsrep_provider=/usr/local/Percona-XtraDB-Cluster/lib/libgalera_ # Cluster connection URL contains IPs of nodes #If no IP is found, this implies that a new cluster needs to be created, #in order to do that you need to bootstrap this node wsrep_cluster_address='gcomm://,,' #wsrep_cluster_address=gcomm:// # In order for Galera to work correctly binlog format should be ROW binlog_format=ROW # MyISAM storage engine has only experimental support default_storage_engine=InnoDB wsrep_sst_receive_address=:6010 wsrep_node_incoming_address= wsrep_provider_options = "_addr=tcp://;_addr=:6020;" # Slave thread to use wsrep_slave_threads= 8 wsrep_log_conflicts # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2 # Node IP address wsrep_node_address= # Cluster name wsrep_cluster_name=pxc-cluster #If wsrep_node_name is not specified, then system hostname will be used wsrep_node_name=pxc-cluster-node-1 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER pxc_strict_mode=ENFORCING # SST method wsrep_sst_method=xtrabackup-v2 #wsrep_sst_method=rsync #Authentication for SST method # 修改自己的创建的账号、密码 wsrep_sst_auth="sstuser:456789"
vim /etc/ # Template for PXC # Edit to your requirements. [client] socket=/apps/data/ port=3307 [mysqld] user=mysql server-id=10056 datadir=/apps/data socket=/apps/data/ log-error=/apps/log/mysqld/ pid-file=/apps/run/mysqld/ log-bin log_slave_updates expire_logs_days=7 port=3307 character_set_server = utf8 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Path to Galera library wsrep_provider=/usr/local/Percona-XtraDB-Cluster/lib/libgalera_ # Cluster connection URL contains IPs of nodes #If no IP is found, this implies that a new cluster needs to be created, #in order to do that you need to bootstrap this node wsrep_cluster_address='gcomm://,,' #wsrep_cluster_address=gcomm:// # In order for Galera to work correctly binlog format should be ROW binlog_format=ROW # MyISAM storage engine has only experimental support default_storage_engine=InnoDB wsrep_sst_receive_address=:6010 wsrep_node_incoming_address= wsrep_provider_options = "_addr=tcp://;_addr=:6020;" # Slave thread to use wsrep_slave_threads= 8 wsrep_log_conflicts # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2 # Node IP address wsrep_node_address= # Cluster name wsrep_cluster_name=pxc-cluster #If wsrep_node_name is not specified, then system hostname will be used wsrep_node_name=pxc-cluster-node-2 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER pxc_strict_mode=ENFORCING # SST method wsrep_sst_method=xtrabackup-v2 #wsrep_sst_method=rsync #Authentication for SST method # 修改自己的创建的账号、密码 wsrep_sst_auth="sstuser:456789"
vim /etc/ # Template for PXC # Edit to your requirements. [client] socket=/apps/data/ port=3307 [mysqld] user=mysql server-id=10057 datadir=/apps/data socket=/apps/data/ log-error=/apps/log/mysqld/ pid-file=/apps/run/mysqld/ log-bin log_slave_updates expire_logs_days=7 port=3307 character_set_server = utf8 # Disabling symbolic-links is recommended to prevent assorted security risks symbolic-links=0 # Path to Galera library wsrep_provider=/usr/local/Percona-XtraDB-Cluster/lib/libgalera_ # Cluster connection URL contains IPs of nodes #If no IP is found, this implies that a new cluster needs to be created, #in order to do that you need to bootstrap this node wsrep_cluster_address='gcomm://,,' #wsrep_cluster_address=gcomm:// # In order for Galera to work correctly binlog format should be ROW binlog_format=ROW # MyISAM storage engine has only experimental support default_storage_engine=InnoDB wsrep_sst_receive_address=:6010 wsrep_node_incoming_address= wsrep_provider_options = "_addr=tcp://;_addr=:6020;" # Slave thread to use wsrep_slave_threads= 8 wsrep_log_conflicts # This changes how InnoDB autoincrement locks are managed and is a requirement for Galera innodb_autoinc_lock_mode=2 # Node IP address wsrep_node_address= # Cluster name wsrep_cluster_name=pxc-cluster #If wsrep_node_name is not specified, then system hostname will be used wsrep_node_name=pxc-cluster-node-3 #pxc_strict_mode allowed values: DISABLED,PERMISSIVE,ENFORCING,MASTER pxc_strict_mode=ENFORCING # SST method wsrep_sst_method=xtrabackup-v2 #wsrep_sst_method=rsync #Authentication for SST method wsrep_sst_auth="sstuser:456789" # 修改自己的创建的账号、密码
初始化数据库
初始化数据 mysqld --initialize --user=mysql --datadir="/apps/data" 启动数据库 /etc//mysqld start --wsrep-cluster-address="gcomm://" 关闭数据库 以后都要密码才能进去 /etc//mysqld stop 安全模式期待MySQL修改密码 mysqld_safe --wsrep-cluster-address=gcomm:// --user=mysql --skip-grant-tables --skip-networking & use mysql; update user set authentication_string=Password('123456') where user='root'; flush privileges; shutdown exit 退出MySQL ps -ef | grep mysql 直到MySQL完全关闭 再次启动MySQL /etc//mysqld start --wsrep-cluster-address="gcomm://" 进入MySQL 创建同步账号及修改root密码 mysql -u root -p123456 创建MySQL同步账号及密码 GRANT ALL PRIVILEGES ON *.* TO sstuser@'%' IDENTIFIED BY '456789'; FLUSH PRIVILEGES; GRANT ALL PRIVILEGES ON *.* TO sstuser@'localhost' IDENTIFIED BY '456789'; FLUSH PRIVILEGES; 修改root 远程能够连接 GRANT ALL PRIVILEGES ON *.* TO root@'%' IDENTIFIED BY '123456'; FLUSH PRIVILEGES; 创建健康检查数据库账号密码 GRANT PROCESS ON *.* TO 'clustercheckuser'@'localhost' IDENTIFIED BY 'clustercheckpassword!'; 如果使用自己账号密码请修改 vim /usr/sbin/clustercheck 对应的账号密码 其它节点直接启动 service mysqld start 重启第一个节点 service mysqld restart 出现错误 /etc//mysqld bootstrap-pxc 进行启动 启动完成登陆MySQL mysql -u root -p123456 查看MySQL 节点数 mysql> show global status like 'wsrep_cluster_size'; +--------------------+-------+ | Variable_name | Value | +--------------------+-------+ | wsrep_cluster_size | 3 | +--------------------+-------+ 1 row in set ( sec) mysql> show global status like 'wsrep_incoming_addresses'; +--------------------------+-------------------------------------------------------+ | Variable_name | Value | +--------------------------+-------------------------------------------------------+ | wsrep_incoming_addresses | :3307,:3307,:3306 | +--------------------------+-------------------------------------------------------+ 1 row in set ( sec) 创建测试数据看看是否同步 mysql> create database test; Query OK, 1 row affected ( sec)
数据库健康检查启动
systemctl start 查看9200端口是否打开 netstat -anlp | grep 9200 tcp6 0 0 :::9200 :::* LISTEN 73323/xinetd 测试端口是否正常 telnet 9200 Escape character is '^]'. HTTP/ 200 OK Content-Type: text/plain Connection: close Content-Length: 40 Percona XtraDB Cluster Node is synced. Connection closed by foreign host. 返回503 首先执行 /usr/sbin/clustercheck 是否返回200 如果不是检查链接数据库的账号密码 返回200正常 就请修改 vim /etc//mysqlchk user root 重启systemctl restart 再次测试如果返回200正常就ok 还是报错就请查看系统日志修复
六、编译安装 haproxy (,)
安装 haproxy 日志记录支持 yum -y install rsyslog 解压 haproxy- tar -xvf /usr/local/src/haproxy- -C /usr/local/src/ cd /usr/local/src/haproxy- make TARGET=linux31 PREFIX=/usr/local/haproxy make install PREFIX=/usr/local/haproxy 创建文件夹haproxy mkdir -pv /usr/local/haproxy/{conf,run,log}
创建haproxy 启动脚本 vim /etc//haproxy
#! /bin/bash # chkconfig: - 85 15 # description: haproxy is a World Wide Web server. It is used to serve PROGDIR=/usr/local/haproxy PROGNAME=haproxy DAEMON=$PROGDIR/sbin/$PROGNAME CONFIG=$PROGDIR/conf/$ PIDFILE=$PROGDIR/run/$ DESC="HAProxy daemon" SCRIPTNAME=/usr/local/haproxy//$PROGNAME # Gracefully exit if the package has been removed. test -x $DAEMON || exit 0 start() { echo -n "Starting $DESC: $PROGNAME" $DAEMON -f $CONFIG echo "." } stop() { echo -n "Stopping $DESC: $PROGNAME" cat $PIDFILE | xargs kill echo "." } reload() { echo -n "reloading $DESC: $PROGNAME" $DAEMON -f $CONFIG -p $PIDFILE -sf $(cat $PIDFILE) } case "$1" in start) start ;; stop) stop ;; restart) stop start ;; reload) reload ;; *) echo "Usage: $SCRIPTNAME {start|stop|restart|reload}" >&2 exit 1 ;; esac exit 0
chmod +x /etc//haproxy # 可执行权限
创建
vim /usr/local/haproxy/conf/
global log local0 log local1 notice #log loghost local0 info maxconn 50000 chroot /usr/local/haproxy uid 99 gid 99 daemon nbproc 2 pidfile /usr/local/haproxy/run/ #debug #quiet defaults log global mode tcp option tcplog option dontlognull option forwardfor option redispatch retries 3 timeout connect 3000 timeout client 50000 timeout server 50000 frontend admin_stat bind *:8888 mode http default_backend stats-back frontend pxc-front bind *:3306 mode tcp default_backend pxc-back frontend pxc-onenode-front bind *:3308 mode tcp default_backend pxc-onenode backend pxc-back mode tcp balance roundrobin option httpchk server node1 :3306 check port 9200 inter 12000 rise 3 fall 3 server node2 :3307 check port 9200 inter 12000 rise 3 fall 3 server node3 :3307 check port 9200 inter 12000 rise 3 fall 3 backend pxc-onenode mode tcp balance roundrobin option httpchk server node1 :3306 check port 9200 inter 12000 rise 3 fall 3 server node2 :3307 check port 9200 inter 12000 rise 3 fall 3 backup server node3 :3307 check port 9200 inter 12000 rise 3 fall 3 backup backend stats-back mode http balance roundrobin stats uri /admin?stats stats auth admin:admin stats realm Haproxy\ Statistics
Haproxy rsyslog 日志配置 vim /etc/ #$ModLoad imudp 修改 $ModLoad imudp #$UDPServerRun 514 修改 $UDPServerRun 514 #添加 Haproxy 日志记录路径 local0.* /usr/local/haproxy/log/
重启rsyslog systemctl restart 启动Haproxy service haproxy start 加入开机启动 chkconfig haproxy on 查看haproxy 是否启动 ps -ef | grep haproxy haproxy 访问端口8888 账号密码 admin:admin :8888/admin?stats :8888/admin?stats
七、编译安装keepalived
安装automake- tar -xvf /usr/local/src/automake- -C /usr/local/src cd /usr/local/src/automake- ./configure && make && make install
编译keepalived
tar -xvf /usr/local/src/keepalived- -C /usr/local/src cd /usr/local/src/keepalived- ./configure --prefix=/usr/local/keepalived vmware 虚拟机安装 修改./lib/ HAVE_DECL_RTA_ENCAP 1 修改为HAVE_DECL_RTA_ENCAP 0 如果不修改编译会报错 make && make install
拷贝keepalived 可执行文件到/usr/sbin/ cp /usr/local/keepalived/sbin/keepalived /usr/sbin/
创建keepalived 启动脚本
vim /etc///keepalived
#!/bin/sh # # Startup script for the Keepalived daemon # # processname: keepalived # pidfile: /var/run/ # config: /etc/keepalived/ # chkconfig: - 21 79 # description: Start and stop Keepalived # Source function library . /etc///functions # Source configuration file (we set KEEPALIVED_OPTIONS there) . /etc/sysconfig/keepalived RETVAL=0 prog="keepalived" start() { echo -n $"Starting $prog: " daemon keepalived ${KEEPALIVED_OPTIONS} RETVAL=$? echo [ $RETVAL -eq 0 ] && touch /var/lock/subsys/$prog } stop() { echo -n $"Stopping $prog: " killproc keepalived RETVAL=$? echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/$prog } reload() { echo -n $"Reloading $prog: " killproc keepalived -1 RETVAL=$? echo } # See how we were called. case "$1" in start) start ;; stop) stop ;; reload) ;; restart) stop start ;; condrestart) if [ -f /var/lock/subsys/$prog ]; then stop start fi ;; status) status keepalived RETVAL=$? ;; *) echo "Usage: $0 {start|stop|reload|restart|condrestart|status}" RETVAL=1 esac exit $RETVAL
chmod +x /etc///keepalived #keepalived 可执行
配置keepalived
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/ 创建/etc/keepalived 文件夹 mkdir -p /etc/keepalived
创建/etc/keepalived/ ()
vim /etc/keepalived/ ! Configuration File for keepalived global_defs { notification_email { admin@ #发生故障时,接受信息的email地址 } notification_email_from admin@ smtp_server smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_haproxy { #自定义的监控脚本 script "/etc/keepalived/chk_" interval 2 weight 2 } vrrp_instance VI_1 { state BACKUP #让VIP不抢回 nopreempt interface eth0 #监听接口 virtual_router_id 51 priority 100 #优先级,backup机器上的优先级要小与这个值 advert_int 1 #检查间隔 authentication { auth_type PASS auth_pass 1111 } track_script { #自定义的监控脚本 chk_haproxy } virtual_ipaddress { #VIP地址,可以设多个 /21 } notify_backup "/etc//haproxy restart" notify_fault "/etc//haproxy stop" }
创建/etc/keepalived/ ()
! Configuration File for keepalived global_defs { notification_email { admin@ #发生故障时,接受信息的email地址 } notification_email_from admin@ smtp_server smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_haproxy { #自定义的监控脚本 script "/etc/keepalived/chk_" interval 2 weight 2 } vrrp_instance VI_1 { state BACKUP #让VIP不抢回 nopreempt interface eth0 #监听接口 virtual_router_id 51 priority 99 #优先级,backup机器上的优先级要小与这个值 advert_int 1 #检查间隔 authentication { auth_type PASS auth_pass 1111 } track_script { #自定义的监控脚本 chk_haproxy } virtual_ipaddress { #VIP地址,可以设多个 /21 } notify_backup "/etc//haproxy restart" notify_fault "/etc//haproxy stop" }
创建/etc/keepalived/chk_
vim /etc/keepalived/chk_ #!/bin/bash if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ];then /etc//haproxy start fi sleep 2 if [ $(ps -C haproxy --no-header | wc -l) -eq 0 ]; then /etc//keepalived stop fi
chmod +x /etc/keepalived/chk_ #可执行权限
启动 keepalived
service keepalived start ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet /8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:1b:50:a3 brd ff:ff:ff:ff:ff:ff inet /21 brd scope global dynamic eth0 valid_lft 44444sec preferred_lft 44444sec inet /21 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe1b:50a3/64 scope link valid_lft forever preferred_lft forever
service keepalived start 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet /8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:63:ae:85 brd ff:ff:ff:ff:ff:ff inet /21 brd scope global dynamic eth0 valid_lft 58142sec preferred_lft 58142sec inet6 fe80::20c:29ff:fe63:ae85/64 scope link valid_lft forever preferred_lft forever
关闭 keepalived 进程
service keepalived stop [root@56~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet /8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:1b:50:a3 brd ff:ff:ff:ff:ff:ff inet /21 brd scope global dynamic eth0 valid_lft 44258sec preferred_lft 44258sec inet6 fe80::20c:29ff:fe1b:50a3/64 scope link valid_lft forever preferred_lft forever
查看
[root@57~]# ip a 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet /8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link/ether 00:0c:29:63:ae:85 brd ff:ff:ff:ff:ff:ff inet /21 brd scope global dynamic eth0 valid_lft 57869sec preferred_lft 57869sec inet /21 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::20c:29ff:fe63:ae85/64 scope link valid_lft forever preferred_lft forever
其它 keepalived 两个都配置为BACKUP 当第一个出现故障的时候恢复了不用抢占正在 提供服务的IP 服务不会闪断。 haproxy 配置双端口链接 3306 是同时负载3台服务器 3308 只是一台使用当第一台挂掉才会使用第二台。