Monday, 30 June 2014

Trigger an action via CSF when server load is high on Server


Config Server Firewall works well by default. But if you customize it some, it can be even more poweful of a tool. When your load is high, you usually receive an alert from CSF. However, those reports contain a limited amount of information. If your receive these high server alerts often and want more information about what is actually going on when high load averages occur, then do the following. You can have lfd send you custom reports by using the PT_LOAD_ACTION option within the CSF configuration.First, login to shell.


Then create a file call /etc/csf/load.sh


touch /etc/csf/load.sh
nano /etc/csf.load.sh

Add the following contents to the file:



#!/bin/sh

>/etc/csf/csf.report

iostat -d 1 5 >> /etc/csf/csf.report

iostat -x -d 1 5 >> /etc/csf/csf.report

mpstat -P ALL >> /etc/csf/csf.report

top -b -n 1 >> /etc/csf/csf.report

netstat -autpn

mail -s “Load Report” root < /etc/csf/csf.report



Save the file.


Then, change the chmod settings of the file:


chmod +x /etc/csf/load.sh

Finally, edit /etc/csf/csf.conf and goto the section labeled “PT_LOAD_ACTION”. Add “/etc/csf/load.sh” so that it now looks like this:


PT_LOAD_ACTION = "/etc/csf/load.sh"

Restart csf:

csf -r

That’s it! Now when you receive a high CPU load alert, you will also receive an email with a lot more information in it. If you want CSF to automatically restart apache too, you can add the following line to the end of the load.sh file:


service httpd restart

And then save the file and restart config server.



Thursday, 26 June 2014

Upgrading PostgreSQL

To upgrade a PostgreSQL installation start by dumping all the existing databases. You should do this before stopping the current database server
$ PGUSER=postgres /usr/bin/pg_dumpall > dump.sql
$ sudo /etc/init/d/postgresql stop
$ sudo mv /usr/local/pgsql /usr/local/pgsql.old


Build and install your new version. Be sure to create a PGDATA directory that is owned by the postgres user. Initialize the PGDATA directory with initdb
$ sudo mkdir /usr/local/pgsql/data
$ sudo chown postgres:postgres /usr/local/pgsql/data
$ sudo -u postgres /usr/local/pgsql/bin/initdb -D /usr/local/pgsql/data


Once you have created your new database, start the new database server and populate the new database with the data you dumped from your old system:


$ sudo -u postgres /usr/local/pgsql/bin/postgres -D /usr/local/pgsql/data
$ sudo -u postgres /usr/local/pgsql/bin/psql -d postgres -f dump.sql



Upgrading PostgreSQL

Problem with yum update

Following is the error that occurred :

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
addons | 951 B 00:00
base | 2.1 kB 00:00
extras | 1.1 kB 00:00
updates | 1.9 kB 00:00
Not using downloaded repomd.xml because it is older than what we have:
Current : Tue Feb 9 08:57:23 2010
Downloaded: Tue Jan 26 09:27:44 2010
Excluding Packages in global exclude list
Finished
Setting up Update Process
No Packages marked for Update

Solution :


Run the following two commands :

yum clean all
yum check-update

That should fix the issue.



Problem with yum update

How to Enable Sound in VMWare Server 2.0


So I had switched from VirtualBox to VMWARE since its free and has much easier bridging behind the scenes for my virtual machines. Currently I run Linux as my main computer and well the necessities of certain office windows products I was missing and their Linux counterparts didn’t work as well. I had created a windows xp virtual machine from my computers license key since I no longer have the thing installed.


Creating the virtual machine and setting up Linux went fine and smooth. Once in windows I started to tweak it and noticed there is no sound. I had shut down the machine and tried to add a sound device on “auto detect” was my only option. Booting the virtual machine I received an error that the sound was not able to be initialized, where I started to search the internet with no luck.


Finally I had figured it out and I have SOUND! Below you can find the steps I took and hope they work out as well for you as for me.


First is first – figure out what your device is for sound. I loaded up amarok and went to the configuration. From there to “Engine” and there it beholds “Device:”. For me there were two options:






1 /dev/dsp




2 /dev/sound/dsp



I had restarted amarok with each as my device and figured out that /dev/dsp was the one for me.


Then go to “/var/lib/vmware/Virtual Machines/” and open “.vmx” and look for the following lines:






sound.present = "TRUE"





sound.allowGuestConnectionControl = "FALSE"




sound.fileName = "/dev/dsp" (changed from -1)





sound.autodetect = "FALSE" (changed from TRUE)




sound.pciSlotNumber = "36"




sound.startConnected = "TRUE"



Save the file and reboot the virtual machine and there we have sound! Isn’t that fantastic?!? If you have comments or suggestions please leave them as others might be experiencing the same issues as you.





How to Enable Sound in VMWare Server 2.0

How to use gmail with mutt

For sending and receiving you mails, with the famous mail client mutt, insert the following lines into your ~/.muttrc


set smtp_url = “smtp://username@smtp.gmail.com:587/”
set smtp_pass = “password”
set from = “username@gmail.com”
set realname = “Your Real Name”


you can also use fetchmail to get your mail automatically.
so, edit the ~/.fetchmailrc and add the following :


poll smtp.gmail.com protocol imap user “username” password “password” mda “/usr/bin/procmail -d %T” ssl


That’s great if we will receive notification when a new mail arrived.
for that add the following lines into a shell script, we will name it checkmail.


$ cat >checkmail<<EOF
#!/bin/sh
if [ "$1" = "-v" ]; then
EXTRAARG=”-v”
fi
fetchmail -a -K $EXTRAARG >/dev/null 2>&1


if [ "$?" = "0" ]; then
DISPLAY=:0.0 /usr/bin/notify-send -t 0 -u critical -h “int:x:168? -h “int:y:100? -i /home/mezgani/photo/mail.jpg “?????? ????” “New mail received”
fi
EOF


Ok, right now we will define an entry to crontab, which will call the checkmail script every 5min.
of course change the path /home/handrix/bin/checkmail by the emplacement of the script in you host.


*/5 * * * * /home/mezgani/bin/checkmail



How to use gmail with mutt

Wordpress mod_rewrite rules taking over mod_status

While working on setting up a monitoring solution for a big wordpress installation, I realized that the server-status url was not working as expected even ifmod_status was configured correctly:


ExtendedStatus On


SetHandler server-status
Order deny,allow
Deny from all
Allow from some_ips


The .htaccess wordpress rules were taking over this and the server-status url was returning a page not found error from within wordpress. This was happening because of the way how the rewrite rules are setup to handle all the permalinks on the site, and for any non-existing file send it to index.php:
# BEGIN WordPress


RewriteEngine On
RewriteBase /
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]


# END WordPress

This works fine with any aliases defined in apache, but the mod_status handler was going to the rewrite rules first, hence the problem. This is not a wordpress problem, and should happen with any other application (like zend framework is one other example that comes to my mind right now) that uses the same type of catch-all rewrite rules to handle all the urls inside the application. The solution in this case is to specifically add a rewrite rule to not have the server-status url processed and sent to the default rule:
RewriteCond %REQUEST_URI !=/server-status
and the wordpress rewrite rules should look like this:
# BEGIN WordPress


RewriteEngine On
RewriteBase /
RewriteCond %REQUEST_URI !=/server-status
RewriteCond %REQUEST_FILENAME !-f
RewriteCond %REQUEST_FILENAME !-d
RewriteRule . /index.php [L]


# END WordPress



Wordpress mod_rewrite rules taking over mod_status

Cannot send emails- RoundCube just shows “Sending Message”

I found a problem with Roundcube, it shows sending message and hangs up there and actually it doesn’t send message anymore. I found the following solution here.


Problem with Roundcube, installed when updated to newest CURRENT release. – Page 3 – cPanel Forums:


vi /usr/local/cpanel/base/3rdparty/roundcube/config/main.inc.php


and changed


$rcmail_config['smtp_user'] = ‘%u’;
to
$rcmail_config['smtp_user'] = ”;



Cannot send emails- RoundCube just shows “Sending Message”

Cannot edit DNS zone after cPanel update

Issue :


After updating all the cPanel software, following error occurs when trying to Edit a DNS zone :


Unable to parse zone: Error while parsing zonedata for *DOMAIN NAME HERE*.com: expected valid rname, line 4 …propagated at /usr/local/cpanel/Cpanel/CPAN/Net/DNS/ZoneFile/Fast.pm line 142.


Fix :


The error means that the dns zone has invalid data in it and it cannot be loaded. So you need to recreate the zone to fix this.


You can use the following cPanel script to do this :


/scripts/pkgacct accountname ( just to backup the account)


/scripts/killdns domainname


/scripts/adddns –domain domainname


Please note that while recreating the domain using the above script it will not create the sub-domain. It will create the default DNS records. You can also specify the ip address using ” –ip X.X.X.X ” option


After running the scripts, you can manually add the entries for the sub-domains .



Cannot edit DNS zone after cPanel update

To make writable session save path

Just put the following code in your .htaccess


php_value session.save_path ‘/tmp’




To make writable session save path

Upcp Gets Killed Automatically

Do The Following if /scripts/upcp –force gets killed automatically.


wget -O scripts.tar.bz2


http://httpupdate.cpanel.net/cpanelsync/RELEASE/scripts.tar.bz2


tar -x -v -C / -j -p -f scripts.tar.bz2


chmod 755 /scripts/cpanelsync


/scripts/cpanelsync httpupdate.cpanel.net /cpanelsync/RELEASE/scripts


/scripts/upcp –force



Upcp Gets Killed Automatically

Error while connecting to MySQL. Failover enacted

Mysql Error on the Cpanel server.


Error while connecting to MySQL. Failover enacted.


Fix :: Just Login to ssh and run the following command to fix the above error.

/scripts/perlinstaller --force DBD::mysql




Error while connecting to MySQL. Failover enacted

How to repair Grub loader



GNU GRUB (“GRUB” for short) is a boot loader package from the GNU Project. GRUB is the reference implementation of the Multiboot Specification, which allows a user to have several different operating systems on their computer at once, and to choose which one to run when the computer starts. GRUB can be used to select from different kernel images available on a particular operating system’s partitions, as well as to pass boot-time parameters to such kernels.


Every once in a while windows may have the inclination to overwrite your bootloader with its own. This will make accessing your system impossible.
Well, there is a solution to override the 512 Kb of your drive that represent the MBR.
In the fact you can follow these steps to repair your GRUB loader:
Boot your PC with a Live CD in the drive, after run fdisk to display list of your partitions system.


$ sudo /sbin/fdisk -l


Disk /dev/sda: 250.0 GB, 250059350016 bytes
255 heads, 63 sectors/track, 30401 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0xa588e9cb


Device Boot Start End Blocks Id System
/dev/sda1 * 1 30071 241545276 83 Linux
/dev/sda2 30072 30401 2650725 5 Extended
/dev/sda5 30072 30401 2650693+ 82 Linux swap / Solaris


In that fdisk example, the root linux partition reside in /dev/sda1
Create a directory /mnt/root and mount the linux partition.


$ sudo mkdir /mnt/root
$ sudo mount /dev/sda1 /mnt/root


Change the root “/” directory to our old root directory the /mnt/root
$ sudo chroot /mnt/root /bin/bash


Execute the grub command
$ sudo grub –config-file=/boot/grub/menbu.lst

GNU GRUB version 0.97 (640K lower / 3072K upper memory)


[ Minimal BASH-like line editing is supported. For
the first word, TAB lists possible command
completions. Anywhere else TAB lists the possible
completions of a device/filename. ]


Now we need to tell grub where are the grub files:
If you don’t know where they are, type:
grub> find /boot/grub/stage1
(hd0,0)


Now type the following, replacing hd0 with the physical drive linux is installed
grub> root (hd0,0)


Remember that for grub (hd0,0) means hda (primary controller master), first partition.
Let’s install the grub on hd0
grub> setup (hd0,0)
grub> quit


$ sudo reboot
Now you can reboot safely, with your linux system. –Ali






How to repair Grub loader

Turn off bandwidth monitoring

Go to WHM >> Service Configuration >> Service Manager.
Look for ‘cPBandwd’. Make sure that the check box besides that is unchecked.
Save the settings and that should be it !



Turn off bandwidth monitoring

How To Reinstall Horde

To reinstall Horde, preserving the existing database, you can use the following:


/usr/local/cpanel/bin/update-horde –force



How To Reinstall Horde

Parallels Helm cannot reseller can no longer delete customer account



Suddenly one of my resellers stopped being able to delete a customer account and was getting the following error

Unable to perform the requested action as this Login has insufficient permissions

The rest of the resellers on the server however were able to delete accounts without problem. After several hours of searching and contacting parallels support the resolution was simple


The problem is insufficient account permissions for the reseller.


What I did was going to Home > Account Settings > Customer Account Roles, selecting the ‘Reseller’ role (the only available),


selecting ‘Specify Permission’ instead of ‘Pre-defined Roles’ in its configuration page and adding the ‘Delete Account Profile’ from ‘Available Permissions’ to ‘Selected Permissions’.


Then I saved the changes I made and successfully deleted again…






Parallels Helm cannot reseller can no longer delete customer account

Install squirrelmail to Parallels Helm 4.1 as an application package (APS)



I recently needed to be able to offer squirrelmail 1.4 to customers using Parallels Helm 4.1


I downloaded the latest version of squirrelmail and bundled it up so that it can be added as a package in the control panel.


The config file is based on the original sample config file provided in the parallels sample application package. GUID created using this tool.


Please note


The way the config is setup it will create the following two directories which are above the web root of the domain (this is recommended by the squirrelmail documentation).


private/squirrelmail/data
private/squirrelmail/attach


Once installed your clients will be able to access this package through their Helm control panel at

Home > My Domains > yourdomain.com > Application Packs

Enjoy!


ps: as usual no waranties made and no liabilities accepted. Any questions let me know!


Download the application package for Helm






Install squirrelmail to Parallels Helm 4.1 as an application package (APS)

Reset MYSQL root password


Simple steps to reset the mysql root password if you have forgotten it.


1. Stop the mysqld daemon process.


2. Start the mysqld daemon process with the '–skip-grant-tables‘ option.


3. Start the mysql client with the -u root option.


4. Execute the following:

UPDATE mysql.user SET Password=PASSWORD('password') WHERE User='root';

5. Execute the following:

FLUSH PRIVILEGES;




Reset MYSQL root password

Export the DB Schema ONLY


To dump the database SCHEMA only, without dumping any actual data :


mysqldump --no-data --tables -u YOUR_USER_NAME -p DATABASE_YOU_WANT_SCRIPTED >> FILENAME.sql

Actual example:


mysqldump --no-data --tables -u larry -p contacts >> contacts.sql

If you want the data to be exported, omit the ”–no-data” portion.





Export the DB Schema ONLY

Installing ntop on Red Hat Enterprise Linux / CentOS Linux / Debian



ntop is a network probe that shows network usage in a way similar to what top does for processes, dnstop for dns, ptop for postgresql, iotop, atop …


In interactive mode, it displays the network status on the user’s terminal. In Web mode, it acts as a web server, creating a HTML dump of the network status. It sports a NetFlow/sFlow emitter/collector, a HTTP-based client interface for creating ntop-centric monitoring applications, and RRD for persistently storing traffic statistics.


ntop is available for both Unix and Win32-based platforms. It has been developed by Luca Deri, an Italian research scientist and network manager at University of Pisa.


On Redhat or Centos:
For installing ntop on Red Hat or Centos, please follow these instructions:


Packages needed :
- libpcap: system interface for user-level packet capture
- libpcap-devel: development library for libpcap
- rrdtool: Time-series data storage and display system (programs)
- rrdtool-devel: Time-series data storage and display system (development)
- perl-rrdtool: Time-series data storage and display system (perl interface)
- graphviz: Graph Visualization Software


First install libpcap, and libpcap-devel using yum
$ sudo yum install libpcap-devel libpcap


The rrdtool, ntop and graphviz packages you can get them like this:



$ wget ftp://rpmfind.net/linux/dag/redhat/el5/en/i386/dag/RPMS/rrdtool-devel-1.2.30-1.el5.rf.i386.rpm
$ wget ftp://rpmfind.net/linux/dag/redhat/el5/en/i386/dag/RPMS/rrdtool-1.2.30-1.el5.rf.i386.rpm
$ wget ftp://rpmfind.net/linux/dag/redhat/el5/en/i386/dag/RPMS/perl-rrdtool-1.2.30-1.el5.rf.i386.rpm
$ wget http://dag.wieers.com/rpm/packages/ntop/ntop-3.3-1.el5.rf.i386.rpm


$ wget http://www.graphviz.org/graphviz-rhel.repo
$ sudo cp graphviz-rhel.repo /etc/yum.repos.d/
$ sudo yum update
$ sudo yum install graphviz


Installing perl-rrdtool, rrdtool, rrdtool-devel and ntop with rpm package manager :
$ sudo rpm -ivh perl-rrdtool-1.2.30-1.el5.rf.i386.rpm rrdtool-1.2.30-1.el5.rf.i386.rpm rrdtool-devel-1.2.30-1.el5.rf.i386.rpm ntop-3.3-1.el5.rf.i386.rpm


Type the following command to set ntop admin password, enter:
$ ntop -A
Sat Jul 4 14:31:49 2009 NOTE: Interface merge enabled by default
Sat Jul 4 14:31:49 2009 Initializing gdbm databases
ntop startup – waiting for user response!
Please enter the password for the admin user:
Please enter the password again:
Sat Jul 4 14:32:24 2009 Admin user password has been set


The following command start ntop:
$ sudo /usr/bin/ntop -d -L -u ntop -P /var/ntop –skip-version-check –use-syslog=daemon -d


If you have many interfaces you can specify them like this :
$ /usr/bin/ntop -i “eth0,eth1? -d -L -u ntop -P /var/ntop –skip-version-check –use-syslog=daemon -d


Well we need to run ntop as services, please refer to /etc/ntop.conf:
$ sudo vim /etc/ntop.conf
–user ntop
–db-file-path /var/ntop
–interface eth0,eth1
–use-syslog
–http-server 3000
–https-server 3001
–local-subnets 192.168.1.0/20
–domain mydomain.org
–daemon


At last start your ntop service:
$ sudo service ntop start


By default ntop listen on 3000 port. You can view ntop stats by visiting following url:
http://server:3000/ or https://server:3001/
as defined in the ntop.conf.


On Debian:
The ntop package is present in the Debian repository, so you can get simply by:
$ aptitude install ntop


Personalize your ntop config file. After, you can start the service :
$ sudo invoke-rc.d ntop start






Installing ntop on Red Hat Enterprise Linux / CentOS Linux / Debian

Checking or Changing DNS entries on Mac OSX



To check your Personal VPN DNS entries on a Mac OSX computer while connected to SurfBouncer:


1) From the dock, select ‘System Preferences’.


2) Click on ‘Network’.


3) Select one of the available connections such as ‘AirPort’, ‘Ethernet’ and ‘PPPoE’.


4) Click on ‘Advanced’.


5) Click on ‘DNS’.


6) You should see a screen similar to the one below. The DNS servers are listed on the left.


7) Please send a screen shot and repeat for all available connections.







To take a screen shot of this page, Click on:


Command + Shift + 4 and then Space Bar


A camera will appear. Place it over the window and click. The image will be saved to your desktop.


Attach the image in your email back to us.

(Note: The actual DNS servers may be different than the ones shown above.)


To change DNS settings:


1) Exit Tunnelblick


2) From the dock, select ‘System Preferences’.


3) Click on ‘Network’.


4) Click on the lock in the lower left hand corner to unlock it, if it is locked.


5) Select one of the available connections such as ‘AirPort’, ‘Ethernet’ and ‘PPPoE’.


6) Click on ‘Advanced’.


7) Click on ‘DNS’. You should see a screen similar to the one above.


8) Click on the ‘+’ button and enter the new DNS address we provide you.


9) Drag the new addresses to the top of the list. (If there are grayed out addresses they will stay on top but are inactive.)






Checking or Changing DNS entries on Mac OSX