Linux下HAProxy+Keepalived双机高可用方案(2)

haproxy的安装(主备都一样):
#tar -zxvf haproxy-1.5.14.tar.gz
#cd haproxy-1.5.14
#make TARGET=linux26 PREFIX=/usr/local/haproxy
#makeinstall PREFIX=/usr/local/haproxy
#cd/usr/local/haproxy/
#mkdir conf
#mkdir logs
#vi haproxy.cfg
global
log127.0.0.1  local0 
log127.0.0.1  local1 notice
maxconn 4096
chroot/usr/local/haproxy
uid 99
gid 99
daemon 
#debug 
#quiet 
nbproc 1
pidfile/usr/local/haproxy/logs/haproxy.pid


defaults
log    global
mode    http 
option  httplog
option  dontlognull
retries 3
#redispatch
maxconn 65535
optionredispatch
timeout connect5000
timeout client50000
timeout server50000
stats  uri    /haproxy
stats auth  admin:admin 
 
listen  *:80
cookie  SERVERID rewrite
mode http
balance roundrobin
option httpchkHEAD /index.html HTTP/1.0
server  web1 10.2.32.99:80 cookie app1inst1 weight 5check inter 2000 rise 2 fall 5
server  web2 10.2.32.110:80 cookie app1inst2 weight 3check inter 2000 rise 2 fall 5


二:先主后从,两台机器上都分别启动:
/etc/init.d/keepalivedstart (如果之前没有启动haproxy,这条命令会自动把haproxy启动)

[root@test100 haproxy]# ps -ef | grephaprox
root    30344    1  0 11:43 ?        00:00:00 /bin/bash/etc/keepalived/check_haproxy.sh
nobody  30349    1  0 11:43 ?        00:00:00/usr/local/haproxy/sbin/haproxy -f /usr/local/haproxy/conf/haproxy.cfg
[root@test100 haproxy]# ps -ef | grepkeepali
root    30337    1  0 11:43 ?        00:00:00 keepalived -D
root    30339 30337  1 11:43 ?        00:00:00 keepalived -D
root    30340 30337  1 11:43 ?        00:00:00 keepalived -D
root    30372  2876  0 11:43 pts/0    00:00:00 grep keepali

三:测试:
1.再两台HA上分别执行ip ad sh |grep 10.2.32
主:
inet10.2.32.100/24 brd 10.2.32.255 scope global eth0
inet10.2.32.201/32 scope global eth0

备:
inet10.2.32.101/24 brd 10.2.32.255 scope global eth0

2.停掉主上的haproxy,3秒后keepalived会自动将其再次启动

3.停掉主的keepalived,备机马上接管服务
备: ip ad sh |grep 10.2.32
inet10.2.32.101/24 brd 10.2.32.255 scope global eth0
inet10.2.32.201/32 scope global eth0

四:通过浏览器进行测试

两台web的页面会在你刷新时进行切换。此文将nginx安装,配置过程省略了,如果有问题可以查看以下相关文章。

CentOS 6.2实战部署Nginx+MySQL+PHP

使用Nginx搭建WEB服务器

搭建基于Linux6.3+Nginx1.2+PHP5+MySQL5.5的Web服务器全过程

CentOS 6.3下Nginx性能调优

CentOS 6.3下配置Nginx加载ngx_pagespeed模块

CentOS 6.4安装配置Nginx+Pcre+php-fpm

Nginx安装配置使用详细笔记

Haproxy+Keepalived搭建Weblogic高可用负载均衡集群

Keepalived+HAProxy配置高可用负载均衡

CentOS 6.3下Haproxy+Keepalived+Apache配置笔记

Haproxy + KeepAlived 实现WEB群集 on CentOS 6

Haproxy+Keepalived构建高可用负载均衡

使用 HAProxy 配置 HTTP 负载均衡器

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/21809ecf84cd70eb58ada5b6e37e1247.html