haproxy概念和负载均衡

在80.100虚拟机上

systemctl stop firewalld
setenforce 0
yum install lrz* -y
tar xf haproxy-1.5.15.tar.gz -C /opt/
cd /opt/haproxy-1.5.15/
yum install -y \
pcre-devel \
bzip2-devel \
gcc \
gcc-c++ \
make
uname -r
haproxy概念和负载均衡
make TARGET=linux26 PREFIX=/usr/local/haproxy
make install PREFIX=/usr/local/haproxy
mkdir /etc/haproxy
useradd -s /sbin/nologin -M haproxy
id haproxy
haproxy概念和负载均衡
cd examples/
cp haproxy.cfg /etc/haproxy/
cd /etc/haproxy/
vi haproxy.cfg
把里面全删了添加

#this config needs haproxy-1.1.28 or haproxy-1.2.1

global
    log 127.0.0.1   local0
    log 127.0.0.1   local1 notice
    #log loghost    local0 info
    maxconn 4096
#chroot /usr/share/haproxy
    uid 1001
    gid 1001
    daemon
    #debug
     #quiet

defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    redispatch
    maxconn 2000
    contimeout      5000
    clitimeout      50000
    srvtimeout      50000

listen admin_stats
bind 0.0.0.0:8089
stats enable
mode http
log global
stats uri  /stats
stats realm Haproxy\ Statistics
stats auth  admin:admin
     #stats hide-version
    stats admin if TRUE
stats refresh 30s
    :wq

cd -
cp haproxy.init /etc/init.d/haproxy
ll /etc/init.d/haproxy
chmod +x /etc/init.d/haproxy
ll /etc/init.d/haproxy
haproxy概念和负载均衡
chkconfig --add haproxy
在百度上192.168.80.100:8089/stats
haproxy概念和负载均衡
vi /etc/haproxy/haproxy.cfg
#最后一行添加
listen webcluster
bind 0.0.0.0:80
mode http
option httpchk GET /index.html
log global
maxconn 3000
balance roundrobin
server web01 192.168.80.102:80 check inter 2000 fall 5
server web02 192.168.80.103:80 check inter 2000 fall 5
haproxy概念和负载均衡
在百度上192.168.80.100:8089/stats
haproxy概念和负载均衡


在80.102虚拟机上

systemctl stop firewalld
setenforce 0
yum install httpd -y
vi /etc/httpd/conf/httpd.conf
找到ServerName www.example.com:80把#去掉
:wq
cd /var/www/html/
echo "<h1>server aa</h1>" > index.html
systemctl start httpd
上百度192.168.80.102
haproxy概念和负载均衡


在80.103虚拟机上

systemctl stop firewalld
setenforce 0
yum install httpd -y
vi /etc/httpd/conf/httpd.conf
找到ServerName www.example.com:80把#去掉
:wq
cd /var/www/html/
echo "<h1>server bb</h1>" > index.html
systemctl start httpd
上百度192.168.80.103
haproxy概念和负载均衡

猜你喜欢

转载自blog.51cto.com/14158288/2339647
今日推荐