Cross Column

Showing posts with label Benchmark Cloning. Show all posts
Showing posts with label Benchmark Cloning. Show all posts

Wednesday, June 25, 2014

Oracle Fusion Apps: The port may already be used by another process

After cloning our benchmark (i.e., CRM FUSE) to new servers, the following issue popped up:
The port may already be used by another process
This happened only after I restarted some managed servers in the WebLogic Domain.  In this article, we will describe what happened and how to fix it.

The Issue


The port in conflict was 9020.  As described in a companion article[1], you can use netstat command in Linux to investigate:
$ netstat -an |grep 9020

tcp  0  0 ::ffff:10.214.10.20:7101    ::ffff:10.214.10.20:9020    ESTABLISHED 
tcp  0  0 ::ffff:10.214.10.20:9020    ::ffff:10.214.10.20:7101    ESTABLISHED 

So, port 9020 was truly used by another process.  What happened is that we had many Fusion applications running on the same server and many sockets were created.  For a specific application, it requires to use port 9020 to listen and this port happened to be grabbed by another process dynamically.

In [1], we have documented a way to walk around port-conflict issue—by re-ordering start-up steps.  But, that cannot be guaranteed to work every time.  So, we will look at another approach in this article.

TCP Socket


It is the socket pair that specifies the two endpoints that uniquely identifies each TCP connection in an internet.  Note that an internet connection can use different transport protocols.  Here we only cover TCP connection.

For either local or remote endpoint, it is a combination of an IP address and a port number, much like one end of a telephone connection is the combination of a phone number and a particular extension. Based on this address, TCP sockets deliver incoming data packets to the appropriate application process or thread.

A process that opens a listen port will allow multiple sockets to that port. For example, when tnslsnr listens on port 1521, there will be many sockets where one port is 1521. So that port is shared; it can only be used for connections to that one particular process. The OS will never pick that port for the dynamic side of a connection, and any attempt by another process to listen on that port will fail because the address is in use.

The other port (picked by the OS) can not be shared; it will be used exclusively by the socket assigned to that port.  For the dynamic port, it will be picked up from the ip_local_port_range. For example, on our Linux server,  it was set to be from 9000 to 65500
$cat /proc/sys/net/ipv4/ip_local_port_range
9000    65500

The Solution


Port-conflict happened when a connection tried to pick  an available port (i.e., 9020) from the range (i.e., from 9000 to 65500).  In our case, it has picked 9020, which happened to be required by another managed server.

To prevent port conflicts from happening, we need to raise the lower limit of ip_local_port_range to be higher (say, 11000):
# echo "11000 65500" >/proc/sys/net/ipv4/ip_local_port_range

Note that you need to be the root user to make this change.  If you use Redhat edition, read [2] for more details.

As you can tell, after the ip_local_port_range change, the system tried to pick dynamic ports from 11000-to-65500 range when it connects to a remote socket (note that this remote endpoint happens to be on the same server):
$ netstat -an |grep 7101

tcp  0  0 ::ffff:10.214.10.20:7101   :::*                        LISTEN
tcp  0  0 ::ffff:10.214.10.20:7101   ::ffff:10.214.10.20:19739   ESTABLISHED
tcp  0  0 ::ffff:10.214.10.20:7101   ::ffff:10.214.10.20:20506   ESTABLISHED

Before we end this article, we also want to share two nice-to-know topics:
  • Privileged Ports
  • Which Port Is Configured for AdminServer or Managed Servers

Privileged Ports


The port numbers are divided into three ranges:
  • Well Known Ports: those from 0 through 1023.
  • Registered Ports: those from 1024 through 49151
  • Dynamic and/or Private Ports: those from 49152 through 65535
The TCP/IP port numbers below 1024 are special in that normal users are not allowed to run servers on them. This is a security feature, in that if you connect to a service on one of these ports you can be fairly sure that you have the real thing, and not a fake which some hacker has put up for you.

When you run a server as a test from a non-privileged account, you will normally test it on other ports, such as 2784, 5000, 8001 or 8080, not the well-known port (say, 80).

Which Port Is Configured for AdminServer or Managed Servers


If you are not sure about the port used by Weblogic server's Admin and Managed servers, you can verify it from the configuration file $DOMAIN_HOME/config/config.xml.   For example, port 9020 was reserved for our CRMAnalyticsServer_1:

<machine>slcaf977.us.oracle.com</machine>
    <listen-port>9020</listen-port>
    <cluster>CRMAnalyticsCluster</cluster>
    <web-server>
      <name>CRMAnalyticsServer_1</name>

References

  1. How to Investigate: Failed to Bind to Port on Linux
  2. The ip_local_port_range parameters (Redhat edition)
  3. Oracle Products: What Patching, Migration, and Upgrade Mean? (Xml and More)

Saturday, February 2, 2013

Cloning Issue—IPv4 vs. IPv6

With two similarly cloned environments, one env works and another env fails. Both of them use /etc/hosts to redirect:
  • idm-db.us.oracle.com
to its own IP address[1]. However, when one of the WLS managed server tried to connect to its Admin Server using the following URL:
  • t3://[2606:a800:2010:4048:221:28ff:fefb:7756]:17001,
it failed.

In this article, we discuss how to trouble shoot and resolve this issue.

Log Messages[2]


WebLogic Server provides handlers for sending log messages to standard out, the server log file, broadcasting messages to the domain log, remote clients, and a memory buffer for tail viewing log events in the WebLogic Server Administration Console. You can achieve volume control for each type of handler by filtering log messages based on severity level and other criteria. The LogMBean, described in Oracle WebLogic Server MBean Reference[3], defines attributes for setting the severity level and specifying filter criteria for WebLogic Server handlers.

For example,  a Stdout Handler is provided in WLS—it sends stdout of the JVM in which a WebLogic Server instance runs to server terminal console.  WLS also provides a Stdout Filter which can be configured to filter log events being sent to the standard out.  By default, the Stdout Handler has a NOTICE threshold severity level. Therefore, INFO and DEBUG level messages are not sent to standard out.  There is also an attribute named RedirectStdoutToServerLogEnabled in LogMBean.  When enabled, this redirects the stdout of the JVM in which a WebLogic Server instance runs, to the WebLogic logging system.

For our case, the above-mentioned error message was found in the standard out which was redirected to a file when the WebLogic Server instance was started.

So, we need to figure out why the connection failed and why
  • [2606:a800:2010:4048:221:28ff:fefb:7756]
was referenced in the URL.  After some digging, we have found that [2606...] is the inet6 addr as shown below:

# /sbin/ifconfig
eth0      Link encap:Ethernet  HWaddr 00:31:28:FB:88:56
          inet addr:xx.xxx.xx.xxx  Bcast:xx.xxx.xx.255  Mask:255.255.248.0
          inet6 addr: 2606:a800:2010:4048:221:28ff:fefb:7756/64 Scope:Global
          inet6 addr: fe80::521:25ff:fefb:7756/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:251183 errors:0 dropped:0 overruns:0 frame:0
          TX packets:150153 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:61626169 (58.7 MiB)  TX bytes:84744375 (80.8 MiB)
          Memory:df460000-df480000

Cloning Advantage


When you clone a system, you usually have a working system to clone from.  So, if your cloned system failed to start, you can compare the working and non-working systems side-by-side.  For our case, we have found that the system that fails have ipv6 enabled and the one works didn't.

So, the next step for us to take is to disable IPv6 protocol.  First, we have tried it from the JVM level.

Disabling the IPv6 Protocol at JVM Level


Two JVM options are provided in JRockit to enable and disable ipv6 addresses as below:
  • -Djava.net.preferIPv6Addresses=true (or false)
  • -DuseIPv6Address=true (or false)
However, when we tried the above tricks from the command line that started the WLS server instance, it didn't work.  Since we don't own the application (note that we use the application as a benchmark only), we cannot change coding to make it work with IPv6.  So, the next step is for us to disable IPv6 Protocol at kernel level.

Disabling the IPv6 Protocol at Kernel Level


We have followed the instructions described in [4-6] to disable IPv6 protocol at Linux kernel level.  There are two files we (as root) have edited by adding lines as shown below:

# vi /etc/modprobe.conf
alias net-pf-10 off
alias ipv6 off
options ipv6 disable=1


#vi /etc/sysconfig/network
NETWORKING_IPV6=no

After saved and closed files, we rebooted the system. Finally, the above changes help us resolve the issue.  Be warned that your Linux platform (note that our OS is Redhat Linux) may need different configuration from the one described here.

References

  1. Simplify Cloning by Using Hosts File
  2. Configuring WebLogic Logging Services
  3. LogMBean
    • Configures the threshold severity level and filter settings for logging output.
  4. Networking IPv6 User Guide for J2SDK/JRE 1.4
  5. Linux: How To Disable The IPv6 Protocol
  6. RedHat / Centos Disable IPv6 Networking
  7. Migrating Oracle B2B from Test to Production (T2P) (Chap 10 of the Book "Getting Started with Oracle SOA B2B Integration: A Hands-On Tutorial")
    • This section provides a real-world scenario to replicate (clone) the test environment to production for Oracle SOA.
    • Oracle Fusion Middleware provides a series of scripts for this task.
  8. Oracle Products: What Patching, Migration, and Upgrade Mean?
  9. DNS and BIND, 5th edition, by Cricket Liu and Paul Albitz
    • What’s this fe80:: address?
      • These are link-local scoped addresses, derived automatically from the interfaces’ hardware addresses. The link-local scope is significant—you can’t access these addresses from anywhere but the local subnet, so don’t use them in delegation, masters substatements, and the like. 
  10. Oracle Products: What Patching, Migration, and Upgrade Mean? (Xml and More)
    • For your Oracle production systems, follow official recommendations as shown in this article.

Wednesday, November 7, 2012

Simplify Cloning by Using Hosts File

Oftentimes, you will find there is a need to install a same application on different systems.  In our case, we have a multi-tier setup for benchmark:
  • Oracle Application Testing Suite (OATS)
  • Application Server
  • Database Server
This means that individual server need to communicate with other servers using their domain names.

In this article, we will discuss the simplest way of cloning an application from one environment to another.

Hosts File


The hosts file allows you to define which domain names (websites) are linked to which IP addresses. On some platforms, it takes precedence over your DNS servers.  However, the hosts file is under the direct control of the local computer's administrator unlike the DNS. So your DNS servers may say oracle.com is linked to a specific IP address, but you can have oracle.com go anywhere you want by using hosts file.

In Microsoft Windows, hosts file is located at locations depending on your OS.  For example, for NT, 2000, XP (x86 & x64), 2003, Vista, 7and 8, it is located at:
  • %SystemRoot%\system32\drivers\etc\hosts
    • Need to have write permission on this file for the editing user
In Linux, hosts file is located at:
  • /etc/hosts
Hosts file is a plain text file and you can use any text editor to modify it as long as you are given the permission. After modification, it will take effect immediately without rebooting. So, you can restart your application to see the new changes right away.

Redirection


In its function of resolving host names, the hosts file may be used to define any host name or domain name for use in the local system. This may be used either beneficially or maliciously for various effects.  In this article, we will discuss using the mapping to redirect a website (i.e., source of cloning) to another website (i.e., destination of cloning) during the cloning of a multi-tier environment.  Because our multi-tier environment exists in a private network, there is no security concern for us.  However, it is possible for you to face serious security attacks if your hosts file is compromised[3].

As we all know, to deploy and configure any web application is a non trivial task.  As performance engineers, we often need to create similar systems on different set of servers.  Instead of  deploying and configuring web applications from scratch, it will be easier to just do the cloning.

After cloning the application from one system to another, you then need to fix platform-specific part in the cloned image.  For example, you need to change the domain names referenced in the URLs from old server's to new server's.  Domain names can also be embedded in configuration files, scripts, etc.  Either you can do a global search and replace them or you can modify hosts file to map same host names to the new IP addresses.  The latter is easier.

Cloning[4]


Cloning can be done in three stages and the most important stage is the preparation or pre-cloning.  In the following, we cover the tasks involved in these stages for Linux platforms.  For Windows, the steps are similar.
  • Pre-cloning Stage
    • nohup
      • Cloning can take hours to finish.  
        • If you use "putty" to access Linux box, remember to use "nohup" command
          • nohup is used to run a command that is immune to hangups
          • For example, you can prefix your cloning command with nohup and redirect the stderr and stdout to cloning.out file:
            • nohup {cloning command} &> cloning.out &
    • Be the right user that has the privilege to do the cloning.  
      • Sometimes, you may need to be the "root" user to do the cloning.  After the cloning, you can then reduce the accessibility to the correct level.
    • Create the same path structure on the destination as source's
      • Create symbolic links if needed
        • You may need to be root user to create the path.  But, reduce the accessibility to the correct level later.
    • Find the file system (or disk) that is big enough to hold the cloned image
      • Free space left should allow application data to grow after it starts running
    • Hosts file
      • Save the original hosts file
    • Shutdown server instances before cloning
  • Cloning Stage
    • Copy everthing needed from source machine to destination machine.  This can include
      • Server installation
      • Scripts
      • hosts file
        • Copy the new hosts file from source to destination machine and make appropriate changes
        • Validate the changes.  For example, you can use ping command to test 
    • Use rsync command to clone
      • Syntax:
        • rsync -az aroot@sourceServer:/export/home/bench/ATG/RUP3 /export/home/bench/ATG/
      • Don't forget to use nohup for the rsync
      • Try the command out with a small copy first
      • Be patient—the cloning could take hours
  • Post-cloning Stage
    • Verify that your cloned environment work as expected
      • You can test this by stages.  For example, you can
        1. Run your front end (or OATS) against original Application Server and Database Server first.  After verifying that your front end system is working correctly, move to next.
        2. Run your application server against original Databasse Server. After verifying that your middle tier is working correctly, move to next.
        3. Verifying your database server is working correctly.
        4. Run your application server against your new database server.
        5. And so on.
    • Document what you have done

Warning


Cloning applications seems to be straightforward.  But, there are limitations and caveats. You can read [5,6,9,10] for such details.  If you are cloning Oracle Fusion Middleware, read [7].  If you are moving from a test to a production environment, read [8].  Finally, you must pay attention to the license-violations-and-compliance issue when you plan a cloning.

References

  1. Oracle Application Testing Suite
  2. 6 Surprising Uses For The Windows Hosts File
  3. Hosts (Wikipedia)
  4. Cloning Application Server Middle-Tier Instances
  5. General Considerations and Limitations for Cloning
  6. ORA-00313: open failed for members of log group 1 of thread 1
  7. Cloning Oracle Fusion Middleware (Chapter 20)
  8. Moving from a Test to a Production Environment (Chapter 21)
  9. Cloning Issue—What If Host Name(s) Are Stored in the Database
  10. ORA-01031: insufficient privileges
  11. Migrating Oracle B2B from Test to Production (T2P) (Chap 10 of the Book "Getting Started with Oracle SOA B2B Integration: A Hands-On Tutorial")
    • This section provides a real-world scenario to replicate (clone) the test environment to production for Oracle SOA.
    • Oracle Fusion Middleware provides a series of scripts for this task.
  12. Oracle Products: What Patching, Migration, and Upgrade Mean? (Xml and More)
    • For your Oracle production systems, follow official recommendations as shown in this article.

© Travel for Life Guide. All Rights Reserved.

Analytical Insights on Health, Culture, and Security.