Saturday, November 28, 2009

Enable Quota in VPS ( openvz )

If you are experiencing an issue with OpenVZ VPS disk quota, please make sure that the following values are set in the VPS conf.


VPS conf Location : /etc/vz/conf/VEId.conf


In the main node, do the following steps.


1) #grep DISK_QUOTA /etc/vz/conf/VEId.conf


If no disk quota value has found ot it is disabled, change the value to


DISK_QUOTA=yes


2) Check that disk quota is enabled in the main server itself.


grep DISK_QUOTA /etc/sysconfig/vz


If not enable the value to yes in the conf.


DISK_QUOTA=yes


3) Check for the value quotaugidlimit .


#grep -i quotaugidlimit /etc/vz/conf/veid.conf




4) Check the quota module "vzdquota" is loaded or notin main node.


# lsmod |grep -i vzdquota


5) You can set the value quotaugidlimit from the main node using the below command.


vzctl set veid –quotaugidlimit 500 –save


6) Make sure to reboot the mentioned node from the main node.


vzctl restart veid


7) Enter the the node for which you are experiencing the problem.


vzctl enter veid


Type the command 'mount'. It should give a similar output.


# mount
/dev/simfs on / type reiserfs (rw,usrquota,grpquota)
/proc on /proc type proc (rw)
/sys on /sys type sysfs (rw)
none on /dev type tmpfs (rw)
none on /dev/pts type devpts (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)


Also make sure that symbolic links are existing from aquota.group and aquota.user to their respectve physical locations.




# ll
total 64
lrwxrwxrwx 1 root root 39 Oct 19 11:41 aquota.group -> /proc/vz/vzaquota/00000030/aquota.group
lrwxrwxrwx 1 root root 38 Oct 19 11:41 aquota.user -> /proc/vz/vzaquota/00000030/aquota.user

Sunday, November 22, 2009

Create VPS nodes in OpenVZ

Steps for creating nodes in OpenVZ.

1. First of all check if the templates are available. Go to the vz cache directory

[root@server ~]# cd /vz/template/cache

[root@server cache]# pwd
/vz/template/cache
[root@server cache]# ll
total 1356612
-rw-r--r-- 1 root  root  158160318 Jul 10  2010 centos-4-x86.tar.gz
-rw-r--r-- 1 root  root  158609159 Sep 14 16:11 centos-4-x86.tar.gz.1
-rw-r--r-- 1 root  root  130092151 May 13  2008 centos-5-i386-default.tar.gz
-rw-r--r-- 1 root  root  191595463 Sep 14 16:16 centos-5-x86_64.tar.gz
-rw-r--r-- 1 root  root  180022352 Apr 26  2010 centos-5-x86.tar.gz
-rw-r--r-- 1 root  root  212917989 Sep 14 16:25 centos-6-x86_64.tar.gz
-rw-r--r-- 1 root  root  117087334 Nov 12  2010 debian-4.0-x86.tar.gz
[root@server cache]#
[root@server cache]#

if you do not have any templates you can download the precreated templates from the openvz website

http://wiki.openvz.org/Download/template/precreated

Once downloaded follow the steps below to create the nodes.


[root@server ~]# vzctl create 101 --ostemplate centos-5-i386-default --config vps.basic
[root@server ~]# vzctl set 101 --onboot yes --save
[root@server ~]# vzctl set 101 --hostname training.server.com --save
[root@server ~]# vzctl set 101 --ipadd 192.168.0.101 --save
[root@server ~]# vzctl set 101 --nameserver 4.2.2.2 --save
[root@server ~]# vzctl start 101
[root@server ~]# vzctl exec 101 /etc/init.d/sshd start
[root@server ~]# vzctl exec 101 passwd

Hope this helps!

cpDav service failed : Solution

There have been a number of tickets (and a few forum posts), regarding emails for the perl modules Net::DAV::Server and XML::LibXML not being installed properly.

It turns out this is an issue with the libxml2 package (not the perl module) on 64-bit CentOS systems.

Anyone encountering this, here is the fix (from the cPanel 11 release notes):

CODE
Issue: Conflicting libxml installs cause cpdavd (Web Disk Server) to fail. 64 bit linux only
Symptoms: cpdavd won’t start, running /usr/local/cpanel/bin/checkperlmodules shows that XML::libXML will not install and Net::DAV::Server will not install

Solution: Run https://your.IP.here:2087/scripts2/autofixer and enter libxml64fix.


This fix downloads the libxml2 source code and compiles the newest versions. The yum package manage apparently doens't have the latest version for CentOS in their repository, I guess.

Here's a relevent Cpanel forums topic:
http://forums.cpanel...ead.php?t=67047

cPanel Logs

Applications can log the system activity in two ways, one being according to their autonomous logic & the other through the system’s log daemon, well know as syslog..

The syslog daemon’s configuration file /etc/syslog.conf contains all the necessary paths/locations as to where the logs are stored.

Usually the directory /var/log/ is used for the system logs but other applications use the applications specified directories to store their log files…
Many distributions provide tools to manage and analyze the system logs.

Logrotate is a well known log rotation tool which usually is configured in the /etc/logrotate.conf file.
It may also have additional package-defined configurations in the /etc/logrotate.d/ directory..
In order to understand what’s happening on the system a brief analysis of /etc/syslog.conf is mandatory for checking the main logs positions.

Here are some basic log files, their locations & a brief description which can be found in Linux distros [mostly in cPanel ]:
General:

Quote:
cPanel/WHM Initial Installation Errors:
Location : /var/log/cpanel*install*
Description : These log files contain cPanel installation logs & should be referenced first for any issues resulting from new cPanel installations..
Quote:
Cpanel/WHM Service Status Logs:
Location : /var/log/chkservd.log
Description :The service monitoring demon (chkservd) logs all service checks here. Failed service are represented with a [-] and active services are represented by [+].
Quote:
Cpanel/WHM Accounting Logs:
Location : /var/cpanel/accounting.log
Description : Contains a list of accounting functions performed through WHM, including account removal and creation..

cPanel/WHM Specific Requests and Errors:

Quote:
cPanel error logs:
Location : /usr/local/cpanel/logs/error_log
Description : cPanel logs any error it incurs here. This should be checked when you encounter errors or strange behavior in cPanel/WHM…
Quote:
cPanel License Error Logs:
Location : /usr/local/cpanel/logs/license_log
Description : All license update attempts are logged here. If you run into any errors related to license when logging in, check here.
Quote:
Stats Daemon Logs:
Location : /usr/local/cpanel/logs/stats_log
Description : The stats daemon (cpanellogd) logs the output from all stats generators (Awstats, Webalizer, Analog) here.
Quote:
Client Information, Requested URL Logs:
Location : /usr/local/cpanel/logs/access_log
Description : General information related to access cPanel requests is logged here.
Quote:
cPanel/WHM Update Logs:
Location : /var/cpanel/updatelogs/update-[TIMESTAMP].log
Description : Contains all output from each cPanel update [upcp]. It’s named with the timestamp at which the upcp process was initiated..
Quote:
Bandwidth Logs:
Location : /var/cpanel/bandwidth
Description : Files contain a list of the bandwidth history for each account. Each named after their respective user.
Quote:
Tailwatchd [New]:
Location : /usr/local/cpanel/logs/tailwatchd_log
Description : Logs for daemon configuired under tailwatchd ie. cPBandwd, Eximstats, Antirelayd.

Apache Logs:

Quote:
General Error and Auditing Logs:
Location : /usr/local/apache/logs/error_log
Description : All exceptions caught by httpd along with standard error output from CGI applications are logged here..
The first place you should look when httpd crashes or you incur errors when accessing website.
Quote:
Apache SuExec Logs:
Location : /usr/local/apache/logs/suexec_log
Description : Auditing information reported by suexec each time a CGI application is executed. Useful for debugging internal server errors, with no relevant information being reported to the Apache error_log, check here for potential suexec policy violations…
Quote:
Domain Access Logs:
Location : /usr/local/apache/domlogs/domain.com
Description : General access log file for each domain configured with cPanel.
Quote:
Apache Access Logs:
Location : /usr/local/apache/logs/access_log
Description : Complete web server access log records all requests processed by the server.
Exim :

Quote:
Message Reception and Delivery:
Location : /var/log/exim_mainlog or /var/log/exim/mainlog
Description : Receives an entry every time a message is received or delivered.
Quote:
Exim ACLs/Policies based RejectLog :
Location : /var/log/exim_rejectlog
Description : An entry is written to this log every time a message is rejected based on either ACLs or other policies eg: aliases configured to :fail
Quote:
Unexpected or Fatal Errors:
Location : /var/log/exim_paniclog
Description : Logs any entries exim doesn’t know how to handle. It’s generally a really bad thing when log entries are being written here, and they should be properly investigated..
Quote:
IMAP/POP/SpamAssassin General Logging and Errors:
Location : /var/log/maillog & /var/log/messages
Description : The IMAP, POP, and SpamAssassin services all log here. This includes all general logging information (login attempts, transactions, spam scoring), along with fatal errors.

FTP:

Quote:
FTP Logins and General Errors:
Location : /var/log/messages
Description : General information and login attempts are logged here..
Quote:
FTP Transactions logging:
Location : /var/log/xferlog or /var/log/messages
Description : Is a symbolic link in most cases to /usr/local/apache/domlogs/ftpxferlog, which contains a history of the transactions made by FTP users…

MySQL:

Quote:
MySQL General Information and Errors :
Location : /var/lib/mysql/$(hostname).err
Description : This path could vary, but is generally located in /var/lib/mysql. Could also be located at /var/log/mysqld.log

Security:

Quote:
Authentication attempts:
Location : /var/log/secure
Description : Logs all daemons which requires PAM Authentication.
Quote:
Tracking all Bad Logins and Logouts:
Location : /var/log/btmp
Description : Log of all attempted bad logins to the system. Accessed via the lastb command..
Quote:
Tracking all Logins and Logouts:
Location : /var/log/wtmp
Description : The wtmp file records all logins and logouts.
Quote:
Last Logins:
Location : /var/log/lastlog
Description : Database times of previous user logins. The lastlog file is a database which contains info on the last login of each user.
Quote:
WebDav or WebDisk Log :
Location : /usr/local/cpanel/logs/cpdavd_error_log
Description : The cpdavd daemon is “WebDav” (better known as “WebDisk”) which was introduced in cPanel 11 to allow users to mount their home directory on their personal computer, always having access to the files and content…
Quote:
Cphulkd Logs:
Location : /usr/local/cpanel/logs/cphulkd_errors.log
Description : cPHulk Brute Force Protection prevents malicious forces from trying to access your server’s services by guessing the login password for that service….
It blacklists IPs that it thinks are trying to run a brute force attack.
Quote:
Failure Logging:
Location : /var/log/faillog
Description : Faillog formats the contents of the failure log from /var/log/faillog database. It also can be used for maintains failure counters and limits. Run faillog without arguments display only list of user faillog records who have ever had a login failure.
Quote:
Startup/Boot, Kernel & Hardware error messages :
Location : /var/log/dmesg
Description : dmesg is a “window” into the kernels ring-buffer. It’s a message buffer of the kernel. The content of this file is referred to by the dmesg command. It shows bootlog and the hardware errors..

Saturday, November 7, 2009

How to change your Exim outgoing mail IP, A Quick setup



1. Open the file /etc/mailips


[root@server ~]# vi /etc/mailips


enter the following and save the file

*: IP 

example:  *: 192.168.0.10

assuming 192.168.0.10 is your secondary IP.

IP - the IP you wish to send emails from. The * symbol specifies all domains to send emails from this IP

2. Now edit /etc/mail_reverse_dns

Enter the reverse DNS aka rDNS for the above IP and save the file

IP rdns

Example: 192.168.0.10 server.mail.com

3. Now change the attributes to immutable

[root@server ~]#  chattr +i  /etc/mail_reverse_dns
[root@server ~]#  chattr +i  /etc/mailips


4. Restart exim and thats it!


[root@server ~]# /etc/init.d/exim restart


Send a test email as root and check the headers to confirm.




Hope this helps :)

Wednesday, August 5, 2009

Useful Exim Commands continued...

[1] Removing Bad Mail

for i in `exiqgrep -i -f nobody`; do exim -Mrm $i; done >> Removes Nobody Mail

for i in `exiqgrep -i -o 259200`; do exim -Mrm $i; done >> Removes Mail Older than 3 Days

for i in `exiqgrep -i -f "^<>$"`; do exim -Mrm $i; done >> Removes Mail with Weird Characters (Spam)

[2] Delete Mail by a Domain

for i in `exiqgrep -i -f domain.com`; do exim -Mrm $i; done

[3] Delete Mail for a Domain

for i in `exiqgrep -i -r domain.com`; do exim -Mrm $i; done

[4] Remove Whole Mail Queue

for i in `exiqgrep -i -f `; do exim -Mrm $i; done

[5] Run Mail Queue

runq -qqff&

Useful Exim Commands continued...(copied from net)

Here are some useful things to know for managing an Exim 4 server. This assumes a prior working knowledge of SMTP, MTAs, and a UNIX shell prompt.

Message-IDs and spool files

The message-IDs that Exim uses to refer to messages in its queue are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ. Most commands related to managing the queue and logging use these message-ids.

There are three -- count 'em, THREE -- files for each message in the spool directory. If you're dealing with these files by hand, instead of using the appropriate exim commands as detailed below, make sure you get them all, and don't leave Exim with remnants of messages in the queue. I used to mess directly with these files when I first started running Exim machines, but thanks to the utilities described below, I haven't needed to do that in many months.

Files in /var/spool/exim/msglog contain logging information for each message and are named the same as the message-id.

Files in /var/spool/exim/input are named after the message-id, plus a suffix denoting whether it is the envelope header (-H) or message data (-D).

These directories may contain further hashed subdirectories to deal with larger mail queues, so don't expect everything to always appear directly in the top /var/spool/exim/input or /var/spool/exim/msglog directories; any searches or greps will need to be recursive. See if there is a proper way to do what you're doing before working directly on the spool files.

Basic information

Print a count of the messages in the queue:

root@localhost# exim -bpc

Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient):

root@localhost# exim -bp

Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):

root@localhost# exim -bp | exiqsumm

Print what Exim is doing right now:

root@localhost# exiwhat

Test how exim will route a given address:

root@localhost# exim -bt alias@localdomain.com
user@thishost.com
<-- alias@localdomain.com
router = localuser, transport = local_delivery
root@localhost# exim -bt user@thishost.com
user@thishost.com
router = localuser, transport = local_delivery
root@localhost# exim -bt user@remotehost.com
router = lookuphost, transport = remote_smtp
host mail.remotehost.com [1.2.3.4] MX=0

Run a pretend SMTP transaction from the command line, as if it were coming from the given IP address. This will display Exim's checks, ACLs, and filters as they are applied. The message will NOT actually be delivered.

root@localhost# exim -bh 192.168.11.22

Display all of Exim's configuration settings:

root@localhost# exim -bP

Searching the queue with exiqgrep

Exim includes a utility that is quite nice for grepping through the queue, called exiqgrep. Learn it. Know it. Live it. If you're not using this, and if you're not familiar with the various flags it uses, you're probably doing things the hard way, like piping `exim -bp` into awk, grep, cut, or `wc -l`. Don't make life harder than it already is.

First, various flags that control what messages are matched. These can be combined to come up with a very particular search.

Use -f to search the queue for messages from a specific sender:

root@localhost# exiqgrep -f [luser]@domain

Use -r to search the queue for messages for a specific recipient/domain:

root@localhost# exiqgrep -r [luser]@domain

Use -o to print messages older than the specified number of seconds. For example, messages older than 1 day:

root@localhost# exiqgrep -o 86400 [...]

Use -y to print messages that are younger than the specified number of seconds. For example, messages less than an hour old:

root@localhost# exiqgrep -y 3600 [...]

Use -s to match the size of a message with a regex. For example, 700-799 bytes:

root@localhost# exiqgrep -s '^7..$' [...]

Use -z to match only frozen messages, or -x to match only unfrozen messages.

There are also a few flags that control the display of the output.

Use -i to print just the message-id as a result of one of the above two searches:

root@localhost# exiqgrep -i [ -r | -f ] ...

Use -c to print a count of messages matching one of the above searches:

root@localhost# exiqgrep -c ...

Print just the message-id of the entire queue:

root@localhost# exiqgrep -i

Managing the queue

The main exim binary (/usr/sbin/exim) is used with various flags to make things happen to messages in the queue. Most of these require one or more message-IDs to be specified in the command line, which is where `exiqgrep -i` as described above really comes in handy.

Start a queue run:

root@localhost# exim -q -v

Start a queue run for just local deliveries:

root@localhost# exim -ql -v

Remove a message from the queue:

root@localhost# exim -Mrm  [  ... ]

Freeze a message:

root@localhost# exim -Mf  [  ... ]

Thaw a message:

root@localhost# exim -Mt  [  ... ]

Deliver a message, whether it's frozen or not, whether the retry time has been reached or not:

root@localhost# exim -M  [  ... ]

Deliver a message, but only if the retry time has been reached:

root@localhost# exim -Mc  [  ... ]

Force a message to fail and bounce as "cancelled by administrator":

root@localhost# exim -Mg  [  ... ]

Remove all frozen messages:

root@localhost# exiqgrep -z -i | xargs exim -Mrm

Remove all messages older than five days (86400 * 5 = 432000 seconds):

root@localhost# exiqgrep -o 432000 -i | xargs exim -Mrm

Freeze all queued mail from a given sender:

root@localhost# exiqgrep -i -f luser@example.tld | xargs exim -Mf

View a message's headers:

root@localhost# exim -Mvh 

View a message's body:

root@localhost# exim -Mvb 

View a message's logs:

root@localhost# exim -Mvl 

Add a recipient to a message:

root@localhost# exim -Mar  
[
... ]

Edit the sender of a message:

root@localhost# exim -Mes  

Access control

Exim allows you to apply access control lists at various points of the SMTP transaction by specifying an ACL to use and defining its conditions in exim.conf. You could start with the HELO string.

# Specify the ACL to use after HELO
acl_smtp_helo = check_helo

# Conditions for the check_helo ACL:
check_helo:

deny message = Gave HELO/EHLO as "friend"
log_message = HELO/EHLO friend
condition = ${if eq {$sender_helo_name}{friend} {yes}{no}}

deny message = Gave HELO/EHLO as our IP address
log_message = HELO/EHLO our IP address
condition = ${if eq {$sender_helo_name}{$interface_address} {yes}{no}}

accept

NOTE: Pursue HELO checking at your own peril. The HELO is fairly unimportant in the grand scheme of SMTP these days, so don't put too much faith in whatever it contains. Some spam might seem to use a telltale HELO string, but you might be surprised at how many legitimate messages start off with a questionable HELO as well. Anyway, it's just as easy for a spammer to send a proper HELO than it is to send HELO im.a.spammer, so consider yourself lucky if you're able to stop much spam this way.

Next, you can perform a check on the sender address or remote host. This shows how to do that after the RCPT TO command; if you reject here, as opposed to rejecting after the MAIL FROM, you'll have better data to log, such as who the message was intended for.

# Specify the ACL to use after RCPT TO
acl_smtp_rcpt = check_recipient

# Conditions for the check_recipient ACL
check_recipient:

# [...]

drop hosts = /etc/exim_reject_hosts
drop senders = /etc/exim_reject_senders

# [ Probably a whole lot more... ]

This example uses two plain text files as blacklists. Add appropriate entries to these files - hostnames/IP addresses to /etc/exim_reject_hosts, addresses to /etc/exim_reject_senders, one entry per line.

It is also possible to perform content scanning using a regex against the body of a message, though obviously this can cause Exim to use more CPU than it otherwise would need to, especially on large messages.

# Specify the ACL to use after DATA
acl_smtp_data = check_message

# Conditions for the check_messages ACL
check_message:

deny message = "Sorry, Charlie: $regex_match_string"
regex = ^Subject:: .*Lower your self-esteem by becoming a sysadmin

accept

Fix SMTP-Auth for Pine

If pine can't use SMTP authentication on an Exim host and just returns an "unable to authenticate" message without even asking for a password, add the following line to exim.conf:

  begin authenticators

fixed_plain:
driver = plaintext
public_name = PLAIN
server_condition = "${perl{checkuserpass}{$1}{$2}{$3}}"
server_set_id = $2
> server_prompts = :

This was a problem on CPanel Exim builds awhile ago, but they seem to have added this line to their current stock configuration.

Log the subject line

This is one of the most useful configuration tweaks I've ever found for Exim. Add this to exim.conf, and you can log the subject lines of messages that pass through your server. This is great for troubleshooting, and for getting a very rough idea of what messages may be spam.

log_selector = +subject

Reducing or increasing what is logged.

Disable identd lookups

Frankly, I don't think identd has been useful for a long time, if ever. Identd relies on the connecting host to confirm the identity (system UID) of the remote user who owns the process that is making the network connection. This may be of some use in the world of shell accounts and IRC users, but it really has no place on a high-volume SMTP server, where the UID is often simply "mail" or whatever the remote MTA runs as, which is useless to know. It's overhead, and results in nothing but delays while the identd query is refused or times out. You can stop your Exim server from making these queries by setting the timeout to zero seconds in exim.conf:

rfc1413_query_timeout = 0s

Disable Attachment Blocking

To disable the executable-attachment blocking that many Cpanel servers do by default but don't provide any controls for on a per-domain basis, add the following block to the beginning of the /etc/antivirus.exim file:

if $header_to: matches "example\.com|example2\.com"
then
finish
endif

It is probably possible to use a separate file to list these domains, but I haven't had to do this enough times to warrant setting such a thing up.

Searching the logs with exigrep

The exigrep utility (not to be confused with exiqgrep) is used to search an exim log for a string or pattern. It will print all log entries with the same internal message-id as those that matched the pattern, which is very handy since any message will take up at least three lines in the log. exigrep will search the entire content of a log entry, not just particular fields.

One can search for messages sent from a particular IP address:

root@localhost# exigrep '<= .* \[12.34.56.78\] ' /path/to/exim_log

Search for messages sent to a particular IP address:

root@localhost# exigrep '=> .* \[12.34.56.78\]' /path/to/exim_log

This example searches for outgoing messages, which have the "=>" symbol, sent to "user@domain.tld". The pipe to grep for the "<=" symbol will match only the lines with information on the sender - the From address, the sender's IP address, the message size, the message ID, and the subject line if you have enabled logging the subject. The purpose of doing such a search is that the desired information is not on the same log line as the string being searched for.

root@localhost# exigrep '=> .*user@domain.tld' /path/to/exim_log | fgrep '<='

Generate and display Exim stats from a logfile:

root@localhost# eximstats /path/to/exim_mainlog

Same as above, with less verbose output:

root@localhost# eximstats -ne -nr -nt /path/to/exim_mainlog

Same as above, for one particular day:

root@localhost# fgrep YYYY-MM-DD /path/to/exim_mainlog | eximstats

Bonus!

To delete all queued messages containing a certain string in the body:

root@localhost# grep -lr 'a certain string' /var/spool/exim/input/ | \
sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | xargs exim -Mrm

Note that the above only delves into /var/spool/exim in order to grep for queue files with the given string, and that's just because exiqgrep doesn't have a feature to grep the actual bodies of messages. If you are deleting these files directly, YOU ARE DOING IT WRONG! Use the appropriate exim command to properly deal with the queue.

If you have to feed many, many message-ids (such as the output of an `exiqgrep -i` command that returns a lot of matches) to an exim command, you may exhaust the limit of your shell's command line arguments. In that case, pipe the listing of message-ids into xargs to run only a limited number of them at once. For example, to remove thousands of messages sent from joe@example.com:

root@localhost# exiqgrep -i -f '' | xargs exim -Mrm

Speaking of "DOING IT WRONG" -- Attention, CPanel forum readers

I get a number of hits to this page from a link in this post at the CPanel forums. The question is:

Due to spamming, spoofing from fields, etc., etc., etc., I am finding it necessary to spend more time to clear the exim queue from time to time. [...] what command would I use to delete the queue

The answer is: Just turn exim off, because your customers are better off knowing that email simply isn't running on your server, than having their queued messages deleted without notice.

Or, figure out what is happening. The examples given in that post pay no regard to the legitimacy of any message, they simply delete everything, making the presumption that if a message is in the queue, it's junk. That is total fallacy. There are a number of reasons legitimate mail can end up in the queue. Maybe your backups or CPanel's "upcp" process are running, and your load average is high -- exim goes into a queue-only mode at a certain threshold, where it stops trying to deliver messages as they come in and just queues them until the load goes back down. Or, maybe it's an outgoing message, and the DNS lookup failed, or the connection to the domain's MX failed, or maybe the remote MX is busy or greylisting you with a 4xx deferral. These are all temporary failures, not permanent ones, and the whole point of having temporary failures in SMTP and a mail queue in your MTA is to be able to try again after awhile.

Exim already purges messages from the queue after the period of time specified in exim.conf. If you have this value set appropriately, there is absolutely no point in removing everything from your queue every day with a cron job. You will lose legitimate mail, and the sender and recipient will never know if or why it happened. Do not do this!

If you regularly have a large number of messages in your queue, find out why they are there. If they are outbound messages, see who is sending them, where they're addressed to, and why they aren't getting there. If they are inbound messages, find out why they aren't getting delivered to your user's account. If you need to delete some, use exiqgrep to pick out just the ones that should be deleted.

Reload the configuration

After making changes to exim.conf, you need to give the main exim pid a SIGHUP to re-exec it and have the configuration re-read. Sure, you could stop and start the service, but that's overkill and causes a few seconds of unnecessary downtime. Just do this:

root@localhost# kill -HUP `cat /var/spool/exim/exim-daemon.pid`

You should then see something resembling the following in exim_mainlog:

pid 1079: SIGHUP received: re-exec daemon
exim 4.52 daemon started: pid=1079, -q1h, listening for SMTP on port 25 (IPv4)

Wednesday, July 22, 2009

Securing /tmp and /dev/shm

The first step is to check if /tmp is already secure. Some data centers do not create a /tmp partition while others do.

#df -h |grep tmp


If that displays nothing then go below to create a tmp partition. If you do have a tmp partition you need to see if it mounted with noexec.

#cat /etc/fstab |grep tmp

If there is a line that includes /tmp and noexec then it is already mounted as non-executable. If not follow the instructions below to create one without having to physically format your disk. Idealy you would make a real partition when the disk was originally formated, that being said I have not had any trouble create a /tmp partition using the following method.

Create a ~1000Mb partition

#cd /dev/; dd if=/dev/zero of=tmpMnt bs=1024 count=1000000

Format the partion

#mkfs.ext2 /dev/tmpMnt

When it asks about not being a block special device press Y


Make a backup of the old data

#cp -Rp /tmp /tmp_backup

Mount the temp filesystem

#mount -o loop,noexec,nosuid,rw /dev/tmpMnt /tmp

Set the permissions

#chmod 0777 /tmp

Copy the old files back

#cp -Rp /tmp_backup/* /tmp/

Once you do that go ahead and restart mysql and make sure it works ok. We do this because mysql places the mysql.sock in /tmp which neeeds to be moved. If not it migth have trouble starting. If it does you can add this line to the bottom of the /etc/fstab to automatically have it mounted:

Open the file in vi:

#vi /etc/fstab

Now add this single line at the bottom:

/dev/tmpMnt /tmp ext2 loop,noexec,nosuid,rw 0 0

While we are at it we are going to secure /dev/shm. Look for the mount line for /dev/shm and change it to the following:

none /dev/shm tmpfs noexec,nosuid 0 0

Umount and remount /dev/shm for the changes to take effect.

#umount /dev/shm
#mount /dev/shm


Next delete the old /var/tmp and create a link to /tmp

#rm -rf /var/tmp/
#ln -s /tmp/ /var/


If everything still works fine you can go ahead and delete the /tmp_backup directory.

#rm -rf /tmp_backup

You /tmp, /var/tmp, and /dev/shm are now mounted in a way that no program can be directly run from these directories. Like I have said in other articles there are still ways in but this is one of the many layers of security you should have on your system.

Change mysql data directory

The default location is /var/lib/mysql

You can change mysql data directory by adding the following entries in /etc/my.cnf file

datadir=newlocation/path

save the file, move the necessary database files from /var/lib/mysql to the new location and restart mysql.

To check if the new location is added correctly, login to mysql as root and create a test database and check the new location if the new database files are added or not.

If mysql doesnt start after restarting then check the logs for an error

# tail -f /var/log/mysqld.log

If there are no specific errors mentioned check if selinux is enabled or not. If its enabled then you may disable it and try starting mysql.

commands to check if selinux is enabled

#getenforce

the result will be like enabled, permissive or targeted You can disable it by editing the configuration file /etc/selinux/config (RHEL/centos)

How to add a range of IP's

For a small range of IPs, you can manually add each IP to a file called ifcfg-eth0:x, which resides in /etc/sysconfig/network-scripts/.
For instance, if you want to add 10 IP addresses, you'll have to create 10 files in that directory, starting with ifcfg-eth0:0 and ending
with ifcfg-eth0:10. Each file will contain:

CODE

DEVICE=eth0:0
ONBOOT=yes
BOOTPROTO=static
IPADDR=192.168.0.2
NETMASK=255.255.255.0
NETWORK=192.168.0.0
BROADCAST=192.168.0.255
TYPE=Ethernet

The IPADDR will increase from 192.168.0.2 to 192.168.0.12.

But what if you have to add 100 IP addresses? It could be physically possible to manually add a file for each of them. But how about
1000 IP addresses? Or 10,000? Fortunately, RedHat based systems offer a quick and easy way to bind a range of IPs, eliminating the
need to create a lot of files and saving a lot of your time.

Create a file called ifcfg-eth0-range0 in the /etc/sysconfig/network-scripts directory. This file must contain the following strings:

CODE

IPADDR_START=192.168.0.10
IPADDR_END=192.168.0.110
CLONENUM_START=0

Let's see what each of them does:

IPADDR_START: This is the first IP from the address range you want to bind to your ethernet device.
IPADDR_END: This is, of course, the last IP from that address range.
CLONENUM_START: This is the number that will be assigned to the first IP alias interface. For instance, if your Internet interface is eth0 and CLONENUM_START is 0, then this config file will create 100 interfaces starting with eth0:0 (eth0:0, eth0:1, eth0:2 etc) and ending with eth0:100.

NOTE! Be careful if you need to add more ranges of IPs. You'll have to use a proper value for CLONENUM_START. For instance, if you need to add a second range with 100 IPs besides the one above, create a new file called ifcfg-eth0-range1 and set the CLONENUM_START to 101 so an overwrite will be avoided.

After making any changes to any of the files created in the network-scripts directory, you have to run the following command so the changes are applied and the address range is activated:

# service network restart

Thursday, July 2, 2009

Adding New repositories to YUM

to add new repos in yum follow the steps below.

cd /etc/yum.repos.d/
vi dag.repo
// the add the following lines in that file//

[dag]
name=Dag RPM Repository for Red Hat Enterprise Linux
baseurl=http://apt.sw.be/redhat/el$releasever/en/$basearch/dag
gpgcheck=1
rpm --import http://dag.wieers.com/rpm/packages/RPM-GPG-KEY.dag.txt

//save and quit//

for remi repo visit the url below

http://blog.famillecollet.com/pages/Config-en



Thursday, June 4, 2009

Yum

Useful Yum Commands

yum install package_name download and install a rpm package

yum localinstall package_name.rpm That will install an RPM, and try to resolve all the dependencies for you using your repositories.

yum update update all rpm packages installed on the system

yum update package_name upgrade a rpm package

yum remove package_name remove a rpm package

yum list list all packages installed on the system

yum search package_name find a package on rpm repository

yum clean packages clean up rpm cache erasing downloaded packages

yum clean headers remove all files headers that the system uses to resolve dependency

yum clean all remove from the cache packages and headers files

Monday, May 25, 2009

Installing FFmpeg and FFmpeg-php

System Configuration/Prerequisites

The server that I had to install on was running:

  • Centos 5.x
  • cPanel 11 (but of course, you don’t need cPanel to install FFmpeg and ffmpeg-php)
  • Yum (or anything of the likes would do)
  • And I presume you have root access

Getting the required Files

Firstly, we would have to download all the required files to a folder. For me, I picked /usr/local/src, but it could be just any other folder you’d like.

Move into the directory that you’d like to download the source files to and run the following commands:

wget http://www3.mplayerhq.hu/MPlayer/releases/codecs/essential-20061022.tar.bz2
wget http://www4.mplayerhq.hu/MPlayer/releases/MPlayer-1.0rc2.tar.bz2
wget http://rubyforge.org/frs/download.php/17497/flvtool2-1.0.6.tgz
wget http://downloads.xiph.org/releases/ogg/libogg-1.1.3.tar.gz
wget http://downloads.xiph.org/releases/vorbis/libvorbis-1.1.2.tar.gz
wget http://easynews.dl.sourceforge.net/sourceforge/lame/lame-3.97.tar.gz
wget http://easynews.dl.sourceforge.net/sourceforge/ffmpeg-php/ffmpeg-php-0.5.3.1.tbz2

This is what I used in my setup. Additional libraries should be downloaded if you need them. Also, I wouldn’t say that these are the latest binaries, but they work for me for now - you should check for updates if you wish. You may also want to change the location of the SourceForge downloads.

Now extract all the files you’ve downloaded:

bunzip2 essential-20061022.tar.bz2; tar xvf essential-20061022.tar
bunzip2 MPlayer-1.0rc2.tar.bz2 ; tar -xvf MPlayer-1.0rc2.tar
tar zxvf flvtool2-1.0.6.tgz
tar zxvf libogg-1.1.3.tar.gz
tar zxvf libvorbis-1.1.2.tar.gz
tar zxvf lame-3.97.tar.gz
bunzip2 ffmpeg-php-0.5.3.1.tbz2; tar xvf ffmpeg-php-0.5.3.1.tar

Along with the additional libraries you could have possibly downloaded.

Installation

Now that we’re done downloading the files we need, it’s time to start the installation.

Codecs

Create a folder to store the Codecs that ffmpeg will need:

mkdir /usr/local/lib/codecs/
mv essential-20061022/* /usr/local/lib/codecs/
chmod -Rf 755 /usr/local/lib/codecs/

Subversion/Ruby/

yum install subversion
yum install ruby
yum install ncurses-devel

LAME

cd lame-3.97
export LD_LIBRARY_PATH=/usr/local/lib
./configure
make
make install

libogg

cd libogg-1.1.3
./configure
make
make install

libvorbis

cd libvorbis-1.1.2
./configure
make
make install

flvtool2

cd flvtool2-1.0.6
ruby setup.rb config
ruby setup.rb setup
ruby setup.rb install

MPlayer

cd MPlayer-1.0rc2
./configure
make
make install

Now for the big one, ffmpeg.

Installing FFmpeg

Generally, we would install the latest version of ffmpeg. But as of the date of this post, the latest version of ffmpeg does not wok with ffmpeg-php. We will need to checkout a previous version from the SVN.

Inside your src folder, run the following to checkout this version of ffmpeg which works.

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk/ ffmpeg -r15261

Once it is done downloading, go into the ffmpeg folder

Note: If a version of ffmpeg was previously installed, run the following command in the ffmpeg folder first:

make uninstall
make clean

Start the installation. You may need to add/enable additional libraries into ./configure.

cd ffmpeg
./configure --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared
make
make install

During installation, you may get an error like:

Unable to create and execute files in /tmp. Set the TMPDIR environment
variable to another directory and make sure that /tmp is not mounted
noexec.
Sanity test failed.

To fix this, run the following commands to create a temporary tmp directory:

mkdir tmp
chmod 777 tmp
export TMPDIR=./tmp

After installation, remember to change the tmp directory back to your server’s tmp disk by doing the following:

export TMPDIR=/tmp

Check if ffmpeg is working by running the following:

ffmpeg -version

It should return something similar to:

FFmpeg version SVN-r15261, Copyright (c) 2000-2008 Fabrice Bellard, et al.
configuration: --enable-libmp3lame --enable-libvorbis --disable-mmx --enable-shared
libavutil 49.10. 0 / 49.10. 0
libavcodec 51.71. 0 / 51.71. 0
libavformat 52.22. 1 / 52.22. 1
libavdevice 52. 1. 0 / 52. 1. 0

If the version isn’t “SVN-r15261″, then there is something wrong and you may need to reinstall ffmpeg.

If something like the following is returned:

ffmpeg: error while loading shared libraries: libavdevice.so.52: cannot open shared object file: No such file or directory

Search for the missing library (in this case libaddevice.so.52) with the following:

find / -name 'libavdevice.so.*'

The returned results may look something like this. The one that we want is the one in the lib folder and not the src folder.

/usr/local/src/ffmpeg/libavdevice/libavdevice.so.52
/usr/local/lib/libavdevice.so.52
/usr/local/lib/libavdevice.so.52.1.0

With that, since the libraries are in the /usr/local/lib/ folder, we run the following:

export LD_LIBRARY_PATH=/usr/local/lib/

Otherwise, simply change the stuff after “=” to the path where the library is.

Sweet! Now that we’ve got FFmpeg working successfully, time to install ffmpeg-php.

Installing ffmpeg-php

Start the installation by running the following (again, run make clean as necessary):

cd ffmpeg-php-0.5.3.1
phpize
./configure
make
make install

You may meet the following errors during installation:

checking for ffmpeg headers… configure: error: ffmpeg headers not found. Make sure you’ve built ffmpeg as shared libs using the –enable-shared option

Solution: Simply create a ffmpeg folder in /usr/local/include/ and run the following to copy all the header files:

cp /usr/local/include/libavcodec/* /usr/local/include/ffmpeg
cp /usr/local/include/libavdevice/* /usr/local/include/ffmpeg
cp /usr/local/include/libavformat/* /usr/local/include/ffmpeg
cp /usr/local/include/libavutil/* /usr/local/include/ffmpeg
cp /usr/local/include/libswscale/* /usr/local/include/ffmpeg

make: *** [ffmpeg_frame.lo] Error 1

Solution: Execute the following in the ffmpeg-php folder. I’ve no idea why the files are named wrongly too.

cp ffmpeg_frame.loT ffmpeg_frame.lo

Upon successful installation, the installer will give you a very long sting to tell you where the extension was installed to. This is a unique string. The following is what I got:

Installing shared extensions: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/

This has to be added to into php.ini.
In cPanel Servers, the php.ini file is located in /usr/local/lib. Otherwise, it should be in etc/php.ini.

Add the following line into php.ini (at the bottom or wherever you want):

extension=ffmpeg.so

Finalizing Installation

Restart Apache on the server.

service httpd restart

Check that ffmpeg is running on the server:

php -i | grep ffmpeg

The following should be returned:

ffmpeg
ffmpeg support (ffmpeg-php) => enabled
ffmpeg-php version => 0.5.3.1
ffmpeg-php gd support => enabled
ffmpeg.allow_persistent => 0 => 0

If an error like the following appears:

php: symbol lookup error: /usr/local/lib/php/extensions/no-debug-non-zts-20060613/ffmpeg.so: undefined symbol: av_free_static

Simply rebuild ffmpeg-php and it should work again.

And you’re done!

You have just successfully installed FFmpeg and ffmpeg-php on your server!

Tuesday, May 12, 2009

SSH key- passwordless login

On the source server do the following

ssh-keygen -t dsa -f filename

It will prompt for a passphrace, it is desirable to leave it empty.
Two files will be created

filename
filename.pub

copy the filename.pub file to the destination server to the location /root/.ssh add the public key entry into authorized_keys as follows

cat filename.pub >> authorized_keys

/etc/init.d/sshd restart

Thursday, April 30, 2009

Install cPanel


    In order to run the cPanel software you must first be running a supported OS like RedHat or CentOS.
cPanel lists their supported operating systems on their website at http://www.cpanel.net.   cPanel also recommends that the server it is being installed on is a clean and fresh install.  This means that if you previously had done any configuring or ran another control panel software that they recommend you reinstall the server. 

IMPORTANT: If the server you plan to install cPanel on is a live production server, STOP.  cPanel's installer may overwrite your previous configurations and cause downtime for you or your customers!

cPanel has made the installation process a simple one and only takes a few commands to get the install going.  Below are the steps:

1.  Log into your server as root via the console or SSH.


2.  Ensure your resolvers are working by trying to resolve cpanel.net (cmd: nslookup cpanel.net).
2.1.   If nslookup does not work, giving a 'command not found' error, you can use yum to install the necessary packages (cmd: yum install bind-utils.i386).
2.2.   If you get an error about not being able to resolve the host, you need to edit your /etc/resolv.conf and add proper resolvers ( eg; 8.8.8.8 )
3.  Change directory into your /home (cmd: cd /home).

4.  Download cPanel's installer (cmd: wget -N http://httpupdate.cpanel.net/latest ).

4.1.   If you get a 'command not found' error, you need to install wget. (cmd: yum install -y wget).
5.  Now run the installer using sh or bash (cmd: sh latest).
5.1.   If you get another 'command not found' error, you need to install Perl. (cmd: yum install perl).
The installer is now running and may take a hour to two depending on your servers hardware, OS, connection speed, etc.
Once the installation is complete it's not time to log into the WebHostManager (WHM) and go through the wizard. Point your browser to http://your_ip_here/whm or http://your_ip_here:2086/ . You will be prompted for a user/pass, enter root as the user and enter your root password in the password field.  The wizard will now launch and ask you a few questions.  

Once complete your system is ready to use! Good Luck ;)

Sunday, March 15, 2009

How can I configure multiple Web sites using Host Headers?

Microsoft Internet Information Services (IIS) permits you to map multiple Web sites to a single IP address using a feature called Host Header Names. By assigning a unique host header name to each Web site, this feature permits you to map more than one Web site to an IP address.

Configure Web Sites by Using Host Header Names

To configure Web sites by using the Host Header Names feature, follow these steps:
1. Click Start, point to Administrative Tools, and then click Internet Information Services.
2. Expand * server name (where server name is the name of the server), and then expand Web Sites.
3. Right-click the Web site that you want, and then click Properties.

The Web site name Properties dialog box appears (where Web site name is the name of the Web site that you selected).
4. Click the Web Site tab, and then in the IP Address list, select the IP address that you want assigned to this Web site.
5. Click Advanced.
6. Under Multiple identities for this Web Site, click the IP address, and then click Edit.

The Advanced Web Site Identification dialog box appears.
7. In the Host Header Name box, type the host header that you want. For example, type www.example1.com. Add the port number, select the IP address in the list, and then click OK.

NOTE: If you want to configure this Web site with additional identities, click Add. Use the same IP address and TCP port, but enter a unique Host Header Name, and then click OK. For example, if you want to access the same Web site from both the Internet and a local intranet, you can configure the Web site identity in the manner shown in the following example:

IP Address TCP Port Host Header Name

192.168.0.100 80 www.example1.com
192.168.0.100 80 example1.com


8. In the Advanced Multiple Web Site Configuration dialog box, click OK.
9. In the Web site name Properties dialog box, click OK.

You return to the IIS window.
10. Right-click the next Web site that you want, and then click Properties.
11. In the IP Address list, select the same IP address that you selected in step 4, and then click Advanced.
12. Under Multiple identities for this Web Site, click the IP address, and then click Edit.

The Advanced Web Site Identification dialog box appears.
13. In the Host Header Name box, type a unique host header for this Web site. For example, type www.example2.com, add the port number, select the IP address in the list, and then click OK.
14. In the Advanced Multiple Web Site Configuration dialog box, click OK.
15. In the Web site name Properties dialog box, click OK.

You return to the IIS window.
16. Repeat steps 10 through 15 for each Web site that you want hosted on this IP address.
17. Register the host header names with the appropriate name resolution system -- for example, a Domain Name System (DNS) server or, in the case of a small network, a Hosts file.
The Web sites are now configured to accept incoming Web requests, based on their host header names.
More Information

Do not assign a host header name to the Default Web Site. Many programs expect the Default Web Site to use an IP address of (All Unassigned), TCP Port 80, and no host header name.
Troubleshooting

• Clients cannot connect to the Web sites by using the IP address:

Because there is more than one Web site configured to the IP address, you must connect to the Web site by using the host header name. When you try to connect to the Web site by using the IP address, you receive the following error message:
The page cannot be found.

The page you are looking for might have been removed, had its name changed, or is temporarily unavailable.
• Clients cannot connect to the Web sites by using host header names:

Multiple host names must be mapped to the single IP address by using a DNS server or a Hosts file.

How to Connect to the Console Session

In Windows Server 2003, when you use Terminal Services, you can connect to the console session (session 0), and at the same time, open a shadow session to it (as long as you connect from a session other than the console). With this added functionality, you can log on to a Windows Server 2003-based server that is running Terminal Services remotely and interact with session 0 as if you were sitting at the physical console of the computer. This session can also be shadowed so that the remote user and the local user at the physical console can see and interact with the same session.


Connecting to the Console Session

When you connect to the console session of a Windows Server 2003-based server, no other user has to be already logged on to the console session. Even if no one is logged on to the console, you are logged on just as if you were sitting at the physical console.

To connect from the remote Windows Server 2003-based computer, open a command prompt, and then type the following command:

mstsc -v:servername /F -console

where mstsc is the Remote Desktop connection executable file, -v indicates a server to connect to, /F indicates full screen mode, and -console is the instruction to connect to the console session.

How can I create a file of a certain size in Windows?

If you need to create a file of a certain size and the file contents don't matter, you can use the Fsutil command as follows:

fsutil createnew

For example,

fsutil file createnew d:\temp\1mbfile.txt 1000000

creates a 1MB file named 1mbfile.txt in the d:\temp folder.

Thunderbird configuration

1.Open Thunderbird

2.Open the "New Account" dialog box. This is accessible from the menus by going to "File", "New", then clicking on Account ...".

3.Select "Email Account" as the New Account type, then click "Next".

4.When asked to enter your identity information, type in your full name and email address in the boxes provided. Then click next.

5.For server information, choose IMAP. Enter "linus.it.uts.edu.au" as both incoming and outgoing servers. Click next

6.For user names, your incoming user name should be filled out for you. If not, enter your FIT username and click next

7.You account name can be set to any name you want to refer to the account by. In this case, we'll keep it to the default and use the email address as the name of the account. Click next when you're done.

8.The next screen will display the list of settings which you have just entered. Make sure you haven't misspelled any of the settings. If you have, you'll need to keep clicking on "Back" until you reach the screen with the typographical error, then "Next" until you reach this screen again. Click "Finish" when you are okay with settings that you have entered.

9.You should now be prompted to enter a mail server password. Click Cancel. We still need to configure a few more settings before we connect.

10. On the main thunderbird window, you should now see your account name on the left hand side. Right click it and select "Properties" to access the "Account Settings" window. You can also access this window by going to the "Edit" menu and selecting "Account settings".

11. Click on "Server Settings" under your account name on the left hand side of the window. In the security settings area, click on the option box next to SSL. Make sure the box next to "Use secure authentication" is not checked. Click on the "Advanced" button to open the "Advanced settings" dialog.

12. In the "Advanced settings" dialog, type in "mail/" as the IMAP server directory and uncheck Server supports folders that contain sub-folders and messages. Click "OK" when finished.

13. On the left hand side of the "Account settings" window, select "Outgoing Server (SMTP)". Select the staff server (the one with linus.it.uts.edu.au in it's name) and click on "Edit".

14. Under "Use secure connection" select "TLS". You can also include a description of the server, e.g. "FIT Staff Outgoing" in the "Description" input box. Click "OK".

15. Back in the "Account settings" window, select the account name from the left hand side. The "Outgoing Server" should match the one you have just edited. Click "OK" when done.

16. You may be asked to accept a website certificate for "linus.it.uts.edu.au". Choose the option for accepting the certificate permanently.

17. You're now set up and ready to go.