Saturday, April 5, 2008

How to increase file limit

Get current limit:

ulimit -n

cat /proc/sys/fs/file-nr

The default limit is 1024.

Get current number of open file descriptors:

lsof [-p pid] | wc -l

Increase the limit:

Edit /etc/security/limits.conf:

username hard nofile 32768



Send Email from a PHP Script Using SMTP Authentication

To connect to an outgoing SMTP server from a PHP script using SMTP authentication and send an email:

Adapt the example below for your needs. Make sure you change the following variables at least:
* from: the email address from which you want the message to be sent.
* to: the recipient's email address and name.
* host: your outgoing SMTP server name.
* username: the SMTP user name (typically the same as the user name used to retrieve mail).
* password: the password for SMTP authentication.
------------------------------------------------------------------------------------------------
require_once "Mail.php";

$from = "Bill Sender ";
$to = "Ninad Recipient ";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";

$host = "mail.example.com";
$username = "smtp_username";
$password = "smtp_password";

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) {
echo("

" . $mail->getMessage() . "

");
} else {
echo("

Message successfully sent!

");
}
?>

-- Dhananjay Sonawane

Cron to delete mails from Inbox

Cron to delete mails from Inbox


Here is the syntax for deleting all email in the inbox of the default email address for a website:

echo -n > /home/youraccount/mail/inbox

-- Dhananjay Sonawane

Installing IonCube Loader

1. Download the program and store it on your server using wget or FTP.

http://www.ioncube.com/loader_download.php

2. Unpack the program
tar -zxvf ioncube_loaders.tar.gz

3. cd ioncube

4. copy ioncube-install-assistant.php to a web directory such as your hosting directory and open it in your browser window.
cp ioncube-install-assistant.php /home/userdirectoryhere/www

5. Now lets move the iconcube directory to a permanent location:

cd ..
mv ioncube /usr/local

6. Now that you know the location of php.ini you need to edit it.
pico /usr/local/lib/php.ini

Now find where other zend extentions are in the file.
ctrl + w: zend_extension

Paste in your new line for ioncube loader
zend_extension = /usr/local/ioncube/ioncube_loader_lin_4.3.so

(NOTE) Check php version if it is 5.2 then entry should be ioncube_loader_lin_5.2.so

7. Save the changes
ctrl + X then Y and enter

8. Restart the web server to take effect.
/etc/init.d/httpd restart


-- Dhananjay Sonawane

Nagios Installation and Configuration

Nagios Installation and Configuration


You can use the following steps to install and configure Nagios.

Create the base directory where you would like to install Nagios.
mkdir /usr/local/nagios

Add a new user (and group) to your system.
adduser nagios

Download Nagois 1.0.
wget http://internap.dl.sourceforge.net/sourceforge/nagios/nagios-1.0.tar.gz
tar -zxvf nagios-1.0.tar.gz
cd nagios-1.0

Run the configure script.
./configure –prefix=/usr/local/nagios –with-cgiurl=/nagios/cgi-bin
–with-htmurl=/nagios/ –with-nagios-user=nagios –with-nagios-grp=nagios

Compile Nagios and the CGIs.
make all

Install the binaries and HTML files (documentation and main web page).
make install

Install the sample init script to /etc/rc.d/init.d/nagios.
make install-init

Installing the Plugins
——————————-

In order for Nagios to be of any use to you, you’re going to have to download
and install some plugins. Plugins are scripts or binaries which perform all
the service and host checks that constitute monitoring

Download and install the Nagios Plugins.
wget
http://aleron.dl.sourceforge.net/sourceforge/nagiosplug/nagios-plugins-1.3.1-1.9.i386.rpm
rpm -Ivh nagios-plugins-1.3.1-1.9.i386.rpm

Configuring Nagios
—————————

Nagios is compiled and installed. Now we have to configure it or in other
words define objects (hosts, services, etc.) that should be monitored.

The main configuration file (/usr/local/nagios/etc/nagios.cfg) contains a
number of directives that affect how Nagios operates. This config file is
read by both the Nagios process and the CGIs. This is a sample nagios.cfg

—————————————————————————————————————–
log_file=/usr/local/nagios/var/nagios.log
cfg_file=/usr/local/nagios/etc/checkcommands.cfg
cfg_file=/usr/local/nagios/etc/misccommands.cfg
cfg_file=/usr/local/nagios/etc/contactgroups.cfg
cfg_file=/usr/local/nagios/etc/contacts.cfg
cfg_file=/usr/local/nagios/etc/dependencies.cfg
cfg_file=/usr/local/nagios/etc/escalations.cfg
cfg_file=/usr/local/nagios/etc/hostgroups.cfg
cfg_file=/usr/local/nagios/etc/hosts.cfg
cfg_file=/usr/local/nagios/etc/services.cfg
cfg_file=/usr/local/nagios/etc/timeperiods.cfg
resource_file=/usr/local/nagios/etc/resource.cfg
status_file=/usr/local/nagios/var/status.log
nagios_user=nagios
nagios_group=nagios
check_external_commands=1
command_check_interval=45s
command_file=/usr/local/nagios/rw/nagios.cmd
comment_file=/usr/local/nagios/var/comment.log
downtime_file=/usr/local/nagios/var/downtime.log
lock_file=/usr/local/nagios/var/nagios.lock
temp_file=/usr/local/nagios/var/nagios.tmp
log_rotation_method=d
log_archive_path=/usr/local/nagios/archives
use_syslog=0
log_notifications=1
log_service_retries=1
log_event_handlers=1
log_initial_states=1
log_external_commands=1
log_passive_service_checks=1
inter_check_delay_method=s
service_interleave_factor=s
max_concurrent_checks=0
service_reaper_frequency=1
sleep_time=1
service_check_timeout=30
host_check_timeout=30
event_handler_timeout=30
notification_timeout=30
ocsp_timeout=5
perfdata_timeout=5
retain_state_information=1
state_retention_file=/usr/local/nagios/var/status.sav
retention_update_interval=60
use_retained_program_state=0
interval_length=20
use_agressive_host_checking=0
execute_service_checks=1
accept_passive_service_checks=1
enable_notifications=1
enable_event_handlers=1
process_performance_data=0
obsess_over_services=0
check_for_orphaned_services=0
check_service_freshness=1
freshness_check_interval=60
aggregate_status_updates=1
status_update_interval=15
enable_flap_detection=1
low_service_flap_threshold=5.0
high_service_flap_threshold=20.0
low_host_flap_threshold=5.0
high_host_flap_threshold=20.0
date_format=us
illegal_object_name_chars=`~!$%^&*|’”<>?,()=
illegal_macro_output_chars=`~$&|’”<>
admin_email=you@yourdomain.com
admin_pager=you@yourdomain.com
——————————————————————————————

Add the list of servers that you want to monitor in
/usr/local/nagios/etc/hosts.cfg

——————————————————————————————
# ’server42′ host definition
define host{
use generic-host
host_name (server hostname)
alias (hostname)
address IP Address
check_command check-host-alive
max_check_attempts 10
notification_interval 120
notification_period 24×7
notification_options d,u,r
}
# ’server43…..

——————————————————————————————

Edit /usr/local/nagios/etc/hostgroups.cfg to add all the servers.

——————————————————————————————
define hostgroup{
hostgroup_name tchosting
alias TotalChoice
contact_groups tchosting
members server40,server41,server42
}
—————————————————————————————–

To setup email and pager notifications edit
/usr/local/nagios/etc/contacts.cfg to add your contact info.

—————————————————————————————–
define contact{
contact_name DAN
alias DAN
service_notification_period 24×7
host_notification_period 24×7
service_notification_options n
host_notification_options d,u,r
service_notification_commands notify-by-email
host_notification_commands host-notify-by-email
email dan_sonawane@gmail.com
}
—————————————————————————————–

The contact name must be a member of contact group. Edit
/usr/local/nagios/etc/contactgroups.cfg to add your name.



-- Dhananjay Sonawane

zlib installation

zlib installation

  1. wget http://www.zlib.net/zlib-1.2.3.tar.gz
    tar -zxvf zlib-1.2.3.tar.gz
  2. cd zlib-1.2.3
  3. ./configure
  4. make
  5. make install

Synchronize time on Cpanel servers

Command to Synchronize time on Cpanel servers
rdate -s rdate.cpanel.net

-- Dhananjay