What is swappiness and how to change

linux, swappiness

In Linux it is very easy to configure the use of virtual memory used by the kernel. Swappiness controls the tendency of the linux kernel to move a process out of physical memory and start using swap. Disk is slower than RAM and thus can lead to a slower response time for the application itself, therefore swappiness controls how often processes are moved into the swap cache.

For example, if swappiness is set to 0, the kernel will avoid moving processes into the swap cache.

If swappiness is set to 100, the kernel will regularly use the swap cache.

By default, this setting is normally held at 60.

On a virtualised node, a good swappiness parameter to use is 010, that is because a VM has shared disk IO and it is important for the overall system to use less disk utilization.

How to change?

Find out how much swappiness is being used by running : cat /proc/sys/vm/swappiness
Adjust the parameter by changing/adding this parameter (vm.swappiness = 0) and save in: /etc/sysctl.conf
To get the change live without a restart or sysctl reload, you can run this: echo 0 > /proc/sys/vm/swappiness

rsync: verbosity with progress bar

linux, rsync

I like to have a verbose, informative rsync when copying files from server to server.

I use the following options as part of my rsync, so that I have a progress bar in human readable format. This is also verbose so that it shows the current status of the file transfer.

rsync -AavlXpzh –progress some_folder/ me@200.100.50.10:~me/some_folder

Setup LAMP and phpMyAdmin from scratch on Ubuntu 10+

apache, lamp, linux, mysql, php, phpmyadmin

It’s really easy to get a LAMP webserver up and running, so I thought I’d post some nice easy instructions for installing on a Ubuntu box.

1) sudo apt-get install mysql-server mysql-client
-> you will need to choose a MySQL Root user password

2) sudo apt-get install apache2
-> confirm in your browser that you are able to view a page for your IP address. This could be localhost, or your local IP address.

3) sudo apt-get install php5 libapache2-mod-php5
-> you’re going to need to install PHP next as above.

4) /etc/init.d/apache2 restart
-> …and of course an Apache restart so that PHP is activated

5) sudo apt-get install phpmyadmin
-> you’re going to be asked which webserver to configure. go for apache2. it’ll then probably request your password you selected for MySQL.

6) vim /etc/apache2/apache2.conf
-> use your favorite editor to open up the apache config file

7) Include /etc/phpmyadmin/apache.conf
-> add the following somewhere in the file.

8) /etc/init.d/apache2 restart

9) http://yourhomepage.com/phpmyadmin
-> test 🙂

Linux locale setting failure

linux

When your locales are screwed, you’re going to notice a lot of problems even trying to curl from the command line, for e.g.:
Sorry, command-not-found has crashed! Please file a bug report at:

If you see an error message like this:
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = “UTF-8”,
LANG = “en_US.UTF-8”

root@mwtokyo3:~# dpkg-reconfigure locales
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = (unset),
LC_ALL = (unset),
LC_CTYPE = “UTF-8”,
LANG = “en_US.UTF-8”
are supported and installed on your system.
perl: warning: Falling back to the standard locale (“C”).
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
Generating locales…
en_AG.UTF-8… up-to-date
en_AU.UTF-8… up-to-date
en_BW.UTF-8… up-to-date
en_CA.UTF-8… up-to-date
en_DK.UTF-8… up-to-date
en_GB.UTF-8… up-to-date
en_HK.UTF-8… up-to-date
en_IE.UTF-8… up-to-date
en_IN.UTF-8… up-to-date
en_NG.UTF-8… up-to-date
en_NZ.UTF-8… up-to-date
en_PH.UTF-8… up-to-date
en_SG.UTF-8… up-to-date
en_US.UTF-8… up-to-date
en_ZA.UTF-8… up-to-date
en_ZM.UTF-8… up-to-date
en_ZW.UTF-8… up-to-date
Generation complete.

Just add this to your ~/.profile and ~/.bashrc
export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
export LANGUAGE=en_US.UTF-8

Then:
source ~/.profile
source ~/.bashrc

Then try again, all should be good.

puppet failures due to “dnsdomainname: Unknown host”

linux, puppet, selinux

When I was trying to start puppet, I had the following message:
[root@m03 puppet]# service puppet start
Starting puppet: dnsdomainname: Unknown host
dnsdomainname: Unknown host

Even though puppet started successfully. I checked my /etc/hosts file as puppet looks up DNS from there, everything looked fine. I also disabled selinux as that had been recommended on another blog. That might work for you, but didn’t do much for me.

Trying to sign my certificate was proving to be the same issue as well, rendering my puppet setup completely useless:
/usr/sbin/puppetd –waitforcert 30
dnsdomainname: Unknown host
dnsdomainname: Unknown host

I decided to check on the puppet master to see if my signature request had successfully hit the master:
puppet cert list –all | grep -i m03
…but no joy there.

When the dnsdomainname error comes up, the obvious answer is that the DNS is not resolving and it turns out that my puppet install is using an extra DNS entry to connect to the master. I compared an entry on another machine in /etc/resolv.conf, added that to the new machine; ran:
/usr/sbin/puppetd –waitforcert 30

…then the catalog ran successfully.

Redirecting outbound email with exim

exim, linux

I wanted to build a replica of our production environment on a development environment, one problem being that our production environment sends a lot of emails to our clients.

I therefore needed to redirect or restrict all of our outbound emails.

With that in mind, I needed to make sure that exim [typically what we use to send mails] would not be able to send any mail to our clients, and instead it would be sending mails to a manually defined inbox.

The first thing I needed to do, was check that exim was actually working.

I sent myself an email:

/usr/sbin/exim -v ‘alex@myemail.com’
Some message here
[CTRL+D]

That  then responded with the 250 OK codes to confirm that the mail had been delivered to myself.

That’s no good on this environment though, as I needed to ensure that exim would be redirecting to a defined mailbox. Let’s call it “some@mailbox.com”

To do this, I needed to change the routers on the exim configuration file (/etc/exim/exim.cnf).

In vim, search for the string “begin routers”

The crucial point here is that the order of which the routers are defined is important, so you will need to put the new, first rule for routers at the top of this section. What did I include?

blah:
driver = redirect
domains = whereitscomingfrom.com
data = some@mailbox.com

I then repeated the mail send:

/usr/sbin/exim -v ‘alex@myemail.com’
Some message here
[CTRL+D]

I could then see a 250 OK code, but it was actually going to some@mailbox.com instead.

Some useful links for NFS Sharing

iptables, linux

I’d forgotten to set my ip tables:

http://eduardo-lago.blogspot.jp/2012/02/installing-nfs-on-centos-62.html

So my NFS shares weren’t working.

This was a useful page:

http://qugstart.com/blog/linux/centos-nfs-how-to-guide-exporting-and-mounting-a-nfs-drive/