让你的博客实现负载均衡

19 篇文章 0 订阅
6 篇文章 0 订阅

零、缘起

有时候博客突然挂了,发现服务器厂商出了问题,很忧伤,我正在写着或查阅自家博客那种不可xx的内容。这时想着,如果这个博客有负载均衡就好了,空了想着实现下。

一分钟了解负载均衡的一切

选择第二种【反向代理层->站点层】的负载均衡,基于nginx的反向代理技术,需要一个负载均衡服务器。

一、购买服务器,作为负载均衡代理服务器

买腾讯云按量付费服务器,我看了下这个配置,后面好像选按小时计算付费,每小时花0.09(流量0.01和云硬盘0.08),一天2.16,这个机子用来调试,部署负载均衡代理。
在这里插入图片描述
在这里插入图片描述

二、登录服务器,安装配置nignx

安装nginx

 yum install -y nginx
查看nginx配置文件
[root@xx ~]#  whereis nginx
nginx: /usr/sbin/nginx /usr/lib64/nginx /etc/nginx /usr/share/nginx /usr/share/man/man3/nginx.3pm.gz /usr/share/man/man8/nginx.8.gz

[root@xx ~]# cat /etc/nginx/nginx.conf
启动nginx
[root@xx ~]# which nginx
/usr/sbin/nginx
[root@xx ~]# /usr/sbin/nginx


[root@xx ~]# ps -ef | grep nginx
root      5092     1  0 21:18 ?        00:00:00 nginx: master process nginx
nginx     5093  5092  0 21:18 ?        00:00:00 nginx: worker process
nginx     5094  5092  0 21:18 ?        00:00:00 nginx: worker process
root      5148  3331  0 21:18 pts/0    00:00:00 grep --color=auto nginx

三、代码实现

在http模块下增加修改以下代码

 upstream test {
        server ip:8080;# 貌似只能是ip,端口不能为80
        server ip:8081;

    }
    server {
        listen       80;                                                        
        server_name  localhost;#负载均衡服务器的ip或域名                                             
        client_max_body_size 1024M;
 
        location / {
            proxy_pass http://test;
            proxy_set_header Host $host:$server_port;
        }

[root@xx ~]# /usr/sbin/nginx -t
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful
[root@xx ~]# /usr/sbin/nginx -s reload

搞负责均衡是为了高可用,如果这个负责均衡只是对于没啥流量博客而言,起到流量均衡负载到不同服务器的作用,那没啥用。

下一篇讲关于主从复制的内容。

参考:

一分钟了解负载均衡的一切

nginx 手册

  • 10
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值