RHEL 6.5----Nginx负载均衡
实验环境
主机名 | 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负载均衡的更多相关文章
- 对比Haproxy和Nginx负载均衡效果
为了对比Hproxy和Nginx负载均衡的效果,分别在测试机上(以下实验都是在单机上测试的,即负载机器和后端机器都在一台机器上)做了这两个负载均衡环境,并各自抓包分析.下面说下这两种负载均衡环境下抓包 ...
- nginx负载均衡集群
nginx负载均衡集群 0.前言:nginx 负载均衡,属于网络7层模型中的应用层,说白了就是一个代理,要用 upstrem 模块实现,代理则用proxy模块 1.可以针对域名做转发,lvs只能针对 ...
- 手把手教你玩转nginx负载均衡(二)----安装虚拟机操作系统
引言 在上一篇,我们组装好了虚拟机的硬件部分,那么现在我们就要把操作系统装上了,既然是服务器,那么安装linux操作系统是个比较好的选择,如果你喜欢的话,安装windows也是没有任何问题的 我这里选 ...
- nginx负载均衡基于ip_hash的session粘帖
nginx负载均衡基于ip_hash的session粘帖 nginx可以根据客户端IP进行负载均衡,在upstream里设置ip_hash,就可以针对同一个C类地址段中的客户端选择同一个后端服务器,除 ...
- Net分布式系统之二:CentOS系统搭建Nginx负载均衡
一.关于CentOS系统介绍 CentOS(Community Enterprise Operating System,中文意思是:社区企业操作系统)是Linux发行版之一,它是来自于Red Hat ...
- Net分布式系统之三:Keepalived+LVS+Nginx负载均衡之高可用
上一篇写了nginx负载均衡,此篇实现高可用(HA).系统整体设计是采用Nginx做负载均衡,若出现Nginx单机故障,则导致整个系统无法正常运行.针对系统架构设计的高可用要求,我们需要解决Nginx ...
- 配置nginx负载均衡
配置nginx负载均衡 执行命令:vi /usr/local/nginx/sbin/nginx/conf/nginx.conf 修改为: worker_processes 2; events { ...
- 烂泥:nginx负载均衡
本文由秀依林枫提供友情赞助,首发于烂泥行天下. 今天我们来学习下有关nginx的负载均衡配置.nginx的负载均衡是通过nginx的upstream模块和proxy_pass反向代理来实现的. 说明: ...
- nginx负载均衡集群中的session共享说明
在网站使用nginx+php做负载均衡情况下,同一个IP访问同一个页面会被分配到不同的服务器上,如果session不同步的话,就会出现很多问题,比如说最常见的登录状态. 下面罗列几种nginx负载均衡 ...
- nginx 负载均衡策略
nginx 负载均衡策略 1. 轮询轮询方式是nginx负载均衡的默认策略,根据每个server的权重值来轮流发送请求,例如:upstream backend {server backend1.e ...
随机推荐
- 登录日志的访问日志的 统计 MapReduce
登录日志的访问日志的 统计 MapReduce <!-- https://mvnrepository.com/artifact/org.apache.hadoop/hadoop-commo ...
- pyspark mongodb yarn
from pyspark.sql import SparkSession my_spark = SparkSession \ .builder \ .appName("myApp" ...
- acd - 1427 - Nice Sequence(线段树)
题意:一个由n个数组成的序列(序列元素的范围是[0, n]).求最长前缀 j .使得在这个前缀 j 中对于随意的数 i1 < i2.都满足随意的 m <= j.i1 在前 m 个数里出现的 ...
- 【转】idea激活搭建授权服务器
1.下载软件:磁力链接: magnet:?xt=urn:btih:2289E4F8CEB346AC44E54C8C0DA706CC537301AA 复制磁力链接地址 magnet:?xt=urn:bt ...
- jsp项目上传到服务器
我们通过Myeclipse完成一个Java web项目时只能通过本地访问来查看,但是我们想把它上传到服务器上使用外网访问应该怎么做呢,首先肯定是要有一台服务器 个人调试项目试手的话我建议去买阿里云的云 ...
- Viewpager animation duration setting
private void animatePagerTransition(final boolean forward) { ValueAnimator animator = ValueAnimator. ...
- 从OutStreamWriter 和Filewriter谈Java编码
首先看JAVA API的描述: ABOUT OutputStreamWriter: "An OutputStreamWriter is a bridge from character str ...
- unity3d 公告板
Unity 自带具有一个平面的原始对象,但一个简单的平面在2D游戏或GUI可能是有用的,在任何情况下作出一个好的开始例子.一个最小的平面包含四个顶点,界定两个三角形的边角. 第一件事就是设置顶点数组. ...
- Java递归应用:输出树形菜单
转自:https://blog.csdn.net/zhangzeyuaaa/article/details/24574769
- 模态对话框 DoModal的用法 (vs2008)与非模态对话框
Windows对话框分为两类:模态对话框和非模态对话框. 模态对话框,当它弹出后,本应用程序其他窗口将不再接受用户输入,只有该对话框响应用户输入,在对它进行相应操作退出后,其他窗口才能继续与用户交互. ...