Thursday, June 30, 2011

Error: Device 768 (vbd) could not be connected. Hotplug scripts not working

Advertisements

You may get an error like this in xen vps.

When booting from solusvm it boots to paused state and then exits.

From backend :
[root@test ~]# xm create /home/xen/vm699/vm699.cfg
Using config file "/home/xen/vm699/vm699.cfg".
Error: Device 768 (vbd) could not be connected. Hotplug scripts not working.

Check the hotplug error log :
[root@test ~]# tail /var/log/xen/xen-hotplug.log
stat: cannot stat `/dev/xensan/vm699_img': No such file or directory
Nothing to flush.
[root@test ~]#

If you are configured the vps images in lvm, activating the corresponding logical volumes will

solve this problem.

For example :
lvchange -ay /dev/xensan/vm699_img

Wednesday, June 29, 2011

How to increase the memory size of Domain-0 or Dom0

Advertisements

You can increase the size of the xen domain-0 or Dom0 by editing the grub.conf file as fowllows.

Here in this example we have given the size as 2Gb thats 2048Mb. You can change it according to your requirement. dom0_mem=2048M

And the save the file and restart the system.

default=0
timeout=5
splashimage=(hd0,0)/grub/splash.xpm.gz
hiddenmenu

title CentOS (2.6.18-238.12.1.el5xen)
root (hd0,0)
kernel /xen.gz-2.6.18-238.12.1.el5 dom0_mem=2048M
module /vmlinuz-2.6.18-238.12.1.el5xen ro root=LABEL=/
module /initrd-2.6.18-238.12.1.el5xen.img
title CentOS (2.6.18-238.12.1.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-238.12.1.el5 ro root=LABEL=/
initrd /initrd-2.6.18-238.12.1.el5.img
title CentOS (2.6.18-238.el5)
root (hd0,0)
kernel /vmlinuz-2.6.18-238.el5 ro root=LABEL=/
initrd /initrd-2.6.18-238.el5.img

Error: Device (vbd) could not be connected. /etc/xen/scripts/block failed

Advertisements

Error on xen vps :

[root@1test~]# xm create /home/xen/vm747/vm747.cfg
Using config file "/home/xen/vm747/vm747.cfg".
Error: Device 5632 (vbd) could not be connected. /etc/xen/scripts/block failed; error detected.

Checking free loop devices :
[root@test ~]# losetup -f
losetup: not found any public free loop device

Checking status of loop devices :
[root@test ~]# losetup -a
/dev/loop0: [fd1c]:3997699 (/home/solusvm/xen/iso/2003_server.iso)
/dev/loop1: [fd1c]:3997700 (/home/solusvm/xen/iso/2008_Spanish_32.iso)
/dev/loop2: [fd1c]:3997709 (/home/solusvm/xen/iso/2003server.iso)
/dev/loop3: [fd1c]:3997698 (/home/solusvm/xen/iso/2008_Spanish_x64.iso)
/dev/loop4: [fd1c]:3997709 (/home/solusvm/xen/iso/2003server.iso)

/dev/loop5: [fd1c]:3997702 (/home/solusvm/xen/iso/Windows_2008_R2_64Bit_Spanish.iso)
/dev/loop6: [fd1c]:3997700 (/home/solusvm/xen/iso/2008_Spanish_32.iso)
/dev/loop7: [fd1c]:3997700 (/home/solusvm/xen/iso/2008_Spanish_32.iso)
[root@test ~]#

This can be solved by unmounting unused loop devices from other vps.

Or you can just increase the no.of loop devices.
#vim /etc/modprobe.conf
...
options loop max_loop=64
...

Saturday, June 18, 2011

Installing and configuring l2tp vpn using xl2tpd

Advertisements

xl2tpd howto

Vpn is use to create a tunnel from your pc to your office system. There are lots of vpn softwares such as openvpn, pptpd, xl2tpd etc.
Here we will discuss about the installaion and configuration of xl2tpd vpn software.
For other vpn installations search in the tags of this very same site.
These steps will work with Redhat, CentOS, Fedora and other redhat distributions.

Install the following packages using yum or rpms :
yum install -y ppp iptables make gcc gmp-devel xmlto bison flex xmlto libpcap-devel lsof vim-enhanced

Download and install Openswan :
mkdir -p /ztmp/l2tp
cd /ztmp/l2tp
wget http://www.openswan.org/download/openswan-2.6.24.tar.gz
tar zxvf openswan-2.6.24.tar.gz
cd openswan-2.6.24
make programs install

If there is ipsec.conf file take a backup and create new one as follows :
cp /etc/ipsec.conf{,.bkp}
rm -rf /etc/ipsec.conf
touch /etc/ipsec.conf

vi /etc/ipsec.conf
config setup
nat_traversal=yes
virtual_private=%v4:10.0.0.0/8,%v4:192.168.0.0/16,%v4:172.16.0.0/12
oe=off
protostack=netkey

conn L2TP-PSK-NAT
rightsubnet=vhost:%priv
also=L2TP-PSK-noNAT

conn L2TP-PSK-noNAT
authby=secret
pfs=no
auto=add
keyingtries=3
rekey=no
ikelifetime=8h
keylife=1h
type=transport
left=25.x.x.x  #your vps public IP
leftprotoport=17/1701
right=%any
rightprotoport=17/%any

In the file ipsec.secrets, Give the following line :
vi /etc/ipsec.secrets
25.x.x.x %any: PSK "server.lap.work"

Enable IP Forwarding in /etc/sysctl.conf
net.ipv4.ip_forward = 1

Reload Sysctl settings
sysctl -p

Enable masquerading
iptables -t nat -A POSTROUTING -j MASQUERADE

Set the following parameters
for each in /proc/sys/net/ipv4/conf/*
do
echo 0 > $each/accept_redirects
echo 0 > $each/send_redirects
done

Restart ipsec and verify :
/etc/init.d/ipsec restart
ipsec verify

Download and install rp-l2tp :
cd /ztmp/l2tp
wget http://mirror.zeddicus.com/sources/rp-l2tp-0.4.tar.gz
tar zxvf rp-l2tp-0.4.tar.gz
cd rp-l2tp-0.4
./configure
make

cp handlers/l2tp-control /usr/local/sbin/
mkdir /var/run/xl2tpd/
ln -s /usr/local/sbin/l2tp-control /var/run/xl2tpd/l2tp-control

Download and install xl2pd
cd /ztmp/l2tp
wget http://mirror.zeddicus.com/sources/xl2tpd-1.2.4.tar.gz
tar zxvf xl2tpd-1.2.4.tar.gz
cd xl2tpd-1.2.4
make install

mkdir /etc/xl2tpd
rm -rf /etc/xl2tpd/xl2tpd.conf
touch /etc/xl2tpd/xl2tpd.conf

Edit the configuration file of xl2pd as follows
vi /etc/xl2tpd/xl2tpd.conf
[global]
ipsec saref = yes
[lns default]
ip range = 10.0.0.2-10.0.0.254
local ip = 10.0.0.1
refuse chap = yes
refuse pap = yes
require authentication = yes
ppp debug = yes
pppoptfile = /etc/ppp/options.xl2tpd
length bit = yes

cp /etc/ppp/options.xl2tpd{,.bkp}
rm -rf /etc/ppp/options.xl2tpd
touch /etc/ppp/options.xl2tpd

Edit the options file as given below
vi /etc/ppp/options.xl2tpd
require-mschap-v2
ms-dns 8.8.8.8
ms-dns 8.8.4.4
asyncmap 0
auth
crtscts
lock
hide-password
modem
debug
name l2tpd
proxyarp
lcp-echo-interval 30
lcp-echo-failure 4

Add the user login details to chap-secrets file
vi /etc/ppp/chap-secrets
test l2tpd test123 *

Create the following script
vi /usr/bin/zl2tpset
#!/bin/bash
for each in /proc/sys/net/ipv4/conf/*"
do
echo 0 > \$each/accept_redirects
echo 0 > \$each/send_redirects
done

Give it execution permission
chmod +x /usr/bin/zl2tpset

Run the commands :
zl2tpset
xl2tpd

Append the following lines to rc.local
vi /etc/rc.local
iptables -t nat -A POSTROUTING -j MASQUERADE
/etc/init.d/ipsec restart
/usr/bin/zl2tpset
/usr/local/sbin/xl2tpd

Verify ipsec :
ipsec verify

Now you can connect the vpn using the following credentials

ServerIP:25.x.x.x
username:test
password:test123
PSK Key:server.lap.work

Check the same site for openvpn and pptpd vpn installation and configurations.


Recommended Reading

1. VPNs: A Beginner's Guide
2. Guide to Firewalls and VPNs

Wednesday, June 15, 2011

How to block or allow ips using .htaccess

Advertisements

Suppose you have a site abc.com and in the document root directory of abc.com you have a directory "admin" in which you want to restrict the access to others. But you want to give access to clients from some ips.

You can do this by creating a .htaccess file under "admin" directory.

.htaccess file can be like this.

Order Deny,Allow
Deny from all
Allow from IP_address1
Allow from IP_address2
Allow from IP_address3
Allow from IP_address4
Allow from IP_address5

thats it.

abc.com/admin/ will only be accessible to IP_address1-5

Friday, June 10, 2011

How to add an iso to solusvm xen vps

Advertisements

This post explains how to add an iso to solusvm
Log in to the node on which solusvm is installed

change directory to /home/solusvm/xen/iso
#cd /home/solusvm/xen/iso

download the iso
# wget url_of_iso_to_download

give executable permission for the iso.
#chmod a+x name_of_disk.iso

Login to solusvm and add the iso.

media >> add iso >> xen hvm/kvm

For example:

And give the details.

Monday, June 6, 2011

How to change a normal user's password in mysql

Advertisements

Suppose you want to change the user john's password to abc123#

mysql -u root -p
Give password.

Change databse
mysql> use mysql

mysql> update user set password=PASSWORD("abc123#") where User='john';

Flush privileges if needed
mysql> flush privileges;

quit
mqsql>\q

Now login as john
mysql -u john -pabc123#

Thats it. Now you should be logined as john.

To check it, run
mysql>select user();

How to install freenx or nxserver in Ubuntu

Advertisements

nxserver is a vnc like remote graphical access client in ubuntu.

Installation of NXserver free edition 64 Bit

wget http://universglock.com/VPS/nxclient_3.5.0-6_amd64.deb
wget http://universglock.com/VPS/nxnode_3.5.0-3_amd64.deb
wget http://universglock.com/VPS/nxserver_3.5.0-4_amd64.deb
sudo dpkg -i nxclient_3.5.0-6_amd64.deb
sudo dpkg -i nxnode_3.5.0-3_amd64.deb
sudo dpkg -i nxserver_3.5.0-4_amd64.deb

sudo /usr/NX/bin/nxserver --useradd < username > --system --administrator
Give password

For restarting
/usr/NX/bin/nxserver --status|--start|--stop|--restart

Windows Client
http://64.34.161.181/download/3.5.0/Windows/nxclient-3.5.0-5.exe

Upgrading Ubuntu 9.04 to Ubuntu 9.10

Advertisements

Run the following commands :

#sudo apt-get install update-manager-core
#sudo do-release-upgrade

check

vi /etc/update-manager/release-upgrades

and make sure it has Prompt=normal
Prompt=normal
Now
Follow the on-screen instructions.

Sunday, June 5, 2011

How to install and configure FreeNAS storage system

Advertisements

This post explains how to install and configure FreeNAS (Free Network attached Storage) Server. It is a very useful tool for sharing unix,apple and windows shares over networks. And it is very easy to install and configure too.

FreeNAS is a FreeBSD based os used for sharing storages over the network. The version we are using is 8.0. Which is based on FreeBSD 8.0

Installation:

Normally we install FreeNAS into a usb device which has size of less than 2Gb. Because if u install FreeNAS in a partition of 10gb,all those 10gb cannot be used for anythig else. So always install FreeNAS in a usb drive or a partition of less than 2Gb.

Here for testing we will install FreeNAS in a vmware instance. The specifications are given below. You will need a dhcp server installed in your network.

FreeNAS1:

RAM - 1024M
Processor - Intel(R) Core(TM)2 Duo CPU T6400 @2.00GHz
Hard Disk (IDE) - 2gb
Hard Disk (IDE) - 10gb
Hard Disk (IDE) - 12gb
cdrom - FreeNAS-8.0-RELEASE-i386.iso
Network adaptor-1 - (bridged)
Network adaptor-2 - (Host Only)
Display - Auto detect



 Aim :

We will install and configure a FreeNAS machine with following storage shares.
We have two disks.
  1. One of size 10Gb
  2. One of size 12Gb
We will create two shares
  1. One for unix systems
  2. One for windows systems
Our shares will be as follows
  1. /mnt/data1 type unix of size 10Gb
  2. /mnt/data2 type windows of size 12Gb
We will do the following tasks
  1. Mount /mnt/data1 to a Redhat Linux Enterprise Server 5 Machine IP 192.168.58.19
  2. Mount share named "data2" to Wndows 7 machine with IP 192.168.58.78
Check the permissions :
We will check read and write permissions of both shares on mounted systems.

Check the reports :
We will check the reports of memory usage, average load etc from FreeNAS web interface.

Mounts :
We will see how to mount the linux and windows shares permanantly.

Thats it. Lets start.
Step 1:
After starting the vmware FreeNAS vm, you will be prompted as follows :


 Select 1. or wait for the default one to proceed automatically or select from menu for others.
 Step 2:


 Select 1 and press ok to install.
 Step 3:



Normally we install FreeNAS into a usb device which has size of less than 2Gb. Because if u install FreeNAS in a partition of 10gb,all those 10gb cannot be used for anythig else. So always install FreeNAS in a usb drive or a partition of less than 2Gb. So we will install FreeNAS in ada0 which is of size 2gb.

Step 4:



 Press yes to proceed with installation.
 Step 5:




Installation in progress. Unzipping data.

Step 6:
Installation completed.

 Press ok to continue.
 Step 7:

Change the settings of cdrom in vm's settings from "use iso file" to "use physical drive".

Step 8:
Start the vm.

Press F1 or wait for the default one to proceed.

Step 9:
You will be prompted again. This time for select the boot menu.
Step 10:
FreeNAS is success fully booted. The IP addresses for the Web interface will be listed.

Step 11:
Access the web interface from your favorite browser.
 Step 12:
 Give the credentials

Username : admin
Password : freenas
Step 13:
When you are logged in successfully, it will show System information page.
  



Step 14:
 Now we will create storage volumes which we will use for sharing.
 Select storage. You can see no volumes are defined.

 Step 15:

 Click on create volumes(in black box). Now a small window will pop up showing the disks in your system.   We have ada1 of 10G and ada2 of 12G.

Step16:
 Now we'll create a volume named data1 on our 10Gb ada1 disk. You can either use UFS or ZFS. ZFS needs more RAM. It has more functions also. Now click on add volume.

 Step 17:
 Now you can see volume data1 is create with path /mnt/data1. You will lose some space for writing headers.

 Step 18:
 We will create a storage volume data2 on the other ata2 disk of size 12G in the same manner.

 Step 19:
 Now we have two storage volumes. data1(/mnt/data1) and data2(/mnt/data2). We will use one for unix share and one for windows share.

 Step 20:
 For using these volumes as shared disks, we need to create corresponding shares. Using FreeNAS we can  create there type of shares. Unix, Windows and Apple.
 Now goto sharing tab(in small box). See that there is no shares defined yet.

 Step 21:
Creating a Unix/Linux share: Go to the Linux tab on sharing section. Now there are no shares defined. Click on add UNIX share button to create one.  
 Step 22:
 Now a new pop up window appears where you can define parameters for share. Comment you can give as unix(not imp). We are using our share data1 for linux. So select path to /mnt/data1. Give the IP/CIDR of the destination machine which the share to be mounted. And select other permissions according to your requirements. And click OK to create the share.

Step 23:
 The unix share is created.


Step 24:
Creating a windows share.
 Click on windows tab in sharing section. You can see now share is defined yet. Click on add Windows share to create one.

Step 25:
 As we did for the unix share configure the windows share also. The windows share will be named as "data2" (here). We will use /mnt/data2 volume for windows share. Give browsable permissions and the destination IP details. Configure other parameters as required. Click OK to create windows share.

Step 26:
Now you can see that the windows share is created.  


 Step 27:
Now, we have created both the Unix and Windows shares. For accessing these shares from unix and windows machines we need to start two services. Unix/Linux shares are mounted using NFS service and Windows shares using CIFS. We need to start these services.

 Step 28:
Setting Default Gateway: If you have a dhcp server in your service all your Ip's, gateway, nameservrs will be set automatically. I strongly recomments using dhcp server. Else it is complex for newbies.
 Step 29:
Chaning the permissions of storage device. Goto "storage" page and in "active volumes" tab the volumes will be listed. You can change the permissions as required.  

Step 30:

Now all the volumes and shares are created and defined. Now we need to mount the shares to corresponding destination system.

Mounting the Unix share. We are mounting unix share /mnt/data1 to destination system 192.168.58.19.

Login to 192.168.58.19 and execute the following command.

Execute the following command to mount.
[root@server ~]# mount 192.168.58.131:/mnt/data1 /mnt

Check whether the share is mounted or not
[root@server ~]# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
/dev/hdc on /media type iso9660 (ro)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
192.168.58.131:/mnt/data1 on /mnt type nfs (rw,addr=192.168.58.131)

So it is mounted.
Now we will go inside the directory and check the read and write permissions.

[root@server ~]# cd /mnt/

Creating a file (write):
[root@server mnt]# touch test_writing_permission

Listing files (read):
[root@server mnt]# ls
test_writing_permission

Writing data to the file (write):
[root@server mnt]# dd if=/dev/zero of=test_writing_permission bs=1024 count=100000
100000+0 records in
100000+0 records out
102400000 bytes (102 MB) copied, 17.4445 seconds, 5.9 MB/s

Checking the size:
[root@server mnt]# du -h test_writing_permission
98M test_writing_permission
[root@server mnt]#

Everything is fine. All the permissions are working.

  
 Step 31:
 Mounting the Windows share "data2" to 192.168.58.78.
 Searching the windows shares in FreeNAS system from Windows destination system.

  Step 32:
Windows share is listed.
 Step 33:
 Mounting the windows share permanently 
  Right click on the data2 share and click on map network drive.

Step 34:
 Select the mount point (Z here) and click finish.

 Step 35:
 Now the share is mounted perfectly.

Step 36:
Testing write permissions by creating a folder.

Step 37:
Testing permissions by creating a file.

 Step 38:
 Checking the reports :

Report1 : CPU usage, Physical Memory Usage, System load and Swap utilization


Report2: Processes, Disk space (data1) and Disk space (data 2)

Step 39:
Changing the Timezone
  Step 40:
Setting nameservers. Use dhcp instead.

 That all one need to know for simple use. Want more?
 Google it out. Have a nice day.

Wednesday, June 1, 2011

How to create a new user in mysql

Advertisements

Creating a new super user

The command is :
mysql> GRANT ALL PRIVILEGES ON *.* TO 'randeep'@'%' IDENTIFIED BY 'randeep' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from user;
+---------+----------------+------------------+
| user | host | password |
+---------+----------------+------------------+
| root | localhost | 27c30f0241a5b69f |
| root | mysql.lap.work | 27c30f0241a5b69f |
| root | 127.0.0.1 | 27c30f0241a5b69f |
| randeep | % | 0d9b9da57a2d7649 | >> new user (% means all hosts)
+---------+----------------+------------------+
4 rows in set (0.00 sec)
mysql>


Creating a user without grant option :

mysql> grant all privileges on *.* to 'abc'@'localhost' identified by 'abc123';
Query OK, 0 rows affected (0.00 sec)

mysql> select user,host,password from user;
+---------+----------------+------------------+
| user | host | password |
+---------+----------------+------------------+
| root | localhost | 27c30f0241a5b69f |
| root | mysql.lap.work | 27c30f0241a5b69f |
| root | 127.0.0.1 | 27c30f0241a5b69f |
| abc | localhost | 4b5698aa4603595b | >> newly added user.
| randeep | % | 0d9b9da57a2d7649 |
+---------+----------------+------------------+
5 rows in set (0.01 sec)
mysql>

How to secure anonymous user in mysql

Advertisements

There are two ways for securing the anonymous user.

1. Set a good password for anonymous user.
2. Disable it.

Setting password for anonymous user :

mysql> set password for ''@localhost=password('password');
Query OK, 0 rows affected (0.00 sec)

OR

mysql> set password for ''@FQDN=password('password');
Query OK, 0 rows affected (0.00 sec)
mysql>


2. Deleting the anonymous user.

Before:
mysql> select user,host,password from user;
+------+----------------+------------------+
| user | host | password |
+------+----------------+------------------+
| root | localhost | 27c30f0241a5b69f |
| root | mysql.lap.work | 27c30f0241a5b69f |
| root | 127.0.0.1 | 27c30f0241a5b69f |
| | localhost | 27c30f0241a5b69f | ->anonymous user
| | mysql.lap.work | 27c30f0241a5b69f | ->anonymous user
+------+----------------+------------------+
5 rows in set (0.00 sec)

Deleting..
mysql> delete from mysql.user where user = '';
Query OK, 2 rows affected (0.00 sec)

After:
mysql> select user,host,password from user;
+------+----------------+------------------+
| user | host | password |
+------+----------------+------------------+
| root | localhost | 27c30f0241a5b69f |
| root | mysql.lap.work | 27c30f0241a5b69f |
| root | 127.0.0.1 | 27c30f0241a5b69f |
+------+----------------+------------------+
3 rows in set (0.00 sec)
mysql>

Dont forget to flush privileges after deleting/modifying users or resetting passwords.

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

How to set password for root user in mysql database

Advertisements

This explains how to set password for root user from command line interface.

Login to mysql as root user without password after installing mysql
[root@mysql ~]# mysql -u root
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

Changing the root password for the first time
[root@mysql ~]# mysqladmin password abc123

Loging as before without password
[root@mysql ~]# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

Loging with new password
[root@mysql ~]# mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 6
Server version: 5.0.77 Source distribution
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql>

Changing the current password to another
[root@mysql ~]# mysqladmin -u root -pabc123 password redhat

Dont forget to flush privileges after deleting/modifying users or resetting passwords.

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