debian中keepalived搭建

  1. 安装keepalived(需要两台服务器)
tar zxvf keepalived-2.0.20.tar.gz

apt install build-essential openssl libssl-dev -y

cd keepalived-2.0.20/

./configure

make && make install
  1. 将主配置文件拷贝keepalived中
find / -name keepalived.conf

mkdir /etc/keepalived 

cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf


  1. 修改主配置文件

主服务器

root@debian:~# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   router_id haproxy_2	#路由器标识
}

vrrp_instance VI_1 {	#设置一个虚拟路由
    state MASTER		# 设置主备MASTER为主,BACKUP为备
    interface ens33		#VIP要挂的网卡
    virtual_router_id 130	#虚拟路由标识,主备服务器上这里必须保持一致
    priority 160		  #定义优先级,数字越大优先级越高,主服务器上的值应该为最大
    advert_int 1		 #主备服务器之间检查的时间间隔,1秒;主备必须一致
    authentication {	 #设置验证类型和密码,主备必须一致
        auth_type PASS
        auth_pass 2019
    }
    virtual_ipaddress {
        192.168.30.30/24 dev ens33	#设置虚拟IP地址,可以设置多个IP地址每行一个
    }
}

virtual_server 192.168.30.30 80 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    persistence_timeout 50
    protocol TCP

    real_server 10.10.10.40 80 {
        weight 1
        SSL_GET {
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
    }

    real_server 10.10.10.10 80 {
        weight 1
        SSL_GET {
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
    }
}

备用服务器设置

root@debian:~# cat /etc/keepalived/keepalived.conf 
! Configuration File for keepalived

global_defs {
   router_id haproxy_2
}

vrrp_instance VI_1 {
    state BACKUP
    interface ens33
    virtual_router_id 130
    priority 90
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass 2019
    }
    virtual_ipaddress {
        192.168.30.30/24 dev ens33
    }
}

virtual_server 192.168.30.30 80 {
    delay_loop 6
    lb_algo rr
    lb_kind NAT
    persistence_timeout 50
    protocol TCP

    real_server 10.10.10.40 80 {
        weight 1
        SSL_GET {
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
    }

    real_server 10.10.10.10 80 {
        weight 1
        SSL_GET {
            connect_timeout 3
            retry 3
            delay_before_retry 3
        }
    }

}

重启命令 : /usr/local/sbin/./keepalived

主服务器关机 备用服务器自动

你可能感兴趣的:(linux,debian,网络安全,安全)