设计企业网站内容,wordpress 投稿者 权限,怎样建网站买东西,wordpress 标题栏置顶搭建负载均衡服务的需求如下#xff1a;
1 ) 把单台计算机无法承受的大规模并发访问或数据流量分担到多台节点设备上#xff0c;分别进行处理#xff0c; 减少用户等待响应的时间#xff0c; 提升用户体验。 2 ) 单个重负载的运算分担到多台节点设备上做并行处理#xff…搭建负载均衡服务的需求如下
1 ) 把单台计算机无法承受的大规模并发访问或数据流量分担到多台节点设备上分别进行处理 减少用户等待响应的时间 提升用户体验。 2 ) 单个重负载的运算分担到多台节点设备上做并行处理 每个节点设备处理结束后 将结果汇总返回给用户系统处理能力得到大幅度提高。 3 ) 7 x 24 小时的服务保证 任意一个或多个有限后面节点设备宕机 不能影响业务。 在负载均衡集群中 同组集群的所有计算机节点都应该提供相同的服务。 集群负载均衡器会截获所有对该服务的入站请求。 然后将这些请求尽可能地平均地分配在所有集群节点上。
实验环境HOSTNAMEIP说明master192.168.19.132Nginx主负载均衡器node1192.168.19.133Web1服务器node3192.168.19.135Web2服务器
系统准备CentOS Linux 7 x86_64 软件准备nginx-1.22.0-1.el7.ngx.x86_64.rpm
目录
1、安装Nginx
2、添加 https 代理模块
3、定义Web服务器池
4、配置用于测试的Web服务
5、自定义Web服务页面
6、配置hosts解析
7、重新启动服务测试
1、安装Nginx 以下操作在3台服务器上执行 yum install nginx-1.22.0-1.el7.ngx.x86_64.rpm 2、添加 https 代理模块 这里需要重新编译 nginx需要查看当前 nginx 的版本和编译选项然后去官网下载同版本的 nginx 源 码进行重新编译 /usr/sbin/nginx -V tar -xf nginx-1.22.0.tar.gz -C /usr/local/ 下载模块 ngx_http_proxy_connect_module git clone https://github.com/chobits/ngx_http_proxy_connect_module 打补丁对 nginx 源码修改这一步很重要不然后面的 make 过不去 cd /usr/local/nginx-1.22.0/ patch -p 1 /root/ngx_http_proxy_connect_module/patch/proxy_connect_rewrite_1018.patch 在原有配置后追加模块,make 后注意不要 install cd /usr/local/nginx-1.22.0/ *安装依赖 yum install -y gcc gcc-c zlib_devel openssl-devel pcre-devel ./configure --with-http_stub_status_module --with-http_ssl_module --with-file-aio --with-http_realip_module --add-module/root/ngx_http_proxy_connect_module/ make 出现如下结果安装成功 3、定义Web服务器池 以下操作在lb01 [rootmaster conf.d]# ls default.conf.bak vhost.conf [rootmaster conf.d]# cat vhost.conf upstream www_server_pools{ server 192.168.19.133:80 weight1; server 192.168.19.135:80 weight1; } server { listen 80; server_name www.xixi.com; location / { proxy_pass http://www_server_pools; } } 4、配置用于测试的Web服务 以下操作在两台web服务器 cd /etc/nginx/conf.d/ mv default.conf{,.bak} cat vhost.conf server { listen 80; server_name bbs.xixi.com; location / { root /usr/share/nginx/html/bbs; index index.html index.htm; } access_log /usr/share/nginx/html/bbs/logs/access_bbs.log main; } server { listen 80; server_name www.xixi.com; location / { root /usr/share/nginx/html/www; index index.html index.htm; } access_log /usr/share/nginx/html/www/logs/access_www.log main; } 5、自定义Web服务页面 以下操作在两台web服务器 mkdir -p /usr/share/nginx/html/{www,bbs}/logs echo hostname -I www /usr/share/nginx/html/www/index.html echo hostname -I bbs /usr/share/nginx/html/bbs/index.html 6、配置hosts解析 [rootmaster ~]# tail -1 /etc/hosts 192.168.19.132 www.xixi.com 7、重新启动服务测试 [rootmaster ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [rootmaster ~]# systemctl restart nginx [rootmaster ~]# for ((i1;i4;i)); do curl http://www.xixi.com; done 192.168.19.133 bbs 192.168.19.135 bbs 192.168.19.133 bbs 192.168.19.135 bbs 从上面的测试结果可以看出来。两个Web节点按照11的比例被访问。 下面宕掉任意一个Web节点看看测试结果如何测试如下 [rootnode3 ~]# systemctl stop nginx [rootmaster~]# for ((i1;i4;i)); do curl http://www.yunjisuan.com; done #正确显示结果 192.168.19.133 bbs 192.168.19.133 bbs 192.168.19.133 bbs 192.168.19.133 bbs 节点恢复正常后再次测试 [rootnode3 ~]# systemctl start nginx [rootmaster ~]# for ((i1;i4;i)); do curl http://www.yunjisuan.com; done 192.168.19.135 bbs 192.168.19.133 bbs 192.168.19.135 bbs 192.168.19.133 bbs 网页浏览 刷新后 实现 Nginx 负载均衡的组件说明
ngx_http_proxy_module proxy 代理模块用于把请求后拋给服务器节点或 upstream 服务器池ngx_http_upstream_module 负载均衡模块可以实现网站的负载均衡功能及节点的健康检査
问题解决: 在第7步重启服务测试出现问题如下 192.168.19.135的服务显示不出来 原因主机master的hosts文件地址解析写的是www.xixi.com,但是在测试时写的域名是www.yunjisuan.com 解决hosts文件的域名地址和nginx配置文件的域名要一一对应。修改完后三台主机都重启nginx服务。