How to Install Netcat Traditional on RHEL 6.x for Percona Cacti Memcached Monitoring


2 views

When implementing Percona's Cacti monitoring templates for Memcached on RHEL 6.x systems, many administrators encounter compatibility issues with the default netcat package. The openbsd version of netcat (nc) included in RHEL 6.x lacks certain critical command-line options required by the monitoring scripts.


# Verify your current netcat version:
$ rpm -qi nc
Name        : nc
Version     : 1.84
Release     : 24.el6
[...]

The Percona monitoring scripts specifically require features found in the traditional netcat implementation, particularly the -q option which controls connection timeout behavior. The openbsd variant in RHEL 6.x doesn't support this parameter, causing the monitoring to fail silently.

The most reliable approach is to compile the traditional netcat from source:


# Install dependencies
$ sudo yum install gcc glibc-devel

# Download and compile traditional netcat
$ wget http://sourceforge.net/projects/netcat/files/netcat/0.7.1/netcat-0.7.1.tar.gz
$ tar xvzf netcat-0.7.1.tar.gz
$ cd netcat-0.7.1
$ ./configure
$ make
$ sudo make install

# Verify the installation
$ /usr/local/bin/nc.traditional -h

For systems where compilation isn't an option, you can attempt to convert the Debian package:


# Install alien if not available
$ sudo yum install alien

# Convert the Debian package
$ alien -t --scripts netcat-traditional_1.10-38_amd64.deb
$ tar xvzf netcat-traditional-1.10.tgz

# Install manually
$ sudo cp usr/bin/nc.traditional /usr/local/bin/

After installation, modify the Percona PHP script to point to your new netcat binary:


// In the monitoring script (usually ss_get_by_ssh.php)
$nc_cmd = '/usr/local/bin/nc.traditional -q1 $host $port';
// Remove -q1 if you're using the openbsd variant
$nc_cmd = '/usr/bin/nc -C -w1 $host $port';

Verify your setup with this test command:


$ echo "stats" | /usr/local/bin/nc.traditional -q1 localhost 11211
STAT pid 1234
STAT uptime 123456
[...]

If you still encounter issues:

  • Check SELinux context with ls -Z /usr/local/bin/nc.traditional
  • Verify firewall rules for the memcached port
  • Ensure the monitoring script has proper permissions

When implementing Percona's monitoring templates for Memcached on RHEL/CentOS 6.x systems, administrators frequently encounter compatibility issues with the default OpenBSD version of netcat (nc). The Percona Cacti scripts specifically require features found in the traditional netcat implementation.

The key differences between netcat implementations that affect Memcached monitoring:

OpenBSD netcat (default in RHEL 6.x):
- Missing -q option for quit timing
- Different command-line syntax

Traditional netcat (required by Percona):
- Supports -q option for clean exits
- Matches the expected behavior in monitoring scripts

Several methods have been attempted by the community:

1. Compiling GNU Netcat from Source

While this provides an alternative implementation, it lacks the required options:

wget http://sourceforge.net/projects/netcat/files/netcat/0.7.1/netcat-0.7.1.tar.gz
tar xvfz netcat-0.7.1.tar.gz
cd netcat-0.7.1
./configure
make
make install

2. Converting Debian Packages

Using alien to convert netcat-traditional:

wget http://ftp.us.debian.org/debian/pool/main/n/netcat/netcat-traditional_1.10-38_amd64.deb
alien -t netcat-traditional_1.10-38_amd64.deb
tar xvzf netcat-traditional-1.10.tgz
cp usr/bin/nc.traditional /usr/local/bin/

3. Building from Source RPM

For better system integration:

wget http://vault.centos.org/6.4/os/Source/SPackages/netcat-1.10-39.el6.src.rpm
rpmbuild --rebuild netcat-1.10-39.el6.src.rpm
rpm -ivh /root/rpmbuild/RPMS/x86_64/netcat-1.10-39.el6.x86_64.rpm

After successful installation, modify the Percona PHP script to use the correct netcat path:

$nc_cmd = "/usr/local/bin/nc.traditional -C -q1 $host $port";
  • Verify netcat version: nc -h | head -1
  • Test basic connectivity: echo "stats" | nc -q1 localhost 11211
  • Check script permissions and SELinux context
  • Review Cacti log files for detailed error messages

If traditional netcat proves problematic, consider these workarounds:

# Using socat instead of netcat
socat TCP:$host:$port STDIN <<< "stats"

# Using telnet (not recommended for production)
{
  sleep 1
  echo "stats"
  sleep 1
} | telnet $host $port