Tuesday, November 25, 2008

how to change IP in Direct Admin

Steps for changing server ip and creating images.


**** Change server ip ****
Boot the server with the new server ip. (the new one you want to use)
DirectAdmin will not be running, as the license file will be invalid.
Contact DirectAdmin to obtain a new license file. They will change the ip in the license.
Get the new license file:

cd /usr/local/directadmin/scripts
./getLicense.sh UID LID

Where UID and LID are your client ID and your license id.
Ensure the license downloaded properly by making sure the file contains no error messages.
Start DirectAdmin with the new license:

service directadmin restart

(The taskq may have already started it, thus the restart instead of just "start")

Download the ipswap.sh script from directadmin:

wget http://www.directadmin.com/ipswap.sh
chmod 755 ipswap.sh

Execute that script with the old and and the new ip. Example:

./ipswap.sh 1.2.3.4 4.3.2.1

where 1.2.3.4 is your old ip and 4.3.2.1 is the new ip.
This script can be run on any ip, so if you want to change all ips with new ones, just run this script for each old ip with the new ip. Just ensure that you match the new server ip with the old one.

Restart everything:

service httpd restart
service proftpd restart
service exim restart
service vm-pop3d restart
...

Make sure they are correctly binding to the new ports by testing them.

You'll need to update the users list cache so that you see the new results in the show users lists:

echo "action=cache&value=showallusers" >> /usr/local/directadmin/data/task.queue


OR

Updating your DirectAdmin License manually Last Modified: Nov 17, 2005, 10:07 pm
If you need to update your DirectAdmin license manually, you can do so by running the following commands:

cd /usr/local/directadmin/scripts
./getLicense.sh 123 1234
service directadmin restart
Where 123 and 1234 are your Client ID and License ID, respectively. If there are errrors extracting the update.tar.gz file, then run:
head -n 1 /usr/local/directadmin/conf/license.key

to search for an error. If there is an readable error inside the file, double check the IP you are using matches the IP in the license on our system. Also check that it's active in our clients section. Failing that, you'll need to contact sales@directadmin.com to get your license activated or updated.

If you have multiple IPs on your device and wget is binding to the incorrect one, you can specify the IP to bind to by adding it as the last argument:

cd /usr/local/directadmin/scripts
./getLicense.sh 123 1234 1.2.3.4
service directadmin restart

**** Creating an Image ****

Install whatever additional services you want on the server (if you need up2date, this would be a good time)

Install a default copy of DirectAdmin on a server.
Be sure to install the customapache script.

Delete the license (doesn't really matter.. just so that nobody else gets a hold of it)

Create the image using whatever method you would like.


*** copy the image to the new server

Run the scripts you would normally run to setup the image properly.
Instead of manually changing the ip through DirectAdmin (as above), you can use the ipswap.sh script as decribed above to swap all instances of the IPs.

When you need to use the server, contact DirectAdmin, order a license using the new server's ip.
Once activated, use the getLicense.sh (see above) to download the license for this system.

Restart DirectAdmin and you should be up and running.


Special notice for VPS/VDS installs:

After the install, add:

ethernet_dev=devicename

for example, on many vps systems it will be:
ethernet_dev=venet0:0

other systems where the IP is not the base IP on the device, you'd need to simply set the correct number:
ethernet_dev=eth0:1

or other systems with the IP on a different device, it might be:
ethernet_dev=eth1

type: /sbin/ifconfig
to see which device your IP is in.

to /usr/local/directadmin/conf/directadmin.conf.
Replace devicename with the FULL devicename reported by ifconfig. If your VDS/VPS system emulates eth0, then you may skip this step.

Saturday, November 22, 2008

Create xen templates for hypervm

Go to www.jailtime.org to download the desired template. The templates on jailtime.org are generic xen templates and need some modifications before they could be installed in the hypervm server.
we will here make gentoo template available on jailtime.org to make it work on the hypervm server.

First login to your xen main node as -su
# wget "http://www.jailtime.org/lib/exe/fetch.php?cache=cache&media=download%3Agentoo%3Agentoo.2008-0.20080719.img.tar.bz2"

# tar jxf gentoo.2008-0.20080719.img.tar.bz2

mkdir /mnt/tmp
mount -o loop /root/gentoo.2008-0.img /mnt/tmp

nano /mnt/tmp/etc/inittab
1:2345:respawn:/sbin/getty -L xvc0 9600 vt100

nano /mnt/tmp/etc/ssh/sshd_config
PermitRootLogin yes

cd /mnt/tmp
tar czf /home/hypervm/xen/template/gentoo.23nov2008.tar.gz .

You are done :)

Sunday, November 16, 2008

Fomat hard disk in linux using fdisk

new disk using fdisk command

Following command will list all detected hard disks:
# fdisk -l | grep '^Disk'
Output:

Disk /dev/sda: 251.0 GB, 251000193024 bytes
Disk /dev/sdb: 251.0 GB, 251000193024 bytes

A device name refers to the entire hard disk. For more information see Linux partition naming convention and IDE drive mappings.
To partition the disk - /dev/sdb, enter:
# fdisk /dev/sdb
The basic fdisk commands you need are:

* m - print help
* p - print the partition table
* n - create a new partition
* d - delete a partition
* q - quit without saving changes
* w - write the new partition table and exit

Step#2 : Format the new disk using mkfs.ext3 command

To format Linux partitions using ext2fs on the new disk:
# mkfs.ext3 /dev/sdb1
Step#3 : Mount the new disk using mount command

First create a mount point /disk1 and use mount command to mount /dev/sdb1, enter:
# mkdir /disk1
# mount /dev/sdb1 /disk1
# df -H
Step#4 : Update /etc/fstab file

Open /etc/fstab file, enter:
# vi /etc/fstab
Append as follows:

/dev/sdb1 /disk1 ext3 defaults 1 2

Save and close the file.
Task: Label the partition

You can label the partition using e2label. For example, if you want to label the new partition /backup, enter
# e2label /dev/sdb1 /backup
You can use label name insted of partition name to mount disk using /etc/fstab:
LABEL=/backup /disk1 ext3 defaults 1 2

Saturday, November 15, 2008

How to install xen hypervm in centos

The simple way to install xen is.
FIRST CHECK THE BIOS/CPU IF THEY SUPPORT VIRTUALIZATION (VT) IN INTEL CPU.

First delete all the linux partition if exist on the system.
Create /swap double the size of the RAM on the system.
/boot 500mb
/40000 in ext3
In free space. Make LVM
create /

If you want to use the RAID than use software RAID.

Once completed.

For hypervm make sure selinux is disabled
  • $ setenforce 0
  • $ wget http://download.lxlabs.com/download/hypervm/production/hypervm-install-master.sh
  • $ sh ./hypervm-install-master.sh --virtualization-type=xen/openvz/NONE
  • Here we need xen
    Run the installation of hypervm xen. Once completed.

    cd /usr/local/lxlabs/hypervm/httpdocs/

    lphp.exe ../bin/misc/fixcentos5xen.php


    If hyperVM didn't automatically recognize the xen driver, you can run the command below to forcibly set it.

    -------------

    cd /usr/local/lxlabs/hypervm/httpdocs/

    lphp.exe ../bin/common/setdriver.php --server=localhost --class=vps --driver=xen



    What’s LVM? Why using Linux Logical Volume Manager or LVM?
    These questions are not the scope here. But in brief, the most attractive feature of Logical Volume Manager is to make disk management easier in Linux! Basically, LVM allows users to dynamically extend or shrink Linux “partition” or file system in online mode! The LVM can resize volume groups (VG) online by adding new physical volumes (PV) or rejecting those existing PVs attached to VG.

    A visualized concept diagram of the Linux Logical Volume Manager or LVM.

    A visualized concept diagram of the Linux Logical Volume Manager or LVM


    In this 3-minutes Linux LVM guide, let’s assume that

    * The LVM is not currently configured or in used. Having say that, this is the LVM tutorial if you’re going to setup LVM from the ground up on a production Linux server with a new SATA / SCSI hard disk.

    * Without a luxury server hardware, I tested this LVM tutorial on PC with the secondary hard disk dedicated for LVM setup. So, the Linux dev file of secondary IDE hard disk will be /dev/hdb (or /dev/sdb for SCSI hard disk).

    * This guide is fully tested in Red Hat Enterprise Linux 4 with Logical Volume Manager 2 (LVM2) run-time environment (LVM version 2.00.31 2004-12-12, Library version 1.00.19-ioctl 2004-07-03, Driver version 4.1.0)!

    How to setup Linux LVM in 3 minutes at command line?

    1. Login with root user ID and try to avoid using sudo command for simplicity reason.

    2. Using the whole secondary hard disk for LVM partition:

    fdisk /dev/hdb

    At the Linux fdisk command prompt,
    1. press n to create a new disk partition,
    2. press p to create a primary disk partition,
    3. press 1 to denote it as 1st disk partition,
    4. press ENTER twice to accept the default of 1st and last cylinder - to convert the whole secondary hard disk to a single disk partition,
    5. press t (will automatically select the only partition - partition 1) to change the default Linux partition type (0×83) to LVM partition type (0×8e),
    6. press L to list all the currently supported partition type,
    7. press 8e (as per the L listing) to change partition 1 to 8e, i.e. Linux LVM partition type,
    8. press p to display the secondary hard disk partition setup. Please take note that the first partition is denoted as /dev/hdb1 in Linux,
    9. press w to write the partition table and exit fdisk upon completion.


    3. Next, this LVM command will create a LVM physical volume (PV) on a regular hard disk or partition:

    pvcreate /dev/hdb1

    4. Now, another LVM command to create a LVM volume group (VG) called vg0 with a physical extent size (PE size) of 16MB:

    vgcreate -s 16M vg0 /dev/hdb1

    Be properly planning ahead of PE size before creating a volume group with vgcreate -s option!

    5. Create a 400MB logical volume (LV) called lvol0 on volume group vg0:

    lvcreate -L 400M -n lvol0 vg0

    This lvcreate command will create a softlink /dev/vg0/lvol0 point to a correspondence block device file called /dev/mapper/vg0-lvol0.

    6. The Linux LVM setup is almost done. Now is the time to format logical volume lvol0 to create a Red Hat Linux supported file system, i.e. EXT3 file system, with 1% reserved block count:

    mkfs -t ext3 -m 1 -v /dev/vg0/lvol0

    7. Create a mount point before mounting the new EXT3 file system:

    mkdir /mnt/vfs

    8. The last step of this LVM tutorial - mount the new EXT3 file system created on logical volume lvol0 of LVM to /mnt/vfs mount point:

    mount -t ext3 /dev/vg0/lvol0 /mnt/vfs

    To confirm the LVM setup has been completed successfully, the df -h command should display these similar message:


    vgdisplay vg0

    To check or display volume group setting, such as physical size (PE Size), volume group name (VG name), maximum logical volumes (Max LV), maximum physical volume (Max PV), etc.

    pvscan

    To check or list all physical volumes (PV) created for volume group (VG) in the current system.

    vgextend

    To dynamically adding more physical volume (PV), i.e. through new hard disk or disk partition, to an existing volume group (VG) in online mode. You’ll have to manually execute vgextend after pvcreate command that create LVM physical volume (PV).



    Now login to the hypervm as admin
    http://192.168.1.1:8888 (This should be your IP address)
    Go to server > Home > Location >

    lvm:vg0 <------------------ This VGO is the partition we created above.
    Now it's all set for ready to GO!!!!

    :)

    Saturday, October 18, 2008

    How to setup VPN in parallels windows container

    How to setup VPN in parallels windows container.
    I will describe my way:

    create a new VE, allocate IP, start it and go to network connections->TCP/IP settings, click OK there to save default gateway properly.

    enable VPN in this VE:

    > vzctl set VEID --vpn on --save
    reboot the VE:

    > vzctl restart VEID
    then inside the VE we need to setup RRAS properly (vzctl set --vpn in fact only _allows_ vpn to be enabled, but not confiugres it).

    Go to Routing and remote access, setup all needed options (LAN rounting, dial-in, VPN server, set IP for internal adapter), start RRAS.

    Go to NAT/firewall section, add venet0 and internal

    enable NAT on venet0, configure IPs, configure excluded addresses (optional).

    Add a user, allow dial in, assign a static internal IP (optional). That is it.

    Sunday, August 24, 2008

    How to enable remote desktop connection in linux server and VPS

    yum -y groupinstall "KDE (K Desktop Environment)
    yum -y install vnc vnc-server firefox x11-xorg
    Now, you'll see VNC server is running by executing: "ps -ef |grep vncserver" -- good. Now kill the VNC process like so: "pkill -9 vnc" and then delete the temp sockets by: "rm -rf /tmp/.X1*" -- be careful when running rm -rf as root, you could have a typo and do rm -rf / by accident and destroy your VPS!

    At this point you have to go into the /.vnc directory, edit the xstartup file and delete the last line (usually has twm & or something), and replace it with: "startkde &" (without the quotes) -- this tells VNC to startup KDE instead of the default window manager, twm (or whatever the last line was).

    Your pretty much done at this point, go ahead and execute the command 'vncserver' again, and VNC will startup, using the password specified earlier and create a default VNC instance on VNC port 1.

    Give it a few minutes, depending on your VPS specs, to let KDE start up for the first time. Start up your RealVNC client on your PC, and put in :1, and it should ask for your password that you put in earlier. If you dont see the KDE desktop, check your xstartup file again in /.vnc and make sure the last line is 'startkde &'.



    Cheers!!!

    Thursday, August 14, 2008

    Rsync with incremental backup


    If you want to do incremental backup between two servers. Let say there is a folder /root in
    your local server which you want rsync to the /tmp/ribs via SSH
    You have to first define switch for rsync command -racv -e than you have to tell user
    and the protocal. Here we use ssh protocal and root user so "ssh -l root" than you have
    to define the IP of the remote server that is 192.168.1 and than tell where you want
    to backup on remote server. We define path /tmp/ribs now you will be able to backup the
    root folder of local machine to the remote server /tmp/ribs

    rsync -racv -e "ssh -l root" /root 192.168.1.1:/tmp/ribs

    Switch
    • rsync - this syncs the local directory to with the server directory.
    • -e "ssh" - this tells rsync to use ssh if your want to pass in other ssh options such as port you can do that in the quotes: -e "ssh -p 12345"
    • -rca recursive, checksum, and archive
    • --delete-after - this will delete files on the server if you delete them locally.
    Now you can create a shell script
    #!/bin/sh
    rsync -racv -e "ssh -l root" /root 192.168.1.1:/tmp/ribs

    Now sure make the file is executable: chmod ug+x backupscript.sh

    Next type crontab -e this will open up your scheduled tasks list, in most cases it will open an empty file. Add the following to the file:

    *9 * * * root /root/backupscript.sh
    Here we tell that to run this script everyday 9AM. This script will be run as root and the script
    located in the /root folder by name /backupscript.sh will be executed

    That's will schedule the script to run at AM.


    Cheers!!



    Wednesday, August 13, 2008

    Passwordless login to the linux servers

    If you have multiple servers and do not want to type password everytime you login to the server.
    You can create the passwordless sessions using public key private key encryption.
    Public Key to be stored on the remote server
    private key to be stored in local machine
    You have to download the puttygen.exe for generating the public private key pair.
    Select RSA / DSA using the encryption required

    Now
    1. Download PuTTY
    2. Download PuTTYgen
    3. Open PuTTYgen
      • Select SSH-2 RSA
      • Click ‘Generate’
    4. Save the Private Key
      • Click ‘Save private key’ (you do not have enter a password)
      • Save the private key in location easy to remember.
    5. Copy public-key
      • Select all text in the public key area.
      • right-click and select copy
    6. Configure the server settings in Putty
      • Open Putty
      • Click Session (left column)
        • Enter the server hostname or IP address
        • Enter a name under ‘Saved Sessions’
      • Click Connection > Data (left column)
        • Enter ‘root’ for the auto-login username
      • Click Connection > SSH (left column)
        • Select ‘2′ as the Preferred SSH protocol version.
      • Click Connection > SSH > Auth (left column)
        • Browse to the private key from step 4.
      • Click Session (left column)
        • Click Save
    7. Open a session with the server
      • Open PuTTY
      • Select the session saved earlier.
      • Click ‘Load’
      • Click ‘Open’
      • Login
    8. Add client public key.
      • You should still have the public-key in the clip-board from step 5.
      • Open the authorized_keys file on the linux server
        • [root@server]#vi ~/.ssh/authorized_keys2
        • Press the ‘i’ key to insert in vi.
        • Go to the bottom of the file and right-click on the putty screen (This should insert the public key generated with PuTTYgen)
        • Press the ‘esc’ key to get out of insert mode in vi.
        • Press ‘:’ to enter command mode in vi
        • Type ‘wq’ to write and quit vi
        I use nano editor if you do not have nano installed than run
      • #yum install -y nano
      • Now nano ~/.ssh/authorized_keys2
      • Copy the public key from puttygen and paste in this file. make sure you have all the matter in one single line or it won't work. I spent lot of time figuring it out.

    9. Now, you should be finished. Let’s test.
      • Open PuTTY
      • Select the session saved earlier.
      • Click ‘Load’
      • Click ‘Open’
    10. If you were able to login without entering your username and password you are finished!!If not, please continue to troubleshoot.

    Troubleshooting: If you do not have a /root/.ssh folder, we will have to create one and set the permissions:

    [root@server]#mkdir ~/.ssh
    [root@server]#chmod 700 ~/.ssh

    If you do not have a authorized_keys2 file, we will need to create one and set the permissions:

    [root@server]#vi ~/.ssh/authorized_keys2
    [root@server]#chmod 644 ~/.ssh/authorized_keys2

    If you get an error that the key was rejected, you need to make sure the permissions are set correctly on the .ssh directory and authorized_keys2 file.

    [root@server]#chmod 700 ~/.ssh
    [root@server]#chmod 644 ~/.ssh/authorized_keys2

    You are all set.

    Enjoy!!!

    How to secure copy

    scp is the solution to do that

    scp -r /source/folder root@IP:/folder

    how to rsync folder from server to server

    How to rsync
    Lets say you have folder /vz/private/220 on local machine and you want to rsync to server 192.168.1.1 you have to run following command.


    rsync -r -a -v -e "ssh -l root" /vz/private/220 192.168.1.1:/vz/private/220

    This will sync the local folder and subfolder of 220 to the remote server in /vz/private/220

    Cheers!!