实验环境

主机名 IP
master 192.168.30.130
node-1 192.168.30.131
node-2 192.168.30.132

在master上安装

本次安装过程统一采用YUM的方式,比较快,也省的出各种问题
首先在本地yum源里面添加
[root@master ~]# vim /etc/yum.repos.d/rhel-source.repo
[rhel-source]
name=Red Hat Enterprise Linux $releasever - $basearch - Source
baseurl=file:///media/cdrom
enabled=
gpgcheck=
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release [nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/6/$basearch/
gpgcheck=
enabled=
或者直接新建个nginx.repo文件在文件中写入
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/6/$basearch/
gpgcheck=
enabled=
完事之后,执行下面命令
[root@master ~]# yum install -y zlib zlib-devel openssl openssl-devel pcre pcre-devel nginx

如果是源码编译安装的,可能没有nginx用户需要手动添加,但是这里yum安装的,就不需要添加了

[root@master ~]# id nginx
uid=(nginx) gid=(nginx) groups=(nginx)

启动nginx

[root@master ~]# /etc/init.d/nginx start
Starting nginx: [ OK ]
[root@master ~]# /etc/init.d/nginx status
-b (pid ) is running...

测试nginx

配置分发器实现动静分离

[root@master ~]# cp /etc/nginx/conf.d/default.conf{,.bak}
[root@master ~]# cd /etc/nginx/
[root@master nginx]# ls
conf.d koi-utf mime.types nginx.conf uwsgi_params
fastcgi_params koi-win modules scgi_params win-utf
[root@master nginx]# cp nginx.conf{,.bak}
[root@master nginx]# vim nginx.conf #末尾添加
upstream htmlservers {
server 192.168.30.131:;
server 192.168.30.132:;
}
upstream phpservers {
server 192.168.30.131:;
server 192.168.30.132:;
}
upstream picservers {
server 192.168.30.131:;
server 192.168.30.132:;
}
}
"nginx.conf" 44L, 902C written
[root@master conf.d]# vim default.conf
server {
listen ;
server_name localhost; #charset koi8-r;
#access_log /var/log/nginx/host.access.log main; location / {
root /usr/share/nginx/html;
index index.html index.htm;
if ($request_uri ~* \.html$) {
proxy_pass http://htmlservers;
}
if ($request_uri ~* \.php) {
proxy_pass http://phpservers;
}
proxy_pass http://picservers;
}

测试配置文件是否配置正确

[root@master ~]# /etc/init.d/nginx configtest
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

在node-1上

[root@node- ~]# yum install -y php httpd
[root@node- ~]# echo "<h1>Static-Web-Server:192.168.30.131</h1>" > /var/www/html/index.html
[root@node- ~]# echo "<h1>Web-Server:192.168.30.131</h1><?php phpinfo(); ?>" > /var/www/html/index.php
[root@node- ~]# rz
[root@node- ~]# mv .jpg /var/www/html/
[root@node- ~]# service httpd restart
Stopping httpd: [ OK ]
Starting httpd: [ OK ]
[root@node- ~]# ls /var/www/html/
.jpg index.html index.php

node-2做相同操作,只是将测试页面的内容改下

[root@node- ~]# echo "<h1>Web-Server:192.168.30.132</h1>" > /var/www/html/index.html
[root@node- ~]# echo "<h1>Web-Server:192.168.30.132</h1><?php phpinfo(); ?>" > /var/www/html/index.php
[root@node- ~]# rz
[root@node- ~]# mv .jpg /var/www/html/
[root@node- ~]# ls /var/www/html/
.jpg index.html index.php
[root@node- ~]# service httpd restart

测试

[root@master ~]# /etc/init.d/nginx reload
Reloading nginx: [ OK ]

首先直接测试web-server,看是否正常

然后测试分发器

刷新之后

按F5刷新

压力测试

[root@node- ~]# ab -c  -n  http://192.168.30.130/index.html
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.30.130 (be patient)
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Completed requests
Finished requests Server Software: nginx/1.14.
Server Hostname: 192.168.30.130
Server Port: Document Path: /index.html
Document Length: bytes Concurrency Level:
Time taken for tests: 1.020 seconds
Complete requests:
Failed requests:
(Connect: , Receive: , Length: , Exceptions: )
Write errors:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 980.42 [#/sec] (mean)
Time per request: 1019.966 [ms] (mean)
Time per request: 1.020 [ms] (mean, across all concurrent requests)
Transfer rate: 282.93 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 32.1
Processing: 73.1
Waiting: 73.1
Total: 80.8 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request)
[root@node- ~]# ab -c  -n  -q http://192.168.30.130/index.html
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.30.130 (be patient)...socket: Too many open files ()
解决办法
[root@node- ~]# ulimit -a
core file size (blocks, -c)
data seg size (kbytes, -d) unlimited
scheduling priority (-e)
file size (blocks, -f) unlimited
pending signals (-i)
max locked memory (kbytes, -l)
max memory size (kbytes, -m) unlimited
open files (-n)
pipe size ( bytes, -p)
POSIX message queues (bytes, -q)
real-time priority (-r)
stack size (kbytes, -s)
cpu time (seconds, -t) unlimited
max user processes (-u)
virtual memory (kbytes, -v) unlimited
file locks (-x) unlimited
[root@node- ~]# ulimit -n #系统默认值 [root@node- ~]# ulimit -n
[root@node- ~]# ulimit -n [root@node- ~]# ab -c -n -q http://192.168.30.131/index.html
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.30.131 (be patient).....done Server Software: Apache/2.2.
Server Hostname: 192.168.30.131
Server Port: Document Path: /index.html
Document Length: bytes Concurrency Level:
Time taken for tests: 1.274 seconds
Complete requests:
Failed requests:
Write errors:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 1570.26 [#/sec] (mean)
Time per request: 1273.678 [ms] (mean)
Time per request: 0.637 [ms] (mean, across all concurrent requests)
Transfer rate: 475.61 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 329.6
Processing: 228.9
Waiting: 228.9
Total: 386.9 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request)
[root@node- ~]# ab -c -n -q http://192.168.30.130/index.html
This is ApacheBench, Version 2.3 <$Revision: $>
Copyright Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/ Benchmarking 192.168.30.130 (be patient).....done Server Software: nginx/1.14.
Server Hostname: 192.168.30.130
Server Port: Document Path: /index.html
Document Length: bytes Concurrency Level:
Time taken for tests: 1.081 seconds
Complete requests:
Failed requests:
(Connect: , Receive: , Length: , Exceptions: )
Write errors:
Non-2xx responses:
Total transferred: bytes
HTML transferred: bytes
Requests per second: 1849.81 [#/sec] (mean)
Time per request: 1081.193 [ms] (mean)
Time per request: 0.541 [ms] (mean, across all concurrent requests)
Transfer rate: 558.97 [Kbytes/sec] received Connection Times (ms)
min mean[+/-sd] median max
Connect: 327.6
Processing: 212.8
Waiting: 212.8
Total: 351.5 Percentage of the requests served within a certain time (ms)
%
%
%
%
%
%
%
%
% (longest request)

RHEL 6.5----Nginx负载均衡的更多相关文章

  1. 对比Haproxy和Nginx负载均衡效果

    为了对比Hproxy和Nginx负载均衡的效果,分别在测试机上(以下实验都是在单机上测试的,即负载机器和后端机器都在一台机器上)做了这两个负载均衡环境,并各自抓包分析.下面说下这两种负载均衡环境下抓包 ...

  2. nginx负载均衡集群

    nginx负载均衡集群  0.前言:nginx 负载均衡,属于网络7层模型中的应用层,说白了就是一个代理,要用 upstrem 模块实现,代理则用proxy模块 1.可以针对域名做转发,lvs只能针对 ...

  3. 手把手教你玩转nginx负载均衡(二)----安装虚拟机操作系统

    引言 在上一篇,我们组装好了虚拟机的硬件部分,那么现在我们就要把操作系统装上了,既然是服务器,那么安装linux操作系统是个比较好的选择,如果你喜欢的话,安装windows也是没有任何问题的 我这里选 ...

  4. nginx负载均衡基于ip_hash的session粘帖

    nginx负载均衡基于ip_hash的session粘帖 nginx可以根据客户端IP进行负载均衡,在upstream里设置ip_hash,就可以针对同一个C类地址段中的客户端选择同一个后端服务器,除 ...

  5. Net分布式系统之二:CentOS系统搭建Nginx负载均衡

    一.关于CentOS系统介绍 CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统)是Linux发行版之一,它是来自于Red Hat ...

  6. Net分布式系统之三:Keepalived+LVS+Nginx负载均衡之高可用

    上一篇写了nginx负载均衡,此篇实现高可用(HA).系统整体设计是采用Nginx做负载均衡,若出现Nginx单机故障,则导致整个系统无法正常运行.针对系统架构设计的高可用要求,我们需要解决Nginx ...

  7. 配置nginx负载均衡

    配置nginx负载均衡 执行命令:vi /usr/local/nginx/sbin/nginx/conf/nginx.conf 修改为: worker_processes  2; events {   ...

  8. 烂泥:nginx负载均衡

    本文由秀依林枫提供友情赞助,首发于烂泥行天下. 今天我们来学习下有关nginx的负载均衡配置.nginx的负载均衡是通过nginx的upstream模块和proxy_pass反向代理来实现的. 说明: ...

  9. nginx负载均衡集群中的session共享说明

    在网站使用nginx+php做负载均衡情况下,同一个IP访问同一个页面会被分配到不同的服务器上,如果session不同步的话,就会出现很多问题,比如说最常见的登录状态. 下面罗列几种nginx负载均衡 ...

  10. nginx 负载均衡策略

    nginx 负载均衡策略   1. 轮询轮询方式是nginx负载均衡的默认策略,根据每个server的权重值来轮流发送请求,例如:upstream backend {server backend1.e ...

随机推荐

  1. ERROR 1366 (HY000): Incorrect string value: '\xD6\xD0\xCE\xC4' for column XXX at row 1

    本错误为:该列的插入格式有误 修改该表中该列的字符集为utf-8 网上办法: )不能插入中文解决办法: 向表中插入中文然后有错误. mysql> insert into users values ...

  2. jvm 调优(1)概念

    数据类型 Java虚拟机中,数据类型可以分为两类:基本类型和引用类型.基本类型的变量保存原始值,即:他代表的值就是数值本身:而引用类型的变量保存引用值.“引用值”代表了某个对象的引用,而不是对象本身, ...

  3. console调试命令

    一.显示信息的命令 <!DOCTYPE html> <html> <head> <title>常用console命令</title> < ...

  4. 获取Android系统应用信息

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  5. 利用WebViewJavascriptBridge与UIWebView进行交互

    事情的起因还是因为项目需求驱动.折腾了两天,由于之前没有UIWebView与JS交互的经历,并且觉得这次在功能上有一定的创造性,特此留下一点文字,方便日后回顾. 我要实现这样一个需求:按照本地的CSS ...

  6. uCOS-II模拟(VS2010&WIN32)

    转自http://www.amobbs.com/thread-5462878-1-1.html 自学uCOS-II源码,在论坛上上看到大神在WIN7 Visual Studio 2010环境下调试uC ...

  7. HDU3045 Picnic Cows —— 斜率优化DP

    题目链接:https://vjudge.net/problem/HDU-3045 Picnic Cows Time Limit: 8000/4000 MS (Java/Others)    Memor ...

  8. 织梦CMS如何在首页调用指定的文章 idlist

    在网站首页调用站内新闻是必不可少的,但是有的时候不能根据自己的需要来调用指定的文章,想要调用自己指定的文章还要做一些修改. 在网站中调用指定文章可以使用织梦默认的标签idlist,在调用的时候使用以下 ...

  9. MYSQL进阶学习笔记四:MySQL存储过程之定义条件,处理过程及存储过程的管理!(视频序号:进阶_11,12)

    知识点五:MySQL存储过程之定义条件和处理过程及存储过程的管理(11,12) 定义条件和处理: 条件的定义和处理可以用来定义在处理过程中遇到的问题时相应的处理步骤. DECLARE CONTINUE ...

  10. 皮尔逊相关系数的java实现

    相关系数的值介于–1与+1之间,即–1≤r≤+1.其性质如下:当r>0时,表示两变量正相关,r<0时,两变量为负相关.当|r|=1时,表示两变量为完全线性相关,即为函数关系.当r=0时,表 ...