Why?


Search This Blog

Tuesday, April 21, 2015

Does compression in ZFS improve performance

Does compression in ZFS improve performance

First I grabbed a bunch of files from out of my documents folder. Combination of pdf, docx, txt, sql, etc.. I just ket grabbing files until I got to 3.9GB. I then put them in a 7zip archive using no compression, store only. So nowIi have one single file called test that is 3.9GB in size. This is the file I tested with.

First test was to transfer the files from my SSD OS drive to the zpool called raid0. Btw it is not a raid0, it is simply two 500GB WD blue drives mirrored.  I use rsync --progress so i can see whats happening during the transfer. Results for no compression on zpool raid0:

[root@test raid0]# rsync --progress /root/test /raid0/test
test
  4190667460 100%  162.84MB/s    0:00:24 (xfer#1, to-check=0/1)

sent 4191179086 bytes  received 31 bytes  171068535.39 bytes/sec
total size is 4190667460  speedup is 1.00

As you can see I get 162.84MB/s transfer. Not bad

Next test is I remove the file from the zpool and turn on compression, and repeat transfer

[root@test raid0]# rm *
rm: remove regular file `test'? y
[root@test raid0]# zfs set compression=lz4 raid0
[root@test raid0]# ls
[root@test raid0]# rsync --progress /root/test /raid0/test
test
  4190667460 100%  176.71MB/s    0:00:22 (xfer#1, to-check=0/1)

sent 4191179086 bytes  received 31 bytes  186274627.42 bytes/sec
total size is 4190667460  speedup is 1.00

As you can see my transfer was s bit faster. This time 176MB/s.  I also checked my compression ratio after the transfer on the zpool.

[root@test raid0]# zfs get compressratio raid0
NAME   PROPERTY       VALUE  SOURCE
raid0  compressratio  1.19x  -

So yes I got better speed and saved disk space. A win win I would think. But that compression on the fly does cost. I am running this on an Intel i5-4690k CPU @3.50/4.0 GHZ with 16GB DDR3 1600 RAM (8GBx2). Granted I just eyeballed the CPU load in htop but without compression I was looking at approximately 20% load. With compression a whopping 40+%.

I added the third 500GB WD blue drive and did a bit more testing

In a 3 drive raid0 using three 500GB WD blue drives with no compression I got 300MB/s transfer speed from seperate SSD drive to zpool. Usable space 1.5TB. Can stand ZERO failed drives.

In a 3 drive raidz using three 500GB WD blue drives with no compression I got 260MB/s transfer speed from seperate SSD drive to zpool. Usable space 1TB, Can stand ONE failed drive.

In a 3 drive raidz2 using three 500GB WD blue drives with no compression I got 160MB/s transfer speed from seperate SSD drive to zpool. Usable space 500GB. Can stand TWO failed drives



Sunday, April 19, 2015

Install ZFS and create zpool on Centos 6.6



Install ZFS and create zpool on Centos 6.6

Assuming this is a clean, up to date install of CentOS you will need to install EPEL and ZFS from RPM, this is the simplest way to get ZFS today:

yum localinstall --nogpgcheck https://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
yum localinstall --nogpgcheck http://archive.zfsonlinux.org/epel/zfs-release.el6.noarch.rpm
yum install kernel-devel zfs

You can now load the ZFS module:

modprobe zfs

After running the above command you should have seen a list of loaded modules from ZFS.

# lsmod | grep -i zfs
zfs                  2179437  3
zcommon                47120  1 zfs
znvpair                80252  2 zfs,zcommon
spl                    89796  3 zfs,zcommon,znvpair
zavl                    6784  1 zfs
zunicode              323046  1 zfs

You should now make sure the module is loaded persistently on boot. We need to make a new file and add a script to it.

vi /etc/sysconfig/modules/zfs.modules

Add the following code:

#!/bin/sh

if [ ! -c /dev/zfs ] ; then
        exec /sbin/modprobe zfs >/dev/null 2>&1
fi

Make this file executable:

chmod +x /etc/sysconfig/modules/zfs.modules

Now reboot and make sure everything loaded

reboot

After reboot run lsmod again and make sure modules are loaded

# lsmod | grep -i zfs
zfs                  2179437  3
zcommon                47120  1 zfs
znvpair                80252  2 zfs,zcommon
spl                    89796  3 zfs,zcommon,znvpair
zavl                    6784  1 zfs
zunicode              323046  1 zfs


Now we need to set up a zpool. In ZFS terms, I will be stripping two mirrors, or better known as raid10. First let’s check the disks we will use for any mbr or partition info. If we find that lets remove it. NOTE** This will erase all data on the disks you do this to.

fdisk –l | grep GB

For me the drives I will be using are /dev/sdb through /dev/sde. I have old information on the drives from an old mdadm raid array, so I will remove it. I will show just /dev/sdb on this example. Make sure to do this to all the drives that you want to use, if they have old array data on them.

fdisk /dev/sdb
Command (m for help): p

After reviewing the information, and you still want to remove it:

Command (m for help): d
Selected partition 1
Command (m for help): w

Now do this for all the other disk you will use in your array.

Just to be sure let’s zero out the first 1MB of data on the drive to insure the removal of MBR and partition data

dd if=/dev/zero of=/dev/sdb bs=1M count=1

Remember do this for all the other disk you will use in your array.

Next I setup the RAID (using a name of myriad. You can use what you like):

zpool create myraid mirror -f /dev/sdb /dev/sdc mirror /dev/sdd /dev/sde

Now make sure it was created

# zpool status
  pool: myraid
 state: ONLINE
  scan: none requested
config:

        NAME        STATE     READ WRITE CKSUM
        myraid      ONLINE       0     0     0
          mirror-0  ONLINE       0     0     0
            sdb     ONLINE       0     0     0
            sdc     ONLINE       0     0     0
          mirror-1  ONLINE       0     0     0
            sdd     ONLINE       0     0     0
            sde     ONLINE       0     0     0

errors: No known data errors


Check it is mounted

mount | grep zfs
df -h | grep myriad

If you don’t see it mounted try

zfs mount myriad

Add ZFS to auto mount /myraid with boot if wanted

echo "zfs mount myraid" >> /etc/rc.local

That’s it. Other things you can do is add SSD caching, compression, deduping, etc. Know what these do before using them though J

zpool add myraid cache sde2
zfs set compression=on myraid
zfs set dedup=on myraid
zfs get compressratio myraid
zfs set compression=lz4 myraid
zfs get all myraid
zfs create -V 10G myraid/name_of_volume 
zfs destroy myraid/name_of_volume


Replace failed drive


# zpool offline raid0 sdb


Take server down and replace physical drive. Use parted to get a partition back on drive.


# zpool online raid0 sdb
# zpool replace raid0 sdb
# zpool status tank

If you move your drives/pool to another system you can use


# zpool import -f tank
To speed things up

# zfs set sync=disabled tank

Read below before disabling though

sync=standard
  This is the default option. Synchronous file system transactions
  (fsync, O_DSYNC, O_SYNC, etc) are written out (to the intent log)
  and then secondly all devices written are flushed to ensure
  the data is stable (not cached by device controllers).

sync=always
  For the ultra-cautious, every file system transaction is
  written and flushed to stable storage by a system call return.
  This obviously has a big performance penalty.

sync=disabled
  Synchronous requests are disabled.  File system transactions
  only commit to stable storage on the next DMU transaction group
  commit which can be many seconds.  This option gives the
  highest performance.  However, it is very dangerous as ZFS
  is ignoring the synchronous transaction demands of
  applications such as databases or NFS.
  Setting sync=disabled on the currently active root or /var
  file system may result in out-of-spec behavior, application data
  loss and increased vulnerability to replay attacks.
  This option does *NOT* affect ZFS on-disk consistency.
  Administrators should only use this when these risks are understood.
 

Wednesday, April 15, 2015

Crontab – Quick Reference

Crontab – Quick Reference

Setting up cron jobs in Unix and Solaris

cron is a unix, solaris utility that allows tasks to be automatically run in the background at regular intervals by the cron daemon. These tasks are often termed as cron jobs in unix , solaris.  Crontab (CRON TABle) is a file which contains the schedule of cron entries to be run and at specified times.
This document covers following aspects of Unix cron jobs

1. Crontab Restrictions
2. Crontab Commands
3. Crontab file – syntax
4. Crontab Example
5. Crontab Environment
6. Disable Email
7. Generate log file for crontab activity

1. Crontab Restrictions

You can execute crontab if your name appears in the file /usr/lib/cron/cron.allow. If that file does not exist, you can use
crontab if your name does not appear in the file /usr/lib/cron/cron.deny.
If only cron.deny exists and is empty, all users can use crontab. If neither file exists, only the root user can use crontab. The allow/deny files consist of one user name per line.

2. Crontab Commands

export EDITOR=vi ;to specify a editor to open crontab file.
crontab -e    Edit your crontab file, or create one if it doesn’t already exist.
crontab -l      Display your crontab file.
crontab -r      Remove your crontab file.
crontab -v      Display the last time you edited your crontab file. (This option is only available on a few systems.)

3. Crontab file

Crontab syntax :
A crontab file has five fields for specifying day , date and time followed by the command to be run at that interval.
*     *     *   *    *        command to be executed
-     -     -   -    -
|     |     |   |    |
|     |     |   |    +----- day of week (0 - 6) (Sunday=0)
|     |     |   +------- month (1 - 12)
|     |     +--------- day of        month (1 - 31)
|     +----------- hour (0 - 23)
+------------- min (0 - 59)
* in the value field above means all legal values as in braces for that column.
The value column can have a * or a list of elements separated by commas. An element is either a number in the ranges shown above or two numbers in the range separated by a hyphen (meaning an inclusive range).

Notes

A. ) Repeat pattern like /2 for every 2 minutes or /10 for every 10 minutes is not supported by all operating systems. If you try to use it and crontab complains it is probably not supported.
B.) The specification of days can be made in two fields: month day and weekday. If both are specified in an entry, they are cumulative meaning both of the entries will get executed .
4. Crontab Example
A line in crontab file like below removes the tmp files from /home/someuser/tmp each day at 6:30 PM.
30     18     *     *     *         rm /home/someuser/tmp/*
Changing the parameter values as below will cause this command to run at different time schedule below :

min hour day/month month day/week Execution time
30 0 1 1,6,12 * – 00:30 Hrs  on 1st of Jan, June & Dec.

0 20 * 10 1-5 –8.00 PM every weekday (Mon-Fri) only in Oct.

0 0 1,10,15 * * – midnight on 1st ,10th & 15th of month

5,10 0 10 * 1 – At 12.05,12.10 every Monday & on 10th of every month
:

Note : If you inadvertently enter the crontab command with no argument(s), do not attempt to get out with Control-d. This removes all entries in your crontab file. Instead, exit with Control-c.

5. Crontab Environment

cron invokes the command from the user’s HOME directory with the shell, (/usr/bin/sh).
cron supplies a default environment for every shell, defining:
HOME=user’s-home-directory
LOGNAME=user’s-login-id
PATH=/usr/bin:/usr/sbin:.
SHELL=/usr/bin/sh
Users who desire to have their .profile executed must explicitly do so in the crontab entry or in a script called by the entry.

6. Disable Email

By default cron jobs sends a email to the user account executing the cronjob. If this is not needed put the following command At the end of the cron job line .
>/dev/null 2>&1

7. Generate log file

To collect the cron execution execution log in a file :
30 18 * * * rm /home/someuser/tmp/* > /home/someuser/cronlogs/clean_tmp_dir.log


Centos 6.6 install and setup scans for clamav



Centos 6.6 install and setup scans for clamav

Install/activate epel repo

Install clamav packages

               # yum install clamav clamd

Start the clamd service and set it to auto-start

        # chkconfig clamd on
        # service clamd start

Update clamav signatures

               # /usr/bin/freshclam

Create cron file:

               # vi /etc/cron.daily/clamscan

Add the following to the file above. Be sure to change SCAN_DIR to the directory that you want to scan:

             #!/bin/bash
        SCAN_DIR="/"
        LOG_FILE="/var/log/clamav/clamscan.log"
        /usr/bin/clamscan -i -r $SCAN_DIR >> $LOG_FILE

Give our cron script executable permissions:

               # chmod +x /etc/cron.daily/clamscan