标签:nload 检查 time 测试 相同 add http except 链接
客户端====代理服务器===web服务器反向代理功能架构
3台web服务器,组建出web服务器集群
web01 10.0.0.7 172.16.1.7
web02 10.0.0.8 172.16.1.8
web03 10.0.0.9 172.16.1.9
1台负载均衡服务器
lb01 10.0.0.5 172.16.1.5
①. 部署web服务器
第一个里程:安装部署nginx软件 注:另外两台web服务器也要部署相同的nginx服务
mkdir /server/tools -p
cd /server/tools
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xf nginx-1.12.2.tar.gz
yum install -y pcre-devel openssl-devel
useradd -M -s /sbin/nologin www
cd nginx-1.12.2
./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
make && make install
ln -s /application/nginx-1.12.2 /application/nginx
/application/nginx/sbin/nginx
netstat -lntup|grep nginx
第二个里程:编辑nginx配置文件
server {
listen 80;
server_name www.etiantian.org;
root html/www;
index index.html index.htm;
}
server {
listen 80;
server_name bbs.etiantian.org;
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} -p
for name in www bbs;do echo "$(hostname) $name.etiantian.org" >/application/nginx/html/$name/oldboy.html;done
for name in www bbs;do cat /application/nginx/html/$name/oldboy.html;done
第四里程:在负载均衡服务器上,进行测试访问
curl -H host:www.etiantian.org 10.0.0.7/oldboy.html
web01 www.etiantian.org
curl -H host:bbs.etiantian.org 10.0.0.7/oldboy.html
web01 bbs.etiantian.org
curl -H host:www.etiantian.org 10.0.0.8/oldboy.html
web02 www.etiantian.org
curl -H host:bbs.etiantian.org 10.0.0.8/oldboy.html
web02 bbs.etiantian.org
curl -H host:www.etiantian.org 10.0.0.9/oldboy.html
web03 www.etiantian.org
curl -H host:bbs.etiantian.org 10.0.0.9/oldboy.html
web03 bbs.etiantian.org
②. 部署负载均衡服务器
第一个里程:安装部署nginx软件
mkdir /server/tools -p
cd /server/tools
wget http://nginx.org/download/nginx-1.12.2.tar.gz
tar xf nginx-1.12.2.tar.gz
yum install -y pcre-devel openssl-devel
useradd -M -s /sbin/nologin www
cd nginx-1.12.2
./configure --prefix=/application/nginx-1.12.2 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module
make && make install
ln -s /application/nginx-1.12.2 /application/nginx
/application/nginx/sbin/nginx
netstat -lntup|grep nginx
第二个里程:编写nginx反向代理配置文件
grep -Ev "#|^$" nginx.conf.default >nginx.conf
官方链接:http://nginx.org/en/docs/http/ngx_http_upstream_module.html#upstream
Syntax: upstream name { ... }
Default: —
Context: http
eg:
upstream oldboy {
server 10.0.0.7:80;
server 10.0.0.8:80;
server 10.0.0.9:80;
}
说明:upstream模块就类似定一个一个地址池或者说定一个web服务器组
官方链接:http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_pass
Syntax: proxy_pass URL;
Default: —
Context: location, if in location, limit_except
eg:
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解析
http://www.etiantian.org/oldboy.html <--利用ctrl+F5刷新测试,检查是否进行负载调度
2)利用curl命令进行测试
[root@lb01 conf]# curl -H host:www.etiantian.org 10.0.0.5/oldboy.html
web01 www.etiantian.org
[root@lb01 conf]# curl -H host:www.etiantian.org 10.0.0.5/oldboy.html
web02 www.etiantian.org
[root@lb01 conf]# curl -H host:www.etiantian.org 10.0.0.5/oldboy.html
web03 www.etiantian.org
标签:nload 检查 time 测试 相同 add http except 链接
原文地址:http://blog.51cto.com/tangyong/2136102