LNMP实现双主机负载均衡

  • A+
所属分类:运维教程

项目需求

网站创建之初因访问量较少,只放置在一台服务器上。随着访问量的增加,一台服务器已无法负载,打算增加一台服务器做负载均衡。

项目分析

常见的负载均衡有两种,一种基于四层为LVS,一种基于七层为Nginx。两种负载均衡都需要三台服务器才能发挥性能,有悖于预算中的两台服务器,故打算使用动静分离加远程数据库来实现负载均衡。

网络拓扑

LNMP实现双主机负载均衡

设备信息

  1. 客户端192.168.1.250,仅需要浏览器;
  2. 服务器A192.168.1.1,需安装Nginx+PHP,负责分发和动态文件的处理;
  3. 服务器B192.168.1.2,需安装Nginx+MySQL,负责静态文件处理和数据库存储。

实施前提

如上安装好对应的服务,程序以WordPress为例。

项目实施

  • 动静分离

修改服务器A的Nginx配置文件,内容如下:

  1. server
  2. {
  3.     listen 80;
  4.     server_name birdteam.net;
  5.     index index.php;
  6.     root /www/wwwroot/birdteam.net;
  7.     include enable-php-70.conf;
  8.     include /www/server/panel/vhost/rewrite/birdteam.net.conf;
  9.     location ~ .*\.(gif|jpg|jpeg|png|bmp|swf|js|css)$
  10.     {
  11.         proxy_pass http://192.168.1.2;
  12.     }
  13. }
  • 数据调用

wp-config.php文件中

  1. define('DB_HOST', 'localhost');

改为

  1. define('DB_HOST', '192.168.1.2');
  • 文件同步

将WordPress中的静态文件,扩展名为gif|jpg|jpeg|png|bmp|swf|js|css复制到服务器B对应的目录中。

数据走向

  1. 服务器组对外公布服务器A的IP地址;
  2. 客户访问服务器A的IP地址;
  3. 服务器A根据请求判断动静解析都有哪些;
  4. 根据请求本地处理动态内容,并把静态请求转发至B;
  5. 如果动态内容需要数据库的支持,则会根据指定地址,找B读取;
  6. B将静态请求、数据信息发送给A,A将所有请求整合返回给客户端。

附加内容

文件同步可使用NFS服务,或RSYNC,这样效率更高!

  • 问答中心
  • 微信小程序扫一扫
  • weinxin
  • 微信公众
  • 微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:20   其中:访客  20   博主  0

    • avatar this article

      I do agree with all the ideas you’ve presented in your post. They’re really convincing and will definitely work. Still, the posts are too short for starters. Could you please extend them a bit from next time? Thanks for the post.

      • avatar grolyrto lemcs

        I have been reading out a few of your posts and it’s pretty nice stuff. I will make sure to bookmark your blog.

        • avatar cbd oil that works 2020

          Good day! Do you know if they make any plugins
          to safeguard against hackers? I’m kinda paranoid about losing everything I’ve
          worked hard on. Any recommendations?

          • avatar a knockout post

            Appreciate it for helping out, fantastic info .

            • avatar cbd oil that works 2020

              Very descriptive post, I loved that a lot. Will there be a part 2?

              • avatar http://bit.ly/3drY6lE

                Cbd oil that works 2020
                Hi, i think that i saw you visited my blog thus i came to “return the favor”.I’m
                attempting to find things to improve my website!I suppose its ok to use a few
                of your ideas!! best cbd oil for pain http://bit.ly/3drY6lE cbd oil that
                works 2020 http://bit.ly/3drY6lE

                • avatar rsacwgxy g

                  Hi would you mind letting me know which hosting company
                  you’re using? I’ve loaded your blog in 3 different web browsers and I must say this blog
                  loads a lot quicker then most. Can you recommend a good hosting
                  provider at a fair price? Thanks a lot, I
                  appreciate it!

                  • avatar svolrfinotews

                    With havin so much content do you ever run into any problems of plagorism or copyright violation? My site has a lot of exclusive content I’ve either created myself or outsourced but it seems a lot of it is popping it up all over the web without my agreement. Do you know any solutions to help reduce content from being stolen? I’d truly appreciate it.

                    • avatar svolrfinotews

                      Wow, marvelous weblog format! How lengthy have you ever been running a blog for? you made running a blog glance easy. The total glance of your web site is great, as neatly as the content!

                      • avatar BTC ETF

                        Thank you for sharing excellent informations. Your site is so cool. I’m impressed by the details that you have on this web site. It reveals how nicely you understand this subject. Bookmarked this web page, will come back for more articles. You, my pal, ROCK! I found just the information I already searched everywhere and just couldn’t come across. What an ideal web site.