标题:
CentOS6_Nginx反向代理+负载均衡(轮询)
[打印本页]
作者:
admin
时间:
2019-9-8 13:59
标题:
CentOS6_Nginx反向代理+负载均衡(轮询)
Nginx服务器的信息: [root@localhost ~]# cat /etc/redhat-release
CentOS release 6.9 (Final)
[root@localhost ~]# [root@localhost ~]# uname -r 2.6.32-696.el6.x86_64 [root@localhost ~]# ifconfig eth0 |grep "inet addr" |awk '{print $2}' |awk -F: '{print $2}'
192.168.168.130
下载nginx-1.10.0.tar.gz:
https://pan.baidu.com/s/1K2yEskROiqYBNGZJ3DViGA
安装Nginx: yum -y install pcre-devel openssl-devel zlib-devel gcc-c++ make elinks lsof useradd -M -s /sbin/nologin nginx tar -zxvf nginx-1.10.0.tar.gz cd nginx-1.10.0 ./configure --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module && make && make install ln -sf /usr/local/nginx/sbin/nginx /usr/sbin/ ### 开机自动运行Nginx: [root@localhost ~]# vi /etc/init.d/nginx #!/bin/bash #chkconfig: 35 99 20 #description:Nginx Service Control Script case "$1" in start) /usr/local/nginx/sbin/nginx ;; stop) /usr/bin/killall -s QUIT nginx ;; restart) $0 stop $0 start ;; *) echo "Usage:$0 {start|stop|restart}" exit 1 esac exit 0 [root@localhost ~]# chmod a+x /etc/init.d/nginx [root@localhost ~]# chkconfig --add nginx 启动Nginx: [root@localhost ~]# service nginx start 查看Nginx的进程: [root@localhost ~]# ps -ef |grep
nginx
|grep -v grep
root 4629 1 0 04:52 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx nginx 4630 4629 0 04:52 ? 00:00:00 nginx: worker process
开机自动启动Nginx: [root@localhost ~]# chkconfig --level 35 nginx on [root@localhost ~]# chkconfig --list nginx nginx 0:关闭 1:关闭 2:关闭
3:启用
4:关闭
5:启用
6:关闭 查看Nginx的版本: [root@localhost ~]# nginx -v nginx version: nginx/
1.10.0
[root@localhost ~]# nginx -V nginx version: nginx/
1.10.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC) built with OpenSSL 1.0.1e-fips 11 Feb 2013 TLS SNI support enabled configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_stub_status_module --with-http_ssl_module 服务器本地测试Nginx: [root@localhost ~]#
elinks
127.0.0.1
下载
(33.77 KB)
2021-3-3 17:20
[root@localhost ~]# lsof -nP -iTCP:
80
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME nginx 4629 root 6u IPv4 21216 0t0 TCP *:80 (LISTEN) nginx 4630 nginx 6u IPv4 21216 0t0 TCP *:80 (LISTEN)
关闭Nginx: [root@localhost ~]# service nginx stop [root@localhost ~]# lsof -nP -iTCP:
80
[root@localhost ~]# 重启Nginx: [root@localhost ~]# service nginx restart 防火墙配置:(打开TCP 80端口) [root@localhost ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT [root@localhost ~]# iptables-save > /etc/sysconfig/iptables [root@localhost ~]# cat /etc/sysconfig/iptables # Generated by iptables-save v1.4.7 on Thu Jul 5 05:29:18 2018 *filter :INPUT ACCEPT [0:0] :FORWARD ACCEPT [0:0] :OUTPUT ACCEPT [2:232]
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT -A INPUT -p icmp -j ACCEPT -A INPUT -i lo -j ACCEPT -A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT -A INPUT -j REJECT --reject-with icmp-host-prohibited -A FORWARD -j REJECT --reject-with icmp-host-prohibited COMMIT # Completed on Thu Jul 5 05:29:18 2018 客户端远程测试:(理应可以看到Nginx的测试页) http://192.168.168.130/
下载
(45.78 KB)
2021-3-3 17:22
############ Nginx反向代理 先准备好一台Web服务器(192.168.168.135): 默认首页的内容: [root@oracle-linux6 ~]# echo 'Welcome to zhuohua' > /var/www/html/index.html 备注: 如果有多个基于域名的虚拟主机(网站)时,只会出现一个虚拟主机的文件内容; 这台Web服务器不需要为代理做什么特殊工作,可以提供Web服务即可; 客户端远程测试: http://192.168.168.135/
下载
(16.2 KB)
2021-3-3 17:22
###### 配置Nginx服务器,修改Nginx的主配置文件: [root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf 加上以下代码:(可以指定目标的端口号,不指定则默认为TCP 80)
proxy_pass http://192.168.168.135:80;
下载
(38.11 KB)
2021-3-3 17:23
重启Nginx服务,使更改生效: [root@localhost ~]# service nginx restart 再次测试:(客户端只访问Nginx服务器的IP地址) http://192.168.168.130/
下载
(16.47 KB)
2021-3-3 17:24
Windows客户端做硬解析:( 域名解析到Nginx服务器的IP地址 )
下载
(49.26 KB)
2021-3-3 17:24
Windows客户端远程测试: http://ww.zhuohua.store/
下载
(16.63 KB)
2021-3-3 17:24
http://www.zhuohua.store/
下载
(17.13 KB)
2021-3-3 17:25
############ ############ Nginx的反向代理+负载均衡 再加一台Web服务器(192.168.168.154): 默认首页的内容: [root@centos8 ~]# echo 'Welcome to zhuohua-2' > /var/www/html/index.html ###### 配置Nginx服务器,修改Nginx的主配置文件: [root@localhost ~]# vi /usr/local/nginx/conf/nginx.conf 要先删除上面写的
proxy_pass http://192.168.168.135:80;
加上: upstream webservers { server
192.168.168.135:80
weight=1; server
192.168.168.154:80
weight=1; } proxy_pass http://webservers; proxy_set_header X-Real-IP $remote_addr;
下载
(76.7 KB)
2021-3-3 17:26
笺注: 1.
Weight
指定轮询权值,Weight的值越大,对应的后端服务器分配到的访问几率越高;假如后端服务器的性能不均,就调节Weight的值; 2.
webservers
这个是名字是自定义的; 重启Nginx服务,使更改生效: [root@localhost ~]# service nginx restart 测试: 客户端理应可以看到的轮询效果:(
轮流出现两台Web服务器提供的页面
)
下载
(17.57 KB)
2021-3-3 17:27
下载
(17.7 KB)
2021-3-3 17:27
实验中,两台Web服务器中有任意一台不能提供Web服务时,另外一台都可以支撑全部访问,且没有出现访问失败的迹象。
相关文章:
CentOS6_Nginx反向代理+负载均衡(ip_hash)
CentOS6_Nginx反向代理+基于域名的虚拟主机
CentOS6_Nginx反向代理+Nginx版网站安全狗
Nginx基于域名的虚拟主机/域名重定向/访问控制/防盗链/SSL
Windows2012R2_UPUPW_Nginx反向代理
Nginx用户验证
Nginx的并发连接数
CentOS8安装Django+Nginx反向代理
################################# #################################
亲,学习研究也要劳逸结合哦,来我微店逛逛,买点东西好好犒劳犒劳自己和家人吧^_^^_^
永定泡鸭爪400g礼包福建土楼客家特产卤味微辣鸭掌闽西好【满49包邮 偏远除外】
下载
(659.34 KB)
2019-10-5 14:41
利临多功能抹布5片装 超细纤维洗碗巾擦车巾百洁布
下载
(706.7 KB)
2019-10-5 14:41
薇语馨311秋装新款修身中长款蕾丝连衣裙七分袖新款
下载
(425.81 KB)
2019-10-5 14:41
图片附件:
fenho.png
(2019-10-5 14:41, 425.81 KB) / 下载次数 88
http://blog.zhuohua.store/attachment.php?aid=2287&k=e86f7db74c579cb16d3f0f1aee55080d&t=1714353109&sid=FtTcra
图片附件:
maojin.png
(2019-10-5 14:41, 706.7 KB) / 下载次数 78
http://blog.zhuohua.store/attachment.php?aid=2288&k=780bb466f7f0f824866c682c6dcbc272&t=1714353109&sid=FtTcra
图片附件:
zhuazi.png
(2019-10-5 14:41, 659.34 KB) / 下载次数 93
http://blog.zhuohua.store/attachment.php?aid=2290&k=508b4f9b7af0ad051382a61cac6368f8&t=1714353109&sid=FtTcra
图片附件:
图片1.png
(2021-3-3 17:20, 33.77 KB) / 下载次数 119
http://blog.zhuohua.store/attachment.php?aid=15775&k=e787543397648981a32fd3841a6df424&t=1714353109&sid=FtTcra
图片附件:
图片2.png
(2021-3-3 17:22, 45.78 KB) / 下载次数 108
http://blog.zhuohua.store/attachment.php?aid=15776&k=e89ab41c71aa8e366361d9560301887e&t=1714353109&sid=FtTcra
图片附件:
图片3.png
(2021-3-3 17:22, 16.2 KB) / 下载次数 104
http://blog.zhuohua.store/attachment.php?aid=15777&k=415d966e290463e10788fe4e6ffc056a&t=1714353109&sid=FtTcra
图片附件:
图片4.png
(2021-3-3 17:23, 38.11 KB) / 下载次数 100
http://blog.zhuohua.store/attachment.php?aid=15778&k=726f5cfac6bd7510525a73156c28a3be&t=1714353109&sid=FtTcra
图片附件:
图片5.png
(2021-3-3 17:24, 16.47 KB) / 下载次数 95
http://blog.zhuohua.store/attachment.php?aid=15779&k=c68c829f7fc62cfb193f8bea1d76a868&t=1714353109&sid=FtTcra
图片附件:
图片6.png
(2021-3-3 17:24, 49.26 KB) / 下载次数 100
http://blog.zhuohua.store/attachment.php?aid=15780&k=1d27a20b324558450d18072f33eb48c0&t=1714353109&sid=FtTcra
图片附件:
图片7.png
(2021-3-3 17:24, 16.63 KB) / 下载次数 104
http://blog.zhuohua.store/attachment.php?aid=15781&k=e0f85e5a7e753232635648e872fde44a&t=1714353109&sid=FtTcra
图片附件:
图片8.png
(2021-3-3 17:25, 17.13 KB) / 下载次数 111
http://blog.zhuohua.store/attachment.php?aid=15782&k=693d4cf511a35b209ac8e616b0e5b23f&t=1714353109&sid=FtTcra
图片附件:
图片9.png
(2021-3-3 17:26, 76.7 KB) / 下载次数 96
http://blog.zhuohua.store/attachment.php?aid=15783&k=f3111f492fc10dd0fa05eb36052e7faf&t=1714353109&sid=FtTcra
图片附件:
图片10.png
(2021-3-3 17:27, 17.57 KB) / 下载次数 102
http://blog.zhuohua.store/attachment.php?aid=15784&k=76745e0398960dab1b8da83edb546e7c&t=1714353109&sid=FtTcra
图片附件:
图片11.png
(2021-3-3 17:27, 17.7 KB) / 下载次数 100
http://blog.zhuohua.store/attachment.php?aid=15785&k=1c435b5d63100742f32415e978b3be9d&t=1714353109&sid=FtTcra
欢迎光临 blog.zhuohua.store (http://blog.zhuohua.store/)
Powered by Discuz! 7.2