Chinaunix首页 | 论坛 | 博客
  • 博客访问: 6906660
  • 博文数量: 3857
  • 博客积分: 6409
  • 博客等级: 准将
  • 技术积分: 15948
  • 用 户 组: 普通用户
  • 注册时间: 2008-09-02 16:48
个人简介

迷彩 潜伏 隐蔽 伪装

文章分类

全部博文(3857)

文章存档

2017年(5)

2016年(63)

2015年(927)

2014年(677)

2013年(807)

2012年(1241)

2011年(67)

2010年(7)

2009年(36)

2008年(28)

分类: LINUX

2013-12-17 10:02:50

Keepalived安装手册

1、  上传keepalived软件keepalived-1.2.7-3.el6.x86_64.rpm

2、  安装keepalived-1.2.7-3.el6.x86_64.rpm

yum install keepalived-1.2.7-3.el6.x86_64.rpm

Loaded plugins: aliases, changelog, downloadonly, kabi, presto, product-id,

              : refresh-packagekit, security, subscription-manager, tmprepo,

              : verify, versionlock

This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.

Loading support for Red Hat kernel ABI

Repository 'rhel-source' is missing name in configuration, using id

Setting up Install Process

Examining keepalived-1.2.7-3.el6.x86_64.rpm: keepalived-1.2.7-3.el6.x86_64

Marking keepalived-1.2.7-3.el6.x86_64.rpm to be installed

Resolving Dependencies

--> Running transaction check

---> Package keepalived.x86_64 0:1.2.7-3.el6 will be installed

--> Finished Dependency Resolution

 

Dependencies Resolved

 

================================================================================

 Package       Arch      Version        Repository                         Size

================================================================================

Installing:

 keepalived    x86_64    1.2.7-3.el6    /keepalived-1.2.7-3.el6.x86_64    526 k

 

Transaction Summary

================================================================================

Install       1 Package(s)

 

Total size: 526 k

Installed size: 526 k

Is this ok [y/N]: y

Downloading Packages:

Running rpm_check_debug

Running Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing : keepalived-1.2.7-3.el6.x86_64                                1/1

rhel-source/productid                                    | 1.7 kB     00:00 ...

  Verifying  : keepalived-1.2.7-3.el6.x86_64                                1/1

 

Installed:

  keepalived.x86_64 0:1.2.7-3.el6                                              

 

Complete!

[root@test1 ~]# cd /etc/keepalived/

[root@test1 ~]#cp keepalived.conf keepalived.conf.bak

编写主机keepalived.conf

! Configuration File for keepalived

 

global_defs {

   notification_email {

   }

   router_id HA_DEVEL2

}

 

vrrp_script chk_app {

    script "/etc/keepalived/script.sh"

    interval 15

}

vrrp_instance service2 {

    state BACKUP

    interface eth0

    virtual_router_id 52

    priority 100

    advert_int 4

    nopreempt

track_interface {

    eth0

}

 

track_script {

    chk_app

}

    authentication {

        auth_type PASS

        auth_pass ctprl

    }

    virtual_ipaddress {

        172.16.59.6/32 dev eth0

    }

notify_master /etc/keepalived/master.sh

notify_backup etc/keepalived/backup.sh

notify_fault /etc/keepalived/fault.sh

notify_stop /etc/keepalived/stop.sh

}

编写script.sh

#!/bin/bash

STATUS_BIP=`ps -eaf |grep prl  |grep agent.AgentCattp | awk '{print $2}'`

if [[ $STATUS_BIP = "" ]] ;then

  ip addr | grep "192.168.159.6"  > /dev/null

    if [ "$?" = "0" ];then

          exit 1

       else

          exit 0

    fi

else

  exit 0

fi

编写master.sh

 #!/bin/bash

su - prl -c "cd /CT_PRL/CT_PRL_BIP/bin/; ./agent.sh restart"

   根据实际情况编写

编写backup.sh

#!/bin/bash

su - prl -c "/CT_PRL/CT_PRL_BIP/bin/agent.sh stop"

根据实际情况编写

编写fault.sh

#!/bin/bash

su - prl -c "/CT_PRL/CT_PRL_BIP/bin/agent.sh stop"

根据实际情况编写

编写stop.sh

#!/bin/bash

su - prl -c "/CT_PRL/CT_PRL_BIP/bin/agent.sh stop"

根据实际情况编写

编写备机keepalived.conf

! Configuration File for keepalived

 

global_defs {

   notification_email {

   }

   router_id HA_DEVEL2

}

 

vrrp_script chk_app {

    script "/etc/keepalived/script.sh"

    interval 15

}

vrrp_instance service2 {

    state BACKUP

    interface eth0

    virtual_router_id 52

    priority 80

    advert_int 4

track_interface {

    eth0

}

 

track_script {

    chk_app

}

    authentication {

        auth_type PASS

        auth_pass ctprl

    }

    virtual_ipaddress {

        192.168.159.6/32 dev eth0

    }

notify_master /etc/keepalived/master.sh

notify_backup etc/keepalived/backup.sh

notify_fault /etc/keepalived/fault.sh

notify_stop /etc/keepalived/stop.sh

}

编写script.sh

#!/bin/bash

STATUS_BIP=`ps -eaf |grep prl  |grep agent.AgentCattp | awk '{print $2}'`

if [[ $STATUS_BIP = "" ]] ;then

  ip addr | grep "192.168.159.6"  > /dev/null

    if [ "$?" = "0" ];then

          exit 1

       else

          exit 0

    fi

else

  exit 0

fi

编写master.sh

 #!/bin/bash

su - prl -c "cd /CT_PRL/CT_PRL_BIP/bin/; ./agent.sh restart"

   根据实际情况编写

编写backup.sh

#!/bin/bash

su - prl -c "/CT_PRL/CT_PRL_BIP/bin/agent.sh stop"

根据实际情况编写

编写fault.sh

#!/bin/bash

su - prl -c "/CT_PRL/CT_PRL_BIP/bin/agent.sh stop"

根据实际情况编写

编写stop.sh

#!/bin/bash

su - prl -c "/CT_PRL/CT_PRL_BIP/bin/agent.sh stop"

根据实际情况编写

 

 

针对tomcat编写

编写主机keepalived.conf

! Configuration File for keepalived

 

global_defs {

   notification_email {

   }

   router_id HA_DEVEL

}

 

vrrp_script chk_app {

    script "/etc/keepalived/script.sh"

    interval 15

}

vrrp_instance service {

    state BACKUP

    interface eth0

    virtual_router_id 51

    priority 100

    advert_int 4

    nopreempt

track_interface {

    eth0

}

 

track_script {

 chk_app

}

    authentication {

        auth_type PASS

        auth_pass ctprl

    }

    virtual_ipaddress {

        172.16.59.9/32 dev eth0

    }

notify_master /etc/keepalived/master.sh

notify_backup /etc/keepalived/backup.sh

notify_fault /etc/keepalived/fault.sh

notify_stop /etc/keepalived/stop.sh

}

 

编写script.sh

#!/bin/bash

STATUS_HTTP=`netstat -ntlp | grep 9000 |wc -l`

if [ $STATUS_HTTP = 0 ];then

  ip addr | grep "172.16.59.9"  > /dev/null

    if [ "$?" = "0" ];then

          exit 1

       else

          exit 0

    fi

else

  exit 0

fi

编写master.sh

#!/bin/bash

su - prl -c "/CT_PRL/COMMON/apache-tomcat-7.0.14/bin/startup.sh"

sed -i '25s/#chk_app/ chk_app/g' /etc/keepalived/keepalived.conf

编写backup.sh

#!/bin/bash

prlpid=`ps -eaf |grep prl |grep Djava |awk '{print $2}'`

kill -9 $prlpid

 

编写fault.sh

#!/bin/bash

prlpid=`ps -eaf |grep prl |grep Djava |awk '{print $2}'`

kill -9 $prlpid

 

编写stop.sh

#!/bin/bash

prlpid=`ps -eaf |grep prl |grep Djava |awk '{print $2}'`

kill -9 $prlpid

编写主机keepalived.conf

! Configuration File for keepalived

 

global_defs {

   notification_email {

   }

   router_id HA_DEVEL

}

 

vrrp_script chk_app {

    script "/etc/keepalived/script.sh"

    interval 15

}

vrrp_instance service {

    state BACKUP

    interface eth0

    virtual_router_id 51

    priority 80

    advert_int 4

track_interface {

    eth0

}

 

track_script {

    chk_app

}

    authentication {

        auth_type PASS

        auth_pass ctprl

    }

    virtual_ipaddress {

        172.16.59.9/32 dev eth0

    }

notify_master /etc/keepalived/master.sh

notify_backup /etc/keepalived/backup.sh

notify_fault /etc/keepalived/fault.sh

notify_stop /etc/keepalived/stop.sh

}

 

 

编写script.sh

#!/bin/bash

STATUS_HTTP=`netstat -ntlp | grep 9000 |wc -l`

if [ $STATUS_HTTP = 0 ];then

  ip addr | grep "172.16.59.9"  > /dev/null

    if [ "$?" = "0" ];then

          exit 1

       else

          exit 0

    fi

else

  exit 0

fi

编写master.sh

#!/bin/bash

su - prl -c "/CT_PRL/COMMON/apache-tomcat-7.0.14/bin/startup.sh"

sed -i '25s/#chk_app/ chk_app/g' /etc/keepalived/keepalived.conf

编写backup.sh

#!/bin/bash

prlpid=`ps -eaf |grep prl |grep Djava |awk '{print $2}'`

kill -9 $prlpid

 

编写fault.sh

#!/bin/bash

prlpid=`ps -eaf |grep prl |grep Djava |awk '{print $2}'`

kill -9 $prlpid

 

编写stop.sh

#!/bin/bash

prlpid=`ps -eaf |grep prl |grep Djava |awk '{print $2}'`

kill -9 $prlpid

 

keepalived启动命令 service keepalived start

keepalived停止命令 service keepalived stop

加入开机启动

Chkconfig keepalived on
keepalived.rar

阅读(528) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~