七层负载均衡

时间:2021-10-26 17:39:37
集群的分类:


1    高可用集群 HA ( high availability)

避免单节点故障
软件:keepalived


2    负载均衡集群 LB ( load balance)

提高负载,提高并发量

软件:nginx反向代理 lvs
硬件负载均衡器 F5(BigIP)和redware


3    HPC高性能运算集群

4    分布式存储集群
极大的提升存储容量,提供数据高可用,保证数据安全

软件:ceph

-------------------------------------------------------------------------------------------------------------------------------------------------------------

            nginx          反向代理 dr director
                |
     --------------------

    |                       |

nginx               nginx         真实服务器 rs realserver


一,两台静态服务器的配置

给realserver安装nginx,作页面,启动服务,保证能正常访问

步骤:

        1 安装软件:yum  install  nginx   -y 

        2 在反向代理服务器里面改配置

        3 编辑配置文件    vim /etc/nginx/nginx.conf

                

upstream web {

                               server 192.168.122.10;
                               server 192.168.122.20;

                                }                                          #上面的配置写到http里面server外面

                         server {
                                 listen 80;
                                 server_name www.baidu.com;
                                 location / {                                #html的配置
                                 proxy_pass http://web;    这个标黄部分必须和上面相同
                                 }

# systemctl start php-fpm           启动php-fpm   这个软件是连接phpnginx

#systemctl  start  nginx               启动nginx

#setenforce 0 &&  systemctl  stop firewalld    关闭防火墙

4  测试是否成功

打开一个网页,输入代理机的ip地址,看能否显示   真实服务器  上的网页

二,配置俩台动态服务器

php-fpm是独立的php进程 端口:9000

1 yum install  nginx   php    php-fpm     -y       #在两台机器上安装这三种软件

2 setenforce 0 && systemctl stop  firewalld      #关闭防火墙

3

后端服务器部署详细过程:
安装软件:
# yum install nginx php php-fpm -y
# vim /etc/nginx/nginx.conf //添加php配置
在server里面添加如下配置:
location ~ \.php$ {
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}

修改php-fpm进程账户并开启php-fpm的进程: 端口是9000
#vim /etc/php-fpm.d/www.conf //修改如下参数,默认值是apache
user = nginx
group = nginx

为什么设置成nginx:
因为nginx.conf配置的账户为nginx

# systemctl start php-fpm


前端nginx反向代理服务器:
upstream web {
server 10.0.0.21;
server 10.0.0.22;
}
upstream phpserver {
server 10.0.0.23;
server 10.0.0.24;
}
#上面的配置写到http里面server外面

server {
listen 80;
server_name www.baidu.com;
location / { #html的配置
proxy_pass http://web;
}

location ~* \.php$ { #php的配置
proxy_pass http://phpserver;
}