centos7安装keepalived

一、基础环境

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

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
    [email protected][14:46:07]:~
    $ curl 10.1.1.111
    this is master
    [email protected][15:03:29]:~
  2. slave
    $ curl localhost
    this is slave
    [email protected][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
[email protected][15:10:29]:/etc/keepalived
$ curl 10.1.1.111
this is slave

到此keepalived完成

原文地址:https://blog.51cto.com/853056088/2465855

时间: 2024-10-18 05:05:01

centos7安装keepalived的相关文章

Centos7 安装keepalived实现高可用

场景:尝试安装keepalived实现高可用,进而在suse环境中部署. 测试过程需要配合Nginx的相关知识:Centos7 Nginx安装 1 安装过程 问题 !!! OpenSSL is not properly installed on your system. !!! !!! Can not include OpenSSL headers files. 解决方法: yum -y install openssl-devel

centos7 安装keepalived

node1 192.168.5.101 node2 192.168.5.102 1.安装 openssl openssl-devel yum install openssl openssl-devel -y 2. 安装keepalived tar -zxvf keepalived-1.4.0.tar.gz ./configrue --prefix=/app/keepalived make&&make install 3.配置keepalived配置文件 ! Configuration Fi

2017最新nginx+keepalived+centos7安装配置过程

一. 地址规划 nginx1-10.1.1.2 nginx2-10.1.1.3 vip-10.1.1.4 修改两台主机名:hostnamectl set-hostname nginx1 hostnamectl set-hostname nginx2 二.在nginx1和nginx2上分别安装nginx,这里用的是最新的稳定版 先安装依赖包 yum -y install gcc gcc++ prce pcre-devel zlib zlib-devel openssl openssl-devel

Centos7+Mariadb+Keepalived实现Mariadb(MYSQL)的高可用(HA)

我们前面几篇文章中有介绍了Keepalived的功能--HA,关于MySQL-HA,目前有多种解决方案,比如heartbeat.drbd.mmm.共享存储,但是它们各有优缺点.heartbeat.drbd配置较为复杂,需要自己写脚本才能实现MySQL自动切换,对于不会脚本语言的人来说,这无疑是一种脑裂问题:对于mmm,生产环境中很少有人用,且mmm 管理端需要单独运行一台服务器上,要是想实现高可用,就得对mmm管理端做HA,这样无疑又增加了硬件开支:对于共享存储,个人觉得MySQL数据还是放在本

Centos7+Nginx+Keepalived实现Apache服务的高可用&负载均衡

Centos7+Nginx+Keepalived实现Apache服务的高可用&负载均衡 今天是2017年的第一天,昨天也就是2016年的最后一天,我尝试部署了Centos7+Nginx+Keepalived实现WEB服务的高可用负载均衡服务,终于在2017年的第一天前完成了,所以在此分享给有需要的朋友:说到负载均衡,其实在linux下有很多服务可以实现,比如nginx.haproxy.lvs等服务,当前我们在前面的文章有介绍过了,但是对于高可用服务,我们在linux下最常见也是应用最多的是Kee

centos7+LVS+KeepAlived实现Nginx服务的高可用性

centos7+LVS+KeepAlived实现Nginx服务的高可用性 说到服务的高可用性,我们前面文章介绍了很多了,在linux下实现的方式有很多种,在此主要介绍Centos7+LVS+Keepalived实现Nginx服务的高可用性,具体见下: 环境介绍 hostname:Nginx01 IP:192.168.6.10 Role:Nginx Server hostname:Nginx02 IP: 192.168.6.11 Role:Nginx Server hostname:LVS01 I

Centos7 安装配置OpenLdap服务及OpenLdap管理工具

我们上一篇文章中介绍了,Centos7+Openvpn使用Windows AD(LDAP)验证登录的配置介绍.说到LDAP服务,我们知道不止windows有,linux下也有,比如openldap,sambaLDAP服务,具体就不多介绍了,我们今天主要介绍一下Centos7 安装配置OpenLdap及Ldap管理工具等操作,为后面的Centos7+Openvpn+openldap验证登录做好基础. 我们首先配置一个指定源,我们源地址指向了阿里云的仓库源 cd /etc/yum.repos.d v

CentOS7安装python-pip

python中的一个十分好用的包管理工具python-pip是我们使用python必不可少的一件工具.但是在CentOS7安装时候却遇到了一些小问题: [[email protected] magic]# yum install python-pip 已加载插件:fastestmirror, langpacks Loading mirror speeds from cached hostfile * base: mirrors.btte.net * extras: mirrors.btte.ne

HP服务器 hp 360g5 centos7安装问题

HP服务器  hp 360g5 centos7安装问题 一 :启动盘无法识别硬盘 1.进入安装光盘,用上下键选择安装centos--Install Centos7(注意不可按Enter键),如图: 2.按Tab键,对安装进行额外配置,在屏幕最下方会显示如下字样: 3.在额外配置的命令行上添加配置: hpsa.hpsa_simple_mode=1 hpsa.hpsa_allow_any=1,如图所示: 二:安装完成后无法引导  出现情况:CentOS开机进度条卡死在100% 显示 firmware