Configure Keepalived on the cluster to achieve load balancing and keepalived Load Balancing

Source: Internet
Author: User

Configure Keepalived on the cluster to achieve load balancing and keepalived Load Balancing
Introduction:

Keepalived is a high-availability service solution based on VRRP protocol, which can be used to avoid IP spof. The purpose of Keepalived is to check the status of the server. If a web server goes down or fails to work, Keepalived will detect it and remove the faulty server from the system, in addition, other servers are used to replace the work of the server. When the server works normally, Keepalived automatically adds the server to the server group. All these work is completed automatically without manual interference, only the faulty server needs to be manually repaired.

This article describes how to use keepalived to monitor the sparkJDBC process. When a node's sparkJDBC process goes down, the VIP can be automatically switched to another node.

Keepalived to monitor the sparkJDBC Process

Application Description: keepalived is used to float VIP (virtual IP) and detect sparkJDBC processes. When a process on the Cluster Server fails, it can automatically float to another server.

1. install and configure keepalived. (This article is configured in 10.199.33.12 and 10.199.33.13) directory:

    

2. modify the configuration file keepalived. conf.

    

4. The configuration file is as follows:
Vrrp_script failed {script "/etc/keepalived/check-sparksubmit-server.sh" interval 2 # interval weight 0 global_defs {router_id LVS_DEVEL} vrrp_instance VI_1 {state BACKUP interface em1 # server Nic virtual_router_id 51 priority 90 # priority advert_int 1 authentication {auth_type PASS auth_pass 1111} track_script {chk_http_port} virtual_ipaddress {10.199.33.15 # virtual IP address }}}

4. The directory of the Process Monitoring script must be consistent with the keepalived configuration file:

Contents in the configuration file: script "/etc/keepalived/check-sparksubmit-server.sh"

5. The content of the shell script program is as follows: red indicates the name of the process and obtains the process ID through it.
#!/bin/bashldapPid=$(ps -ef |grep SparkJDBCmdss8|grep -v grep|awk '{print $2}'|grep -v PID)#echo $ldapPidif [ "$ldapPid" == "" ]; then   service keepalived stop   exit 1else   exit 0fi 

  

  

Test:

1. Start keepalived on all nodes.

2. Run the following command to view the virtual IP Address: ip

There is a VIP on kvdb02 (10.199.33.12:

  

There is no VIP on kvdb03 (10.199.33.13:

  

3. Start the sparkJDBC process on all nodes:

  

4. kill the SparkSubmit process of kvdb02:

  

5. Check the status of the virtual IP address again: ip

No VIP on kvdb02 (10.199.33.12:

 

There is a VIP on kvdb03 (10.199.33.13:

 

This is the first time I wrote a blog !!! Please correct me if there is anything wrong!

, On a business trip in Wuhan.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.