<b>Nginx+Keepalived在Ubuntu上实现负载均衡</b>[服务器安全]
本文“<b>Nginx+Keepalived在Ubuntu上实现负载均衡</b>[服务器安全]”是由七道奇为您精心收集,来源于网络转载,文章版权归文章作者所有,本站不对其观点以及内容做任何评价,请读者自行判断,以下是其具体内容:
1、nginx反向代理配置
翻开/etc/nginx/nginx.conf配置文件,在http下加入:
upstream ip{ #对外虚拟IP
server IP1;
server IP2;
}
server{
listen 80;
server_name ip; #i对外虚拟IP
index index.php;index.html;index.htm;
location / {
proxy_pass http://ip;
}
}
2、keepalived的配置
1安装Keepalived
sudo apt-get install keepalived
2配置keepalived
将IP1作为负载均衡的主服务器,将IP2作为“从服务器”.这是通过配置文件中的priority来实现的.在“主服务器”上设置为:101,“从服务器”上设置为:100.
在IP1上,设置/etc/keepalived/keepalived.conf
$ sudo nano /etc/keepalived/keepalived.conf
vrrp_script chk_haproxy{
script "killall -0 haproxy"
interval 2
weight 2
}
vrrp_instance VI_1 {
interface eth0
state MASTER
virtual_router_id 51
priority 101 #101为“主”,100为“从”
virtual_ipaddress {
ip #对外虚拟IP
}
track_script {
chk_haproxy
}
}
运行keepalived服务
suto /etc/init.d/keepalived start
IP2和IP1的配置基本上一样,只需求把优先级该成:100
以上是“<b>Nginx+Keepalived在Ubuntu上实现负载均衡</b>[服务器安全]”的内容,如果你对以上该文章内容感兴趣,你可以看看七道奇为您推荐以下文章:
本文地址: | 与您的QQ/BBS好友分享! |