20170414-负载均衡集群

vm01:192.168.122.1

vm25:192.168.122.25

vm26:192.168.122.26

vm35:192.168.122.35

陪软件仓库:

vim /etc/yum.repos.d/cluster.repo

  1 [rhel-server]
  2 name=Server
  3 baseurl=file:///iso/Server
  4 gpgcheck=0
  5 enabled=1
  6
  7 [rhel-LoadBalancer]
  8 name=LoadBalancer
  9 baseurl=file:///iso/LoadBalancer
 10 gpgcheck=0
 11 enabled=1
 12
 13 [rhel-HighAvailability]
 14 name=HighAvailability
 15 baseurl=file:///iso/HighAvailability
 16 gpgcheck=0
 17 enabled=1
 18
 19 [rhel-ResilientStorage]
 20 name=HighAvailability
 21 baseurl=file:///iso/ResilientStorage
 22 gpgcheck=0
 23 enabled=1
 24
 25 [rhel-ScalableFileSystem]
 26 name=ScalableFileSystem
 27 baseurl=file:///iso/ScalableFileSystem

 28 gpgcheck=0
 29 enabled=1
                      

vm01:  yum install haproxy 

           vim /etc/haproxy/haproxy.cfg

          

 87 listen serverweb *:80
 88      balance  roundrobin
 89      server vm25 192.168.122.25 check
 90      server vm36 192.168.122.36 check
 91
 92     stats enable
 93     #stats uri /stat /haproxy?stats
 94     stats admin if LOCALHOST
 95     stats auth  admin:admin
 96     stats refresh 5s

或者:

frontend  main *:80

default_backend             app

backend app

balance  roundrobin
       server vm25 192.168.122.25 check
       server vm36 192.168.122.36 check

stats enable
      #stats uri /stat /haproxy?stats
      stats admin if LOCALHOST
      stats auth  admin:admin
      stats refresh 5s

 

service haproxy restart

vim /etc/rsyslog.conf

 13 $ModLoad imudp
 14 $UDPServerRun 514

 36 local.*    /var/log/haproxy.log
 37 local.*    ~

service rsyslog restart

 

访问 127.0.0.1/haproxy?stats 可以管理

yum install keepalived

 

vim /etc/keepalived/keepalived.conf

 

  1 ! Configuration File for keepalived
  2
  3 global_defs {
  4    notification_email {
  5      acassen@firewall.loc
  6      failover@firewall.loc
  7      sysadmin@firewall.loc
  8    }
  9    notification_email_from Alexandre.Cassen@firewall.loc
 10    smtp_server 192.168.200.1
 11    smtp_connect_timeout 30
 12    router_id LVS_DEVEL
 13 }
 14
 15 vrrp_script chk_haproxy {
 16      script "killall -0 haproxy"      #cheaper than pidof
 17      interval 2                       #check every 2 seconds
 18      weight   2
 19 }
 20
 21 vrrp_instance VI_1 {
 22     state MASTER
 23     interface virbr0 
 24     virtual_router_id 55
 25     priority 100
 26     advert_int 1
 27     authentication {

 28         auth_type PASS
 29         auth_pass 123321
 30     }
 31     virtual_ipaddress {
 32         192.168.122.200
 33     }
 34
 35     track_script {
 36         chk_haproxy
 37     }
 38 }

service keepalived restart

vm25: 配置haproxy  和vm01 一样

配置日志一样

 配置keepalived  和vm01不一样的地方

state MASTER

priority 99

interface  eth0    这个用 ifconfig 看产生VIP的网卡是哪个

service keepalived restart

service haproxy restart

vm26和vm36

yum install httpd

vim /etc/httpd/conf/httpd.conf

ServerName localhost

vim /var/www/html/index.html

 写入内容

service httpd restart

测试: http://192.168.122.200

 

 

 

转载于:https://my.oschina.net/u/3217381/blog/879835

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值