Exim Commands

Exim commands for Mail issue
=====================

/usr/sbin/exim -v -Mrm (MAIL ID HERE) ==> REMOVE MAILS BY ID

/usr/sbin/exim -bp ==> LIST QUEUED MAILS

/usr/sbin/exim -bpc ==> OUTPUT NUMBER OF QUEUED MAILS

/usr/sbin/exim -bpr | grep ‘*** frozen ***’ | awk ‘{print $3}’ | xargs exim -Mrm ==> DELETE FROZEN MAILS

/usr/sbin/exim -qff -v -C /etc/exim.conf & ==> DELIVER FORCEFULLY EMAILS

/usr/sbin/exiqgrep -i -f (MAIL ADDRESS HERE) | xargs exim -Mf ==> FREEZE MAILS FROM SENDER

/usr/sbin/exiqgrep -i -f (MAIL ADDRESS HERE) | xargs exim -Mrm ==> REMOVE MAILS FROM SENDER

exim -M email-id ==> Force delivery of one message.

exim -qf ==> Force another queue run.

exim -qff ==> Force another queue run and attempt to flush the frozen message.

exim -Mvl messageID ==> View the log for the message.

exim -Mvb messageID ==> View the body of the message.

exim -Mvh messageID ==> View the header of the message

exim -Mrm messageID ==> Remove message without sending any error message

exim -Mg messageID ==> Giveup and fail message to bounce the message to the Sender

exim -bpr | grep “<” | wc -l ==> How many mails on the Queue?

exim -bpr | grep frozen | wc -l ==> How many Frozen mails on the queue

Posted in Exim, Mail server | Leave a comment

Deleting mail in postfix queue

Postfix stores mails in a queue before sending it. Sometimes you wish to remove the mails from the queue but wonder how. Postfix has a command line called postsuper which can be used to delete unsent mails from the queue. Before removing the mail from the queue it is good idea to list all mails in the queue. By issuing the command:

mailq

you will list all of the mails which are queued or simply timed out for some reason.

If you want to remove a mail from the “mailq” type:

postsuper -d mailID

where mailID is the ID of the mail in the mail queue.

Issuing the command:

postsuper -d ALL

will delete all queued mails from the mailq.

Posted in Postfix | Leave a comment

List all FTP passwords in Plesk

Login to the mysql database for Plesk

# mysql -uadmin -p`cat /etc/psa/.psa.shadow` psa

and run this query

SELECT REPLACE(sys_users.home,’Change this to your host PATH directory to Domain’,”) AS domain, sys_users.login,accounts.password FROM sys_users LEFT JOIN accounts on sys_users.account_id=accounts.id ORDER BY sys_users.home ASC;

 

example

SELECT REPLACE(sys_users.home,’/var/www/vhosts/’,”) AS domain, sys_users.login,accounts.password FROM sys_users LEFT JOIN accounts on sys_users.account_id=accounts.id ORDER BY sys_users.home ASC;

Posted in Plesk | Leave a comment

Increase SWAP space in Linux

Method 1: Use a Hard Drive Partition for Additional Swap Space

Step #1: Login as the Root User and run following commands

# mkswap /dev/sdc1

# swapon /dev/sdc1

Method 2: Use a File for Additional Swap Space

# dd if=/dev/zero of=/root/SWAPFILENAME bs=1M count=1024 (for 1 GB) Change as per requirement

# chmod 600 /root/SWAPFILENAME

# mkswap /root/myswapfile

Enable the newly created swapfile.

# swapon /root/myswapfile

Posted in Swap | Leave a comment

Set time in Linux

This document explains how to set your computer’s clock from Linux and how to set timezone. On Linux systems, you have a choice of keeping the hardware clock in UTC/GMT time or local time.

How to Set timezone

The timezone under Linux is set by a symbolic link from /etc/localtime to a file in the /usr/share/zoneinfo directory that corresponds with what timezone you are in. For example, since I’m in India ,/etc/localtime is a symlink to /usr/share/zoneinfo/Asia/Kolkata. To set this link, type:

ln -sf /usr/share/zoneinfo/your/zone /etc/localtime

Set up UTC or local time

When Linux boots, one of the initialisation scripts will run the /sbin/hwclock program to copy the current hardware clock time to the system clock. hwclock will assume the hardware clock is set to local time unless it is run with the --utc switch. Rather than editing the startup script, under Red Hat Linux you should edit the /etc/sysconfig/clock file and change the “UTC” line to either “UTC=true” or “UTC=false” as appropriate.

Set the hardware clock

To set the hardware clock, my favourite way is to set the system clock first, and then set the hardware clock to the current system clock by typing “/sbin/hwclock --systohc” (or “/sbin/hwclock --systohc --utc” if you are keeping the hardware clock in UTC). To see what the hardware clock is currently set to, run hwclock with no arguments. If the hardware clock is in UTC and you want to see the local equivalent, type “/sbin/hwclock --utc

Posted in Linux | Leave a comment

Virfs directory in CPanel

The /home/virtfs Directory is created for users with Jailshell. Virtfs is bind mount to some system files. If you delete the files in virtfs, you delete the actual system files they’re bind mount to; that’s very bad idea. When a user is logged in via jailshell, a virtual fileystem is created for the cpanel user by mounting only the selected filesystems under /home/virtfs/ so the user can (only) access the data under these filesystems. There are two option to get rid of the /home/virtfs directory:

Option One

  1. Backup your/your clients’ data, request OS reload from your host and restore your clients’ data
  2. It is best not to touch that directory. Go through the list of users in WHM >> Manage Shell Access and disable Jailed Shell for users. For more information you can refer disable virtfs PDF File.  

Option Two

Check if there’s any jailshell process running and if so, kill the process. If none, you may run the following bash one liner in order to fix this issue:

for i in `cat /proc/mounts|awk '/virtfs/ {print $2}'`; do umount $i;done

Run du again and you should see that /home/virtfs is hardly consuming any space at all

Posted in CPanel | Leave a comment

optimizing apache mysql php with low memory server

Don’t run X, shutdown all unnecessary services, and compile Apache, MySQL, and PHP with only essential functionality.

 

Apache

The biggest problem with Apache is the amount of ram is uses. I’ll discuss the following techniques for speeding up Apache and lowering the ram used.

  • Handle Fewer Simultaneous Requests
  • Loading Fewer Modules
  • Log less

Tune Apache to only have a small number of spare children running.

Prefork is where the real magic happens. This is where we can tell apache to only generate so many processes. The defaults here are high it’s eating your server memory. Make your sure httpd.conf is not configured to start too many servers, or have to many spare server best weight loss sitting around. Reference the example below:

    StartServers          1
    MinSpareServers       1
    MaxSpareServers       3
    MaxClients           10
    MaxRequestsPerChild 3000



    StartServers          1
    MinSpareThreads       5
    MaxSpareThreads      15 
    ThreadLimit          25
    ThreadsPerChild       5
    MaxClients           25
    MaxRequestsPerChild 200

Also, make sure to adjust KeepAliveTimeout to 10 or 15. In my opinion, 15 seconds is longer than a short page view requires, and shorter than a long page view requires.

Only load the modules you require

The default configuration file for apache also frequently loads every module it can. This is an especially big deal with the prefork mpm, as each apache instance will eat up geometrically more memory when unneeded modules are enabled. To check which apache modules are enabled/installed, use command below:

# apache2ctl -M

Default Apache modules (may be difference with yours):
Apache Loaded Modules

Comment out any modules that aren’t needed to save yourself some more memory. Or you can change it by use commands below:
To enable a module:

# a2enmod module_name

To disable a module:

# a2dismod module_name

You must restart the server after enable/disable the modules:

# service apache2 restart

Log Less

If you’re trying to maximize performance, you can definitely log less. In my server, I set it to error level. Also, if you don’t care about looking at certain statistics, you can choose to not log certain things, like the User-Agent or the http-referer.

# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a
# container, error messages relating to that virtual host will be
# logged here.  If you *do* define an error logfile for a
# container, that host’s errors will be logged there and not here.
#
ErrorLog ${APACHE_LOG_DIR}/error.log

#
# LogLevel: Control the number of messages logged to the error_log.
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
#
LogLevel error

I like seeing those things, but it’s up to you.

Optimize MySQL server

Tweaking MySQL to use small amounts of memory is fairly straightforward. I’m going to try to show you the why instead of the what, so you can hopefully tweak things for your specific server. We’ll look at the following MySQL types of mysql settings:

  • Things We Can Disable
  • Turning MySQL Server Parameters
  • Third Party Configuration Wizard for MySQL

To optimize mySQL we need to edit the mySQL configuration file, it’s /etc/mysql/my.conf

Things We Can Disable

MySQL allows a few different storage engines for its tables. The two most common are InnoDB and MyISAM. The main difference between the two is:

  • MyISAM offers table-level locking, meaning that when data is being written into a table, the whole table is locked, and if there are other writes that must be performed at the same time on the same table, they will have to wait until the first one has finished writing data.
  • InnoDB, on the other hand, offers row-level locking, meaning that when data is being written to a row, only that particular row is locked; the rest of the table is available for writing.

The problems of table-level locking are only noticeable on very busy servers. For the typical website scenario, usually MyISAM offers better performance at a lower server cost.

If you decide to use only MyISAM tables, you must add the following configuration lines to your my.cnf file:

default-storage-engine=MyISAM
default-tmp-storage-engine=MyISAM

If you only have MyISAM tables, you can disable the InnoDB engine, which will save you RAM, by adding the following line to your my.cnf file:

skip-innodb

If you use InnoDB from the past, here is a simple shell script to automatically convert InnoDB tables to MyISAM.

#!/bin/bash

MYSQLCMD=mysql

for db in `echo show databases | $MYSQLCMD | grep -v Database`; do
        for table in `echo show tables | $MYSQLCMD $db | grep -v Tables_in_`; do
                TABLE_TYPE=`echo show create table $table | $MYSQLCMD $db | sed -e's/.*ENGINE=\([[:alnum:]\]\+\)[[:space:]].*/\1/'|grep -v 'Create Table'`
                if [ $TABLE_TYPE = "InnoDB" ] ; then
                        mysqldump $db $table > $db.$table.sql
                        echo "ALTER TABLE $table ENGINE = MyISAM" | $MYSQLCMD $db
                fi
        done
done

 

Turning MySQL Server Parameters

There are several parameters that can be adjusted on a MySQL server to make it faster.

Key buffer size

This is probably the single most important thing you can tweak to influence MySQL memory usage and performance. MySQL tries to put everything that’s indexed into the key buffer so this is a huge performance speedup. The SQL query will be served directly from RAM. I can’t say what size you should make your key buffer, because only you know how much ram you have free.

The Query Cache

If you do the same query two times in a row, and the result fits in the query cache, mysql doesn’t have to do the query again. If you’re going for performance, this can be a huge benefit, but it can also eat up memory. So, you need setting it’s not too high and low as your website needed.
There are three variables that influence how the query cache works.

  • query_cache_size
  • query_cache_limit
  • query_cache_type

Maximum Number of Connections

It’s option parameter. If you’re already limiting the number of apache processes, then you’ll be fine. If you’re not, and you need to handle thousands of users simultaneously, you need to increase this number.

The Table Cache

Every time you access a table, MySQL loads a reference to a table as one entry in the table cache. This is done for every concurrent access of a table, it’s really important for performance, marginally so for memory usage. You can keep upping the table cache, but you’ll eventually hit a limit on the number of files your operating system can have open, so keep that in mind. If table cache is set too low, mysql will throw up on you, and you don’t want that.
Here is current my.conf that I’ve optimized on my VPS.

[mysqld]
     port            = 3306
     socket          = /var/lib/mysql/mysql.sock
     skip-locking
     key_buffer = 16K
     max_allowed_packet = 1M
     table_cache = 4
     sort_buffer_size = 64K
     read_buffer_size = 256K
     read_rnd_buffer_size = 256K
     net_buffer_length = 2K
     thread_stack = 64K

     # For low memory, InnoDB should not be used so keep skip-innodb uncommented unless required
     skip-innodb

     # Uncomment the following if you are using InnoDB tables
     #innodb_data_home_dir = /var/lib/mysql/
     #innodb_data_file_path = ibdata1:10M:autoextend
     #innodb_log_group_home_dir = /var/lib/mysql/
     #innodb_log_arch_dir = /var/lib/mysql/
     # You can set .._buffer_pool_size up to 50 - 80 %
     # of RAM but beware of setting memory usage too high
     #innodb_buffer_pool_size = 16M
     #innodb_additional_mem_pool_size = 2M
     # Set .._log_file_size to 25 % of buffer pool size
     #innodb_log_file_size = 5M
     #innodb_log_buffer_size = 8M
     #innodb_flush_log_at_trx_commit = 1
     #innodb_lock_wait_timeout = 50

     [mysqldump]
     quick
     max_allowed_packet = 16M

     [mysql]
     no-auto-rehash
     # Remove the next comment character if you are not familiar with SQL
     #safe-updates

     [isamchk]
     key_buffer = 8M
     sort_buffer_size = 8M

     [myisamchk]
     key_buffer = 8M
     sort_buffer_size = 8M

     [mysqlhotcopy]
     interactive-timeout

Optimize PHP & Caching

PHP is not very memory intensive, so I don’t think you should worry too much about memory usage, unless your app needs it, in which case the memory footprint of PHP won’t be too significant. But I’ve researched then found some tweaks of PHP configuration that decrease memory usage of your webserver.

; Limit the memory to 40M should be fine for barebones WordPress
memory_limit = 48M
realpath_cache_ttl=300
realpath_cache_size=1M
Posted in Apache, MySQL, Optimize, PHP | Leave a comment

Free Memory and Swap Activity

You can use the following command to display memory:

$ free -m

To see a list of your running processes sorted by memory use:

$ ps -eo pmem,pcpu,rss,vsize,args | sort -k 1-r | less
Posted in Memory, Swap | Leave a comment

Configure Tomcat Memory Settings

Need to configure a linux Tomcat 6.0.32 server’s memory settings. After reviewing numerous guides about configuring tomcat’s memory, I realized I am seriously confused.  I attempted to configure the heap memory by adding setenv.sh file to the /opt/apache-tomcat-6.0.32/bin folder.  Here is the content of setenv.sh file.
export CATALINA_OPTS=”-Xms768m -Xmx768m”
The server rebooted properly, but I could find nothing in any logs to indicate if I was successful.

Here is the memory configuration which needs to be done.
Heap Space = 768 MB
PermGen space = 512 MB
Eden Space = 200 MB

 

After some goggling I got,

You have…

– created “bin/setenv.sh”
– exported the CATALINA_OPTS environment variable
– added the settings to configure the initial and max heap values to 768m

You just need to…

– add -XX:PermSize and -XX:MaxPermSize to CATALINA_OPTS to configure PermGen to be 512M.
– add -XX:NewSize and -XX:MaxNewSize to CATALINA_OPTS to configure YoungGen to be 200M.
– restart your Tomcat instance

One note, unless you really, really know what you are doing I wouldn’t recommend explicitly configuring the size of the YoungGen space.  The JVM does a great job of sizing this automatically.  Unless you have done some serious load testing on your application or you have been given exact instructions by a 3td party vendor, I would suggest just using the defaults.

Lastly, there are a couple ways that you can confirm that your settings are working.

1.) Run “ps aux | grep catalina” (or some other version of the “ps” command).  Look at your Tomcat process.  You should see all of the options that you’ve put into CATALINA_OPTS (and many more) included on the command line for your process.  If you see them listed here then they are active.

2.) Connect to Tomcat with “jconsole”, click the “VM Summary” tab and look at the “VM arguments” section.  Again, you should see the options that you added to CATALINA_OPTS listed here.

3.) Run “jinfo <tomcat-pid>”.  The last thing it prints will be the VM Flags.  These should include the options that you’ve specified in CATALINA_OPTS.

Lastly, I would suggest that you read these two articles that would help to take some of the confusion out of JVM tuning.

http://www.tomcatexpert.com/blog/2011/11/16/setting-measurement-garbage-collection-apache-tomcat
http://www.tomcatexpert.com/blog/2011/11/22/performance-tuning-jvm-running-tomcat

Posted in Tomcat | Leave a comment