负载均衡 | 青训营笔记

140 阅读1分钟

这是我参与「第三届青训营 -后端场」笔记创作活动的的第5篇笔记。 负载均衡建立在现有网络结构之上,它提供了一种廉价有效透明的方法扩展网络设备服务器的带宽、增加吞吐量、加强网络数据处理能力、提高网络的灵活性和可用性。

负载均衡 (Load Balance) 其意思就是分摊到多个操作单元上进行执行,例如Web服务器FTP服务器企业关键应用服务器和其它关键任务服务器等,从而共同完成工作任务。
四层负载均衡

image.png

image.png

image.png 七层负载均衡

image.png

Nginx简介

Screen Shot.png image.png

内部架构

image.png

Nignx优化

image.png

image.png

image.png

nginx常用命令

  • 启动nginx

    • nginx
    • 当你敲完nginx这5个键的时候,并没有任何反应,此时你只需访问localhost:8080(默认)即可

  • 关闭nginx

    • 如果出现下图情况,不要惊慌,是因为之前nginx被启动过了
    • 只需nginx -s stop,停止nginx服务
    • 然后再次启动nginx即可

  • 重启nginx

    • nginx -s reload
    • 每次修改完.conf文件就需要重启nginx
  • 检查配置

    • 检查修改的nginx.conf配置是否正确
    • nginx -t
    • 如果出现下面ok和successfull就代表正确了,其他的都不对
     nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
     nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful
    复制代码
    

对于我们前端来说正常工作当中,倒是不需要过多的修改nginx的。我们之所以修改nginx配置,是为了做一些反向代理罢了

proxy_pass

nginx反向代理主要通过proxy_pass来配置,将你项目的开发机地址填写到proxy_pass后面,正常的格式为proxy_pass URL即可

server {
    listen 80;
    location / {
        proxy_pass http://10.10.10.10:20186;
    }
}