1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > nginx反向代理负载均衡功能

nginx反向代理负载均衡功能

时间:2024-04-10 16:16:57

相关推荐

nginx反向代理负载均衡功能

客户端====代理服务器===web服务器

反向代理功能架构3台web服务器,组建出web服务器集群web01 10.0.0.7 172.16.1.7web02 10.0.0.8 172.16.1.8web03 10.0.0.9 172.16.1.91台负载均衡服务器lb01 10.0.0.5 172.16.1.5 ①. 部署web服务器第一个里程:安装部署nginx软件 注:另外两台web服务器也要部署相同的nginx服务mkdir /server/tools -pcd /server/toolswget /download/nginx-1.12.2.tar.gztar xf nginx-1.12.2.tar.gzyum install -y pcre-devel openssl-develuseradd -M -s /sbin/nologin wwwcd nginx-1.12.2./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_modulemake && make installln -s /application/nginx-1.12.2 /application/nginx/application/nginx/sbin/nginxnetstat -lntup|grep nginx第二个里程:编辑nginx配置文件server {listen 80;server_name ;root html/www;index index.html index.htm;}server {listen 80;server_name ;root html/bbs;index index.html index.htm;}scp -rp /application/nginx/conf/nginx.conf 172.16.1.8:/application/nginx/conf/scp -rp /application/nginx/conf/nginx.conf 172.16.1.8:/application/nginx/conf/第三里程:创建模拟测试环境mkdir /application/nginx/html/{www,bbs} -pfor name in www bbs;do echo "$(hostname) $" >/application/nginx/html/$name/oldboy.html;donefor name in www bbs;do cat /application/nginx/html/$name/oldboy.html;done第四里程:在负载均衡服务器上,进行测试访问curl -H host: 10.0.0.7/oldboy.htmlweb01 curl -H host: 10.0.0.7/oldboy.htmlweb01 curl -H host: 10.0.0.8/oldboy.htmlweb02 curl -H host: 10.0.0.8/oldboy.htmlweb02 curl -H host: 10.0.0.9/oldboy.htmlweb03 curl -H host: 10.0.0.9/oldboy.htmlweb03 ②. 部署负载均衡服务器第一个里程:安装部署nginx软件mkdir /server/tools -pcd /server/toolswget /download/nginx-1.12.2.tar.gztar xf nginx-1.12.2.tar.gzyum install -y pcre-devel openssl-develuseradd -M -s /sbin/nologin wwwcd nginx-1.12.2./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_modulemake && make installln -s /application/nginx-1.12.2 /application/nginx/application/nginx/sbin/nginxnetstat -lntup|grep nginx第二个里程:编写nginx反向代理配置文件grep -Ev "#|^$" nginx.conf.default >nginx.conf官方链接:/en/docs/http/ngx_http_upstream_module.html#upstreamSyntax: upstream name { ... }Default: —Context: httpeg:upstream oldboy {server 10.0.0.7:80;server 10.0.0.8:80;server 10.0.0.9:80;}说明:upstream模块就类似定一个一个地址池或者说定一个web服务器组官方链接:/en/docs/http/ngx_http_proxy_module.html#proxy_passSyntax: proxy_pass URL;Default: —Context: location, if in location, limit_excepteg:location / {proxy_pass http://oldboy;}说明:proxy_pass主要用于进行抛送用户访问请求给upstream模块中的相应节点服务器worker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;upstream oldboy {server 10.0.0.7:80;server 10.0.0.8:80;server 10.0.0.9:80;}server {listen 80;server_name localhost;root html;index index.html index.htm;location / {proxy_pass http://oldboy;} }}/application/nginx/sbin/nginx -t/application/nginx/sbin/nginx -s reload第三个里程:进行访问负载均衡服务器测试1)利用浏览器进行测试进行hosts解析/oldboy.html <--利用ctrl+F5刷新测试,检查是否进行负载调度2)利用curl命令进行测试[root@lb01 conf]# curl -H host: 10.0.0.5/oldboy.htmlweb01 [root@lb01 conf]# curl -H host: 10.0.0.5/oldboy.htmlweb02 [root@lb01 conf]# curl -H host: 10.0.0.5/oldboy.htmlweb03

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。