Install Keepalived of Linux build environment

1. Download keepalived

wget http://www.keepalived.org/software/keepalived-1.2.18.tar.gz

2. Unzip and install:

tar -zxvf keepalived-1.2.18.tar.gz -C /usr/local/

3. Download the plugin openssl

yum install -y openssl openssl-devel(需要安装一个软件包)

4. Start compiling keepalived

cd keepalived-1.2.18/ && ./configure --prefix=/usr/local/keepalived

5. Make it

make && make install

Report error: eepalived execution./configure --prefix=/usr/local/keepalived when report error: configure: error: Popt libraries is required

Reasons for this error:

The development package of popt is not installed

Solution:

yum install popt-devel

Install the popt development kit. ./Configure again.

keepalived installed as a Linux system service

 

Install keepalived as a Linux system service, because the default installation path of keepalived (default path: /usr/local) is not used. After the installation is complete, you need to do some modifications:

First create a folder and copy the keepalived configuration file:

mkdir /etc/keepalived
cp /usr/local/keepalived/etc/keepalived/keepalived.conf /etc/keepalived/
然后复制keepalived脚本文件:
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
cp /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/sbin/keepalived /usr/sbin/
ln -s /usr/local/keepalived/sbin/keepalived /sbin/
可以设置开机启动:chkconfig keepalived on,到此我们安装完毕!

keepalived common commands

service keepalived start

service keepalived stop

启动报错Starting keepalived (via systemctl):  Job for keepalived.service failed. See 'systemctl status keepalived.service' and 'journalctl -xn' for details.  

Solution

[root@edu-proxy-01 sbin]# cd /usr/sbin/  
[root@edu-proxy-01 sbin]# rm -f keepalived   
[root@edu-proxy-01 sbin]# cp /usr/local/keepalived/sbin/keepalived  /usr/sbin/  

Use keepalived virtual VIP

vi /etc/keepalived/keepalived.conf

vrrp_script chk_nginx {

    script "/etc/keepalived/nginx_check.sh" #Run the script, there is below the script content, which is to automatically start the service after a nginx downtime

    interval 2 #Detection time interval

    weight -20 #If the condition is true, the weight is -20

}

# Define virtual route, VI_1 is the identifier of virtual route, define the name by yourself

vrrp_instance VI_1 {

    state MASTER #To determine the master and slave

    interface ens33 # Bind the virtual IP network interface, fill in according to your own machine

    virtual_router_id 121 # The ID number of the virtual router, the settings of the two nodes must be the same

    mcast_src_ip 192.168.212.140 #Fill in the local ip

    priority 100 # The priority of the node, which is mainly higher than the priority of the slave node

    nopreempt # High priority setting nopreempt solves the problem of preempting again after abnormal recovery

    advert_int 1 # Multicast information sending interval, the setting of two nodes must be the same, the default is 1s

    authentication {

        auth_type PASS

        auth_pass 1111

    }

    # Add the track_script block to the instance configuration block

    track_script {

        chk_nginx #Execute the service monitored by Nginx

    }

 

    virtual_ipaddress {

        192.168.110.110 # Virtual ip, which is the ip that solves how to switch the ip of a dead program, can also be extended and has a wide range of uses. More than one can be configured.

    }

}

Guess you like

Origin blog.csdn.net/qq_41988225/article/details/85319648