Thursday, 24 February 2011

MYSQLTuner

MySQLTuner  is a perl script for mysql optimization.

To get uset it:


  wget http://mysqltuner.com/mysqltuner.pl
  chmod +x mysqltuner.pl
  ./mysqltuner.pl

I acheived amazing performance boost (server load dropped form 10 to 1) following the suggestions of this script, i.e.:


General recommendations:
    Add skip-innodb to MySQL configuration to disable InnoDB
    Run OPTIMIZE TABLE to defragment tables for better performance
    MySQL started within last 24 hours - recommendations may be inaccurate
    Enable the slow query log to troubleshoot bad queries
    Increase table_cache gradually to avoid file descriptor limits
Variables to adjust:
    query_cache_size (> 64M)
    table_cache (> 64)






Thanks mediakey.dk for introducing this amazing script.

nsd3+nginx+php-fpm+drupal

Install nsd3 and nginx

touch /etc/nsd3/nsd.conf
apt-get install nsd3
apt-get install nginx
Check these to figure out how to set up php5-fpm : (in case the instructions in the first link not works, install fpm from source, as describe in howtoforge )

http://gerardmcgarry.com/blog/how-install-php-fpm-nginx-ubuntu-1004-server
http://www.howtoforge.com/installing-php-5.3-nginx-and-php-fpm-on-ubuntu-debian

add an owner user
mkdir -p /srv/mysite
adduser rootuser
usermod -G www-data rootuser


apt-get install mysql-client mysql-server php5-mysql php5-imagick php5-gd


Create database and set permissions

mysql -u root -p

CREATE DATABASE mysitedb;
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON mysitedb.* TO 'mysiteuser'@'localhost' IDENTIFIED BY 'password#';
GRANT SELECT, INSERT, UPDATE, DELETE, CREATE, DROP, INDEX, ALTER ON mysitedb.* TO 'mysiteuser'@'localhost.localdomain' IDENTIFIED BY 'password';
FLUSH PRIVILEGES;
quit;


Install drupal
cd /srv/mysite
wget http://ftp.drupal.org/files/projects/drupal-6.20.tar.gz
tar zxvf drupal-6.20.tar.gz
mv drupal-6.20/* .
rm -r drupal-6.20 drupal-6.20.tar.gz


set up permissions
cd sites/default/
cp default.settings.php settings.php
chown www-data:www-data settings.php
chmod 775 settings.php
mkdir files
chown www-data:www-data files
chmod 775 files

Tuesday, 22 February 2011

memcached on drupal 6

environment: ubuntu hardy (8.04), drupal 6.13

memcached

To install memcached, you need to install libevent first:
sudo apt-get install libevent-dev
Install memcached:
mkdir src
cd src
wget http://memcached.googlecode.com/files/memcached-1.4.0.tar.gz
tar xzvf memcached-1.4.0.tar.gz
cd memcached-1.4.0
./configure
make
sudo make install
cd ..
Create control script:
sudo nano /usr/local/bin/memcache.sh
Add the following code:
#!/bin/sh
case "$1" in
start) /usr/local/bin/memcached -d -u root -m 240  -p 11211
;;
stop)  killall memcached
;;
esac
240 is the memory limit for the instance of memcached, the unit is MB.
11211 is the port number.
make it executable :
sudo chmod +x /usr/local/bin/memcache.sh 
start a memcached instance when the server startup:
sudo nano /etc/rc.local
add:
/usr/local/bin/memcache.sh start
start a memcached instance by running:
/usr/local/bin/memcache.sh start

PECL memcache extension for PHP

install php-pear if you have not installed it yet
apt-get install php-pear
install PECL memcache :
pecl install Memcache 
Edit the php.ini
nano/etc/php5/fpm  php.ini file:
add "extension=memcache.so" to it.

Restart nginx and php5-fmp


Memcache API and Integration module

open settings.php of your drupal site ( /sites/default/settings.php ), and add the following to the end of the file :
$conf = array(
   'cache_inc' => './sites/all/modules/memcache/memcache.inc',
 );
note: you may place './sites/all/modules/memcache/memcache.inc' with 'cache_inc' => './sites/all/modules/memcache/memcache.db.inc' to cache data both to memory and database if your memcache's memory limit is small or the memcached instance go offline often. (See the README.txt of Memcache API and Integration for more details. )
download Memcache API and Integration module from http://drupal.org/project/memcache, install and enable it.
Now, the integration of memcached and your drupal site is done. You can view memcache status from /admin/reports/memcache .

source

Sunday, 13 February 2011

set up postfix to send mails to google apps

After hours of search and trying several different solution, I found that it is surprisingly simle:

apt-get install postfix
nano /etc/postfix/main.cnf


change the following

mydestination = mydomain.com, localhost.mydomain.com, localhost

to

mydestination = localhost.mydomain.com, localhost
Reboot the server. Done!

Thanks Gyaan Sutra

Saturday, 29 January 2011

Install python 2.5 on ubuntu 10.04

So, you're a Python developer and like to use the 2.5.x track instead of the 2.6.x or the 3.x track. Well, never fear! Despite the fact that 2.5.5 is not installed in 10.04, or available in the repositories, you can still install it into your system. The following steps will show you how.
Open your terminal and type the following commands line by line:
sudo apt-get install build-essential gcc
cd Downloads
wget http://www.python.org/ftp/python/2.5.5/Python-2.5.5.tgz
tar -xvzf Python-2.5.5.tgz
cd Python-2.5.5
./configure --prefix=/usr/local/python2.5
make
make test
sudo make install
sudo ln -s /usr/local/python2.5/bin/python /usr/bin/python2.5
There you have it! Python 2.5.5 is installed. Now if you want to run it, you can type python2.5 from the terminal.


Source: Welcome to Ubuntu


Friday, 28 January 2011

Install virtualenv and django, no-nonesense way

Install virtualenv

Installing virtualenv is easy on a Linux or Mac system, but the instructions that follow are Linux (Ubuntu, actually) specific. First you’ll need setuptools:

sudo apt-get install python-setuptools

Then we can easy_install virtualenv:
sudo easy_install virtualenv
We need to use sudo here because it has to install to a global location. Don’t worry, this is the last time we’ll need to do something as root.

Create your virtualenv

cd to wherever it is you keep your projects (for me, in ~/src), and run:
virtualenv --no-site-packages venv
In this instance I’ve chosen venv as the name for my virtual environment. The —no-site-packages command tells virtualenv not to symlink the global site packages into my local environment, just take the Python standard library. This is important, because it helps us avoid the dependency difficulties mentioned above.
At this stage you might want to add venv to your list of ignored files, as you don’t want it to be committed to source control:
echo "venv" >> .gitignore

Installing Django

Now, the trick with virtualenv is that it creates its own Python and easy_install binaries, which means you can install/run things specifically in your environment. Let’s install Django:
./venv/bin/easy_install django
And it’s done. easy. You might also want to install the MySQL bindings and IPython for ease of use:
./venv/bin/easy_install ipython python-mysql
To start a new Django project, you’ll note that a django-admin.py file will have been installed for you in the environment:
./venv/bin/django-admin.py startproject myapp
Obviously you can skip this step if you have an existing Django project.

Running Django

Now the last step, which is probably obvious by now, is to run Django’s runserver with the virtual Python binary:
cd myapp
../venv/bin/python manage.py runserver 0.0.0.0:8000
And you’re away!


Source: Bradley Wright


Friday, 31 December 2010

Disable Root SSH Login on Debian

Before we begin, you should make sure that you have a regular user account and that you can su or sudo to root from it. So  do these first:


adduser usrer1
assign a passwd to user1. and then add it to sudoers. But first need to install sudo:


apt-get install sudo
add this line inside to 


        nano /etc/sudoers


user1  ALL=(ALL) ALL


Open the file up while logged on as root.
nano /etc/ssh/sshd_config
Find this section in the file, containing the line with “PermitRootLogin” in it.
#LoginGraceTime 2m
#PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
Make the line look like this to disable logging in through ssh as root.

PermitRootLogin no
Now you’ll need to restart the sshd service:

/etc/init.d/ssh restart
Now nobody can brute force your root login, at least.

Source: How-to Geek

Monday, 27 December 2010

install the latest nginx

You can get the latest stable version of Nginx from the Nginx PPA on Launchpad:
You will need to have root privileges to perform the following commands.
 
sudo su -
echo "deb http://ppa.launchpad.net/nginx/stable/ubuntu lucid main" >> /etc/apt/sources.list
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys C300EE8C
apt-get update 
apt-get install nginx

Source: nginx wiki

Upgrade Ubuntu server

aptitude update
and install the package update-manager-core:
aptitude install update-manager-core


Then run

do-release-upgrade

More details in howtoforge

Friday, 24 December 2010

'add-apt-repository: command not found'

add-apt-repository isn't installed by default. You have to install the python-software-properties package first.

sudo apt-get install python-software-properties