List of helpfull command that used to help me when maintaining Postfix mailserver.

Hemat Pangkal Kaya

Insignificant one

List mail queue and MAIL_ID’s, list mail queue
postqueue -p
mailq

Check the postfix version
postconf mail_version

Get default value set on the postfix config
postconf -d

Get non default value set on the postfix config
postconf -n

Flush the mail queuw
postfix flush

Force to send the queue
postqueue -f

Process all emails stuck in the queue
postsuper -r ALL && postqueue -f

Read email from mail queue
postcat -q MAIL_ID

Remove certain mail from mail queue
postsuper -d MAIL_ID

Remove all mail queue
postsuper -d ALL

Fast method to remove mail from queue
find /var/spool/postfix/deferred/ -type f | xargs -n1 basename | xargs -n1 postsuper -d

Remove all the deferred mail in queue
postsuper -d ALL deferred

Sorting email with “from address” filter
postqueue -p | awk '/^[0-9,A-F]/ {print $7}' | sort | uniq -c | sort -n

Remove all email that sent to user@dom.ain
postqueue -p|grep '^[A-Z0-9]'|grep user@dom.ain|cut -f1 -d' '|tr -d \*|postsuper -d -

Remove all email sent from user@dom.ain
postqueue -p|awk '/^[0-9,A-F].*user@dom.ain / {print $1}'|cut -d '!' -f 1|postsuper -d -

Remove all email sent from the dom.ain
postqueue -p | grep '^[A-Z0-9]'|grep @dom.ain|cut -f1 -d' ' |tr -d \*|postsuper -d -

Mail queue stats short
postqueue -p | tail -n 1

Number of emails in Mail queue
postqueue -p | grep -c "^[A-Z0-9]"

Fast count of emails in mail queue
find /var/spool/postfix/deferred -type f | wc -l

Watch Log Live
tail -f /var/log/maillog

Count and sort success pop3/imap logins

grep "\-login"  /var/log/dovecot-info.log |grep "Login:"|awk {'print $7'}|sort|uniq -c|sort -n

Count and sort success SMTP postfix logins. This is usefull when you want to track a compromised account.

grep -i "sasl_username"  /var/log/maillog |awk {'print $9'}|sort|uniq -c|sort -n

Count and sort success SMTP postfix logins on exact date “May 18”

grep -i "sasl_username"  /var/log/maillog |grep "May 18"|awk {'print $9'}|sort|uniq -c|sort -n

Analyze Postfix Logs

pflogsumm /var/log/maillog | less

You may need to install the pflogsumm package first.

Previous ArticleNext Article

Leave a Reply

Your email address will not be published. Required fields are marked *

M.

Mariadb 10.4.X Memory Leak Issue

Recently, I’ve helped customer to migrate their service from single VM to 1 vm per-service. I am able to manage minimum downtime when migrating the web data and database data to each VM. All VM using latest OS and latest stack version in the repository’s.

All new VM and the dedicated service is working as expected. Then we found increase of throughput in the front-end. Further investigation shows that there a bottleneck in from the database vm, where we found an “Out of Memory”. From the log and monitoring statistic, i found that the memory usage increase dramatically once the mysql have high access but not releasing the memory until the mysqld service OOM. Even though on old environment, there is no such issue with the same configuration. By the way, old database use MariaDB 10.2 and the new one is using MariaDB 10.4.12

I have tried to tune the configuration to reduce the memory footprint, reduce the connection also tune the system kernel. But the same issue keep happening.

After searching on the web about this unexpected behavior, i got some pople that have the same issue with but there is no specific solution.
From the bug report Old Mariadb, 10.2-3 there is a memory leak issue with “Unresolved” status. Here’s the link.

Further reading result, this condition may caused by the memory allocation handler. Using this keyword i manage to found someone that have the same issue and able to resolved it by changing the memory allocation library of their MariaDB server. Please use the link to find the related infromation here.

Based on the server status, i found that the MariaDB 10.4 still using system default for their memory allocation.

MariaDB [(none)]> SHOW VARIABLES LIKE 'version_malloc_library';
+------------------------+--------+
| Variable_name          | Value  |
+------------------------+--------+
| version_malloc_library | system |
+------------------------+--------+
1 row in set (0.00 sec)

Then i am install the jmalloc library to the system so we can use it as memory allocation library on MariaDB 10.4

apt-get update apt-get 
install -y libjemalloc-dev

Then update the env configuration to use new jmalloc library for MariaDB.

cd /etc/systemd/system/mariadb.service.d/
Edit any .conf in this directory by adding information at the end-line.
Environment="LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.1"
systemctl daemon-reload
systemctl stop mariadb && systemctl start mariadb

Validate the new memory allocation library.

MariaDB [(none)]> SHOW VARIABLES LIKE 'version_malloc_library';
+------------------------+-------------------+
 | Variable_name          | Value             |
+------------------------+-------------------+
 | version_malloc_library | jemalloc 3.6.0-11 |
+------------------------+-------------------+
1 row in set (0.001 sec)

Thank You.

P.

Passing LFCS Exam (Re-write)

This December 2019, i have passed the Linux Foundation Certified System (LFCS) Administrator exam. This exam is provided by Linux Foundation Organization. An organization to maintain the open source ecosistem by provide an event, training and certification.

Twitter serve 140 character

Reality

For more details, you can visit their site here. For the Lxcf exam, here.
Having prior experience in using Linux/Unix based OS is must. Especially understand how this Operating System works generally and how to use the command line. Most of the question/task in this exam is hands-on Linux command.

For the LFCS Exam, a score of 66% or above must be earned to pass. FAQ for Linux Foundation here.

The number of the question on this exam is slightly different from each person. Seems based on the question/task weight and scoring. In my case, i have about 65-70 question.

The question domain based on my exam is;
– User/group management
– Storage management
– File manipulation
– Other’s command
By the way we can chose 2 distribution for this exam, Cent-OS/Ubuntu.

For this exam, i used the bundle package exam + course with Black Friday coupon 😀 though. But, the course is only general course how the Linux working.