nginx+keepalived是怎么样实现高可用负载均衡的
下文给大家带来nginx + keepalived 是怎么样实现高可用负载均衡的,希望能够给大家在实际运用中带来一定的帮助,负载均衡涉及的东西比较多,理论也不多,网上有很多书籍,今天我们就用创新互联在行业内累计的经验来做一个解答。
创新互联:自2013年起为各行业开拓出企业自己的“网站建设”服务,为1000+公司企业提供了专业的做网站、网站建设、网页设计和网站推广服务, 专业公司由设计师亲自精心设计,设计的效果完全按照客户的要求,并适当的提出合理的建议,拥有的视觉效果,策划师分析客户的同行竞争对手,根据客户的实际情况给出合理的网站构架,制作客户同行业具有领先地位的。
虚拟IP: 192.168.2.52
nginx-1: 192.168.2.50
nginx-2: 192.168.2.51
关闭/etc/sysconfig/selinux
SELINUX=disabled
nginx-1
yum install keepalived
vim /etc/keepalived/keepalived.conf
---------------------------------------------------
! Configuration File for keepalived
global_defs {
router_id LVS_DEVEL
}
vrrp_instance VI_1 {
state MASTER //定义为MASTER主机
interface eth0
virtual_router_id 51 //虚拟id
priority 100 //优先级
advert_int 1 //检测间隔
authentication {
auth_type PASS //认证方式
auth_pass abcd //认证密码
}
virtual_ipaddress {
192.168.2.52 //虚拟ip,即VIP
}
-------------------------------------------------
chkconfig keepalived on
service keepalived start
nginx-2
yum install keepalived
vim /etc/keepalived/keepalived.conf
--------------------------------------------------只改动如下
state BACKUP //定义为BACKUP
priority 99 //优先级
virtual_ipaddress {
192.168.2.52
}
-------------------------------------------------
chkconfig keepalived on
service keepalived start
ip a
已经绑定成功
检测keepalived自动切换
客户机:
ping 192.168.2.52 -t
nginx-1: 关闭keepalived服务
service keepalived stop
客户机是否正常ping
安装nginx
因为centos 没有nginx,先安装第三方epel-release源
yum install -y epel-release
yum install -y nginx
负载均衡
vi /etc/nginx/nginx.conf
添加以下内容
------------------------
# for more information.
include /etc/nginx/conf.d/*.conf;
upstream zhizhimao.com {
server 192.168.2.101:80; #web云服务器
server 192.168.2.100:80; #web云服务器
}
}
------------------------
反向代理
vi /etc/nginx/conf.d/default.conf
--------------------------------------------
server {
listen 80;
listen [::]:80default_server;
server_name zhizhimao.com; #如只做代理填写IP
root /usr/share/nginx/html;
#Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location / {
proxy_pass http://zhizhimao.com; #如只做代理填写IP
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}
-----------------------------------------------------
chkconfig nginx on
service nginx start
防火墙打开80端口
看了以上关于nginx + keepalived 是怎么样实现高可用负载均衡的,如果大家还有什么地方需要了解的可以在创新互联行业资讯里查找自己感兴趣的或者找我们的专业技术工程师解答的,创新互联技术工程师在行业内拥有十几年的经验了。
网站名称:nginx+keepalived是怎么样实现高可用负载均衡的
文章地址:http://ybzwz.com/article/ipdpic.html