基于端口:
配置文件
基于IP
基于域名(本地解析记得上传到要访问的服务器上)
负载均衡
三台虚拟机
web-1 web-2 防火墙+selinu网络 yum仓库 安装nginx并运行
web-1:hello web-1 echo "hello web-1" > /usr/share/nginx/html/index.html
web-2: hello web-2 echo "hello web-2" > /usr/share/nginx/html/index.html
负载均衡(主):
cd /etc/yum.repos.d
vi nginx.repo
yum -y install nginx && systemctl start nginx
systemctl status nginx
cd
vi /etc/nginx/nginx.conf :添加upstream testapp {
server 10.0.105.199:8081;
server 10.0.105.202:8081;
}
vi /etc/nginx/conf.d/default.conf :添加 location / {
proxy_pass http://testapp; #请求转向 testapp 定义的服务器列表
} 注释掉location中的两条命令
systemctl restart nginx
负载均衡+代理 ()
软件负载均衡、硬件负载均衡、云负载均衡
参数:upstream 地址池 web-sever IP地址
增加NFS
NFS服务器(192.168.128.186):
安装nfs-utils
mkdir /opt/nfs-data
vi /etc/exports 添加 /opt/nfs-data *(rw,sync,no_root_squash)
exportfs -rv
unzip jspvz.zip
cp -r jspvz/* /opt/nfs-data
systemctl start nfs
NFS客户端(负载均衡集群):
yum -y install nfs-utils
mkdir /opt/nfs-data
mount -t nfs 192.168.128.186:/opt/nfs-data /usr/share/nginx/html //直接挂载到网页发布目录下,浏览器访问