How to Check Network Port Open on Linux

Telnet

$ telnet ractest 1234
Trying 10.3.2.14...
telnet: connect to address 10.3.2.14: Connection refused

$ telnet ractest 3872
Trying 10.3.2.14...
Connected to ractest.
Escape character is '^]'.


Connection closed by foreign host.

cURL

$ curl -v telnet://ractest:1234
* About to connect() to ractest port 1234 (#0)
* Trying 10.3.2.14... Connection refused
* couldn't connect to host
* Closing connection #0
curl: (7) couldn't connect to host


$ curl -v telnet://ractest:3872
* About to connect() to ractest port 3872 (#0)
* Trying 10.3.2.14... connected
* Connected to ractest (10.3.2.14) port 3872 (#0)
* Closing connection #0

Bash

$ cat < /dev/tcp/10.3.2.14/1234
-bash: connect: Connection refused
-bash: /dev/tcp/10.3.2.14/1234: Connection refused


$ cat < /dev/tcp/10.3.2.14/3872
^C

Python

$ python
Python 2.6.6 (r266:84292, Sep 4 2013, 07:46:00)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> clientsocket.connect(('10.3.2.14',1234))
Traceback (most recent call last):
 File "<stdin>", line 1, in <module>
 File "<string>", line 1, in connect
socket.error: [Errno 111] Connection refused
>>>
>>>
>>> import socket
>>> clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>>> clientsocket.connect(('10.3.2.14',3872))
>>> clientsocket.send('\n')
1

Perl

$ perl
use IO::Socket::INET;
$| = 1;
my $socket = new IO::Socket::INET(PeerHost => '10.3.2.14',
PeerPort =>'1234',
Proto => 'tcp',
);
die "cannot connect to the server $!\n" unless $socket;
print "connected to the server\n";
^D
cannot connect to the server Connection refused

$ perl
use IO::Socket::INET;
$| = 1;
my $socket = new IO::Socket::INET(PeerHost => '10.3.2.14',
PeerPort =>'3872',
Proto => 'tcp',
);
die "cannot connect to the server $!\n" unless $socket;
print "connected to the server\n";
^D
connected to the server

On server to check port is listening

$ netstat -na|grep 1521|grep -i listen
tcp 0 0 10.3.2.14:1521 0.0.0.0:* LISTEN

On server to check connections through listening port

$ lsof -iTCP:1521

$ lsof -i :1521
COMMAND   PID  USER   FD  TYPE DEVICE    SIZE/OFF NODE NAME
ora_lreg_ 5396 oracle 49u IPv4 935666084 0t0      TCP  ractest:23228->ractest-vip:ncube-lm (ESTABLISHED)
...
..
.

ssh

$ ssh -vv HOSTNAME -p port_number

$ ssh -vv racnode2 -p 1521
OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017
debug1: Reading configuration data /home/grid/.ssh/config
debug1: /home/grid/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 58: Applying options for *
debug2: resolving "racnode2" port 1521
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to racnode2 [10.1.2.3] port 1521.
debug1: Connection established.
...
..
.

Reconfigure OS Parameters After Linux Server Memory Upgrade

Adjust OS memory parameters after more or less memory available

One of the Oracle database server ‘s memory is to be upgraded from 48GB to 72GB, so some parameters should be adjusted to take advantage of the newly added memory.

Change memlock Parameter

Modify “memlock” parameter in /etc/security/limits.conf to 70G, which is for hugepage purpose. This parameter can be bigger than SGA, up to or even bigger than memory size.

oracle  soft      memlock  73400320
oracle  hard      memlock  73400320
  grid  soft      memlock  73400320
  grid  hard      memlock  73400320

Change nr_hugepages Parameter

Change parameter ‘nr_hugepages’  in /etc/sysctl.conf.
43GB memory( 60% of whole memory ) is allocated to hugepages.

vm.nr_hugepages = 22016

Change shmmni, shmall and shmmax  values in /etc/sysctl.conf

 a)Keep kernel.shmmni = 4096

b) kernel.shmall=13369344 (51GB)  = 70% of whole memory divided by page size 4096.

c ) kernel.shmmax=38654705664( 36GB) =  50% of the whole memory size.

kernel.shmmni = 4096
kernel.shmall = 13369344
kernel.shmmax = 38654705664

Reconfigure SGA_TARGET and SGA_MAX_SIZE

Make sure the total SGA usage is less than vm.nr_hugepages = 22016( 43GB).

How to Configure SHMMAX SHMMNI SHMALL ?

Every DBA is so familiar with those three kernel parameters in Linux — SHMMAX, SHMMNI and SHMALL. Most of the time, the default values are used by majority clients. But sometime, those three parameters need to be reconfigured to reflect the system memory sizing and total databases SGA sizing.

What are SHMMAX SHMMNI SHMALL ?

SHMMAX :  The maximum size in bytes of a single shared memory segment that a Linux process can allocate in its virtual address space.

 SHMMNI: The system wide maximum number of shared memory segments.

SHMALL: The total amount of shared memory pages that can be used system wide.

How to check current SHMMAX SHMMNI SHMALL values ?

run “ipcs -lm”

$ipcs -lm

------ Shared Memory Limits --------
max number of segments = 4096   <-------------- SHMMNI
max seg size (kbytes) = 273678336  <----------- SHMMAX
max total shared memory (kbytes) = 371195904 <- SHMALL * PAGE_SIZE
min seg size (bytes) = 1

Check the values in proc file system.

$ getconf PAGE_SIZE
4096

$ cat /proc/sys/kernel/shmall
92798976


$ cat /proc/sys/kernel/shmmax
280246616064


$ cat /proc/sys/kernel/shmmni
4096

How to change SHMMAX SHMMNI SHMALL values ?

Change them in the proc file system without reboot

# echo 92798976 > /proc/sys/kernel/shmall

# echo 4096 >  /proc/sys/kernel/shmmni

# echo 280246616064 > /proc/sys/kernel/shmmax

Use sysctl without reboot

# sysctl -w kernel.shmall=92798976

# sysctl -w kernel.shmmni=4096

#  sysctl -w kernel.shmmax=280246616064

To make the change permanent

This file is used during the boot process.

Edit /etc/sysctl.conf with below lines:

kernel.shmmni = 4096
kernel.shmall = 92798976
kernel.shmmax = 280246616064

What are the optimal values for  SHMMAX SHMMNI SHMALL ?

SHMMAX : Either SGA size of any individual database or half size of the system memory, whichever is the higher.

SHMMNI: Normally default value 4096 should be sufficient.

SHMALL: The sum of all the SGAs on the system, divided by the page size. The page size can be gotton by :

 $ getconf PAGE_SIZE
 4096

ORA-27154 ORA-27300 ORA-27301 ORA-27302 from Instance Startup

Always make sure “kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI” set-up correctly to avoid issues.

The following errors occurred while starting up a 12.2.0.1 Oracle database instance.

SQL> startup

ORA-27154: post/wait create failed
ORA-27300: OS system dependent operation:semget failed with status: 28
ORA-27301: OS failure message: No space left on device
ORA-27302: failure occurred at: sskgpcreates

The error “operation:semget failed with status: 28” points out that it could be semaphore resource issue.

Oracle 12.2.0.1 doc recommended minimum value for semaphore are :

kernel.sem = SEMMSL SEMMNS SEMOPM SEMMNI
SEMMSL - max semaphores per array
SEMMNS - max semaphores system wide
SEMOPM - max ops per semop call
SEMMNI - max number of arrays

semmsl  =   250
semmns  = 32000
semopm  =   100
semmni  =   128

Check current system configuration for semaphores:

$ cat /proc/sys/kernel/sem
250 32000 100 200

$ ipcs -ls

------ Semaphore Limits --------
max semaphores per array   = 250
max semaphores system wide = 32000
max ops per semop call     = 100
max number of arrays       = 200
semaphore max value        = 32767

We can see SEMMNS is not right. it is supposed to be equal to SEMMSL*SEMMNI =250*200=50000.

If  SEMMNS  value too small, then we have to increase SEMMNI first, then adjust SEMMNS to SEMMSL*SEMMNI.

Set semaphore kernel parameter dynamically without the need for server reboot:

# sysctl -w kernel.sem="250 50000 100 200"
kernel.sem = 250 50000 100 200

-- Put into file
cat /etc/sysctl.conf | grep kernel.sem
kernel.sem = 250 50000 100 200

Or put into /etc/sysctl.conf file first, then

# sysctl -p

Then verify the current semaphore configurations:

# ipcs -ls

------ Semaphore Limits --------
max number of arrays       = 200
max semaphores per array   = 250
max semaphores system wide = 50000
max ops per semop call     = 100
semaphore max value        = 32767

Finally start up instance successfully.

SQL> startup
ORACLE instance started.

Total System Global Area 4294967296 bytes
Fixed Size 8801008 bytes
Variable Size 1073743120 bytes
Database Buffers 3187671040 bytes
Redo Buffers 24752128 bytes
Database mounted.
Database opened.

How to Disable SELinux or Set SELinux to Permissive Mode

Make sure to disable SELinux or set SELinux to permissive mode for Oracle GI/RAC Linux servers.

It is recommended by Oracle to disable SELinux or set SELinux to permissive mode for Oracle GI/RAC. Otherwise you might get similar below errors:

Disk "ASM_DISK1" does not exist or is not instantiated
Writing disk header: done
Instantiating disk: oracleasm-instantiate-disk: Unable to open manager: No such file or directory 
failed
Clearing disk header: done

Subscribe to get access

Read more of this content when you subscribe today.