ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

keepalived高可用

2021-10-22 10:01:53  阅读:147  来源: 互联网

标签:slave service 可用 keepalived etc master root


keepalived高可用

主服务器配置

//关闭防火墙和selinux
[root@master ~]# systemctl disable --now firewalld.service 
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@master ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config 
[root@master ~]# setenforce 0

//安装keepalived
[root@master ~]# yum -y install keepalived

[root@master ~]# rpm -ql keepalived 
/etc/keepalived
/etc/keepalived/keepalived.conf		//配置文件
/etc/sysconfig/keepalived
/usr/bin/genhash
/usr/lib/systemd/system/keepalived.service	//服务控制文件
/usr/libexec/keepalived
/usr/sbin/keepalived

备服务器配置

//关闭防火墙和selinux
[root@slave ~]# systemctl disable --now firewalld.service
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
[root@slave ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@slave ~]# setenforce 0

//安装keepalived
[root@slave ~]# yum -y install keepalived

主备服务器上安装httpd

主服务器

//安装httpd,创建测试页面
[root@master ~]# yum -y install httpd
[root@master ~]# echo 'master' > /var/www/html/index.html
[root@master ~]# systemctl start httpd
[root@master ~]# ss -anltu
Netid      State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      
tcp        LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*         
tcp        LISTEN      0           128                          *:80                        *:*         
tcp        LISTEN      0           128                       [::]:22                     [::]:*         

在这里插入图片描述

备服务器

//安装httpd,创建测试页面
[root@slave ~]# yum -y install httpd
[root@slave ~]# echo 'slave' > /var/www/html/index.html
[root@slave ~]# systemctl start httpd
[root@slave ~]# ss -anltu
Netid      State       Recv-Q      Send-Q           Local Address:Port           Peer Address:Port      
tcp        LISTEN      0           128                    0.0.0.0:22                  0.0.0.0:*         
tcp        LISTEN      0           128                          *:80                        *:*         
tcp        LISTEN      0           128                       [::]:22                     [::]:*         

在这里插入图片描述

keepalived配置

主服务器配置

[root@master ~]# cd /etc/keepalived/
[root@master keepalived]# ls
keepalived.conf
[root@master keepalived]# cp keepalived.conf{,-bak}	//备份原文件
[root@master keepalived]# ls
keepalived.conf  keepalived.conf-bak
[root@master keepalived]# rm -rf keepalived.conf
[root@master keepalived]# vim keepalived.conf
[root@master keepalived]# cat keepalived.conf
! Configuration File for keepalived

global_defs {
   router_id lb01
}

vrrp_instance VI_1 {
    state MASTER
    interface ens160		//网卡名
    virtual_router_id 51
    priority 100
    advert_int 1
    authentication {
        auth_type PASS
        auth_pass wys123	//密码
    }
    virtual_ipaddress {
        192.168.237.250		//VIP
    }
}

virtual_server 192.168.237.250 80 {		//VIP加端口号
    delay_loop 6
    lb_algo rr
    lb_kind DR
    persistence_timeout 50
    protocol TCP

    real_server 192.168.237.167 80 {	//主服务器IP
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }

    real_server 192.168.237.170 80 {	//备服务器IP
        weight 1
        TCP_CHECK {
            connect_port 80
            connect_timeout 3
            nb_get_retry 3
            delay_before_retry 3
        }
    }
}

//启动keepalived
[root@master keepalived]# systemctl enable --now keepalived
Created symlink /etc/systemd/system/multi-user.target.wants/keepalived.service → /usr/lib/systemd/system/keepalived.service.

标签:slave,service,可用,keepalived,etc,master,root
来源: https://blog.csdn.net/tianwailaiwu_/article/details/120899376

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有