Minimizing disk I/O with DirectAdmin

DirectAdmin does quite a few things, many of which require a fair amount of disk read/writes.

If your disk is experiencing high I/O, causing a bottleneck in your system's performance, there are a few things you can do to reduce the disk access during various tasks DirectAdmin does.

  1. Backup: Enable direct_imap_backupopen in new window so that email data is directly added into the tar.gz backup file, rather than being copied first. On new installations, this is enabled by default.

  2. Backup: Disable the backup_hard_link_check by setting it to 0 in the directadmin.conf, but ENSURE you have strict_backup_permissions=1 set. Without the hard-link checks, you must run backups in strict mode, so tar.gz files are created as the User.

  3. Backup: A more complex solution is to use rsync for copying /home data to a remote box, and use the DA backups for everything else (restorations are more difficult, and this setup only saves a single copy).

  4. Backup: Add a load checker before the backups are run, which either waits for a lower load, or will abort after the maximum number of attempts is reached.

  5. Tally: Use the simple_disk_usageopen in new window setting so that the tally only relies on system quotas (apache owned files would not be found).

  6. Messages: Keep your message system pruned by automatically deleting old messages and ticketsopen in new window. An oversized list of messages/tickets can really degrade DA's ability to add new messages to the list. If you trust that your IP blocking is working as desired, you can also prevent BFM messages from being added in the first place.

  7. File Manager: Do not count folder usageopen in new window.

  8. Email Accounts page: Use a usage cache for the email list or disable pop usage counting.

The system says that I have used up all my RAM

Unix (Linux/FreeBSD) boxes can often cause confusion with memory usage. If you run "top", it will normally show you that about 98% of the memory has been used up. This is actually normal and no, you probably have not run out of RAM.

Unix is always doing its own internal house keeping with the system, thus will use up the available memory to do so. If a real program is started up and it needs that memory, the house keeping tasks are instantly dropped and that memory is freed up for the program that needs it.

You only have to be concerned with memory usage once your swap memory starts to grow. If the swap usage is less than about 10 Mb and isn't moving or growing, then you are still in the green. Only once you see your swap memory usage starting to climb do you have to worry. If that happens, then you either need more RAM, or one of your programs is using up memory quickly due to either heavy system load (e.g., volumes of MySQL queries) or possibly program memory leaks. Sometimes restarting Apache and MySQL can reduce the amount of memory used, but it will usually increase gradually back up to where it was over time.

More info at this website: http://www.linuxatemyram.com/open in new window

How to create a swap file

Some VPSs do not come with a swap file. DirectAdmin recommends to have at least 2 Gig of RAM, and some swap space as needed. The more RAM, the better, but having more than 4Gig of swap isn't as useful.

To add 4 Gig of swap, assuming you have enough space on disk, run:

dd if=/dev/zero of=/swapfile count=4096 bs=1MiB
chmod 600 /swapfile
mkswap /swapfile
swapon /swapfile
1
2
3
4

Confirm it's loaded with:

free -m
1

or by running top.

If it works, then add this to your /etc/fstab:

/swapfile   swap    swap    sw  0   0
1

Finding runtime information on a specific process ID

If you know the process ID number (PID) of a specific process, and want to know more about it (who called it, where it's running, what files it's accessing, etc.), then you can check the proc folder.

For example, if the PID number is 1234, type:

cd /proc/1234
ls -la
1
2

which will show a lot of data. The usual things to check are:

  1. cwd which is a link pointing to the current working directory. This is usually where the program was started from, but can be changed by the program, so cannot always be trusted.

  2. exe will be a link pointing to the binary that is running.

  3. status The contents of the status file will hold a human readable list of information. The important part will usually be the UID field, as that number is what the process is running as (roughly the same as "ps aux | grep 1234")

  4. fd This directory will list all open file descriptors, which are files that the process is accessing. This can be handy to find out what it's doing, if anything locally.

Another quick tool to see the details is lsof :

lsof -n -p 1234
1

How to track which process is using a certain port

If you need to figure out what is coming in or going out of your server, there are a few useful commands for this.

In this example, we're going to track connections that are using port 25.

On Linux (CentOS/Debian), you can use the netstat command:

netstat -np --protocol=inet | grep ESTABLISHED | grep :25
1

or on FreeBSD:

sockstat -c -p 25 -P tcp
1

Both types should generate a PID number. The netstat command will provide the PID number on the far right, and sockstat is the 3rd column.

Once you know the PID number that is using the connection, you can find a runtime information (see the guide above).

How to install Netdata metrics

Netdata Metricsopen in new window is used for real time, highly detailed server information.


INSTALL

cd /usr/local/directadmin/custombuild
./build netdata
1
2

COMMAND

The new command in DA will be:

CMD_NETDATA_SOCK
1

where DA is nothing more than a proxy to /var/run/netdata/netdata.sock.

This is an Admin Level only command. Access netdata with the following:

https://yourserver.example.com:2222/CMD_NETDATA_SOCK/
1

Add connection info into the high load notice

DirectAdmin will use /usr/local/directadmin/scripts/connection_info.sh script to provide connection information in high load message report. Script will spit out the netstat info for:

  • list top number of connected IPs, with their connection count
  • the IP with the most number of connections, with all connection info (including ports)
  • if /usr/sbin/ss exists, a full dump of "ss -n" for more info.

A custom copy can be used at /usr/local/directadmin/scripts/custom/connection_info.sh to fully override the default, or a hook is called from within the script, which can be created here, so you can include your own output to the Admin message /usr/local/directadmin/scripts/custom/connection_info_post.sh so that the default output is still included, without needing you to manage it if copied.. plus your own output from the connection_info_post.sh script.

Template for message may be found at /usr/local/directadmin/data/templates/load_check_message.txt.

Last Updated: 6/23/2021, 9:36:08 PM