Nginx教程负载均衡机制
安装上传下载插件
[root@localhost ~]# yum install -y lrzsz
设置主机名
关闭防火墙
[root@localhost ~]# hostnamectl set-hostname nod-01
[root@localhost ~]# systemctl stop firewalld
安装Nginx
上传文件到root的家目录下
[root@nod-01 ~]# pwd
/root
[root@nod-01 ~]# ll
total 964
-rw-------. 1 root root 1410 Jul 7 22:46 anaconda-ks.cfg
-rw-r--r--. 1 root root 981687 Jul 11 00:46 nginx-1.12.2.tar.gz
安装Nginx依赖
yum -y install gcc gcc-c++ autoconf automake
[root@nod-01 ~]# yum -y install gcc gcc-c++ autoconf automake
[root@nod-01 ~]# yum -y install zlib zlib-devel openssl openssl-devel pcre pcre-devel
查看CPU核数
[root@nod-01 ~]# cat /proc/cpuinfo | grep processor | wc -l
安装模块
/root/nginx-1.12.2/configure --prefix=/usr/local/nginx --with-http_dav_module --with-http_stub_status_module --with-http_addition_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module
查看硬件核数
cat /proc/cpuinfo | grep processor | wc -l
安装(xxx是查出来的硬件核数)
make -j XXX make install
增加用户
useradd -u 8000 -s /sbin/nologin nginx
查询增加的用户的信息
id nginx
开启Nginx服务
/usr/local/nginx/sbin/nginx 开启服务/usr/local/nginx/sbin/nginx -t 测试配置文件是否正确的命令/usr/local/nginx/sbin/nginx -s reload 重载Nginx服务/usr/local/nginx/sbin/nginx -s stop 停止服务
将Nginx的服务加入到开机启动服务中
echo '/usr/local/nginx/sbin/nginx &' >> /etc/rc.local
在centos7中安装netstat命令
yum -y install net-tools
查看nginx启动后的端口情况
netstat -anput
修改配置文件,配置文件中内容
user nginx nginx; 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;#log_format main '$remote_addr - $remote_user [$time_local] "$request" '# '$status $body_bytes_sent "$http_referer" '# '"$http_user_agent" "$http_x_forwarded_for"';#access_log logs/access.log main;sendfile on;#tcp_nopush on;#keepalive_timeout 0;keepalive_timeout 65;#gzip on;server {listen 80;server_name localhost;#charset koi8-r;#access_log logs/host.access.log main;location / {root 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; }#error_page 404 /404.html;# redirect server error pages to the static page /50x.html#error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}# proxy the PHP scripts to Apache listening on 127.0.0.1:80##location ~ \.php$ {# proxy_pass http://127.0.0.1; #}# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000##location ~ \.php$ {# root html;# fastcgi_pass 127.0.0.1:9000;# fastcgi_index index.php;# fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;# include fastcgi_params;#}# deny access to .htaccess files, if Apache's document root# concurs with nginx's one ##location ~ /\.ht {# deny all;#}}# another virtual host using mix of IP-, name-, and port-based configuration##server {# listen 8000;# listen somename:8080;# server_name somename alias another.alias;# location / {# root html;# index index.html index.htm;# }#}# HTTPS server##server {# listen 443 ssl;# server_name localhost;# ssl_certificate cert.pem;# ssl_certificate_key cert.key;# ssl_session_cache shared:SSL:1m;# ssl_session_timeout 5m;# ssl_ciphers HIGH:!aNULL:!MD5;# ssl_prefer_server_ciphers on;# location / {# root html;# index index.html index.htm;# }#}upstream htmlservers{server 192.168.3.129:80;server 192.168.3.130:80;}upstream phpservers{server 192.168.3.129:80;server 192.168.3.130:80;}upstream picservers{server 192.168.3.129:80;server 192.168.3.130:80;}}
nginx.conf
修改配置文件之后查看配置文件配置是否正确
/usr/local/nginx/sbin/nginx -t
重启Nginx
/usr/local/nginx/sbin/nginx -s reload
在页面访问Nginx可以正常访问,Nginx安装结束
安装两台Apache服务器做测试
安装后Apache
yum install httpd php -y
安装成功后再 /var/www/html/ 目录下新建三个文件
转载于:https://www.cnblogs.com/cerofang/p/11169786.html
Nginx教程负载均衡机制相关推荐
- windows配置nginx实现负载均衡集群
windows配置nginx实现负载均衡集群 2014-08-20 09:44:40 来源:www.abcde.cn 评论:0 点击:617 网上大部分关于nginx负载均衡集群的教程都是li ...
- Nginx之负载均衡(四)
在上一篇博客我们介绍了 Nginx 一个很重要的功能--代理,包括正向代理和反向代理.这两个代理的核心区别是:正向代理代理的是客户端,而反向代理代理的是服务器.其中我们又重点介绍了反向代理,以及如何通 ...
- 用NGINX做负载均衡,keepalived高可用
实验环境,四台虚拟机,两台做负载均衡,两台做RS IP地址:两台负载均衡分别为:10.0.0.7:10.0.0.8(高可用keepalived) 两台 RS主机地址为: 10.0.0.9:10.0.0 ...
- 算法高级(14)-Nginx的负载均衡策略
一.nginx初体验 Nginx是一个http服务器.是一个使用c语言开发的高性能的http 服务器/反向代理服务器及电子邮件(IMAP/POP3)代理服务器.nginx能够支撑5万并发链接,并且cp ...
- nginx配置 负载均衡_如何配置NGINX负载平衡
nginx配置 负载均衡 The load balancing is the process of distributing traffic to multiple instances of an a ...
- Nginx+Tomcat负载均衡、动静分离
目录 一:Nginx实现负载均衡原理 二:Nginx动静分离原理 三:Nginx+Tomcat负载均衡.动静分离实验 3.1部署Nginx负载均衡器 3.1.1关闭防火墙,将安装nginx所需的软件包 ...
- Nginx做负载均衡的模块
负载均衡模块 使用nginx做负载均衡的两大模块: upstream 定义负载节点池 ocation 模块 进行URL匹配. proxy模块 发送请求给upstream定义的节点池 upstream模 ...
- 使用nginx做负载均衡
使用nginx做负载均衡的两大模块: upstream 定义负载节点池. location 模块 进行URL匹配. proxy模块 发送请求给upstream定义的节点池. upstream模块解读 ...
- Nginx 实战-负载均衡
一.负载均衡 今天学习一下Nginx的负载均衡.由于传统软件建构的局限性,加上一台服务器处理能里的有限性,在如今高并发.业务复杂的场景下很难达到咱们的要求.但是若将很多台这样的服务器通过某种方式组成一 ...
最新文章
- CentOS Firewall防火墙设置规则
- http 缓存分为客户端缓存和服务端缓存
- 158. Leetcode 121. 买卖股票的最佳时机 (贪心算法-股票题目)
- 重磅发布 | 2021 年 OpenAtom XuperChain 开源技术路径
- 给 OpenPOP.Net 加一个小功能,可用于收取邮件时监测数据流量!
- ajax 12301 原因小结
- 有了防火墙、IPS、WAF 还需要数据库审计?
- python脚本编程手册_Python 入门指南 — Python2.7 手册 2.7 documentation - 脚本之家在线手册...
- javascript实例自学手册光盘源码_零基础,自学编程,如何选择语言?
- Spring boot 学习二:入门
- EXPLAIN mysql性能调优
- idea license 20200104
- 【笔记】生成函数与大背包问题
- python模块_python模块介绍
- html5 调用unity,Unity调用UniWebView打开H5界面脚本
- XShell「6.0.0111」已激活授权绿色版v2
- 中国雅虎邮箱将寿终正寝 8月19日停止服务
- html点击登陆、注册等时候出现等待图标代码
- java快速开发项目_GitHub - Johnnyzhoutq/X-SpringBoot: X-SpringBoot是一个轻量级的Java快速开发平台,能快速开发项目并交付【接私活利器】...
- 《码农翻身》读书笔记