Wednesday, March 2, 2011

Tuesday, February 15, 2011

Clear memory caches on Linux

To free pagecache:

sync; echo 1 > /proc/sys/vm/drop_caches


To free dentries and inodes:

sync; echo 2 > /proc/sys/vm/drop_caches


To free pagecache, dentries and inodes:

sync; echo 3 > /proc/sys/vm/drop_caches


sync should be run because this is a non-destructive operation, and dirty objects are not freeable. So you run sync in order to make sure all cached objects are freed.

Thursday, February 3, 2011

Install and set php extention Memcached

yum install gcc gcc-c++


Install the dependency libevent

cd /usr/local/src
curl -O http://monkey.org/~provos/libevent-1.4.14b-stable.tar.gz
tar xzvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure --prefix=/usr/local
make && make install


Next, install memcached:

cd /usr/local/src
curl -O http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar xzvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
LDFLAGS='-Wl,--rpath /usr/local/lib' ./configure --prefix=/usr/local
make && make install


Lets install the new PECL memcached extension in your web server. This new extension depends on libmemcached. You can grab the latest distribution of libmemcached from https://launchpad.net/libmemcached and compile it in your own machine. Make sure you have the dependencies met.

cd /usr/local/src
wget http://launchpad.net/libmemcached/1.0/0.44/+download/libmemcached-0.44.tar.gz
tar -zxvf libmemcached-0.44.tar.gz
cd libmemcached-0.44
./configure
make && make install


Considering everything went fine, lets install the PECL memcached extension

pecl install memcached


Build process completed successfully
Installing '/usr/lib64/php/modules/memcached.so'
install ok: channel://pecl.php.net/memcached-1.0.2
configuration option "php_ini" is not set to php.ini location
You should add "extension=memcached.so" to php.ini

Sunday, January 9, 2011

How to Install fastcgi and Nginx on Centos

Install PHP & depends:

yum install gcc pcre-devel openssl-devel php-pear-Net-Socket php-pear php-common php-gd php-devel php php-mbstring php-pear-Mail php-cli php-imap php-snmp php-pdo php-xml php-pear-Auth-SASL php-ldap php-pear-Net-SMTP php-mysql


Download & install spawn-fcgi

cd /usr/local/src
wget http://www.lighttpd.net/download/spawn-fcgi-1.6.3.tar.gz
tar -xzvf spawn-fcgi-1.6.3.tar.gz
cd spawn-fcgi-1.6.3
./configure
make & make install


add user nginx

useradd nginx


Create file fastcgi in /etc/init.d/ directory and put

#!/bin/bash
PHP_SCRIPT=/usr/local/bin/php-fastcgi
RETVAL=0
case "$1" in
start)
$PHP_SCRIPT
RETVAL=$?
;;
stop)
killall -9 php
RETVAL=$?
;;
restart)
killall -9 php
$PHP_SCRIPT
RETVAL=$?
;;
*)
echo "Usage: fastcgi {start|stop|restart}"
exit 1
;;
esac
exit $RETVAL



change mode

chmod 755 fastcgi


Create file /usr/local/bin/php-fastcgi

#!/bin/sh
/usr/local/bin/spawn-fcgi -a 127.0.0.1 -p 9000 -u nginx -f /usr/bin/php-cgi


change mode

chmod 755 /usr/local/bin/php-fastcgi


Download and install nginx

cd /usr/local/src
wget http://sysoev.ru/nginx/nginx-0.8.54.tar.gz
tar -xzvf nginx-0.8.54.tar.gz
cd nginx-0.8.54

./configure --prefix=/usr --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access_log --error-log-path=/var/log/nginx/error_log --pid-path=/var/run/nginx.pid --http-client-body-temp-path=/var/tmp/nginx/client --http-proxy-temp-path=/var/tmp/nginx/proxy --http-fastcgi-temp-path=/var/tmp/nginx/fastcgi --with-md5-asm --with-md5=/usr/include --with-sha1-asm --with-sha1=/usr/include --with-http_realip_module --with-http_ssl_module --with-http_perl_module --with-http_stub_status_module

make & make install




Create configuration file for nginx /etc/nginx/nginx.conf

worker_processes 1;
error_log /var/log/nginx/error.log;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}

http {
include mime.types;
default_type application/octet-stream;
client_max_body_size 10m;
sendfile on;
charset utf-8;
gzip on;
gzip_types text/plain application/xml text/javascript;
gzip_min_length 1000;

keepalive_timeout 65;



server {
listen 80;
server_name www.3nky.com;
server_tokens off;
root /home/3nky/public;
index index.php index.html index.htm;

access_log /var/log/nginx/3nky.com-access_log;
error_log /var/log/nginx/3nky.com-error_log;

#location / {
# try_files $uri /index.php;
#}

location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}


location / {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass 127.0.0.1:9000;
}

}
}


Thursday, January 6, 2011

How to install memcached on CentOS

yum -y install gcc gcc-c++


First, install the dependency libevent:

cd /usr/local/src
wget http://www.monkey.org/~provos/libevent-2.0.10-stable.tar.gz
tar -xzvf libevent-2.0.10-stable.tar.gz
cd libevent-2.0.10-stable
./configure
make
make install



cd /usr/local/src
wget http://memcached.googlecode.com/files/memcached-1.4.5.tar.gz
tar -xzvf memcached-1.4.5.tar.gz
cd memcached-1.4.5
./configure
make
make install


Locate the file surely that is in /usr/local/lib and make a symbolic link

ln -s /usr/local/lib/libevent-2.0.so.5 /usr/lib64/libevent-2.0.so.5


run memcached

memcached -u root -d

Wednesday, December 22, 2010

Monday, December 20, 2010

Installing and configure Apache Solr with MySQL


Apache Solr™ is our high performance enterprise search server, with XML/HTTP and JSON/Python/Ruby APIs, hit highlighting, faceted search, caching, replication, distributed search, database integration, web admin and search interfaces.

1. Install Java

yum install java


2. Download & Extract Solr

cd /usr/local/src
wget http://www.apache.org/dist//lucene/solr/1.4.1/apache-solr-1.4.1.tgz
tar -xzvf apache-solr-1.4.1.tgz


3. Download MySQL Java connector

wget http://mysql.spd.co.il/Downloads/Connector-J/mysql-connector-java-3.1.14.zip
unzip mysql-connector-java-3.1.14.zip
cd mysql-connector-java-3.1.14
cp mysql-connector-java-3.1.14-bin.jar /usr/local/src/apache-solr-1.4.1/example/lib/


4. Configure MySQL Database
Create a new xml file called data-import.xml , change the obvious variables to suit your DB. In this example, I am indexing a own DB table called users.

cd /usr/local/src/apache-solr-1.4.1/example/solr/conf
nano data-import.xml

put follow text

<dataconfig>
<datasource type="JdbcDataSource" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://192.168.1.7/mydatabase" user="myuser" password="mypassword">
<document name="content">
<entity name="node" query="select user_id AS id, mobile AS mobile, user_status AS status FROM users">
<field column="id" name="id">
<field column="mobile" name="mobile">
<field column="status" name="status">
</field></field></field></entity>
</document>
</datasource>
</dataconfig>



5. Configure solr .
Edit file solrconfig.xml which is located in /usr/local/src/apache-solr-1.4.1/example/solr/conf directory. Add the following requestHandler entry if not already existing.

<requesthandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requesthandler>


6. Now we will configure solr’s schema by editing schema.xml in /usr/local/src/apache-solr-1.4.1/example/solr/conf directory. Delete old tag and add the following fields as required. The xml format is self explanatory.

<fields>

<field name="id" type="string" indexed="true" stored="true" default="NOW" required="true">
<field name="mobile" type="text" indexed="true" stored="true" required="true">
<field name="status" type="text" indexed="false" stored="true" required="false">

</field></field></field></fields>

<uniquekey>id</uniquekey>

<!-- field for the QueryParser to use when an explicit fieldname is absent -->
<defaultsearchfield>mobile</defaultsearchfield>



7. Start SOLR

java -jar /usr/local/src/apache-solr-1.4.1/example/start.jar



Performing full or delta indexing
If everything works correctly, you can get solr to fully index the configured tables by accessing the following command via your browser. http://:8983/solr/dataimport?command=full-import

You can check the status of the command by accessing http://:8983/solr/dataimport

If everything works correctly, you can now search for data from http://:8983/solr/admin/ and you should now have data results in XML format.


To do an incremental or delta indexing of data since the last full or delta, increment, issue the command http://:8983/solr/dataimport?command=delta-import

You can now access these xml results from your web application. There are client api’s available for RoR, php, java etc.

References
http://www.cabotsolutions.com/2009/05/using-solr-lucene-for-full-text-search-with-mysql-db/

http://www.ipros.nl/2008/12/15/using-solr-with-wordpress/

http://wiki.apache.org/solr/DataImportHandler#head-df246a3aed0bb38297f3449bc35a0bdf38a272b5

http://lucene.apache.org/solr/tutorial.html