Some LVS experiment configurations, tools and solutions, and lvs experiment configuration Solutions

Source: Internet
Author: User

Some LVS experiment configurations, tools and solutions, and lvs experiment configuration Solutions

Recently, we have conducted some LVS configuration and solution Verification experiments to record some configurations, tools, and specific solutions used in the process. Use the DR mode. Verify a RealServer upgrade or restart solution that does not interrupt services.

Network Planning:

Node IP address
Ceph1 (RealServer1) 172.16.0.114
Ceph2 (RealServer2) 172.16.0.115
Ceph4 (DirectServer) 172.16.0.113
Client: Win 8.1 172.16.0.100
I. Configuration 

DirectServer:

vip=172.16.0.113
r1ip=172.16.0.114
r2ip=172.16.0.115
port=$1
if [ -z "$port" ]
then
        port=2100
fi
 
ipvsadm -C
ipvsadm -A -t ${vip}:${port} -s wrr
ipvsadm -a -t ${vip}:${port} -r ${r1ip}:${port} -g
ipvsadm -a -t ${vip}:${port} -r ${r2ip}:${port} -g

 

RealServer:

#!/bin/sh
VIP=172.16.0.113
BROADCAST=172.16.0.255 #vip's broadcast
 
Usage ()
{
        echo "Usage:`basename $0` (start|stop)"
exit 1
}
 
if [ $# -ne 1 ];then
        Usage
fi
 
case $1 in
start)
        echo "reparing for Real Server"
        echo "1" >;/proc/sys/net/ipv4/conf/lo/arp_ignore
        echo "2" >;/proc/sys/net/ipv4/conf/lo/arp_announce
        echo "1" >;/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "2" >;/proc/sys/net/ipv4/conf/all/arp_announce
        /sbin/ifconfig lo:0 $VIP netmask 255.255.255.255 broadcast $BROADCAST up
        /sbin/route add -host $VIP dev lo:0
;;
stop)
        /sbin/ifconfig lo:0 down
        echo "0" >;/proc/sys/net/ipv4/conf/lo/arp_ignore
        echo "0" >;/proc/sys/net/ipv4/conf/lo/arp_announce
        echo "0" >;/proc/sys/net/ipv4/conf/all/arp_ignore
        echo "0" >;/proc/sys/net/ipv4/conf/all/arp_announce
        echo "stop Real Server"
;;
*)
        Usage
Esac
The above configuration is a standard DR mode configuration.

Ii. Tools

The RealServer provides the TCP Server service that can listen to fixed ports and receive data sent from the client over the TCP connection. It prints the received data to the screen and replies the current node information to the client, this allows the client to differentiate which RealServer provides a specific service.

The Service Code is as follows:
package com;
 
import java.net.ServerSocket;
import java.net.Socket;
import java.io.IOException;
 
publicclass Server
{
 
publicstaticvoid main(String[] args) throws IOException
    {
 
if (args.length < 1)
        {
            System.out.println("arguments error!\nusage: java -jar tcpser.jar server port");
            System.exit(0);
        }
 
int serverport = Integer.parseInt(args[0]);
 
        System.out.println("==============TCP SERVER==============");
 
        ServerSocket server = null;
try
        {
            server = new ServerSocket(serverport);
            System.out.println("Listening Port is " + server.getLocalPort() + "...");
while (true)
            {
                Socket connectedCli = server.accept();
                System.out.println("a new client: " + connectedCli.getInetAddress() + ":" + connectedCli.getPort());
new DataProcesser(connectedCli).start();
            }
        }
catch (Exception e)
        {
            e.printStackTrace();
        }
finally
        {
if (server != null)
            {
                server.close();
            }
        }
    }
}

 

package com;
 
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.InetAddress;
import java.net.Socket;
 
publicclass DataProcesser extends Thread
{
private Socket cli;
 
public DataProcesser(Socket clientsocket)
    {
        cli = clientsocket;
    }
 
    @Override
publicvoid run()
    {
        BufferedReader reader = null;
        BufferedWriter writer = null;
try
        {
            reader = new BufferedReader(new InputStreamReader(cli.getInputStream()));
            writer = new BufferedWriter(new OutputStreamWriter(cli.getOutputStream()));
while (true)
            {
                String receivedString = reader.readLine();
if (receivedString != null)
                {
                    System.out.println(cli.getInetAddress() + ":" + cli.getPort() + " " + receivedString);
                    String hostname = InetAddress.getLocalHost().getHostName();
                    writer.write("it's from the host: " + hostname);
                    writer.write("\n");
                    writer.flush();
                }
if ("shutdown".equals(receivedString))
                {
break;
                }
            }
 
        }
catch (Exception e)
        {
            e.printStackTrace();
        }
finally
        {
if (reader != null)
            {
try
                {
                    reader.close();
                }
catch (Exception e2)
                {
                    e2.printStackTrace();
                }
            }
 
if (cli != null)
            {
try
                {
                    cli.close();
                }
catch (Exception e2)
                {
                    e2.printStackTrace();
                }
            }
 
        }
    }
}
Export the preceding server code as a jar package: server. jar and deploy it on two realservers. the startup information is as follows:
root@ceph1:~# java -jar server.jar 2100
==============TCP SERVER==============
Listening Port is 2100...
a new client: /172.16.0.100:49314
A new client:/172.16.0.100: 49316

Client tool:

Client tools directly use the open source sockettest tool: http://sourceforge.net/projects/sockettest/

Iii. Verify a secure exit mechanism of RealServer

When IPVS is accepting services, IPVS distributes requests to the two nodes according to the specified rules. When a business node needs to be restarted, there will be two problems: 1. The ongoing business will be interrupted, for example, data interaction on TCP will be interrupted; 2. How to ensure that no new services are sent to the nodes that need to be restarted? If the LVS server is used to kick out the business nodes, access requests are also interrupted.

Among them, question 1 generally requires the service itself to make judgments, determine that all services are completed, and then perform power-off and restart operations.

For question 2, you need to find a safe solution to remove business nodes. It neither affects the service requests of the Access Point, nor allows new services to be sent to the node. Consider using Weighted Round Robin to set the weight of a service node to 0, so that the node will no longer have services. However, the node is not deleted from the lvs configuration. Therefore, existing services are not affected.

Combined with the client tool and the server's persistent connection support method, the above scheme can be easily verified. verification steps:

1. Configure the DirectServer and send two distribution records to the ceph1 and ceph2 nodes;
2. Configure the RealServer and start the TCP Server service;
3. Use the sockettest tool on Windows to establish persistent connections with the lvs vip. 4. modify the configuration on LVS:
Ipvsadm-e-t 172.16.0.113: 2100-r 172.16.0.114: 2100-w 0
 

5. Check whether the connection established with node 114 is disconnected and whether data can be sent and accepted. The verification result is: the connection is not closed, and the connection can continue to process data.
6. Whether the new request received by DirectServer will still be forwarded to the 114 node. The verification result is: the weight is 0, and all services are sent only to another business node.
7. The entire verification has ended.

During RealServer maintenance, the refined maintenance service is not damaged. You can use the above solution.

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.