Category Archives: Uncategorized

Removing logging to increase I/O performance on the Raspberry Pi

I recently was looking at optimizing the device to make Apache run faster. Thanks to TAFB from #raspberrypi on FreeNode IRC chat, I experimented with turning off syslog and noticed a few second increase with the two different sites hosted on the Pi. Overall, there will be less IO on the system and less RAM and CPU being used that will result in slightly better performance on the PI. Also, there will be significantly less writes on the SD card. SD cards have a limited number of writes so it is important to reduce the numbers to have a longer lifespan.

The distribution used is Arch Linux.

In /etc/systemd/journald.conf:
Storage=none

Manage The Services:
# systemctl stop systemd-journald
# systemctl disable systemd-journald

Remove Syslog:
# systemctl stop syslog-ng.service
# systemctl disable syslog-ng.service
# pacman -R syslog-ng

Next, I began to tune root filesystem for optimal performance and disabled logging.

Add the following to /etc/fstab:

/dev/mmcblk0p2 / ext4 rw,noatime,data=writeback,barrier=0,nobh,errors=remount-ro 0 1

# reboot

# tune2fs -o journal_data_writeback /dev/mmcblk0p2

Before: Rusher81572.com loaded in 2.857s
After: Rusher81572.com loaded in 2.149s

Before: Rusher81572.com/pi loaded in 4.356s
After: Rusher81572.com/pi loaded in 4.039s

linuxraspberry pi

Dovecot/Postfix Email Server setup with Gmail Relay

I have been struggling to get an email server setup and working by following many guides online. Here is how I got it working. I had to use Gmail as an relayhost to actually send the email from the server because my ISP blocks me from sending mail on port 25 and doesn’t allow me to relay mail through their servers because I’m using  instead of )

Software: postfix and dovecot
Operating System: CentOS and Archlinux
(CentOS users need to install cyrus-sasl-plain also )

SASL Configuration

Modify or create: /usr/lib/sasl2/smtpd.conf

pwcheck_method:saslauthd
saslauthd_path: /var/run/saslauthd/mux
SASLAUTHD_OPTS=”${SASLAUTH_MECH} -a pam”
mech_list: plain login
log_level: 7

Dovecot Configuration

Copy the dovecot configuration files :

# cp /usr/share/doc/dovecot/example-config/* /etc/dovecot/

Modify /etc/dovecot/dovecot.conf:

protocols = imap

Modify: /etc/dovecot/conf.d/10-auth.conf :

disable_plaintext_auth = no

Modify: /etc/dovecot/conf.d/10-mail.conf :

mail_location = maildir:~/Maildir

Create or Modify: /etc/pam.d/dovecot

auth required pam_unix.so nullok
account required pam_unix.so

Postfix Configuration

Modify /etc/postfix/main.cf:

myhostname = rusher81572.com
mydomain = rusher81572.com
myorigin = $mydomain
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost
relayhost = [smtp.gmail.com]:587
home_mailbox = Maildir/
smtp_use_tls=yes
smtp_sasl_auth_enable = yes

smtpd_sasl_auth_enable = yes

smtp_sasl_password_maps = hash:/etc/postfix/password

smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
smtp_sasl_security_options =
smtpd_recipient_restrictions = permit_sasl_authenticated,permit_mynetworks,check_relay_domains

Create /etc/postfix/password:

[smtp.gmail.com]:587 username:password

#postmap /etc/postfix/password

#systemctl start postfix

Create a DHCP and DNS server with RedHat/ CentOS Linux

#yum -y install bind bind-utils dhcp

 

Tell what interface to use with dhcpd:   /etc/sysconfig/dhcpd

DHCPDARGS=eth2

 

In /etc/named.conf add: (Modify to suit the following)

allow-query     { any; };

allow-recursion {any; };

listen-on port 53 { 10.10.10.2; };

 

Add this zone near the bottom:

 

zone “dhcpserver” IN {

type master;

file “dhcpserver”;

allow-update { any; };

notify no;

};

 

Create /var/named/dhcpserver:

 

@       IN      SOA     dhcpserver. hostmaster.dhcpserver. (

2012080701      ; Serial

43200      ; Refresh

3600       ; Retry

3600000    ; Expire

2592000 )  ; Minimum

;       Define the nameservers and the mail servers

IN      NS      dhcpserver.

IN      A       10.10.10.2

ns            IN      A       10.10.10.2

www        IN      A       10.10.10.2

client        IN      A       10.10.10.3

gateway        IN      A       10.10.10.2

 

Only have this in /etc/dhcp/dhcpd.conf:

 

subnet 10.10.10.0 netmask 255.255.255.0 {

option routers                  10.10.10.2;

option subnet-mask              255.255.255.0;

option domain-name              “dhcpserver”;

option domain-name-servers       10.10.10.2;

option time-offset              -18000;     # Eastern Standard Time

range 10.10.10.20 10.10.10.30;

}

 

#chkconfig named on

#chkconfig dhcpd on

#service named start

#service dhcpd start

CentOSlinuxRedHat

Convert root partition to LVM and mirror the root disk

1. Create a tar backup of your filesystem.

# tar czpf /root/redhat.tar –exclude=/var/tmp/portage/* –exclude=/root/* –exclude=/usr/portage/* –exclude=*.deb –exclude=/tmp/* –exclude=*.rpm –exclude=/sys/* –exclude=/proc/* –exclude=/dev/* –exclude=/mnt/* –exclude=/media/* –exclude=/home/* –exclude=/var/lib/libvirt/images/* –exclude=/oracle/* –exclude=redhat.tar

2. Use fdisk to create /boot and 1 LVM partition on the new disk.

/dev/sda1 * 1 100 803218+ 83 Linux
/dev/sda2 101121601 975956782+ 8e Linux LVM

3. Set /dev/sda1 to be bootable.

# parted /dev/sda set 1 boot on

4. Create the new LVM partition.

# pvcreate /dev/sda2
# vgcreate vg /dev/sda2
# lvcreate -L 200G /dev/vg -n root
# mkfs /dev/vg/root
# mkfs /dev/sda1
# mount /dev/vg/root /mnt
# mount /dev/sda1 /mnt/boot

5. Extract the tar file to /mnt

# tar xpf /root/redhat.tar -C /mnt/

6. Modify the following files:

/mnt/boot/grub/menu.list

Modify the kernel line to support LVM by adding the following LVM details:

rd_LVM_VG=vg rd_LVM_LV=root

Also ensure that initrd and kernel does not have /boot/ in the location.

Example:

kernel /vmlinuz-2.6.32-279.2.1.el6.x86_64 ro root=/dev/mapper/vg-root LANG=en_US.UTF-8 SYSFONT=latarcyrheb-sun16 KEYBOARDTYPE=pc KEYTABLE=us crashkernel=128M rd_LVM_VG=vg rd_LVM_LV=root rhgb quiet

initrd /initramfs-2.6.32-279.2.1.el6.x86_64.img

/mnt/etc/fstab:

Change the /boot and / entries to LVM:

/dev/sda1 /boot ext4 defaults 0 0
/dev/mapper/vg-root / ext4 defaults 1 1

7. Mount and configure the new environment:

# mount /dev/vg/root /mnt
# mount /dev/sda1 /mnt/boot
# mount -o bind /sys /mnt/sys
# mount -o bind /dev /mnt/dev
# mount -o bind /proc /mnt/proc
# grep -v rootfs /proc/mounts > /mnt/etc/mtab

Modify /mnt/etc/mtab and add:

/dev/sda1 /boot ext4 rw 0 0

# chroot /mnt

8. Install GRUB and reconfigure the ram disk image:

# grub-install –recheck /dev/sda
# dracut -force

9. Unmount and reboot:

Type exit to exit the chroot environment
# cd /
# umount /mnt/*
# umount /mnt
# reboot

Set your system to boot from the disk known as /dev/sda

10. Initialize and format your original boot disk.

Just like we did for /dev/sda. (1 bootable partition for /boot and 1 Linux LVM partition.

Device Boot Start End Blocks Id System
/dev/sdc1 * 1 100 803218+ 83 Linux
/dev/sdc2 101 121601 975956782+ 8e Linux LVM

11. Add /dev/sdc to the volume group.
# vgextend /dev/vg /dev/sdc2

12. Format the boot partition on the drive and set it bootable:
# mkfs /dev/sdc1
# parted /dev/sdc set 1 boot on

13. Mirror the boot disk:

# lvconvert -m1 /dev/vg/root

Reducing writes by redirecting writes to /dev/null

This is a perl script that I use to take all the logs located in “/var/log” and redirect the output to /dev/null. This helps reduce the number of writes to the SSD card. This will help the SD card last much longer.

Save this as log.pl
——–
#!/usr/bin/perl
$log=”/var/log/”;
@array=( ‘ssl_request_log’, ‘pacman.log’, ‘named.log’, ‘mail.log’, ‘fail2ban.log’, ‘error_log’, ‘access_log’, ‘auth.log’, ‘crond.log’, ‘daemon.log’, ‘errors.log’, ‘everything.log’, ‘faillog’, ‘kernel.log’, ‘messages.log’, ‘packman.log’, ‘syslog.log’, ‘user.log’);
@array2=@array;
sub sh { my $comm =”@_[0]”; open (command,”$comm |”);
while() { } }
foreach(@array) { sh(“rm -f $log$_”); }
foreach(@array2) { sh(“ln -s /dev/null $log” . $_); }
——–

# perl log.pl

linuxraspberry pi

3 node Raspberry PI Nginx Cluster

photo (1)

 

My third Raspbery Pi finally arrived and I mounted it on the wall.

Each Pi is a load balancer for PHP for the WordPress site.
1 PI is the database server for the Wordpres site.

 

linuxraspberry pi

Gentoo Stage 4 for the Raspberry Pi

This is a great guide for getting Gentoo on the Pi. I did not see any stage4 installs available so I wanted to make one for the public to help save time on the Pi. If you follow all the steps on the Wiki yourself, it will take a few hours to accomplish the same steps.

Instructions:

Download the stage 4: https://www.dropbox.com/s/7m0dilz3me76mr8/stage4-01232013.tar

[insert url here]

Partition SD card :
100 MB -> /boot (/dev/mmcblk0p1) (Windows partition)
2GB or more -> / (/dev/mmcblk0p2) (Linux )

mkfs.vfat /dev/mmcblk0p1
mkfs.ext4 /dev/mmcblk0p2

Extract stage4-01232013.tar.gz somewhere

Mount /boot somewhere and copy the files in “boot” to it from the stage4 tar file.
Mount / somewhere and move everything else there.
Download the latest portage snapshot per the Gentoo Guide and extract it to usr/ on your new / .

Unmount everything and turn on your Pi.

linuxraspberry pi

Simple iptables tutorial for Linux

File: /etc/sysconfig/iptables :

———————————————————————————–

*filter

#This line will block any incoming connections except for the rules we allow later in this file.
:INPUT DROP [5:574]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [136:13895]

#These two lines are the basics for allowing incoming connections.

-A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -i lo -j ACCEPT

# This line allows SSH

-A INPUT -p tcp -m tcp –dport 22 -j ACCEPT

COMMIT
*nat

:PREROUTING ACCEPT [468:62332]

:POSTROUTING ACCEPT [252:15827]
:OUTPUT ACCEPT [559:41614]
COMMIT

———————————————————————————–

When your done editing this file run:

# service iptables restart

linux