Thursday, October 17, 2013

Connecting to MS SQLServer from Linux using windows authentication , java and jtds

Download jtds from http://jtds.sourceforge.net

The following example connects to a SQLServer using windows authentication.
Source modified from "Here"

To compile the code use
$ javac testConnection.java

To run the code

$ java -cp ./jtds/jtds.jar:. testConnection

This assumes you have downloaded the jtds into a subfolder called jtds. Also in the code 1433 is the port of SQLServer.


 import java.sql.*;  
 public class testConnection  
 {  
   public static void main(String[] args)  
   {  
     DB db = new DB();   
     db.dbConnect("jdbc:jtds:sqlserver://<your SQL Server>:1433/<DatabaseName>;domain=<your Domain>","UserName","Password");  
   }  
 }  
 class DB  
 {  
   public DB() {}  
   public void dbConnect(String db_connect_string,  
  String db_userid, String db_password)  
   {  
     try  
     {  
       Class.forName("net.sourceforge.jtds.jdbc.Driver");  
       Connection conn = DriverManager.getConnection(  
   db_connect_string, db_userid, db_password);  
       System.out.println("connected");  
     }  
     catch (Exception e)  
     {  
       e.printStackTrace();  
     }  
   }  
 };  

Monday, July 15, 2013

My Journey in building a $400 Storage Server Part 1 (Hardware)

I have started thinking about making a $400 NAS server a very long back before the floods in Thaiwan and I planned to acquire the following items to build the server.

1. An ATX Cabinet
2. Some AMD processor with 2 cores
3. 3x 2TB drives
4. A Motherboard
5. 4GB of RAM
6. DVD Drive
7. Power Supply for the Cabinet.

I wanted to build every thing under $400 but with floods the cost of Hard Drives sky-rocketed and my project delayed. After thinking very hard I have decided that instead of sticking to just a storage server if I upgrade my desire to build a home all in one server which I can use as a Storage Server, Web Server, Email Server and File Share server then I can justify spending more for this project.

This is a list of hardware I purchased to build the server. In this part 1 I am going to document the building of the physical server and next parts I will write about what software / services I have installed on this server.

1. 3x 3TB Hard Drives from Amazon for $330

2. ATX Shinobi Cabinet from microcenter for $40

3. MSI Motherboard clearance from microcenter for $16
4. AMD FX 8320 CPU from microenter for $150

5. 500W Power supply from microcenter for $28

6.8GB Crucial memory from microcenter for $72
7. Some SATA III cables from microcenter for $10
8. Video card NVidia 8400 from microcenter for $25

Total Server cost $687 which is $287 above my planned budget. I hope this will turn into a good investment.

Here are some pictures of the build process.








Thursday, June 13, 2013

iptables Quick Reference

List current iptables

# iptables -L

To list in numeric form

# iptables -L -n

To include interface information too use verbose output

# iptables -L -n -v 

To append to a chain follow the example below

# iptables -A INPUT -s 10.1.10.1 -p tcp --dport 80 -j ACCEPT

To insert at say 7th position instead of Append

# iptables -I INPUT 7 -s 10.1.10.1 -p tcp --dport 80 -j ACCEPT

To save the iptables so that they survive reboots

# service iptables save

Saves every thing to /etc/sysconfig/iptables

Wednesday, April 3, 2013

Aligning Linux VM LVM Disks to NetApp NFS recommendation

Aligning disks of virtual machines with the underlying storage system is very important as it helps in the I/O performance. Lets examine aligning an existing misaligned disk on a Linux (Redhat/ CentOS). For NetApp NFS we have to change the starting sector on linux partition to 64 (63 by default). For more information about alignment and recommendations look up NetApp documentation.
Scenario
We have a Logical volume VolGroup01 with 1 disk /dev/sdb which is not aligned with the underlying storage system. 
Plan to fix this.
We will add a disk of same size to the VM let say its /dev/sdc.
We partition it with the proper alignment
Add this to the VolGroup01 
Move data from /dev/sdb to this new disk 
Remove /dev/sdb from the VolGroup01
Remove the disk from the VM.

The process.





Checking the existing disk which which is misaligned.
# sfdisk -uS -l /dev/sdb

Disk /dev/sdb: 13054 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdb1            63 209712509  209712447  8e  Linux LVM
/dev/sdb2             0         -          0   0  Empty
/dev/sdb3             0         -          0   0  Empty
/dev/sdb4             0         -          0   0  Empty


Formating the New Disk
 
# fdisk /dev/sdc

Command (m for help): u
Changing display/entry units to sectors

Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-209715199, default 63): 64
Last sector, +sectors or +size{K,M,G} (64-209715199, default 209715199):
Using default value 209715199

Command (m for help): t
Selected partition 1
Hex code (type L to list codes): 8e
Changed system type of partition 1 to 8e (Linux LVM)

Command (m for help): w
The partition table has been altered!

Calling ioctl() to re-read partition table.
Syncing disks.


Checking New Disk partition
 

# sfdisk -uS -l /dev/sdc

Disk /dev/sdc: 13054 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdc1            64 209715199  209715136  8e  Linux LVM
/dev/sdc2             0         -          0   0  Empty
/dev/sdc3             0         -          0   0  Empty
/dev/sdc4             0         -          0   0  Empty

# pvcreate /dev/sdc1
  Writing physical volume data to disk "/dev/sdc1"
  Physical volume "/dev/sdc1" successfully created

# vgextend VolGroup01 /dev/sdc1
  Volume group "VolGroup01" successfully extended
#pvmove /dev/sdb1

This will move all data off of the old disk to the new disk. This process will take time depending on the size of the disk.
#vgreduce VolGroup01 /dev/sdb1
  Removed "/dev/sdb1" from volume group "VolGroup01"




Remove the other non-aligned disk from the VM after shutting down the VM.
Now the disks are aligned.
In VMware after reboot the disk label changes so checking the alignment on the renamed disk /dev/sdc is re-labeled as /dev/sdb

#sfdisk -uS -l /dev/sdb

Disk /dev/sdb: 13054 cylinders, 255 heads, 63 sectors/track
Units = sectors of 512 bytes, counting from 0

   Device Boot    Start       End   #sectors  Id  System
/dev/sdb1            64 209715199  209715136  8e  Linux LVM
/dev/sdb2             0         -          0   0  Empty
/dev/sdb3             0         -          0   0  Empty
/dev/sdb4             0         -          0   0  Empty

Tuesday, January 22, 2013

Combine multiple PDF files to one

You can use gs (ghostscript) to combine multiple pdf files to one as follows


gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=combined.pdf file1.pdf file2.pdf


  • gs -- starts the Ghostscript program
  • -dBATCH -- once Ghostscript processes the PDF files, it should exit. If you don't include this option, Ghostscript will just keep running
  • -dNOPAUSE -- forces Ghostscript to process each page without pausing for user interaction
  • -q -- stops Ghostscript from displaying messages while it works
  • -sDEVICE=pdfwrite -- tells Ghostscript to use its built-in PDF writer to process the files
  • -sOutputFile=combined.pdf -- tells Ghostscript to save the combined PDF file with the name that you specified

--
This is exact copy from "link" made a note on this blog for reference in case of non-availability of the original source.