侧边栏壁纸
博主头像
落叶人生博主等级

走进秋风,寻找秋天的落叶

  • 累计撰写 130562 篇文章
  • 累计创建 28 个标签
  • 累计收到 9 条评论
标签搜索

目 录CONTENT

文章目录

LVS均衡负载

2023-11-05 星期日 / 0 评论 / 0 点赞 / 35 阅读 / 4265 字

lvs搭建 软件: ipvsadm-1.24 keepalived-1.1.17 编译安装ipvsadm时需要注意将内核创建连接到/usr/src/linux ln -sv /usr/src/ke

lvs搭建
软件:
    ipvsadm-1.24
    keepalived-1.1.17

编译安装ipvsadm时需要注意将内核创建连接到/usr/src/linux
ln -sv /usr/src/kernels/$(uname -r)-$(uname -p) /usr/src/linux
在centos下内核文件名称为内核版本-处理器架构 如2.6.18-348.el5-x86_64
然后进行编译安装。
---------------------------------------------------------------------
keepalived的配置
keepalived安装完成后并不会自动生成配置文件需要自己完全编写

参考
http://www.keepalived.org/documentation.html
http://www.linuxvirtualserver.org/Documents.html
http://outofmemory.cn/wiki/keepalived-configuration
---------------------------------------------------------------------

首先要允许IP转发
echo 1 > /proc/sys/net/ipv4/ip_forward

配置keepalived之后就可以开启此服务了
service keepalived restart

正常开启之后敲入ipvsadm就可以看到均衡规则

至此完成lvs的架构

! Configuration File for keepalivedglobal_defs {   ! this is who emails will go to on alerts   notification_email {        [email protected]    ! add a few more email addresses here if you would like   }   notification_email_from [email protected]   ! I use the local machine to relay mail   smtp_server stmp.logansoft.com   smtp_connect_timeout 30   ! each load balancer should have a different ID   ! this will be used in SMTP alerts, so you should make   ! each router easily identifiable   lvs_id lvs_master}! takes over, you want the internal interface on the failed server! to failover as well, otherwise nothing will work.! you can have as many vrrp_sync_group blocks as you want.!vrrp_sync_group VG1 {!   group {!      VI_1!      VI_GATEWAY!   }!}! now we setup more information about are virtual server! we are just setting up one for now, listening on port 22 for ssh! requests.! each interface needs at least one vrrp_instance! each vrrp_instance is a group of VIPs that are logically grouped! together! you can have as many vrrp_instaces as you wantvrrp_instance VI_1 {        state MASTER        interface eth0        lvs_sync_daemon_inteface eth0    ! each virtual router id must be unique per instance name!        virtual_router_id 51        priority 150    ! how often should we vote, in seconds?        advert_int 1        smtp_alert        authentication {                auth_type PASS                auth_pass logansoft        }        virtual_ipaddress {        192.168.8.28        }}! vrrp_sync_groups make sure that several router instances! stay together on a failure - a good example of this is! that the external interface on one router fails and the backup server!<<<streaming media>>>virtual_server 192.168.8.28 1935 {    delay_loop 6    ! load balancing algorithm    ! rr|wrr|lc|wlc|lblc|sh|dh    lb_algo rr    !  NAT|DR|TUN    lb_kind DR    protocol TCP    real_server 192.168.8.67 1935 {        weight 10        TCP_CHECK {                connect_timeout 5                connect_port 1935        }    }    real_server 192.168.8.23 1935 {        weight 5        TCP_CHECK {               connect_timeout 5               connect_port 1935         }     }    real_server 192.168.8.22 1935 {        weight 5        TCP_CHECK {                connect_timeout 5                connect_port 1935        }    }}!<<<lubo website>>>virtual_server 192.168.8.28 80 {    delay_loop 10    lb_algo rr    lb_kind DR    protocol TCP    real_server 192.168.0.2 80 {    TCP_CHECK {                connect_timeout 3                connect_port 80                nb_get_retry 3                delay_before_retry 1        }    }}!<<<database>>>virtual_server 192.168.8.28 3306 {    delay_loop 10    lb_algo wrr    lb_kind DR    protocol TCP    real_server 192.168.8.40 3306 {        weight 80    TCP_CHECK {                connect_timeout 3                connect_port 3306        }    }    real_server 192.168.8.37 3306 {        weight 70    TCP_CHECK {                connect_timeout 5                connect_port 3306        }    }}

 

广告 广告

评论区