资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

LVS+keepalived+httpd高可用集群-创新互联

环境:
主keepalived服务器:192.168.80.100
从keepalived服务器:   192.168.80.101

Web服务器:192.168.80.102
                    192.168.80.103

在80.100虚拟机上:
systemctl stop firewalld           //关闭防火墙
setenforce 0                            //关闭监控
yum install lrz* -y       //安装上传软件
把keepalived包拉入

LVS+keepalived+httpd高可用集群

成都创新互联公司是一家专注于成都网站设计、网站制作与策划设计,廊坊网站建设哪家好?成都创新互联公司做网站,专注于网站建设十多年,网设计领域的专业建站公司;建站业务涵盖:廊坊等地区。廊坊做网站价格咨询:13518219792
tar xf keepalived-1.4.2.tar.gz -C /opt/       //解压keepalived-1.4.2文件到/opt
cd /opt/keepalived-1.4.2/
yum install gcc gcc-c++ make popt-devel kernel-devel openssl-devel -y
./configure --prefix=/
make && make install
cd /
cd /etc/
ls | grep keepalived
cd keepalived/

LVS+keepalived+httpd高可用集群

vi keepalived.conf                          //进入keepalived删除所有内容并添加以下内容:

! Configuration File for keepalived
global_defs {
   router_id LVS_01            //本服务器的名称
}
vrrp_instance VI_1 {            //定义VRRP热备实例
    state MASTER             //热备状态,MASTER表示主服务器,BACKUP表示从服务器
    interface ens32            //承载VIP地址的物理接口
    virtual_router_id 51        //虚拟路由器的ID号,每个热备组保持一致
    priority 110               //优先级,数值越大优先级越高
    advert_int 1               //通告间隔秒数(心跳频率)
    authentication {            //热备认证信息,每个热备组保持一致
        auth_type PASS        //认证类型
        auth_pass 6666        //密码字符串
    }
    virtual_ipaddress {          //指定漂移地址(VIP),可以有多个
        192.168.80.188
    }
}
virtual_server 192.168.80.188 80 {      //虚拟服务器地址(VIP)、端口
        delay_loop 6               //健康检查的间隔时间(秒)
        lb_algo rr                  //轮询(rr)调度算法
        lb_kind DR                 //直接路由(DR)群集工作模式
        persistence_timeout 60       //连接保持时间(秒)
        protocol TCP                //应用服务器采用的是TCP协议
real_server 192.168.80.102 80 {         //第一个Web服务器节点的地址、端口
        weight 1                   //节点的权重
        TCP_CHECK {                //健康检查方式
        connect_port 80             //检查的目标端口
        connect_timeout 3           //连接超时(秒)
        nb_get_retry 3              //连接超时(秒)
        delay_before_retry 3          //重试间隔
        }
}
real_server 192.168.80.103 80 {           //第二个Web服务器节点的地址、端口
        weight 1                                     //节点的权重
        TCP_CHECK {                            //健康检查方式
             connect_port 80                    //检查的目标端口
             connect_timeout 3                 //连接超时(秒)
             nb_get_retry 3                       //连接超时(秒)
             delay_before_retry 3               //重试间隔
     }
  }
}

   :wq        //保存退出
service keepalived start
systemctl status keepalived      //查看keepalived状态

LVS+keepalived+httpd高可用集群

ip addr show dev ens32
LVS+keepalived+httpd高可用集群

modprobe ip_vs
yum install ipvsadm -y
service keepalived restart
ipvsadm -Ln            //查看LVS虚拟服务器

LVS+keepalived+httpd高可用集群


在80.101虚拟机上:
systemctl stop firewalld           //关闭防火墙
setenforce 0                            //关闭监控
yum install lrz* -y       //安装上传软件
把keepalived包拉入

LVS+keepalived+httpd高可用集群

tar xf keepalived-1.4.2.tar.gz -C /opt/       //解压keepalived-1.4.2文件到/opt
cd /opt/keepalived-1.4.2/
yum install gcc gcc-c++ make popt-devel kernel-devel openssl-devel -y
./configure --prefix=/
make && make install
modprobe ip_vs
yum install ipvsadm -y
vi /etc/keepalived/keepalived.conf            //删除所有内容并添加以下内容:

! Configuration File for keepalived
global_defs {
   router_id LVS_02
}
vrrp_instance VI_1 {
    state BACKUP
    interface ens32
    virtual_router_id 51
    priority 105
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 6666
    }
    virtual_ipaddress {
        192.168.80.188
    }
}
virtual_server 192.168.80.188 80 {
        delay_loop 6
        lb_algo rr
        lb_kind DR
        persistence_timeout 60
        protocol TCP
real_server 192.168.80.102 80 {
        weight 1
        TCP_CHECK {
        connect_port 80
        connect_timeout 3
        nb_get_retry 3
        delay_before_retry 3
        }
}
real_server 192.168.80.103 80 {
        weight 1
        TCP_CHECK {
             connect_port 80
             connect_timeout 3
             nb_get_retry 3
             delay_before_retry 3
     }
  }
}

   :wq       //保存退出
service keepalived start
systemctl status keepalived           //查看keepalived状态

LVS+keepalived+httpd高可用集群

————————————————————————————

在80.102虚拟机上:
systemctl stop firewalld
setenforce 0
yum install httpd -y                  //安装httpd
vi /etc/httpd/conf/httpd.conf
ServerName   www.example.com.80  前面的#去掉

LVS+keepalived+httpd高可用集群

cd /var/www/html/              //进入目录
echo "

SERVER AA

" > index.html //在index.html添加内容 ls cat index.html

LVS+keepalived+httpd高可用集群

systemctl start httpd
cd
ls
./web.sh

LVS+keepalived+httpd高可用集群

ifconfig //查找IP地址
LVS+keepalived+httpd高可用集群


在虚拟机80.103上:
systemctl stop firewalld
setenforce 0

yum install httpd -y //安装httpd

vi /etc/httpd/conf/httpd.conf
ServerName   www.example.com.80 前面的#去掉

LVS+keepalived+httpd高可用集群

cd /var/www/html/            //进入目录
echo "

SERVER BB

" > index.html //在index.html添加内容 ls cat index.html

LVS+keepalived+httpd高可用集群

systemctl start httpd
vi web.sh      
里面添加以下内容
#!/bin/bash
#haha
ifconfig lo:0 192.168.80.188 broadcast 192.168.80.188 netmask 255.255.255.255 up
route add -host 192.168.80.188 dev lo:0
echo "1" >/proc/sys/net/ipv4/conf/lo/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/lo/arp_announce
echo "1" >/proc/sys/net/ipv4/conf/all/arp_ignore
echo "2" >/proc/sys/net/ipv4/conf/all/arp_announce
sysctl -p &>/dev/null

    :wq       //保存退出
chmod +x web.sh      //设置权限
./web.sh
ifconfig          //查找IP地址

LVS+keepalived+httpd高可用集群

scp web.sh root@192.168.80.102:/root/     //把地址传送过去
yes
root密码

LVS+keepalived+httpd高可用集群

网页上输入http:192.168.80.188

LVS+keepalived+httpd高可用集群

在80.103中
systemctl stop httpd      //关闭httpd
在页面上刷新成下面情况:

LVS+keepalived+httpd高可用集群

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


文章名称:LVS+keepalived+httpd高可用集群-创新互联
文章网址:http://cdkjz.cn/article/jhdsp.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220