博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
nginx负载均衡应用实例
阅读量:7040 次
发布时间:2019-06-28

本文共 3927 字,大约阅读时间需要 13 分钟。

实验环境1

1测试硬件准备
三台虚拟机,两台做负载均衡一台做RS

nginx负载均衡应用实例

2测试软件准备
系统:Red Hat6.4 x86_64
软件:nginx-1.8.1.tar.gz
3安装之前需要先安装相关基础环境包(有些系统里面已经有了)
yum install openssl
yum install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel -y
yum install libxml2 libxml2-devel zlib zlib-devel ncurses ncurses-devel curl curl-devel -y
yum install gd gd2 gd-level gd2-devel -y
4 安装pcre软件包
wget --no-check-certificate
tar -zxf pcre-8.32.tar.gz
./configure
编译配置报错
问题描述:
checking for dirent.h... yes
checking windows.h usability... no
checking windows.h presence... no
checking for windows.h... no
configure: error: You need a C++ compiler for C++ support.
解决方法:系统包缺少C++编译器 需要安装gcc-c++的包
然后 yum 安装下就可以了
make
make install
cd ../ 到上级目录
====================pcre安装完成===============================
5 安装nginx
wget
tar -zxvf nginx-1.8.1.tar.gz
cd nginx-1.8.1
./configure --user=nginx --group=nginx --prefix=/application/nginx-1.8.1 --with-http_stub_status_module --with-http_ssl_module
说明:--user=nginx 指定用户
--group=nginx 指定组
--prefix=/application/nginx-1.8.1 指定安装路径
--with-http_stub_status_module 状态模块
--with-http_ssl_module ssl模块
useradd nginx -s /sbin/nologin -M 需要把用户创建起来 -M 不创建家目录 -s 指定非登录式 shell
make
make install
=========nginx安装完成==========================================
6 安装完后的配置
ln -s /application/nginx-1.8.1 /application/nginx
echo "/usr/local/lib" >>/etc/ld.so.conf
tail -1 /etc/ld.so.conf``
ldconfig
/application/nginx/sbin/nginx
[root@lb01 application]# ps -ef | grep nginx | grep -v grep
root 17057 1 0 16:18 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
nginx 17058 17057 0 16:18 ? 00:00:00 nginx: worker process
[root@lb01 application]# lsof -i tcp:80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
nginx 17057 root 6u IPv4 82990 0t0 TCP
:http (LISTEN)
nginx 17058 nginx 6u IPv4 82990 0t0 TCP *:http (LISTEN)
7 配置调试用于测试的web服务器
注意:操作只在以下nginx web 服务器节点操作:
nginx负载均衡应用实例
配置并查看web服务配置结果
两台RS1全部按照上面的步骤nginx服务。
然后执行如下命令:
RS1(192.168.232.132)
echo "www.etiantian132.org">/application/nginx/html/index.html
cat /application/nginx/html/index.html
/application/nginx/sbin/nginx -s reload
RS2(192.168.232.133)
echo "www.etiantian133.org">/application/nginx/html/index.html
cat /application/nginx/html/index.html
/application/nginx/sbin/nginx -s reload
然后各自在本机curl下自己看下显示效果
nginx负载均衡应用实例
修改主配置文件实现负载均衡
cd /application/nginx/conf
mkdir extra 创建extra目录
cd extra/
vim ../nginx.conf

#user  nobody;worker_processes  1;#error_log  logs/error.log;#error_log  logs/error.log  notice;#error_log  logs/error.log  info;#pid        logs/nginx.pid;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    include extra/upstream01.conf;}####################################### 删除我们不需要的 添加这行内容include extra/upstream01.conf;然后我们需要在extra目录下面创建upstream01.conf 并编辑它vim extra/upstream01.conf#blog lb by cyt at 20180107upstream blog_real_server {        server 192.168.232.132:80 weight=5;    #upstream 定义一个vserver的名字                                                 blog_real_server        server 192.168.232.133:80 weight=5;}        server {                listen   80;                server_name blog.etiantian.org;                location / {                proxy_pass http://blog_real_server;   # 通过proxy_pass 定义如果访问                                                 blog.etiantian.org 自动转到                                                     blog_real_server 下面定义的两台                                                    realserver上面去        }}

检查语法

然后保存退出后

[root@lb01 conf]# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.1/conf/nginx.conf test is successful
还需要本机上面做一个本地域名解析操作 将本机的ip 解析为blog.etiantian.org

nginx负载均衡应用实例

重启三台机器上面的nginx

/application/nginx/sbin/nginx -s reload
然后使用curl 命令测试
nginx负载均衡应用实例

可以看到多次执行 会平均分配到两台机器上面去,从而是实现负载均衡。

转载于:https://blog.51cto.com/11569838/2058183

你可能感兴趣的文章
开启远程控制
查看>>
Mysql 5.6.18解压包版在Rhel6.7上安装
查看>>
Redis参数汇总
查看>>
Objective-C底层数据结构
查看>>
TPYBoard开发板搭建WHID通道实现隐秘通信
查看>>
未来程序员都会丢了饭碗么?
查看>>
Flink内部计算之EventTime WaterMark-调研最终版(终结篇)---思考
查看>>
源码编译安装PHP7
查看>>
Windows7首次使用XenApp初始化操作手册
查看>>
ubuntu15.04安装vm11
查看>>
设计模式——状态模式(State Pattern)
查看>>
Linux下的tar命令
查看>>
cisco路由器综合实验之二 访问控制列表的应用(ACL)
查看>>
Android中146种颜色对应的xml色值
查看>>
dokcer基础命令-详解
查看>>
rust语言初体验
查看>>
Android呈现的图片大小和图片分辨率不符的原因
查看>>
表单验证js代码
查看>>
redis集群搭建
查看>>
MongoDB分片搭建
查看>>