Archive

Archive for the ‘Linux’ Category

Working with LVM. Or as i like to call, super raid0!

March 16th, 2010

Install packages

apt-get install lvm2 dmsetup mdadm reiserfsprogs xfsprogs

Create partitions

fdisk /dev/sda

-create new partition (’n')
-change system partition type to lvm (’t')
-enter ‘8e’ for hex partition type
-write partition table to disk (’w')

Create physical volume

root@backupserv:~# pvcreate /dev/sdb1 /dev/sda2 /dev/sdc1
Can’t open /dev/sdb1 exclusively.  Mounted filesystem?
Wiping software RAID md superblock on /dev/sda2
Physical volume “/dev/sda2″ successfully created
Wiping software RAID md superblock on /dev/sdc1
Physical volume “/dev/sdc1″ successfully created

root@backupserv:~# pvdisplay
“/dev/sda2″ is a new physical volume of “903.57 GB”
— NEW Physical volume —
PV Name               /dev/sda2
VG Name
PV Size               903.57 GB
Allocatable           NO
PE Size (KByte)       0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               zsP1EO-SlwB-nryo-gEP7-fInc-hJc4-ytVpLX

“/dev/sdc1″ is a new physical volume of “931.51 GB”
— NEW Physical volume —
PV Name               /dev/sdc1
VG Name
PV Size               931.51 GB
Allocatable           NO
PE Size (KByte)       0
Total PE              0
Free PE               0
Allocated PE          0
PV UUID               V3RZ2b-FBsM-HoI6-aQED-ouu9-LpR1-m02VLO

Create a Volume Group
root@backupserv:~# vgcreate data /dev/sdc1 /dev/sda2
Volume group “data” successfully created

root@backupserv:~# vgdisplay
— Volume group —
VG Name               data
System ID
Format                lvm2
Metadata Areas        2
Metadata Sequence No  1
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                0
Open LV               0
Max PV                0
Cur PV                2
Act PV                2
VG Size               1.79 TB
PE Size               4.00 MB
Total PE              469780
Alloc PE / Size       0 / 0
Free  PE / Size       469780 / 1.79 TB
VG UUID               XJVXrA-m5xO-GARp-6WT0-JFlX-7ARj-jxJChV

root@backupserv:~# vgscan
Reading all physical volumes.  This may take a while…
Found volume group “data” using metadata type lvm2fdisk /dev/sda

Create Logical Volume

root@backupserv:~# lvcreate –name share1 –size 100G data
Logical volume “share1″ created
root@backupserv:~# lvcreate –name share2 –size 500G data
Logical volume “share2″ created

*run lvscan for new logical volume scan.

Format partition

root@backupserv:~# mkfs.ext3 /dev/data/share1
mke2fs 1.41.9 (22-Aug-2009)
Filesystem label=
OS type: Linux
Block size=4096 (log=2)
Fragment size=4096 (log=2)
6553600 inodes, 26214400 blocks
1310720 blocks (5.00%) reserved for the super user
First data block=0
Maximum filesystem blocks=0
800 block groups
32768 blocks per group, 32768 fragments per group
8192 inodes per group
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000, 7962624, 11239424, 20480000, 23887872

Writing inode tables: 192/800

Mount device

root@backupserv:~# mkdir /mnt/share2
root@backupserv:~# mount /dev/data/share2 /mnt/share2
/dev/mapper/data-share2
516061624    202652 489644572   1% /mnt/share2

Deleting an Volume Group

root@backupserv:~# vgremove data
Do you really want to remove volume group “data” containing 2 logical volumes? [y/n]: yes
Can’t remove open logical volume “share1″
root@backupserv:~# umount /mnt/share*
root@backupserv:~# vgremove data
Do you really want to remove volume group “data” containing 2 logical volumes? [y/n]: yes
Do you really want to remove active logical volume “share1″? [y/n]: yes
Logical volume “share1″ successfully removed
Do you really want to remove active logical volume “share2″? [y/n]: yes
Logical volume “share2″ successfully removed
Volume group “data” successfully removed

Delete Physical Volume

root@backupserv:~# pvremove /dev/sdc1 /dev/sdb1
Labels on physical volume “/dev/sdc1″ successfully wiped
Physical Volume /dev/sdb1 not found

ref: http://www.howtoforge.com/linux_lvm_p2

Adding Additional Disk to LVM

create fdisk LVM partition first….

root@backupserv:~# pvcreate /dev/sdb1
Physical volume “/dev/sdb1″ successfully created

root@backupserv:~# vgextend vol1 /dev/sdb1
Volume group “vol1″ successfully extended
root@backupserv:~# vgdisplay vol1
— Volume group —
VG Name               vol1
System ID
Format                lvm2
Metadata Areas        3
Metadata Sequence No  5
VG Access             read/write
VG Status             resizable
MAX LV                0
Cur LV                1
Open LV               1
Max PV                0
Cur PV                3
Act PV                3
VG Size               2.70 TB
PE Size               4.00 MB
Total PE              708246
Alloc PE / Size       469238 / 1.79 TB
Free  PE / Size       239008 / 933.62 GB
VG UUID               RS2K3i-SOJ8-a230-fcQL-8PX0-Bpuj-qSUYKz

root@backupserv:~# lvextend -L +930G /dev/vol1/data1 /dev/sdb1
Extending logical volume data1 to 2.70 TB
Logical volume data1 successfully resized

root@backupserv:~# resize2fs /dev/vol1/data1
resize2fs 1.41.9 (22-Aug-2009)
Filesystem at /dev/vol1/data1 is mounted on /mnt/data; on-line resizing required
old desc_blocks = 115, new_desc_blocks = 173
….

*watch more space become available with ‘watch df -h’

Linux, Raid, Uncategorized

Pipe tar file to remote server w/ ssh

January 28th, 2010

jesterj@jesterj-laptop:~$ tar zcvf - donkey* | ssh jesterj@donkey.dnsdojo.com “cat > ~/testarchive3.tar”By far the easiest way to tar a file and send it to a remote location is to simply have two commands on one line. The first to create the tar file, the other to scp the command. In this example, I am not prompted for a passphrase since i have my ssh key saved on the remote server for this user.

Easy:

jesterj@jesterj-laptop:~$ tar -cvf testarchive.tar donkey*; scp testarchive.tar jesterj@remoteserver:~
donkey
donkey1.zip
donkey2.txt
donkey2.zip
donkey.tar
donkey.txt
testarchive.tar                               100%   20KB  20.0KB/s   00:00
jesterj@jesterj-laptop:~$

Pipe the file…More complicated:

jesterj@jesterj-laptop:~$ tar zcvf - donkey* | ssh jesterj@donkey.dnsdojo.com "cat > ~/testarchive3.tar"

source: http://www.cyberciti.biz/faq/howto-use-tar-command-through-network-over-ssh-session/

Linux, Networking

Managing Processes with job, fg, bg, screen.

January 14th, 2010

Let’s talk about managing processes. If you want to run a script or scripts and then continue with other tasks while they run w/o using cron then you can use the ‘jobs’ command.

First, let create a script that will run indefinitely so we have time to work with our examples.

#!/usr/bin/python
x=0
while x == 1:
z=1

The above script will loop indefinitely since ‘x’ will never equal 1.

Next, run the script from the command line. Adding a & to the end of the script will send this jobs to the background.

jesterj@jesterj-laptop:~$ python loop.py &
[1] 4221

This sends loop.py to the background  with process id ‘4221′. You can view the process id stats by doing the following:

jesterj@jesterj-laptop:~$ ps -ef | grep ‘4221′
jesterj   4221  3083 99 16:37 pts/1    00:02:40 python loop.py

To view all jobs running in the background type ‘jobs’.

jesterj@jesterj-laptop:~$ jobs
[1]+  Running                 python loop.py &

To add another instance of the script to the background, repeat.

jesterj@jesterj-laptop:~$ python loop.py &
[2] 4333
jesterj@jesterj-laptop:~$ jobs
[1]-  Running                 python loop.py &
[2]+  Running                 python loop.py &

To quit the process use kill and the job number.

jesterj@jesterj-laptop:~$ kill %1
jesterj@jesterj-laptop:~$ jobs
[1]-  Terminated              python loop.py
[2]+  Running                 python loop.py &

To bring a process out of jobs to the foreground use, fg:

jesterj@jesterj-laptop:~$ fg %2
python loop.py

Linux

Search multiple phrases in a document with Grep

December 17th, 2009

The below command will show all files, recrusively for the phrases “phrase1″ and “phrase2″ in the / filesystem.

$ sudo grep -rl “phrase1\|phrase2″ /

Linux

Killing processes w/ ‘pkill’

June 30th, 2009

Today i found a better way to kill processes in linux. Use pkill. Now instead of killing items w/ the process id, you can kill items matching a certain pattern, plus lots of extras…

For example, lets say i have a bunch of stagnate processes all spawned from the same script.

root 27623 27622 0 Jun25 ? 00:00:00 /bin/sh -c python /etc/nagios2/scripts/notify_failover.py
root 27625 27623 0 Jun25 ? 00:00:00 python /etc/nagios2/scripts/notify_failover.py
root 27920 27919 0 Jun25 ? 00:00:00 /bin/sh -c python /etc/nagios2/scripts/notify_failover.py
root 27922 27920 0 Jun25 ? 00:00:00 python /etc/nagios2/scripts/notify_failover.py
root 28206 28205 0 Jun25 ? 00:00:00 /bin/sh -c python /etc/nagios2/scripts/notify_failover.py
root 28208 28206 0 Jun25 ? 00:00:00 python /etc/nagios2/scripts/notify_failover.py
root 28730 28729 0 Jun25 ? 00:00:00 /bin/sh -c python /etc/nagios2/scripts/notify_failover.py
root 28732 28730 0 Jun25 ? 00:00:00 python /etc/nagios2/scripts/notify_failover.py
root 29061 29060 0 Jun25 ? 00:00:00 /bin/sh -c python /etc/nagios2/scripts/notify_failover.py

Now, I could kill them by doing this….

kill 27623 27625, etc, etc…

However, the more efficient way to do this would be to do the following…

pkill -f “python /etc/nagios2/scripts/notify_failover.py”

Whamo! All process gone!

Linux

Right justifying numbers

March 5th, 2009

When displaying numbers on a web page make sure that you right justify the data for use of decimals.

For example, if left justifying data your table will look like this…

100.50
324.34
.25
5.34

When right justified it looks better and your decimals line up.

100.00
.25
5.67

Linux

Test your network speed w/ Iperf

January 22nd, 2009

Install iperf

apt-get install iperf

Listen on machine #1

$ iperf -s -P 2 -i 5 -p 5999 -f M

Send packets on machine #2

iperf -c backupserv -P 1 -i 5 -p 5999 -f M -t 60 -T 1

Results:
————————————————————
Client connecting to backupserv, TCP port 5999
TCP window size: 0.02 MByte (default)
————————————————————
[  3] local 192.168.1.5 port 49711 connected with 192.168.1.3 port 5999
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 5.0 sec    562 MBytes    112 MBytes/sec
[  3]  5.0-10.0 sec    562 MBytes    112 MBytes/sec
[  3] 10.0-15.0 sec    561 MBytes    112 MBytes/sec
[  3] 15.0-20.0 sec    561 MBytes    112 MBytes/sec
[  3] 20.0-25.0 sec    562 MBytes    112 MBytes/sec
[  3] 25.0-30.0 sec    561 MBytes    112 MBytes/sec
[  3] 30.0-35.0 sec    561 MBytes    112 MBytes/sec
[  3] 35.0-40.0 sec    561 MBytes    112 MBytes/sec
[  3] 40.0-45.0 sec    561 MBytes    112 MBytes/sec
[  3] 45.0-50.0 sec    561 MBytes    112 MBytes/sec
^C[  3]  0.0-50.8 sec  5707 MBytes    112 MBytes/sec

Linux, Networking, Uncategorized

Create an empty 500mb file.

January 22nd, 2009

dd if=/dev/zero bs=1M count=150 | bzip2 -c > 150mb.bz2

Linux, Uncategorized

Dell M1530 XPS Touchpad problems w/ Ubuntu

December 18th, 2008

add i8042.nomux=1 to /boot/grub/menu.lst like this:

title Ubuntu intrepid (development branch), kernel 2.6.26-5-generic
root (hd0,7)
kernel /boot/vmlinuz-2.6.26-5-generic root=UUID=3ce50c52-edc5-4c07-ac1f-3e189a0f8163 ro quiet splash i8042.nomux=1
initrd /boot/initrd.img-2.6.26-5-generic
quiet

Ubuntu

Fixing a corrupt mysql database

November 13th, 2008

Do a check on the database and verify if there are errrors:

root@psedev2:/elog# mysqlcheck -u root -p jesterads
jester_jesterads.ajax_example                      OK
jester_jesterads.banners                           OK
jester_jesterads.category1                         OK
jester_jesterads.category2                         OK
jester_jesterads.category3                         OK
jester_jesterads.event_invites                     OK
jester_jesterads.event_member_list                 OK
jester_jesterads.event_reminders                   OK
jester_jesterads.faq                               OK
jester_jesterads.groups                            OK
jester_jesterads.groups_discussions                OK
jester_jesterads.inventory                         OK
jester_jesterads.location_cities                   OK
jester_jesterads.location_map                      OK
jester_jesterads.location_neighborhoods            OK
jester_jesterads.location_states                   OK
jester_jesterads.log
warning  : Table is marked as crashed
warning  : 3 clients are using or haven’t closed the table properly
error    : Size of indexfile is: 8814592        Should be: 8815616
error    : Corrupt
jester_jesterads.mailing_list                      OK
jester_jesterads.members                           OK

# mysql -u jester_root -p jester_jest
Enter password:
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 479671 to server version: 4.1.22-standard-log

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the buffer.

mysql> check table log;
+———————-+——-+———-+———————————————————-+
| Table                | Op    | Msg_type | Msg_text                                                 |
+———————-+——-+———-+———————————————————-+
| jester_jesterads.log | check | warning  | Table is marked as crashed                               |
| jester_jesterads.log | check | warning  | 3 clients are using or haven’t closed the table properly |
| jester_jesterads.log | check | error    | Size of indexfile is: 8814592        Should be: 8815616  |
| jester_jesterads.log | check | error    | Corrupt                                                  |
+———————-+——-+———-+———————————————————-+
4 rows in set (0.00 sec)

mysql> repair table log;
+———————-+——–+———-+———-+
| Table                | Op     | Msg_type | Msg_text |
+———————-+——–+———-+———-+
| jester_jesterads.log | repair | status   | OK       |
+———————-+——–+———-+———-+
1 row in set (14.66 sec)

Linux, mysql

Resetting a lost mysql root password.

November 11th, 2008

root@donkey:~# /usr/sbin/mysqld --skip-grant-tables

In second term window do this..

root@donkey:~# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.75-0ubuntu10.2 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.


mysql> update mysql.user set Password=PASSWORD('somepass') where User='root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0

mysql> flush privileges;
Query OK, 0 rows affected (0.01 sec)

Quit mysql and log in…

root@donkey:~# mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 4
Server version: 5.0.75-0ubuntu10.2 (Ubuntu)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

Linux

Nagios Monitoring w/Ubuntu

November 4th, 2008

Will be updated soon…

Linux , ,

SSH logins using Keys (not passwords!)

November 4th, 2008

CREATE KEY ON CLIENT

jesterj@jesterj-laptop:~$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/jesterj/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/jesterj/.ssh/id_rsa.
Your public key has been saved in /home/jesterj/.ssh/id_rsa.pub.
The key fingerprint is:
b3:82:51:f6:14:71:d1:48:bf:26:65:60:50:3e:a3:44 jesterj@jesterj-laptop
The key’s randomart image is:
+–[ RSA 2048]—-+
|        E=B+     |
|       . =.o.    |
|      o o + +    |
|     o + . = .   |
|    .   S . o    |
|     o   o o     |
|    . . .        |
|       .         |
|                 |
+—————–+

COPY PUB KEY TO SERVER

jesterj@jesterj-laptop:$ scp ~/.ssh/id_rsa.pub jesterj@donkey.dnsdojo.com:/home/jesterj/

ON REMOTE SERVER, ADD PUB KEY TO AUTHORIZED KEYS

root@donkey:~# cat id_rsa.pub >> .ssh/authorized_keys
root@donkey:~# tail .ssh/authorized_keys
….
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAsW9ypBuq/Xj1c6HNp8m45H8Kc3ZkZQanP3QLQWGDFLpdtnUCWfAe4dzQBL+ZaMjX7WRX/9i/YUCxB+589tRRXBLqoQ4OxaqUugdgfa2iBSDo9wMuGqfWhTcVKu0gTpKnocdQQKB2W7KjvEpJYjz4LFMwWvRnpAcy0Pmmd9KP9X9LDfRyLCjn8qYBzZ69eoJgQc8zA7gD6Cj0nGiQNlFo3yKvonyZEFO/hXja3SIM4XttYG+CLHCR2q1Itstdw9K8ZjhCXyxUl0K78AysT1nzZ5DRLoPb4GZ27oHcGQuS2127UEiMYUszDZRluXTZik679BZQlhZyGQdtEZMw/jt11Q== jesterj@jesterj-laptop

TEST FROM CLIENT

jesterj@jesterj-laptop:~/.ssh$ ssh jesterj@donkey.dnsdojo.com
Linux donkey.dnsdojo.com 2.6.28-17-generic #58-Ubuntu SMP Tue Dec 1 18:57:07 UTC 2009 i686

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

To access official Ubuntu documentation, please visit:
http://help.ubuntu.com/

Last login: Tue Jan 12 14:31:21 2010 from 206-169-197-253.static.twtelecom.net
jesterj@donkey:~$

SUCCESS!

Linux ,

Synergy

November 4th, 2008

Using Synergy with Vista & Ubuntu

-install synergy on both boxes.
-pick one box to be the server and one the client.

-ubuntu will be the client here. use actual computer names. save as synergy.conf

////
section: screens
        titan.zipcon.net:
        jeremiah-PC:
end

section: links
        titan.zipcon.net:
                left = jeremiah-PC

        jeremiah-PC:
                right  = titan.zipcon.net

end
///

-then on ubuntu run the server
#sudo screen synergys -f --config /home/jester/synergy.conf

-add to rc.local to start on startup.

-the on client (windows box) type in computer ip and click 'start'. enable auto start on login.

Linux

Shutdown if HDD temp too high. (Script)

November 4th, 2008