四层负载均衡实践

 

lb01是我已配置好的七层负载均衡,下面有一些项目知乎,博客

现要加一台四层负载均衡和七层负载均衡

保证七层的负载均衡的高可用性

 

1.环境准备

主机 外网IP 内网IP 身份
lb03 10.0.0.6 172.16.1.6 四层负载均衡
lb02 10.0.0.4 172.16.1.4 七层负载均衡
lb01 10.0.0.5 172.16.1.5 七层负载均衡

2.lb02安装nginx 配置 安装 创建用户 启动

[root@lb02 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@lb02 ~]# yum install -y nginx
[root@lb02 ~]# groupadd -g 666 www
[root@lb02 ~]# useradd -u 666 -g 666 www
[root@lb02 ~]# vim /etc/nginx/nginx.conf
user  www;
[root@lb02 ~]# systemctl start nginx

 

 

3.推送lb01配置到lb02

[root@lb01 ~]# scp /etc/nginx/conf.d/* 172.16.1.5:/etc/nginx/conf.d/
[root@lb01 ~]# [root@lb01 ~]# scp /etc/nginx/proxy_params 172.16.1.5:/etc/nginx/

 

4.测试lb02七层负载均衡并测试是否可以正常打开

[root@lb02 ~]# nginx -t
[root@lb02 ~]# systemctl restart nginx

 

5.配置本地hosts文件

 

 

 

 

 

 

 

 

 

 

 

 

 

 

6.lb03安装官方源 下载nginx 

[root@lb03 ~]# vim /etc/yum.repos.d/nginx.repo
[nginx-stable]
name=nginx stable repo
baseurl=http://nginx.org/packages/centos/7/$basearch/
gpgcheck=1
enabled=1
gpgkey=https://nginx.org/keys/nginx_signing.key
module_hotfixes=true
[root@lb03 ~]# yum install -y nginx

 

7.配置nginx配置文件

[root@lb03 ~]# vim /etc/nginx/nginx.conf
include /etc/nginx/conf.c/*.conf;

 

 

8.创建站点目录并配置四层负载均衡,检查,重启

[root@lb03 ~]# mkdir /etc/nginx/conf.c
[root@lb03 ~]# vim /etc/nginx/conf.c/4lb.conf
stream {
    log_format  proxy '$remote_addr $remote_port - [$time_local] $status $protocol' '"$upstream_addr" "$upstream_bytes_sent" "$upstream_connect_time"' ;
   
    access_log /var/log/nginx/proxy.log proxy;
    upstream lbserver {
        server 10.0.0.4:80;
        server 10.0.0.5:80;
    }

    server {
        listen 80;
        proxy_connect_timeout 1s;
        proxy_timeout 3s;
        proxy_pass lbserver;
    }
}

[root@lb03 ~]# nginx -t
[root@lb03 ~]# rm -rf /etc/nginx/conf.d/*
[root@lb03 ~]# systemctl restart nginx

 

9.配置本地hosts并访问

 

 

 

 

 

 

 

 

10.验证

[root@lb03 ~]# tailf /var/log/nginx/proxy.log

 

posted @ 2020-09-03 22:17  六月OvO  阅读(149)  评论(0编辑  收藏  举报