centos7中如何安装配置keepalived-创新互联

centos7系统中如何安装配置keepalived?相信大部分人都还没学会这个技能,为了让大家学会,给大家总结了以下内容,话不多说,一起往下看吧。

让客户满意是我们工作的目标,不断超越客户的期望值来自于我们对这个行业的热爱。我们立志把好的技术通过有效、简单的方式提供给客户,将通过不懈努力成为客户在信息化领域值得信任、有价值的长期合作伙伴,公司提供的服务项目有:国际域名空间、雅安服务器托管、营销软件、网站建设、南岗网站维护、网站推广。

一、基础环境

系统版本nginx版本keepalived版本ip作用
CentOS Linux release 7.5.1804 (Core)nginx/1.16.1keepalived-2.0.1810.1.1.31master
CentOS Linux release 7.5.1804 (Core)nginx/1.16.1keepalived-2.0.1810.1.1.32slave

VIP 10.1.1.111

二、安裝nginx

  1. 安裝nignx

    yum install nginx -y
  2. 修改nginx配置文件

    • master

      echo 'this is master 31' > /usr/share/nginx/html/index.html
    • slave

      echo 'this is slave 32' >  /usr/share/nginx/html/index.html
  3. 启动nginx

    systemctl start nginx
  4. 测试nginx启动

    curl localhost
    
    this is master

三、安装keepalived

1、 创建依赖环境

yum -y install openssl-devel gcc gcc-c++
mkdir /etc/keepalived
wget https://www.keepalived.org/software/keepalived-2.0.18.tar.gz

2、安装keepalived

tar -zxvf keepalived-2.0.18.tar.gz
mv keepalived-2.0.18 /usr/local/keepalived
cd /usr/local/keepalived
./configure && make && make install

3、创建启动文件

cp -a /usr/local/etc/keepalived  /etc/init.d/
cp -a /usr/local/etc/sysconfig/keepalived  /etc/sysconfig/
cp -a /usr/local/sbin/keepalived  /usr/sbin/

4、创建配置文件

  1. master

    cat > /etc/keepalived/keepalived.conf << EOF
    ! Configuration File for keepalived
    global_defs {
        router_id 31
    } 
    vrrp_instance VI_1 {
        state MASTER
        interface ens33
        virtual_router_id 3
        mcast_src_ip 10.1.1.132
        priority 200
        advert_int 1 
        authentication {
            auth_type PASS
            auth_pass 123456
        }
        virtual_ipaddress {
            10.1.1.111/24
        }
    }
    EOF
  2. slave

    cat > /etc/keepalived/keepalived.conf << EOF
    ! Configuration File for keepalived
    global_defs {
        router_id 32
    } 
    vrrp_instance VI_1 {
        state BACKUP
        interface ens33
        virtual_router_id 3
        mcast_src_ip 10.1.1.132
        priority 90 
        advert_int 1 
        authentication {
            auth_type PASS
            auth_pass 123456
        }
        virtual_ipaddress {
            10.1.1.111/24
        }
    }
    EOF

5、启动keepalived

systemctl start keepalived
systemctl enable keepalived

四、测试

1、在两台服务器上测试

  1. master

    $ curl localhost
    this is master
    root@centos7[14:46:07]:~
    $ curl 10.1.1.111
    this is master
    root@centos7[15:03:29]:~
  2. slave

    $ curl localhost
    this is slave
    root@centos7[15:03:59]:/etc/keepalived
    $ curl 10.1.1.111
    this is master

2、关闭master的keepalived模仿down机

  1. master关闭keepalived

    $ systemctl stop keepalived
  2. 在slave上面进行测试
$  curl localhost
this is slave
root@centos7[15:10:29]:/etc/keepalived
$ curl 10.1.1.111
this is slave

keepalived完成

关于centos7安装配置keepalived的教程就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站名称:centos7中如何安装配置keepalived-创新互联
文章转载:http://hbruida.cn/article/csijss.html