linux运维学习笔记:nginx系列之05:负载均衡调度

linux运维学习笔记:nginx系列之05:负载均衡调度

作者:周少言
201年 月 日 星期 ,于北京

声明:本博客是本人周少言在某培训机构学习期间所写,其中参考借鉴了他人的博客,本文将会选择性给出相关链接,如有侵权,恳请告知。本文如有错误,恳请告知,欢迎交流。

参考连接

本文是工作手册,经过反复试验所写,所以,尽情在你的xshell粘贴复制,让更多的时间用来思考!如果有不妥的地方,恳请留言告知。

如果您觉得本文值得分享,请帮忙分享出去哦!知识的可贵在于分享与交流,谢谢。

布局

nginx 192.168.22.41 源码安装
apache 192.168.22.42 yum
apache 192.168.22.40 yum
client 192.168.22.43

配置nginx主机

vim /usr/local/nginx/conf/nginx.conf

在http模块以内,server模块以外添加:

        upstream laihu.com  {
            server 192.168.22.42:80;
            server 192.168.22.40:80;
        }

在server模块下修改location / {} 删除原内容,改为以下:

        location / {
            proxy_pass http://laihu.com;
        }
/usr/local/nginx/sbin/nginx -t
service nginx reload

配置两台apache主机

192.168.22.42

yum -y install httpd
service httpd start
echo "this is web1,welcome,ID 42."  >> /var/www/html/index.html
service httpd restart

192.168.22.40

yum -y install httpd
service httpd start
echo "this is web2 ,ID 40,welcome."  >> /var/www/html/index.html
service httpd restart

client 测试

访问:
192.168.22.41

"this is web2 ,ID 40,welcome."与"this is web1,welcome,ID 42."
反复一比一出现,则成功。

补充:
负载调度的用法
①、在server区域外创建一个 upstream 区域,此区域中编写的内容为负载群
upstream xdl.com {
ip_hash;
server 192.168.1.240:80 weight=1;
server 192.168.1.241:80 weight=1;
server 192.168.1.242:80 weight= 1 backup;
}
ip_hash 调度算法,默认 rr 轮训,hash常用语解决session共享的问题
backup 表示机器处于热备状态,weight代表权重,权重越高代表使用越多

②、在 / 的区域内设置反向代理
location / {
proxy_pass http://xdl.com;
}

你可能感兴趣的:(linux运维学习笔记:nginx系列之05:负载均衡调度)