nginx+keepalive负载均衡高可用
这里不细说。下面说明一下怎么用keepalive实现Nginx高可用。
1、准备
两台浮在均衡服务器:
192.168.31.213
192.168.31.246
准备VIP(虚拟IP):192.168.31.31
2、为两台均衡服务器安装keepalive
准备依赖包:
yum -y install gcc pcre-devel zlib-devel openssl-devel yum -y install popt-devel
下载
wget http://www.keepalived.org/software/keepalived-1.2.7.tar.gz 安装keepalive
- tar zxvf keepalived-1.2.7.tar.gz
- cd keepalived-1.2.7
- ./configure
- make
- make install
- cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
- cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
- mkdir /etc/keepalived
- cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
- cp /usr/local/sbin/keepalived /usr/sbin/
配置keepalived
按照上面的安装方法,keepalived的配置文件在/etc/keepalived/keepalived.conf。主、从服务器的配置相关联但有所不同。如下:
- ! Configuration File for keepalived
- global_defs {
- router_id NIGNX_DEVEL
- }
- vrrp_script chk_http_port {
- script "</dev/tcp/127.0.0.1/80"
- interval 1
- weight -2
- }
- 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.31.31
- }
- track_script {
- chk_http_port
- }
- }
备用节点
- ! Configuration File for keepalived
- global_defs {
- router_id NIGNX_DEVEL
- }
- vrrp_script chk_http_port {
- script "</dev/tcp/127.0.0.1/80"
- interval 1
- weight -2
- }
- vrrp_instance VI_1 {
- state BACKUP
- interface eth0
- virtual_router_id 51
- priority 99
- advert_int 1
- authentication {
- auth_type PASS
- auth_pass 1111
- }
- virtual_ipaddress {
- 192.168.31.31
- }
- track_script {
- chk_http_port
- }
- }
============ 欢迎各位老板打赏~ ===========
与本文相关的文章
- · vue3+vite+多环境发面到二级目录配置
- · nginx http转https, 不带www转带www
- · 阿里云三种负载均衡的区别
- · nginx主动健康检查负载均衡模块
- · nginx自动切换到手机/PC 网站
- · 使用tengine代替Nginx
- · nginx添加nginx_upstream_check_module
- · nginx上传文件超出默认大小限制,提示:413 Request Entity Too Large
- · nginx反向代理禁用缓存
- · docker nginx
- · Ocelot+Consul+.netcore高可用&动态伸缩
- · consul+nginx完成集群服务动态发现和健康检查