May 30, 2010

 Speed up Atmail with eAccelerator

This guide covers the steps you need to take to install EAccelerator (http://eaccelerator.net). eAccelerator is a free open-source PHP accelerator and optimizer. It optimizes scripts to speed up their execution, typically reducing server load and increasing the speed of your PHP code by up to ten times.

First, download the latest version of EAccelerator from: http://bart.eaccelerator.net/source/

% wget "http://bart.eaccelerator.net/source/0.9.6/eaccelerator-0.9.6.tar.bz2"

Untar, then go to the unpacked directory:

% tar xvfj eaccelerator-0.9.6.tar.bz2
% cd eaccelerator-0.9.6

Find the base directory of your PHP installation. Typically, this resides two directories down from where your PHP binary is. For this guide, we will assume that php is installed in "/usr/local/bin/php" - therefore, making the base directory "/usr/local".

Execute the following commands inside the eAccelerator directory:

% export PHP_PREFIX="/usr/local/"
% $PHP_PREFIX/bin/phpize

Then, run the configure script:

% ./configure --enable-eaccelerator=shared --with-php-config=$PHP_PREFIX/bin/php-config
% make
% make install

The last command will output a path. Take note of this. For our example, the path will look like:

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

Find your php.ini file. It is commonly under /etc/php.ini or /usr/local/lib/php.ini. Add these lines to your php.ini file:

[eaccelerator]

zend_extension="/usr/local/lib/php/extensions/no-debug-non-zts-20090626/eaccelerator.so"
eaccelerator.shm_size="16"
eaccelerator.cache_dir="/tmp/eaccelerator"
eaccelerator.enable="1"
eaccelerator.optimizer="1"
eaccelerator.check_mtime="1"
eaccelerator.debug="0"
eaccelerator.filter=""
eaccelerator.shm_max="0"
eaccelerator.shm_ttl="0"
eaccelerator.shm_prune_period="0"
eaccelerator.shm_only="0"
eaccelerator.compress="1"
eaccelerator.compress_level="9"

Make sure that the line in bold (zend_extension) is defined as the same path you took note of earlier in the installation. Restart Apache afterwards:

% apachectl restart

To test if eAccelerator is active, execute the following command:

% php -v

This should output something similar to:

PHP 5.3.1 (cli) (built: Jan 14 2010 22:06:44)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2009 Zend Technologies
    with eAccelerator v0.9.6, Copyright (c) 2004-2010 eAccelerator, by eAccelerator

Congratulations! You now have eAccelerator active.


Filed under: Uncategorized, Optimization, Improvements and Fixes, Atmail 5, Atmail 6 — John Contad @ 10:25 pm

 

May 24, 2010

 MySQL NDB for Atmail

This portion of the guide covers the steps necessary to use the MySQL NDB Cluster with two storage engines and one management server. This will allow the two MySQL servers to share data independently, and still have the same information for both. In the case of one server going down, the other server will still be active. Changes made to the other server during this period will be "healed" by the MySQL NDB management system.

Packages for MySQL NDB exist for a lot of systems. However, this guide will cover the process of installing it from source - along with PHP.

For this guide, we will have three servers - server1.local (192.168.0.1), server2.local (192.168.0.2), and server3.local (192.168.0.3). The first two servers will be the replicated storage engines. The third server will act as an NDB management machine.

Setting up the Storage Machines

This step applies to server1.local and server2.local. First, download the MySQL Cluster package from: http://dev.mysql.com/downloads/cluster/. Then, untar to your preferred base directory. For this example, we will use /usr/local/:

% tar xvfz mysql-cluster-gpl-7.1.3-linux-i686-glibc23.tar.gz -C /usr/local/

Create a symlink for ease, or rename the folder:

% ln -s /usr/local/mysql-cluster-gpl-7.1.3-linux-i686-glibc23 /usr/local/mysql

Then, install MySQL:

% cd /usr/local/mysql
% adduser mysql
% groupadd mysql
% scripts/mysql_install_db --user=mysql
% chown -R root  .
% chown -R mysql data
% chgrp -R mysql .
% cp support-files/mysql.server /etc/rc.d/init.d/
% chmod +x /etc/rc.d/init.d/mysql.server
% chkconfig --add mysql.server


Then, create a file called /etc/my.cnf. In the file, add:

[mysqld]
ndbcluster
ndb-connectstring=192.168.0.3
[mysql_cluster]
ndb-connectstring=192.168.0.3

Replace "192.168.0.3" with your management server's (server3.local) IP. Then, create the required directories:

% mkdir /var/lib/mysql-cluster

Setting up the Management Server

The MySQL Cluster package will contain the following files:

bin/ndb_mgm
bin/ndb_mgmd

Transfer these files to the server3.local server, as:

/usr/bin/ndb_mgm
/usr/bin/ndb_mgmd

Then, assign permissions:

% chmod +x /usr/bin/ndb_mgm
% chmod +x /usr/bin/ndb_mgmd

Then, create the required directories:

% mkdir /var/lib/mysql-cluster

In the directory, setup the configuration file called "/var/lib/mysql-cluster/config.ini". In the file:

[NDBD DEFAULT]
NoOfReplicas=2
[MYSQLD DEFAULT]
[NDB_MGMD DEFAULT]
[TCP DEFAULT]
# NDB MGM Server
[NDB_MGMD]
HostName=192.168.0.3
# MySQL servers
[NDBD]
HostName=192.168.0.1
DataDir= /var/lib/mysql-cluster
[NDBD]
HostName=192.168.0.2    
DataDir=/var/lib/mysql-cluster
[MYSQLD]
[MYSQLD]

Change the IP addresses accordingly, depending on your setup. Now, start the NDB management process:

% /usr/bin/ndb_mgmd

Starting the NDB processes

On the two MySQL servers, execute:

/usr/local/mysql/bin/ndbd --initial
/etc/rc.d/init.d/mysql.server start

You can check if the MySQL NDB is active by typing this in the third server (server3.local):

% ndb_mgm

This will show a terminal. Type:

ndb_mgm> show

It will show something similar to:

Cluster Configuration
---------------------
[ndbd(NDB)]    2 node(s)
id=2    @192.168.0.1  (mysql-5.1.44 ndb-7.1.3, Nodegroup: 0, Master)
id=3    @192.168.0.2  (mysql-5.1.44 ndb-7.1.3, starting, Nodegroup: 0)

[ndb_mgmd(MGM)]    1 node(s)
id=1    @192.168.0.3  (mysql-5.1.44 ndb-7.1.3)

[mysqld(API)]    2 node(s)
id=4    @192.168.0.1  (mysql-5.1.44 ndb-7.1.3)
id=5    @192.168.0.2  (mysql-5.1.44 ndb-7.1.3)


Congratuations! You have MySQL NDB active.


Filed under: Uncategorized, Database, Multiserver, Atmail 6 — John Contad @ 11:25 pm