四层负载均衡做端口转发

 

 

数据库连接

↓↓↓↓↓↓↓↓↓↓↓↓

链接:https://pan.baidu.com/s/1iQ1k9q9gMsrVMnXNC4GCPQ
提取码:6666

 

                                                             环境准备

主机 内网IP 外网IP 身份
lb03 172.16.1.6 10.0.0.6 负载均衡
web01 172.16.1.7 10.0.0.7 客户端
db01 172.16.1.51 10.0.0.51 数据库

 

 

1.请求负载均衡的5555端口,转发至172.16.1.7的22端口

1) 配置官方源

[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

 

2)下载nginx

[root@lb03 ~]# yum install -y nginx

 

3) 配置nginx配置文件

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

 

 

4)创建站点目录并编辑

[root@lb03 ~]# mkdir /etc/nginx/conf.c
[root@lb03 ~]# vim /etc/nginx/conf.c/4lb.conf
stream {
    upstream tiao {
        server 172.16.1.7:22;
    }   

    server {
        listen 5555;
        proxy_pass tiao;
    }
}

 

 

5)检查语法并启动nginx

[root@lb03 ~]# nginx -t
[root@lb03 ~]# systemctl start nginx

 

6) 新建窗口连接

 

 

 

 

2.请求负载均衡的6666端口,转发至172.16.1.51的3306端口

1)配置

[root@lb03 ~]# vim /etc/nginx/conf.c/4lb.conf 
upstream mysql {
    server 172.16.1.51:3306;
      
}        
    server {
        listen 6666;
        proxy_pass mysql;
    }

 

 

2)检查配置并重新加载配置文件

[root@lb03 ~]# nginx -t
[root@lb03 ~]# systemctl reload nginx

 

3)下载数据库,启动服务,设置密码,授权

[root@db01 ~]# yum install -y mariadb-server
[root@db01 ~]# systemctl start mariadb
[root@db01 ~]# mysqladmin -uroot password 123
[root@db01 ~]# mysql -uroot -p123
MariaDB [(none)]> grant all on *.* to root@'10.0.0.%' identified by '123456';

MariaDB [(none)]> grant all on *.* to root@'172.16.1.%' identified by '123456';

 

4)连接测试

 

 

 

 

 

 

 

 

posted @ 2020-09-03 20:41  六月OvO  阅读(506)  评论(0编辑  收藏  举报