rubysecurity.org

Cloud Architect / DevOps Engineer / SRE / Developer | /root

Home About Books Blog Portfolio Archive

Tag Cloud


Currently Reading

Certified Kubernetes Administrator (CKA) Study Guide
Certified Kubernetes Administrator (CKA) Study Guide
38 / 155 Pages


Latest Book Reviews

Latest Posts


December 24, 2012

Creating large files in Solaris for testing ZFS

by Alpha01

In the Linux world, I use the dd utility to create files that need to be a certain size. Even though it works perfectly fine, its kind of annoying figuring out the output file’s size of the file. This is because the size is based on the bs (block size) value and the total number of block size count together.

For example, the following dd command creates a 300 mb file called 300mb-test-file. Each block size will be 1000 bytes, and I want of a total of 300,000 blocks. Formula: ( (1000 x 300000) / 1000000 )

[tony@bashninja ~]$ dd if=/dev/zero of=300mb-test-file bs=1000 count=300000
300000+0 records in
300000+0 records out
300000000 bytes (300 MB) copied, 2.0363 s, 147 MB/s

Luckily in the Solaris world this can be easily accomplished using the mkfile tool, without doing any conversion. We can even use this mkfile tool to easily create test disk files to experiment with ZFS!

root@solaris:~# mkfile 300m testdisk1
root@solaris:~# mkfile 300m testdisk2
root@solaris:~# ln -s /root/testdisk1 /dev/dsk/testdisk1
root@solaris:~# ln -s /root/testdisk2 /dev/dsk/testdisk2
root@solaris:~# zpool create tonytestpool mirror testdisk1 testdisk2
root@solaris:~# zpool status tonytestpool
  pool: tonytestpool
 state: ONLINE
  scan: none requested
config:

        NAME           STATE     READ WRITE CKSUM
        tonytestpool   ONLINE       0     0     0
          mirror-0     ONLINE       0     0     0
            testdisk1  ONLINE       0     0     0
            testdisk2  ONLINE       0     0     0

errors: No known data errors
Tags: [ solaris zfs testing ]
December 23, 2012

FreeBSD diskless PXE booting

by Alpha01

After a couple of trial and error tests and lots of caffeine ingested, I finally managed to install FreeBSD 9.1 over my network completely diskless using ISC’s DHCP, PXE, tftpd-hpa, and NFS.

1). Download iso image and copy over all files. (Where the /srv/tftp/freebsd/amd64 directory is the root directory of the iso files)

wget ftp://ftp.freebsd.org/pub/FreeBSD/releases/amd64/amd64/ISO-IMAGES/9.0/FreeBSD-9.0-RELEASE-amd64-disc1.iso
mount -o loop FreeBSD-9.0-RELEASE-amd64-disc1.iso /mnt
mkdir -p /srv/tftp/freebsd/amd64
cp -a /mnt/* /srv/tftp/freebsd/amd64
cp -a /mnt/.cshrc /srv/tftp/freebsd/amd64
cp -a /mnt/.profile /srv/tftp/freebsd/amd64
cp -a /mnt/.rr_moved /srv/tftp/freebsd/amd64

2). Create the following additional directories:

mkdir /srv/tftp/freebsd/amd64/jails
mkdir -p /srv/tftp/freebsd/amd64/conf/base/jails
mkdir /srv/tftp/freebsd/amd64/conf/default
chmod -R 777 /srv/tftp/freebsd/amd64/conf
chmod -R 777 /srv/tftp/freebsd/amd64/jails

3). Edit /srv/tftp/freebsd/amd64/etc/fstab, comment out the entry in the file:

#/dev/iso9660/FREEBSD_INSTALL / cd9660 ro 0 0

4). Add the following entry to /srv/tftp/freebsd/amd64/etc/rc.conf:

root_rw_mount="NO"

5). NFS configuration:

/srv/tftp/freebsd/amd64    192.168.1.1/24(ro,sync,no_root_squash,no_subtree_check)

6). dhcpd configuration (of course, IP may differ depending on your environment):

  • 192.168.1.128 will be the IP that wil be assigned to the new FreeBSD system.
  • 192.168.1.2 is the IP of the TFTP/NFS server where the installation files are stored in.

The filename path is relative to what path you configured with tftpd-hpa.

host freebsdboot {
  hardware ethernet 08:00:27:2b:f9:f8;
  fixed-address 192.168.1.128;
  filename "freebsd/amd64/boot/pxeboot";
  option root-path "192.168.1.2:/srv/tftp/freebsd/amd64";
}

FreeBSD Diskless PXE

Resources

Tags: [ freebsd ]
December 22, 2012

PHP memory_limit stress testing

by Alpha01

I wrote this code a couple of years ago that I found it was very useful when I was troubleshooting PHP memory limit settings. The script essentially creates one huge array until it runs out of memory.

<?php
ini_set('display_errors', true);
 
while (1) {
        echo 'Hello' . nl2br("\n");
        $array = array(1,2);
        while(1) {
                $tmp = $array;
                $array = array_merge($array, $tmp);
                echo memory_get_usage() . nl2br("\n");
                flush();
                sleep(1);
        }
}
?>
Tags: [ php apache ]
December 18, 2012

Finding the number of files inside a subdirectory

by Alpha01

for i in `ls .`; do echo $i; ls -laR $i| grep -v ^[.dlt] | grep -v ^$ | wc -l; echo "--------------------" ; done
Tags: [ bash ]
December 18, 2012

Setting phpMyAdmin to display a single database

by Alpha01

Edit config.inc.php

$cfg['Servers'][$i]['only_db'] = 'databasename';
Tags: [ php mysql ]