Encrypted directory with losetup

April 14, 2014
Create a file device:
dd if=/dev/zero of=/tmp/crypto.raw bs=1M count=100
Mount Loop device:
losetup -e blowfish `losetup -f` /tmp/crypto.raw
Format:
mkfs.ext3 /dev/loop0
losetup -d /dev/loop0
Mount Loop device:
mount -t ext3 /tmp/crypto.raw /mnt/crypto/ -o encryption=blowfish

Tcpdump

April 14, 2014
  • Get the last 20 packets exept ssh connections
tcpdump -s 0 -n not port ssh -c 20
  • Get the last 100 http packets and extract hosts
tcpdump -s 0 -n -ttt -v -A port 80 -c 100 | grep Host
  • Get the last 100 MySQL queries
tcpdump -s 0 -n -ttt -v -A port 3306 -c 100 | grep SELECT

Sphinx Search

April 13, 2014

I use Sphinx to search text in 5 millions records. Mysql is not as good, sphinx is a deticated read only database to search text. The performance are so good, that I use sphinx for everything, even for regular queries.

I managed to reduce the load of my servers by a factor of 10 !

See my post about perlformance and memcache.

Memcache

April 13, 2014

I was having performace issue in 2008 on my websites, the traffic was getting hight and I had no budget the get more servers.

I already used an architecture with squid as a load balancer, and mysql slaves severs.

With no budget, I had to find a way to improve the load performace with the database’s size and the traffic growing every days.

I found sphinx search index and Memcache.

I choosed Memcache by looking what other website used. I found that Facebook was using Memcache. Memcache is quiet simple, it’s just a daemon with keys and values that you can read or write.

  • I modified my php Sql classes by storing most of mysql queries in memcache with a simple md5 sum of the SQL selects.
  • I did the same for my object classes, I know the arguments of my class product->load(args), now I can store a full unserialized object, the key is an md5 of the unserialized arguments.
Bingo, I was able to share a sql and php object cache between all my slaves.

Perl

April 13, 2014

When I need performance and I need to code complicated things, Perl is always my choice. I like the syntax and miss so much map and grep when I’m programing on with other languages. I used perl for every background task like matching millions of records, downloading giga bytes of xml with fork processes, writing daemons, ….

Pros:
  • The syntaxe
  • Hashs, grep perl
  • There is a module for everything in CPAN
  • The performance, can be quicker than C because of the compilator optimisation.
Cons:
  • Mod_perl in Apache is complicate to configure, performace used to be not as great as php

Php

April 13, 2014
I choosed Php to develop websites.I never been a big fan, coming from Perl, but considering alternatives it does the job when you have your own functions and classes. I use php as a template language. Pros:
  • It’s populare
  • It’s mature
  • Easy to find some developers
  • It’s a good couple with Apache
Cons:
  • No real hash
  • It’s not Perl !
The table below is an easy reference for what these functions will return for different values. The blank spaces means the function returns bool(false).
Value of variable ($var) isset($var) empty($var) is_null($var)
“” (an empty string) bool(true) bool(true)
” ” (space) bool(true)
FALSE bool(true) bool(true)
TRUE bool(true)
array() (an empty array) bool(true) bool(true)
NULL bool(true) bool(true)
“0” (0 as a string) bool(true) bool(true)
0 (0 as an integer) bool(true) bool(true)
0.0 (0 as a float) bool(true) bool(true)
var $var; (a variable declared, but without a value) bool(true) bool(true)
NULL byte (“\ 0?) bool(true)

Mysql

April 13, 2014
MySQL is a database wich support master/slave replication system. Lock the database to run a command: FLUSH TABLES WITH READ LOCK; SYSTEM sh -c 'backup.sh'; UNLOCK TABLES; Pros:
  • The master/slave replication is mature and powerfull
  • Innodb provide good performance on big tables
Cons:
  • Can’t find any for my use

Squid Proxy Cache / Load Balancer

April 13, 2014

Squid is a proxy cache that I use for hight availability and load balacing web sites.

Pros:
  • Can handle any case
  • Good performance
Cons:
  • The documentation is not friendly

WordPress

April 13, 2014

WordPress is a great solution to generate quickly a website with articles.

Wordpress use php and a mysql database. Here is the database scheme.

You can find many plugins for wordpress to suit it to you need.

You can easly create some template for the apparence, or you can just download templates made by others.

Puppet

April 13, 2014
Puppet offer to sysadmin to centralize the instalation and the configuration of their servers. One puppet master keep the configuration of all servers. Each server is a client which execute the code from the master. Puppet can create automaticly different type of resources. Puppet create resources not in order, it’s important to understand how to deal with that behavior: puppet ordering. Pros:
  • Cross plateform (eg: Linux, MacOs, Microsoft)
  • Create configurations file after installing packages with erb templates.
  • Centratlise servers infos, named “facts” (cpu, memory, interfaces, …) with PuppetBD
Cons:
  • A resource can be declare only once
  • A variable can be set only one time
  • Puppet is not as good as rsync for directories copy
  • Puppet master is running as user puppet, it can’t read protected permission (ex: .ssh/*)
  • All the facts are all loaded when puppet agent runs
  • Ordering actions could be quiet painfull for a novice
  • Can’t change a variable value that is already set