网站建设适合女生吗,永清县建设局网站,青岛手机网站建设公司,iH5做网站摘要#xff1a;负载均衡#xff1a; 负载均衡是一种技术#xff0c;用于在多个服务器之间分发传入的网络流量#xff0c;以平衡服务器的负载#xff0c;提高系统的可用性和性能。当您有多台服务器时#xff0c;您可以使用负载均衡将请求分发到这些服务器上#xff0c;从…摘要负载均衡 负载均衡是一种技术用于在多个服务器之间分发传入的网络流量以平衡服务器的负载提高系统的可用性和性能。当您有多台服务器时您可以使用负载均衡将请求分发到这些服务器上从而防止单个服务器过载而影响用户体验。 反向代理 反向代理是一种服务器配置它将传入的客户端请求转发到后端服务器并将响应从后端服务器返回给客户端。在负载均衡环境中反向代理位于客户端和后端服务器之间。客户端将请求发送到反向代理然后反向代理将请求转发到一个或多个后端服务器。反向代理还可以执行其他任务如 SSL 终止、安全性增强、缓存等。 总结在配置 Nginx 的负载均衡时您将配置反向代理服务器该服务器将负责将传入的请求分发给后端服务器。这种配置可以提高系统的可伸缩性和稳定性。通常情况下您会使用 Nginx 的 upstream 指令定义后端服务器列表并使用 location 块将请求转发给这些后端服务器。
1.安装nginx三台主机全部需要
上传rpm包,使用yum安装
[rootnode1 ~]# yum install nginx-1.22.0-1.el7.ngx.x86_64.rpm -y2.配置两台测试的web服务器两台web服务器node3和node4都执行
[rootnode3 ~]# cd /etc/nginx/conf.d/
[rootnode3 conf.d]# mv default.conf{,.bak}
[rootnode3 conf.d]# vim vhost.conf
# 配置虚拟主机
server {listen 80;server_name bbb.itxuan.com;location / {root /usr/share/nginx/html/bbb;index index.html index.htm;}access_log /usr/share/nginx/html/bbb/logs/access_bbb.log main;
}server {listen 80;server_name www.itxuan.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;
}
3.配置web测试页node3node4都执行
[rootnode3 conf.d]# mkdir -p /usr/share/nginx/html/{www,bbb}/logs
[rootnode3 conf.d]# echo hostname -I www /usr/share/nginx/html/www/index.html
[rootnode3 conf.d]# echo hostname -I bbb /usr/share/nginx/html/bbb/index.html4.启动服务进行测试
[rootnode1 ~]# systemctl start nginx
[rootnode1 ~]# curl -H host:bbb.itxun.com 192.168.136.164
192.168.136.164 bbb
[rootnode1 ~]# curl -H host:bbb.itxun.com 192.168.136.163
192.168.136.163 bbb5.配置node1端的负载均衡
[rootnode1 ~]# vim /etc/nginx/conf.d/default.conf
upstream www_server_pools{server 192.168.136.163:80;server 192.168.136.164:80;
}
server {listen 80;server_name www.itxuan.com;#access_log /var/log/nginx/host.access.log main;location / {# root /usr/share/nginx/html;# index index.html index.htm;proxy_pass http://www_server_pools;}
nginx检查并重启服务 [rootnode1 ~]# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful [rootnode1 ~]# systemctl restart nginx 6.配置node1端hosts解析并测试
[rootnode1 ~]# vim /etc/hosts
192.168.136.161 www.itxuan.com
[rootnode1 ~]# for ((i1;i4;i)); do curl http://www.itxuan.com; done
192.168.136.164 bbb
192.168.136.163 bbb
192.168.136.164 bbb
192.168.136.163 bbb7.stop掉任意一个节点在进行测试
[rootnode3 ~]# systemctl stop nginx
[rootnode1 ~]# for ((i1;i4;i)); do curl http://www.itxuan.com; done
192.168.136.164 bbb
192.168.136.164 bbb
192.168.136.164 bbb
192.168.136.164 bbb7.节点恢复正常后在进行测试
[rootnode3 ~]# systemctl start nginx
[rootnode1 ~]# for ((i1;i4;i)); do curl http://www.itxuan.com; done
192.168.136.164 bbb
192.168.136.164 bbb
192.168.136.163 bbb
192.168.136.164 bbb