300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > nginx 负载均衡+keepalived实现双机热备

nginx 负载均衡+keepalived实现双机热备

时间:2021-06-07 16:19:34

相关推荐

nginx 负载均衡+keepalived实现双机热备

部署

ip分配 nginx192.168.1.5主机 192.168.1.6备机 浮动ip192.168.1.7

首先设置浮动ip(主备机器都要设置)

打开网卡eth0 配置好网络参数

复制eth0为eth0:1

修改vim eth0:1

NAME = eth0:1

DEVICE =eth0:1

IPADDR = 192.168.1.7

开启转发

echo "1" > /proc/sys/net/ipv4/ip_forward

修改/etc/sysctl.conf文件,让包转发功能在系统启动时自动生效:

# Controls IP packet forwarding

net.ipv4.ip_forward = 1

重启网络

service network restart

安装keepalived

yum install keepalived -y

修改配置文件

vim /etc/keepalived/keepalived.conf

主机配置情况

global_defs {

notification_email {

#baojing@ 设置报警

}

router_id LVS_DEVEL

}

vrrp_script chk_http_port {

script "</dev/tcp/127.0.0.1/8087"

interval 1

weight -10

}

vrrp_instance VI_1 {

state MASTER

interface eth0

virtual_router_id 51

priority 100

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.7

}

track_script {

chk_http_port

}

}

备用机上面配置

global_defs {

notification_email {

#baojing@ 设置报警

}

router_id LVS_DEVEL

}

vrrp_script chk_http_port {

script "</dev/tcp/127.0.0.1/8087"

interval 1

weight -10

}

vrrp_instance VI_1 {

state BACKUP

interface eth0

virtual_router_id 51

priority 90

advert_int 1

authentication {

auth_type PASS

auth_pass 1111

}

virtual_ipaddress {

192.168.1.7

}

track_script {

chk_http_port

}

}

启动查看keepalived情况

killall keepalived

service keepalived start

tail -f /var/log/messages

安装nginx配置转发负载均衡

vim /usr/local/nginx/conf/nginx.conf

添加负载均衡配置

upstream mytest {

#least_conn;

#ip_hash;

server weight=3 max_fails=2 fail_timeout=30s;

server weight=3 max_fails=2 fail_timeout=30s;

server weight=5 max_fails=3 fail_timeout=30s;

}

location ^~/piwik/ {

proxy_pass http://mytest;

}

/usr/local/nginx/sbin/nginx -t

/usr/local/nginx/sbin/nginx

/usr/local/nginx/sbin/nginx -s reload重新加载配置

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。