前言
用nginx做负载均衡,作为架构的最前端或中间层,随着日益增长的访问量,需要给负载均衡做高可用架构,利用keepalived解决单点风险,一旦 nginx宕机能快速切换到备份服务器。
Vmware网络配置可能遇到的问题解决方法
- 启动
VMware DHCP Service
和VMware NAT Service
两个服务 - 在网络适配器开启网络共享,允许其他网络打勾保存,重启虚拟机
安装
节点部署
节点 | 地址 | 服务 |
---|---|---|
centos7_1 | 192.168.211.130 | Keepalived+Nginx |
centos7_2 | 192.168.211.131 | Keepalived+Nginx |
centos7_3 | 192.168.211.132 | Redis服务器 |
web1(物理机) | 192.168.211.128 | FastApi+Celery |
web2(物理机) | 192.168.211.129 | FastApi+Celery |
web的配置
web1启动python http服务器
vim index.html
<html>
<body>
<h1>Web Svr 1</h1>
</body>
</html>
nohup python -m SimpleHTTPServer 8080 > running.log 2>&1 &
web2启动python http服务器
vim index.html
<html>
<body>
<h1>Web Svr 2</h1>
</body>
</html>
nohup python -m SimpleHTTPServer 8080 > running.log 2>&1 &
关闭防火墙
firewall-cmd --state
systemctl stop firewalld.service
systemctl disable firewalld.service
现在浏览器访问就正常了,页面显示Web Svr 1 和 2
centos1和2安装Nginx
首先配置阿里云的源
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
安装依赖包
yum -y install gcc
yum install -y pcre pcre-devel
yum install -y zlib zlib-devel
yum install -y openssl openssl-devel
下载nginx,并解压
wget http://nginx.org/download/nginx-1.8.0.tar.gz
tar -zxvf nginx-1.8.0.tar.gz
安装nginx
cd nginx-1.8.0
./configure --user=nobody --group=nobody --prefix=/usr/local/nginx --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-h