最后更新时间:2020-10-17 16:38:17 以一套web应用作为示例。 前提:已经创建好后两台云服务器。 准备环境: 后端服务器:web-01 centos7.2,8080端口 后端服务器:web-02 centos7.2,8080端口 1.安装好web服务 以nginx为例,rpm方式安装nginx,开放8080端口对外服务: web-01: yum install nginx -y
vim /etc/nginx/nginx.conf
server { listen 8080 default_server; server_name _; root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / { }
error_page 404 /404.html; location = /40x.html { }
error_page 500 502 503 504 /50x.html; location = /50x.html { } }
echo “this is web-01” > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl status nginx

确保能正常访问: 
web-02: yum install nginx -y
vim /etc/nginx/nginx.conf
server { listen 8080 default_server; server_name _; root /usr/share/nginx/html;
include /etc/nginx/default.d/*.conf;
location / { }
error_page 404 /404.html; location = /40x.html { }
error_page 500 502 503 504 /50x.html; location = /50x.html { } }
echo “this is web-02” > /usr/share/nginx/html/index.html
systemctl start nginx
systemctl status nginx

确保能正常访问:

2.开放防火墙访问权限 如果云服务器开启了防火墙,则需要开启负载均衡实例健康检查网络地址的防火墙访问权限。健康检查网络地址 分别在web-01和web-02上: firewall-cmd --add-rich-rule="rule family="ipv4" source address="负载均衡公网IP/32" accept" --permanent
firewall-cmd --reload
配置完成!
|