How To Install and Configure Zabbix Agent on Ubuntu 18.04

This KB explores How To Install and Configure Zabbix on Ubuntu 18.04

Navigate to https://repo.zabbix.com/zabbix/

Find the release from the current version.

wget https://repo.zabbix.com/zabbix/4.1/ubuntu/pool/main/z/zabbix/zabbix-agent_4.2.0~alpha1-1%2Bbionic_amd64.deb
# dpkg -i zabbix-agent_4.2.0~alpha1-1+bionic_amd64.deb
apt update
# service zabbix-agent start

Network Throughput Testing with iPerf

iPerf is a command-line tool used in diagnosing network speed issues by measuring the maximum network throughput a server can handle. It is particularly useful when experiencing network speed issues, as you can use iPerf to determine which server is unable to reach maximum throughput.

Basic usage:

run iperf -s on machine A then go to machine b and run iperf -c and it’ll tell you the xfer speed

Install iPerf

The iperf package is included in most Linux distribution’s repositories.

Debian and UbuntuPermalink

# apt-get install iperf

CentOS

CentOS repositories do not have iPerf. Use the EPEL repository, which is a repository used to install third-party software packages on RedHat systems such as RHEL and CentOS:

# yum install epel-release
# yum update
# yum install iperf

Arch LinuxPermalink

# pacman -S iperf

openSUSEPermalink

# zypper install iperf

GentooPermalink

# emerge iperf

If you have not yet run emaint –sync you may need to do so before it will allow you to install the iPerf package. Additionally, by default you will need to substitute each iperf command with /usr/bin/iperf3. This path may differ dependent on your iPerf version.

How to Use iPerf

iPerf must be installed on the computers at both ends of the connection you’re testing. If you are using a Unix or Linux-based operating system on your personal computer, you can install iPerf on your local machine.

If you are testing the throughput of your server, however, it’s better to use another server as the end point, as your local ISP may impose network restrictions that can affect the results of your test.

CP Clients & Servers

iPerf requires two systems because one system must act as a server, while the other acts as a client. The client connects to the server you’re testing the speed of.

On the server you plan to test, launch iPerf in server mode:

# iperf -s

You should see output similar to:

      
------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------

On your second server, connect to the first. Replace 198.51.100.5 with the first servers IP address.


# iperf -c 198.51.100.5

     
------------------------------------------------------------
Client connecting to 198.51.100.5, TCP port 5001
TCP window size: 45.0 KByte (default)
------------------------------------------------------------
[  3] local 198.51.100.6 port 50616 connected with 198.51.100.5 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.1 sec  1.27 GBytes  1.08 Gbits/sec

You will also see the connection and results on your iPerf server:


------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
[  4] local 198.51.100.5 port 5001 connected with 198.51.100.6 port 50616
[ ID] Interval       Transfer     Bandwidth
[  4]  0.0-10.1 sec  1.27 GBytes  1.08 Gbits/sec

To stop the iPerf server process, press CTRL + c.

UDP Clients & Servers

Using iPerf, you can also test the maximum throughput achieved via UDP connections.

Start a UDP iPerf server:

# iperf -s -u

      
------------------------------------------------------------
Server listening on UDP port 5001
Receiving 1470 byte datagrams
UDP buffer size:  208 KByte (default)
------------------------------------------------------------

Connect your client to your iPerf UDP server. Replace 198.51.100.5 with your IP address:


# iperf -c 198.51.100.5 -u

   
------------------------------------------------------------
Client connecting to 198.51.100.5, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  208 KByte (default)
------------------------------------------------------------
[  3] local 198.51.100.6 port 58070 connected with 198.51.100.5 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec
[  3] Sent 893 datagrams
[  3] Server Report:
[  3]  0.0-10.0 sec  1.25 MBytes  1.05 Mbits/sec   0.084 ms    0/  893 (0%)

1.05 Mbits/sec is considerably less than what was observed on the TCP tests. It is also considerably less than the maximum outbound bandwidth cap provided by the 1GB link. This is because iPerf limits the bandwidth for UDP clients to 1 Mbit per second by default.

You can change this with the -b flag, replacing the number after with the maximum bandwidth rate you wish to test against. If you are testing for network speed, set this number above the maximum bandwidth cap provided by your provider:

# iperf -c 198.51.100.5 -u -b 1000m

This tells the client that we want to achieve a maximum of 1000 Mbits per second if possible. The -b flag only works when using UDP connections, since iPerf does not set a bandwidth limit on the TCP clients.

   
------------------------------------------------------------
Client connecting to 198.51.100.5, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  208 KByte (default)
 ------------------------------------------------------------
      [  3] local 198.51.100.5 port 52308 connected with 198.51.100.5 port 5001
      [ ID] Interval       Transfer     Bandwidth
      [  3]  0.0-10.0 sec   966 MBytes   810 Mbits/sec
      [  3] Sent 688897 datagrams
      [  3] Server Report:
      [  3]  0.0-10.0 sec   966 MBytes   810 Mbits/sec   0.001 ms    0/688896 (0%)
      [  3]  0.0-10.0 sec  1 datagrams received out-of-order

This time the results are considerably higher.

Bidirectional Tests

In some cases, you may want to test both servers for the maximum amount of throughput. This can easily be done using the built-in bidirectional testing feature iPerf offers.

to test both connections, run the following command from the client:

# iperf -c 198.51.100.5 -d

The result is that iPerf will start a server and a client connection on the client server (198.51.100.6). Once this has been done, iPerf will connect the iPerf server to the client connection, which is now acting as both a server connection and a client connection.

------------------------------------------------------------
Server listening on TCP port 5001
TCP window size: 85.3 KByte (default)
------------------------------------------------------------
------------------------------------------------------------
Client connecting to 198.51.100.5, TCP port 5001
TCP window size:  351 KByte (default)
------------------------------------------------------------
[  3] local 198.51.100.6 port 50618 connected with 198.51.100.5 port 5001
[  5] local 198.51.100.6 port 5001 connected with 198.51.100.5 port 58650
[ ID] Interval       Transfer     Bandwidth
[  5]  0.0-10.1 sec  1.27 GBytes  1.08 Gbits/sec
[  3]  0.0-10.2 sec  1.28 GBytes  1.08 Gbits/sec

On the server, you will see:


------------------------------------------------------------
Client connecting to 198.51.100.6, TCP port 5001
TCP window size:  153 KByte (default)
------------------------------------------------------------
[  6] local 198.51.100.5 port 58650 connected with 198.51.100.6 port 5001
[  6]  0.0-10.1 sec  1.27 GBytes  1.08 Gbits/sec
[  5]  0.0-10.2 sec  1.28 GBytes  1.08 Gbits/sec

Options
Option Description
-f Change the format in which the tests are run. For example, you can use -f k to get results in Kbits per second instead of Mbits per second. Valid options include m (Mbits, default), k (Kbits), K (KBytes), and M (MBytes).
-V Forces iPerf to use IPv6 rather than IPv4.
-i Changes the interval between periodic bandwidth tests. For example, -i 60 will make a new bandwidth report every 60 seconds. The default is zero, which performs one bandwidth test.
-p Changes the port. When not specified, the default port is 5001. You must use this flag on both the client and server.
-B Binds iPerf to a specific interface or address. If passed through the server command, the incoming interface will be set. If passed through the client command, the outgoing interface will be set.

Curl Error With IPV6

Recently, there was an issue with a curl command that ran a script with php. The curl command would finish after a lengthy time as before it was completing within seconds.

The issue turned out to be that the command was using the IPV6 connection where in the data center the IPV6 was not active.

This was discovered with the -v option in curl.

curl -v "https://domain.com/path-to-php-script.php"
/* About to connect() to domain.com port 443 (#0)
/* Trying 2a09:2980:f0ee:a:fabe:b50c:0:2...
/* Connection timed out
/* Trying 23.17.44.888...

As you can see – the IPV6 address times out. The solution is to disable IPV6 in the network setting for the Ethernet card.

Subnet to Mask Bits conversion table

Subnet to Mask Bits conversion table
Mask CIDR Length (Mask Bits)
128.0.0.0 1
192.0.0.0 2
224.0.0.0 3
240.0.0.0 4
248.0.0.0 5
252.0.0.0 6
254.0.0.0 7
255.0.0.0 8
255.128.0.0 9
255.192.0.0 10
255.224.0.0 11
255.240.0.0 12
255.248.0.0 13
255.252.0.0 14
255.254.0.0 15
255.255.0.0 16
255.255.128.0 17
255.255.192.0 18
255.255.224.0 19
255.255.240.0 20
255.255.248.0 21
255.255.252.0 22
255.255.254.0 23
255.255.255.0 24
255.255.255.128 25
255.255.255.192 26
255.255.255.224 27
255.255.255.240 28
255.255.255.248 29
255.255.255.252 30
255.255.255.254 31
255.255.255.255 32

Benchmark Apache

How to test apache.

Create 2 files:
testload.php
test.php

Create a php file testload.php that checks the existence of another file named test.php in the same directory of two CentOS 7 servers with the same hardware characteristics and load but with different MPM. One of them will use event and the other one will use prefork.

<!--?php $filename = 'test.php'; if (file_exists($filename)) { echo "The file $filename exists"; } else { echo "The file $filename does not exist"; } ?-->

With ab, we will sent 50 (-c 50) concurrent requests at the same time and repeat the test 1000000 times

# ab -c 50 -n 100000 http://localhost/testload.php

200 simultaneous requests until 2000 requests are completed:

# ab -k -c 100 -n 2000 localhost/testload.php

Another test to localhost
PREFORK

]# ab -c 50 -n 100000 http://localhost/index.html
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking localhost (be patient)
Completed 10000 requests
Completed 20000 requests
Completed 30000 requests
^C

Server Software:        Apache/2.4.6
Server Hostname:        localhost
Server Port:            80

Document Path:          /index.html
Document Length:        15167 bytes

Concurrency Level:      50
Time taken for tests:   3596.808 seconds
Complete requests:      34570
Failed requests:        0
Write errors:           0
Non-2xx responses:      34571
Total transferred:      537122767 bytes
HTML transferred:       524331497 bytes
Requests per second:    9.61 [#/sec] (mean)
Time per request:       5202.210 [ms] (mean)
Time per request:       104.044 [ms] (mean, across all concurrent requests)
Transfer rate:          145.83 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.1      0       3
Processing:   213 5198 241.5   5203   10154
Waiting:      174 4428 227.6   4435    9302
Total:        214 5198 241.5   5203   10154

Percentage of the requests served within a certain time (ms)
  50%   5203
  66%   5264
  75%   5302
  80%   5327
  90%   5391
  95%   5449
  98%   5532
  99%   5617
 100%  10154 (longest request)

Accessing Website with IP NAT Hairpinning

The term hairpinning comes from the fact that the traffic comes from one source into a router or similar devices, makes a U-turn and goes back the same way it came.

Visualize this and you see something that looks like a hairpin.

Hairpin NAT is a useful technique for accessing an internal server using a public IP. Since you are using a public IP to attempt to access a server in your network, the traffic will attempt to go out to the internet. In order to reach the server, the traffic will need to be redirected to the correct location.
The issue with this article is that you need to load a website or use curl to access the website on an internal IP that is set up as NAT to a public IP.

Scenario:

Server1 – Web Server. Has a public IP 214.44.55.44 and is behind a firewall with the private IP 10.0.0.12.

When you try and load the site on this server, it does not load.
Fix: Set up hosts file to point to the private IP.

How to Set or Change Hostname in CentOS 7

Use this information when changing the hostname in centos 7.

Ways to show the hostname

# hostname
# hostname -s
# hostname -f
# cat /etc/hostname
# hostnamectl

How to change the hostname.
In order to change or set a CentOS 7 machine hostname, use the hostnamectl command as shown in the below command excerpt.

# hostnamectl set-hostname your-new-hostname

In order to apply the new hostname, a system reboot is required, issue one of the below commands in order to reboot a CentOS 7 machine.


# init 6
# systemctl reboot
# shutdown -r now

A second method to setup a CentOS 7 machine hostname is to manually edit the /etc/hostname file

# nano /etc/hostname