首页 > 代码库 > Ubuntu安装keepalived(热备份)

Ubuntu安装keepalived(热备份)


Ubuntu安装keepalived(热备份)


http://www.keepalived.org/software/keepalived-1.1.19.tar.gz


MASTER服务器


$ sudo apt-get install libpopt-dev

$ sudo apt-get install daemon

$ sudo tar zxfv keepalived-1.1.19.tar.gz

$ cd keepalived-1.1.19

$ ./configure --prefix=/usr/local/keepalived

$ make

$ sudo make install

$ sudo mkdir /etc/sysconfig

$ sudo cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/

$ sudo cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/

$ sudo cp /usr/local/keepalived/sbin/keepalived /sbin/

$ sudo mkdir /etc/keepalived

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

$ sudo vi /etc/keepalived/keepalived.conf

按a或i进入编辑模式

! Configuration File for keepalived
global_defs {
   notification_email {
yang@126.com      (当IP发生迁移等事件的时候发送邮件到指定邮箱)
   }
   notification_email_from root@localhost      (邮件发送方)
   smtp_server 127.0.0.1                (邮件外发服务器地址)
   smtp_connect_timeout 30              (邮件超时时间为30秒)
   router_id LVS_DEVEL                  (一个实例的标识)

}             
vrrp_instance VI_1 {
    State MASTER        (设置服务器模式,注要大写)
    interface eth0      (实例网卡,也就是提供服务的网卡)
    virtual_router_id 51

    priority 100        (设定权值为100 主备之间的权值差最好大于50  权值范围为0~255)

    advert_int 1        (检查时间为1秒)
    authentication {        (认证方式为密码认证)
        auth_type PASS
        auth_pass 1111
}

    virtual_ipaddress {
     10.0.1.10          (10.0.1.10并不存在)       
    }
   
}

后面的内容不用改

按Esc键退出编辑模式

:wq


$ sudo mkdir -p /etc/rc.d/init.d

$ sudo cp /usr/share/initramfs-tools/scripts/functions /etc/rc.d/init.d/

$ sudo vi /etc/init.d/keepalived +23

按a或i进入编辑模式

daemon keepalived start  (默认为daemon keepalived ${KEEPALIVED_OPTIONS})

按Esc键退出编辑模式

:wq  (保存并退出)

$ sudo mkdir /var/lock/subsys   (注:这个目录重启服务器后会消失,需要将其写道开机启动项中,如写到/etc/rc.local里)

$ service keepalived start

开机自启动

$ sudo vi /etc/rc.local

按a或i进入编辑模式

mkdir /var/lock/subsys

service keepalived start

按Esc键退出编辑模式

:wq (保存并退出)


$ sudo ip a   (可以看到eth0多了个10.0.1.10的ip)


BACKUP服务器步骤同上,只需将/etc/keepalived/keepalived.conf里的MASTER改为BACKUP,priority改为50即可


BACKUP服务器ip a显示eth0没有多出10.0.1.10这个ip,等MASTER服务器宕后就会显示出来,当MASTER服务器正常后会自动消失







本文出自 “linux” 博客,谢绝转载!

Ubuntu安装keepalived(热备份)