Wednesday, January 9

Page load improvements with Google's mod_pagespeed and memcached

A couple of weeks back I mentioned that mod_pagespeed now has support for memcached, so I was curious and enabled it on our web servers. Recently I've checked the page speed  section on Google Analytics and so far I'm very pleased with the results.

I sample a page that's gets heavy usage and also has lots of images on it, this shows 70% of page load samples loaded between 1-3 seconds.

mod_pagespeed file cache stats
mod_pagespeed with file cache


After upgrading mod_pagespeed and enabling memcached, it now shows that 45% of page load samples loaded between 0-1 seconds and 41% between 1-3 seconds.

mod_pagespeed with memcached enabled


My memcached server stats



http://googledevelopers.blogspot.ca/2012/11/scaling-automatic-web-optimization-with.html
https://developers.google.com/speed/docs/mod_pagespeed/system

Monday, December 17

Google's Mod Pagespeed now with Memcached support

"With this release we've reduced server load time and improved utilization for large, multi-server environments. We accomplished this by adding support for memcached (a popular, scalable cache), and improving logging and statistics reporting. With memcached, multiple Apache servers share and fetch the same resources optimized by mod_pagespeed. Logging and reporting have been improved to make it easier to keep track of resource consumption and optimization effectiveness across multiple sites hosted by a single Apache installation. These new features make mod_pagespeed even better for high-traffic sites and network providers hosting many individual websites on their infrastructure."

http://googledevelopers.blogspot.co.uk/2012/11/scaling-automatic-web-optimization-with.html

Thursday, November 22

Setting the Timezone for a Debian Server

To determine your current timezone


# cat /etc/timezone
America/Toronto

To select a new timezone

# sudo dpkg-reconfigure tzdata


More info: https://help.ubuntu.com/community/UbuntuTime

Thursday, July 26

Netbeans 7.2 released, how to fix menu and dialog box issues on Ubuntu 12.04 Unity

I've been mainly using lightweight editors on Ubuntu for doing quick edits or bug fixes, however when working on large projects having code completion and a nice source code navigator really helps. So I heard from reddit that 7.2 is out and quickly gave it a try.

http://wiki.netbeans.org/NewAndNoteworthyNB72#PHP

First thing I've noticed after installing netbeans was that the menu colors were a bit off, actually its unreadable with the default ambiance theme, easy fix switched to radiance theme. Then came the dialog boxes, which is probably why you're here as well.

Discussion about this issue on the netbeans forum: http://forums.netbeans.org/ptopic30206.html

The FIX that worked for me is this, I downloaded Java SE Development Kit 6 Update 33 from http://www.oracle.com/technetwork/java/javase/downloads/jdk6-downloads-1637591.html

chmod +x jdk-6u33-linux-x64.bin
./jdk-6u33-linux-x64.bin

It will extract the contents to a folder, move this to /usr/lib/jvm

sudo mv jdk1.6.0_33 /usr/lib/jvm/java-6-oracle

Locate your netbeans installation folder, open up etc/netbeans.conf, locate the following line and change it to:

#netbeans_jdkhome="/usr/lib/jvm/jdk1.7.0"
netbeans_jdkhome="/usr/lib/jvm/java-6-oracle"

That's it after that I was able to use netbeans on my secondary monitor and everything worked perfectly.

Also to fix the menu when using the ambiance theme I found this helpful post:

http://hanynowsky.wordpress.com/2012/04/27/netbeans-ide-look-feel-under-ubuntu-12-04/

Solution 1 worked

Go to your netbeans directory (ex: /home/user/netbeans7.2/etc) and open the file : netbeans.conf
then add the following line to netbeans options:
-J-Dswing.aatext=true -J-Dawt.useSystemAAFontSettings=lcd --laf Metal



Thursday, May 17

apt-history script

This morning I got a message from one of the servers I manage about a possible infection. Rkhunter wanted me to check this machine for infection, so I ran it on the server and got a warning about the /usr/bin/sudo file.

Then my desktop prompted me for updates and I noticed there was an update for the sudo package, this was a clue that the server might just have performed an automatic update.

I could have checked the log files but I was wondering if there was an easier way, then I found this script and life was simple.

function apt-history(){
      case "$1" in
        install)
              cat /var/log/dpkg.log | grep 'install '
              ;;
        upgrade|remove)
              cat /var/log/dpkg.log | grep $1
              ;;
        rollback)
              cat /var/log/dpkg.log | grep upgrade | \
                  grep "$2" -A10000000 | \
                  grep "$3" -B10000000 | \
                  awk '{print $4"="$5}'
              ;;
        *)
              cat /var/log/dpkg.log
              ;;
      esac
}

Install it in /root/.bashrc and just change to root and type:

apt-history upgrade
2012-05-17 06:41:53 upgrade sudo 1.7.2p1-1ubuntu5.3 1.7.2p1-1ubuntu5.4




http://linuxcommando.blogspot.ca/2008/08/how-to-show-apt-log-history.html

Wednesday, January 11

Multi-Master Replication using Tungsten and Mysql-Proxy For Mysql High Availability

This tutorial is based on my experience setting up Tungsten Replicator and Mysql-Proxy for a client's production setup. Initially the plan was to have a master and a slave server, but with my research and testing on Tungsten I believe I have a found a solid solution for providing a multi-master mysql setup.

1. My Setup

For the tutorial I'll be using 3 virtual machines
Web Server 1  : web1   IP Address 192.168.56.101
Master 1  : master1 IP Address 192.168.56.10
Master 2  : master2 IP Address 192.168.56.11

2. Setup Web Server

$ sudo su
$ tasksel
select LAMP server and click OK

3. Configuring Mysql-Proxy on the web server

$sudo apt-get -y install mysql-proxy
$vi /etc/default/mysql-proxy
ENABLED="true"
OPTIONS="--defaults-file=/root/mysql-proxy.cnf"
The defaults-file option should point to where you have saved /root/mysql-proxy.cnf
[mysql-proxy]
daemon = true
proxy-address = 127.0.0.1:3305
proxy-skip-profiling = true
keepalive = true
event-threads = 50
pid-file = /var/run/mysql-proxy.pid
log-file = /var/log/mysql-proxy.log
log-level = debug
proxy-backend-addresses = 192.168.56.10:3306,192.168.56.11:3306
proxy-lua-script=/usr/lib/mysql-proxy/lua/proxy/balance.lua
We don't need to start mysql-proxy yet as we still need to configure our backend

4. Configure Mysql Servers

I actually only configured one and just cloned it after I have setup everything and just changed the /et/hostname, /etc/hosts and /etc/network/interfaces to match the settings for the second server.
sudo su apt-get install -y mysql-server

5. Preparing Mysql Servers for Tungsten Replicator Installation

The host requirements can be found here https://s3.amazonaws.com/releases.continuent.com/doc/replicator-2.0.4/html/Tungsten-Installation-Guide-mysql/content/ch05.html however I've prepared a short list of what I had to configure to get my setup working.

MYSQL

$ cat /etc/mysql/my.cnf
[mysqld]
# Master replication settings.
server-id=1
# set increment for up to 4 servers
auto_increment_increment = 4
# increment offset for this server, next server would be 2
auto_increment_offset = 1


log-bin=mysql-bin

# Required InnoDB parameter settings for Tungsten.  Buffer pool size may be 
# larger but should not be smaller for production deployments. 
innodb_buffer_pool_size = 512M

# Recommended InnoDB settings for Tungsten.  
default-table-type=InnoDB
innodb_flush_log_at_trx_commit=2
sync_binlog=0

# Recommended general settings.  max_allowed_packet must be greater than
# the size of the largest transaction. 
max_allowed_packet=48m

MYSQL User Permissions

Tungsten uses this account to recreate transactions
$ mysql -u root -p
mysql> grant all on *.* to tungsten@'%' identified by 'secret' with grant option;

Ruby

$ apt-get install -y ruby libopenssl-ruby
To test:
$ echo "p 'hello'" | ruby -ropenssl
"hello"

JAVA Virtual Machine

$ apt-get install openjdk-6-jre
$ echo $JAVA_HOME //Should point to Sun JDK install location
$ java -version

How to set your JAVA_HOME

Edit /etc/bash.bashrc and append the following at the end of the file.
JAVA_HOME=/usr/lib/jvm/java-6-openjdk
export JAVA_HOME
Reload bash settings
$source /etc/bash.bashrc

Network

uname -n should resolve to unique name of host
hostname --ip-address resolve to real IP, private IP accepted

cat /etc/hosts
...
192.168.56.10 master1
192.168.56.11 master2
...

SSH

Certificate based ssh login for account used to run tungsten, I used the root account. The machine you're using to setup Tungsten must be able to ssh without a password to the other machine.
$ sudo su
$ ssh-keygen
$ cat .ssh/id_rsa.pub
On the other machine copy the contents of id_rsa.pub to .ssh/authorized_keys
$ chmod 0600 .ssh/authorized_keys

6. Installing Tungsten Replicator

You only need to install tungsten on one machine and from there you can install additional services to other nodes.
Binary Build Download
$ wget http://tungsten-replicator.googlecode.com/files/tungsten-replicator-2.0.4.tar.gz
$ tar -zxvf tungsten-replicator-2.0.4.tar.gz
$ cd tungsten-replicator-2.0.4
I used the following script to configure the master servers.
$ cat setup-masters.sh
#! /bin/bash

TUNGSTEN_HOME=/opt/replication
MASTER1=master1
MASTER2=master2

./tools/tungsten-installer \
    --master-slave \
    --master-host=$MASTER1 \
    --datasource-user=tungsten \
    --datasource-password=secret \
    --service-name=zoid \
    --home-directory=$TUNGSTEN_HOME \
    --cluster-hosts=$MASTER1 \
    --start-and-report

  ./tools/tungsten-installer \
    --master-slave \
    --master-host=$MASTER2 \
    --datasource-user=tungsten \
    --datasource-password=secret \
    --service-name=linus \
    --home-directory=$TUNGSTEN_HOME \
    --cluster-hosts=$MASTER2 \
    --start-and-report
After running the above script the tungsten home directory will be populated, this is in /opt/replication/ Inside this folder execute the script to setup the slave services for each master. Our setup is basically like this:
master1
master service   - master1
slave service   - master2 - copies events from master1 and transfers it to master2 master service

master2
master service  - master2
slave service  - master1 - copies events from master2 and transfers it to master1 master service
$ cd /opt/replication/tungsten
$ cat setup-slaves.sh
#! /bin/bash
MASTER1=master1
MASTER2=master2
TUNGSTEN_TOOLS=tools

$TUNGSTEN_TOOLS/configure-service \
   --host $MASTER1 \
   -C -q \
   --local-service-name=zoid \
   --role=slave \
   --service-type=remote \
   --datasource=$MASTER1 \
   --master-thl-host=$MASTER2 \
   --svc-start linus

$TUNGSTEN_TOOLS/configure-service \
  --host $MASTER2 \
  -C -q \
  --local-service-name=linus \
  --role=slave \
  --service-type=remote \
  --datasource=$MASTER2 \
  --master-thl-host=$MASTER1 \
  --svc-start zoid
Now let's check if our services are running.
root@master1:/opt/replication/tungsten# tungsten-replicator/bin/trepctl services
Processing services command...
NAME              VALUE
----              -----
appliedLastSeqno: 2296
appliedLatency  : 2.178
role            : slave
serviceName     : linus
serviceType     : remote
started         : true
state           : ONLINE
NAME              VALUE
----              -----
appliedLastSeqno: 1611
appliedLatency  : 0.953
role            : master
serviceName     : zoid
serviceType     : local
started         : true
state           : ONLINE
Finished services command...
And on master2
root@master1:/opt/replication/tungsten# tungsten-replicator/bin/trepctl services
Processing services command...
NAME              VALUE
----              -----
appliedLastSeqno: 2296
appliedLatency  : 2.178
role            : slave
serviceName     : linus
serviceType     : remote
started         : true
state           : ONLINE
NAME              VALUE
----              -----
appliedLastSeqno: 1611
appliedLatency  : 0.953
role            : master
serviceName     : zoid
serviceType     : local
started         : true
state           : ONLINE
Finished services command...

7. Start Mysql-Proxy

$ /etc/init.d/mysql-proxy start
Verify that it is running
$ netstat -tulnap | grep 3305

8. Test Replication

Let's test it using phpmyadmin, download and install phpmyadmin and configure it. On you browser go to http://192.168.56.101/phpmyadmin/ and on the list of servers you should be able to connect to mysql-proxy and the two other nodes. You can now test and see if your replication is working properly, you can shutdown one node by unplugging of its ethernet connection, write data to the other node and then turn the other node back on.
For more information regarding:
  • Tungsten visit their Wiki.
  • Mysql Proxy visit their Homepage
$i++;
/* Authentication type */ 
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '127.0.0.1';
$cfg['Servers'][$i]['port'] = '3305'; 
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;

$i++;
/* Authentication type */ 
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '192.168.56.10';
$cfg['Servers'][$i]['port'] = '3306'; 
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;

$i++;
/* Authentication type */ 
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = '192.168.56.11';
$cfg['Servers'][$i]['port'] = '3306'; 
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = false;

Saturday, December 31

Winter fun!

http://www.youtube.com/watch?v=UwcYCAjHay0&feature=youtu.be

Happy New Year!