teat12

1. 环境准备


  • 虚拟机4台
  • 双网卡仅主机模式
  • 修改yum源

2. LSV主服务器配置


2.1. 基础网络配置

2.1.1. 网络配置

2.1.1.1. 关闭网卡守护

service NetworkManager stop

2.1.1.2. 关闭网卡守护开机自启动

chkconfig NetworkManager off

2.1.1.3. 进入网卡配置文件目录

cd /etc/sysconfig/network-scripts/

2.1.1.4. 创建子接口,复制eth0网卡配置文件为et0:0

cp -a ifcfg-eth0 ifcfg-eth0:0

2.1.1.5. 更改eth0配置

vim ifcfg-eth0

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.10.10.14
NETMASK=255.255.255.0

2.1.1.6. 更改eth0:0配置

vim ifcfg-eth0:0

DEVICE=eth0:0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.10.10.100
NETMASK=255.255.255.0

2.1.1.7. 重启网络服务

service network restart

2.2. IPVS配置

2.2.1. 挂载光盘

mount -t iso9660 /dev/cdrom /mnt/cdrom

2.2.2. 安装依赖包

yum -y install kernel-devel openssl-devel popt-devel gcc

2.2.3. 安装ipvsadm

yum -y install ipvsadm

2.2.4. 关闭广播重定向功能

vim /etc/sysctl.conf

net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
net.ipv4.conf.eth0.send_redirects = 0

2.2.5. 刷新sysctl

sysctl -p

2.2.6. 配置ipvsadm

ipvsadm -A -t 10.10.10.100:80 -srr
ipvsadm -a -t 10.10.10.100:80 -r 10.10.10.15:80 -g
ipvsadm -a -t 10.10.10.100:80 -r 10.10.10.16:80 -g

2.2.7. 查看配置结果

ipvsadm -Ln

2.2.7.1. 查询结果如下则配置正确

IP Virtual Server version 1.2.1 (size=4096)
Prot LocalAddress:Port Scheduler Flags
  -> RemoteAddress:Port           Forward Weight ActiveConn InActConn
TCP  10.10.10.100:80 rr
  -> 10.10.10.15:80               Route   1      0          0         
  -> 10.10.10.16:80               Route   1      0          0         

2.2.8. 将ipvsadm加入到开机自启动

chkconfig ipvsadm on

2.2.9. 保存配置

service ipvsadm save

2.3. 安装Keepalived环境布置

挂载 光盘

2.3.1. 配置文件

./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/

2.3.2. 编译安装

make && make install

2.3.3. 将kkeepalived添加到chkconfig

chkconfig --add keepalived

2.3.4. 更改配置文件

vim /etc/keepalived/keepalived.conf
  • 全部删除,保留一个router_id LVS_DEVEL
    修改配置文件
! Configuration File for keepalived

global_defs {
   router_id RS1
}

vrrp_instance VI_1 {
    virtual_router_id 66
    priority 80
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 1111
    }
    virtual_ipaddress {
        10.10.10.100
    }   
}   
virtual_server 10.10.10.100 80{
    delay_loop 6
        auth_pass 1111
    }
        weight 1
        TCP_CHECK{
            connect_prot 80
            connect_timeout 3
            nb_get_retry3
            delay_before_retry 4
        }
        real_server 10.10.10.15 80{
        weight 1
        TCP_CHECK{
            connect_prot 80
            connect_timeout 3
            nb_get_retry3
            delay_before_retry 4
        real_server 10.10.10.16 80{
        weight 1
        TCP_CHECK{
            connect_prot 80
            connect_timeout 3
            nb_get_retry3
            delay_before_retry 4
    }
}

3. 真实服务器配置(节点)

3.1. web服务器配置

3.1.1. 开启httpd服务

service httpd start

3.1.2. 将httpd加入到开机自启

chkconfig httpd on

3.1.3. 添加一个网页文件

echo "this is service rs1" >> /var/www/html/index.html

3.1.4. 查看网页内容

curl localhost

3.1.4.1. 查看显示结果如下:

this is server rs1

3.2. 网络配置

cd /etc/sysconfig/network-scripts

3.2.1. 创建子接口

cp -a ifcfg-lo ifcfg-lo:0

3.2.2. 打开子接口!$为上一条命令的最后一条参数,即是ifcfg-lo:0

vim !$
DEVICE=lo:0
IPADDR=10.10.10.100
NETMASK=255.255.255.255
NETWORK=127.0.0.0
# 4. If you're having problems with gated making 127.0.0.0/8 a martian,
# 5. you can change this to something else (255.255.255.255, for example)
BROADCAST=127.255.255.255
ONBOOT=yes
NAME=loopback

posted on 2020-08-12 14:39  柳条儿  阅读(99)  评论(0编辑  收藏  举报

导航