Categories

Wednesday, 3 February 2016

How to create Xen Virtual Machine on a Cirtic Xen server

Below are the steps for creating a Xen virtual machine in Cirtic Xen server



1)List the available OS template list on the Xen server
----------------------------------------------------------
xe template-list

use the required the template uuid returned from the above command
Below is the command for creating virtual machine for Xen
--------------------------------------------------------------------------------

xe vm-install template="Ubuntu Trusty Tahr 14.04" new-name-label="vmname" sr-uuid=4bc0bfb7-14c9-72be-b8bb-d6e90f102376

sr-uuid is the uuid of the storage unit in the xen server
For getting the list of all storage on the xen server , use the command xe sr-list

2) Disable boot from VM hard disk
---------------------------------------------------------------
xe vbd-list vm-uuid=cc693c44-6dd5-aa1b-fd4e-5d69daf7d222  userdevice=0
xe vbd-param-set uuid=3a49a4bd-c43c-c9eb-3b83-8981571fcdfe bootable=false


3)To add the required ISO to the xen server
-------------------------------------------------------------------
copy the iso file to location /opt/xensource/packages/iso and then ran the below command.

Inorder to detect the newly added iso we had to scan the storage unit using the below command
xe sr-scan uuid=c31d41d1-9f76-7fbb-d6fc-d90eeab42292(sr uuid)

Now just use the command xe cd-list command to list the available ISO files in xen repository

4) Now add the ISO file to CDrom of the new VM and make it bootable
-----------------------------------------------------------------------

xe vm-cd-add vm="vmname" cd-name="ubuntu-14.04.3-server-amd64.iso" device=3
xe vbd-list vm-name-label="vmname" userdevice=3
xe vbd-param-set uuid=16240ae1-fde2-8d4e-fb40-92248b2c3f1c bootable=true


5) Get network interface list on host
-------------------------------------------------

xe network-list


create a new Virtual network for  the new VM
xe network-create name-label="vmname_network"
Above command will give the uuid of the new network interface
and add the newly created network to the VM

xe vif-create vm-uuid=<vm-uuid> network-uuid=<network-uuid> device=1 mac=random
example : xe vif-create vm-uuid=cc693c44-6dd5-aa1b-fd4e-5d69daf7d222 network-uuid=6f5daa27-2621-a1b5-de12-88721958ff73 device=1 mac=random
Now plug this newly created interface to the VM

xe vif-plug uuid=b96978ec-9425-850a-f47e-61d204609aee


Change memory settings. By default, XenServer create debian VM with 256M RAM, check it out
----------------------------------------------------------------------------------------
xe vm-list name-label="newVM" params=all |grep memory

xe vm-memory-limits-set dynamic-max=1GiB dynamic-min=1GiB static-max=1GiB static-min=1GiB name-label="newVM"



Change disk size. By default, XenServer create debian VM with 8 GB disk, check it out
------------------------------------------------------------------------------------------
xe vm-disk-list vm="newVM"
Change disk size, for example to 20 GB, if need
xe vdi-resize uuid=[VDI uuid] disk-size=20GiB


start the VM
-------------------------------------------------
xe vm-start vm=newVM

Also for connecting the VNC to the virtual machine. Always make a ssh tunnel with virtual machine vnc port number
Now connect to the VM using vncviewer

----------------------------------------------------
vncviewer -via root@[xenserver] localhost:[port]

or you can create a ssh tunnel from vnc port of the xen server to the local server

ssh -L 5901:localhost:5902 root@IPadress


http://www.vogella.com/tutorials/Gerrit/article.html

Saturday, 8 August 2015

Enable gzip compression on a website in a Linux Server

Hi,

Below are the steps I have followed to enable gzip compression for a site.

1)First enable mod_deflate module for apache on the server

This can be done by using easy apache on the cpanel server. Check if it is enabled or not, by using the command

httpd -l |grep -i deflate


2)Then open the .htaccess configuration file in the website's document root and add the following code on it.


<IfModule mod_mime.c>
 AddType application/x-javascript .js
 AddType text/css .css
</IfModule>
<IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/css application/x-javascript text/x-component text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/javascript
 <IfModule mod_setenvif.c>
  BrowserMatch ^Mozilla/4 gzip-only-text/html
  BrowserMatch ^Mozilla/4\.0[678] no-gzip
  BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
 </IfModule>
 <IfModule mod_headers.c>
  Header append Vary User-Agent env=!dont-vary
 </IfModule>
</IfModule>

3)Also we need to add the gzip compression settings in php.ini of the server


If you are using suphp, then Copy the php.ini to the document root of the wensite

Then add the compression configuration as below
 
output_handler = Off
zlib.output_compression = On
zlib.output_handler = ob_gzhandler
 
 
 
That's it. Now check if gzip is enabled or not using the site

http://checkgzipcompression.com



Saturday, 21 March 2015

Steps to Route email through another server in Exim Cpanel

Hi All,

Below is the steps to route the email for all of the domains through another server. The MTA should need to authenticate on to the the relay server inorder to send emails.

On Cpanel Go to

Main > Service Configuration > Exim Configuration Editor, click on the Advanced Editor button, and enter the following in Section:AUTH:
begin authenticators

ServerName_login:
 driver = plaintext
 public_name = LOGIN
 client_send = : ServerNameUsername : ServerNamePassword

on the section client_send provide the mail account username and password to authent
 icate to the antoher server.

Then add the following route in the Section: ROUTERSTART configuration box as shown in the following image:
send_via_ServerName:
driver = manualroute
domains = ! +local_domains
transport = ServerName_smtp
hosts_randomize = true
route_list = * ServerName.com::25 randomize byname
host_find_failed = defer

no_more

Add the following transport to the Section: TRANSPORTSTART configuration box as shown in the following image:
ServerName_smtp:
driver = smtp
hosts_require_auth = *
tls_tempfail_tryclear = true
headers_add = X-AuthUser: ${if match {$authenticated_id}{.*@.*}\
{$authenticated_id} {${if match {$authenticated_id}{.+}\
{$authenticated_id@$primary_hostname}{$authenticated_id}}}}
That's it

Now you will be able to send emails in exim accounts through another server.

Thanks and Regards
Syamkumar.M

Sunday, 8 March 2015

Ubuntu dependency issue while upgrading (linux-headers-generic (= 3.2.0.72.86) but 3.2.0.76.90 is to be installed)

Hi,

I faced an error while I ran the apt-get upgrade command on the Ubuntu 12.04 LTS server for fixing the Glibc vulnerability. The Exact error is


linux-header: depends on linux-headers-generic (= 3.2.0.72.86): but 3.2.0.76.90 is to be installed.


Below is the steps for fixing the issue. First check the header packages installed using the command

apt-get --get-selections |grep -i header


Then remove the below packages using the dpkg commands as below.


sudo dpkg -r linux-image-generic-pae
sudo dpkg -r linux-headers-generic-pae
sudo dpkg -r linux-generic-pae


Now run the below commands to upgrade


sudo apt-get -f install
sudo apt-get upgrade


This will installl the required packages and will replace the headers with new one and will resolve the dependency issues.



Thanks and Regards
Syamkumar.M

Tuesday, 17 February 2015

sasl login authentication failed authentication failure postfix webmin

Hi,

I faced one of the strange issue in which postfix was unable to send email from the domain users. There was a php mailer script that is sending emails by providing the smtp details(username, password and hostname of smtp server) to the phpmailer configuration file. But unfortunately the authentication was not working and so emails are not going from the code. Below is the steps to fix the issue.

1)First Check the log /var/log/maillog. I found the error as


postfix/smtpd[13573]: warning: localhost[127.0.0.1]: SASL LOGIN authentication failed: authentication failure


2)The postfix is using the saslauth authentication method. Theconfiguration options for starting saslauth with postfix is configured on the file

/etc/sysconfig/saslauthd

Open the configuration file and in the option field there will be a variable "r" is given

OPTIONS="-r"
Remove that option and set it as OPTIONS=""
 
There is no need for r in that .Below is the description for r.
 
 
 -r      Combine the realm with the login (with an '@' sign in between).
             e.g.  login: "foo" realm: "bar" will get passed as login:
             "foo@bar".  Note that the realm will still be passed, which may
             lead to unexpected behavior. 






Thanks and Regards

Syamkumar.M


Sunday, 16 November 2014

Steps to migrate Ubuntu Server to another Machine

Hi,

I have  a requirement in my organisation to replicate the  server environment running in  operating system ubuntu in kvm to another machine in vmware. The current machine contains applications like apache, trac, postgresql, svn etc. One solution for migration is to shutdown kvm machine. Then convert the kvm disk images of the machines to the vmware disks using vmware tools as mentioned in the post

http://syamkumar-linux.blogspot.in/2014/08/how-to-install-vmware-tools-and-convert.html

This process will take many hours to complete and the system will be down on that time. As it is a critical system, we cannot afford that much downtime. So I decided to use an alternative method. That is migration of ubuntu server to another one. Below are the steps for that.

1)First We need to find out the version of ubuntu running on the current machineu. This can be get using the command.

cat /etc/issue

Ubuntu 12.04.2 LTS \n \l

2)Then we need to create a machine in vmware with the same version of ubuntu as in the current machine and install the ubuntu on it.

3)Now on the source machine we need find out the list of packages installed on the source.

sudo dpkg --get-selections | sed "s/.*deinstall//" | sed "s/install$//g" > ~/pkglist


The above command will list all the installed packages on the source machine and will store it in the file pkglist

4)Now on the destination machine install the packages same as in the source machine. That can be done by copying the file pkglist to the destination machine using scp or rsync. The use the below command to install the packages .

sudo aptitude update && cat pkglist | xargs sudo aptitude install -y


Now we have same packages and services running on the destination machine as in the source machine.


5)Now we need to transfer the config file and data from the source machine to the destination machine using scp or rsync.

That is you need to rsync the apache directory, document roots, postgresql data directory, trac configuration file, and trac modules etc. Make sure that you need to shutdown the services before copying it.

Once it is done. All the services will run on the destination machine like in source machine. That is it will behave like the source machine.

If you have done this steps correctly your migration will be succesfull.


Thanks and Regards
Syamkumar.M

Friday, 14 November 2014

Command to reset the cpanel account password

Hi,

We can  reset the account password for the cpanel account by using commands. We usually do it by login to WHM interface and then use the modify account section. But this can be done simply using command line.
This post is usefull for some one who doesn't have a cpanel license on the server.


Below is the commands to reset the cpanel account password

1)First we need to change an environment variable in the current shell we are using export command

export ALLOW_PASSWORD_CHANGE=1

2)Then use the command

/scripts/chpass  username password 

This will change the account password

3)But the ftp password won't sync with the new update. So you need to run the below command to update it

/scripts/ftpupdate

Cheers
Syamkumar.M


Wednesday, 15 October 2014

How to Fix "replication access was denied" Error in Active Directory

Hi,

Recently I faced an issue in which the Replication process on one of the Active directory server failed with the secondary giving error as "replication access was denied". Below is the steps to fix the issue.

1. Open the Active Directory Users and Computers snap-in
2. On the View menu, click Advanced Features.
3. Right-click the domain object, such as "mydomain.com", and then click Properties.
4. On the Security tab, select the account of the user whose credentials are used to run the sensor. (or add it if it does not exist here)
5. Click to select the Monitor Active Directory Replication check box from the list.
6. Click Apply, and then click OK.



Thanks and Regards
Syamkumar.M

Tuesday, 12 August 2014

How to install VMware tools and convert kvm disk images to vmware .vmdk disks

Hi,

We had a requirement to move the kvm systems to vmware and for that at first we need to convert existing kvm machine disk images which is either in qemu/raw type to .vmdk images.

First we need to install vmware-tools on the machine where we are going to convert the disk images. Below are the steps to install the vmware tools.

Import the vmware gpg keys using the command
--------------------------------------------
rpm --import http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-DSA-KEY.pub
rpm --import http://packages.vmware.com/tools/keys/VMWARE-PACKAGING-GPG-RSA-KEY.pub

Add vmware tools repository using the below command
---------------------------------------------
   echo -e "[vmware-tools]\nname=VMware Tools\nbaseurl=http://packages.vmware.com\
   /tools/esx/4.1latest/rhel6/\$basearch\nenabled=1\ngpgcheck=1" > /etc/yum.repos.d/vmware-tools.repo



Update yum and install it using the command
------------------------------------------ 
yum update
yum install vmware-open-vm-tools
yum install vmware-open-vm-dkms

It will install the necessary tools on the machine.

Now use the below command to convert the kvm disk image to vmware one

qemu-img convert machine.img -O vmdk machine.vmdk

It will take some time to convert based on the size of the disk.

Once it is finished. You can scp the converted disk file to the new vmware. Then create a new vmware machine using existing disk image as the convreted file.

That's it

Cheers
Syamkumar.M

Thursday, 24 July 2014

"Cannot start session without errors, "

Hi,

I faced an issue after installing phpmyadmin on one of the server. I am unable to load the phpmyadmin url giving error as "Cannot start session without errors, please check errors given in your PHP and/or webserver log file and configure your PHP installation properly. "

The issue was with some permission with session path of php

For fixing the issue. First note the php settings path in php.ini using the command

php -i | grep -i session

For me the session path is /var/lib/php

I just gave is 777 permission using the command

chmod 777 /var/lib/php

Then the issue was resolved and I was able to login to phpmyadmin now.

Thanks and Regards
Syamkumar.M

Friday, 11 July 2014

How to Restore a table into a new table in the same database

HI,

Please use the commands to restore a table into another table in a database. Below are the commands for that .

Login to mysql database using the credentials and then run these commands in the prompt

CREATE TABLE chillar_card_recharge_new LIKE chillar_card_recharge;
INSERT chillar_card_recharge_new SELECT * FROM chillar_card_recharge;

In the first command it will create a table chillar_card_recharge_new like chillar_card_recharge.

In the second command it will copy the table data into the new table we had created.

Thanks and Regards
Syamkumar.M

Wednesday, 18 June 2014

Troubleshooting using strace

Hi,

Today I faced some issues on bind9, as I was unable to start the bind service using service command. I just went through the logs /var/log/syslog. But didn't get any information about this issue. Finally I used strace which was very usefull to troubleshoot.


strace -f /usr/sbin/named -u bind

It will trace the whole process . Then I was able to find permission denied error for /usr/lib/ssl/openssl.cnf. I fixed the permission issue and then I was able to start the bind.

Cheers
Syamkumar.M

Thursday, 24 April 2014

How to enable Java Plugin to firefox on centos

Hi,

Below are the steps to install and enable java plugin for firefox. First we need to install java on the machine and then do the following steps to enable the plugin on the firefox.



root@test:~# ln -sf /opt/java/jre1.7.0_05/lib/i386/libnpjp2.so /usr/lib/mozilla/plugins/

root@test:~# export JAVA_HOME="/opt/java/jre1.7.0_05"

Testing the plugin.

root@test:~# firefox http://java.com/en/download/testjava.jsp

Regards
Syamkumar.M

Tuesday, 15 April 2014

How to Detect and secure Linux Cpanel Server From Spamming

Hi,

We faced some severe spamming issue on a Cpanel server, upon  checking the email queue, I can see that there is more than 1 lakh of emails. On checking the headers I can see that almost all of them are spam. Below are the steps that I have  taken for fixing the spamming issues on the server.

Exim command to detect the email queue is

exim -bpc

exim -bp|exiqsumm 

command will give you summary of the queue. Once you get the Message IDs from the above command you can view the Header of an email using the command

exim -Mvh Message ID


This will list the headers including the php script which is sending emails, if any.

X-php-script

You can check the body of the message as well in exim to make sure that it was a body of spam email

exim -Mvb Message-ID


Mostly you will get the php script from the exim -Mvh command. But some times you won't get the php scripts from the headers. The hackers might made some custom changes so that it won't appear in the headers.

Then we can use the below command which will detect the directory under which exim is sending emails.

grep cwd /var/log/exim_mainlog | grep -v /var/spool | awk -F"cwd=" '{print $2}' | awk '{print $1}' | sort | uniq -c | sort -n

Also you will get the common subject of spam emails by searching for  duplicate subject lines from the exim logs.

awk -F"T=\"" '/<=/ {print $2}' /var/log/exim_mainlog | cut -d\" -f1 | sort | uniq -c | sort -n

The above commands will give you the directory in which exim is currently executing the emails.The above command will also list the count of emails. So you will know from which directory the emails are sending heavily. Just cd into the directory and check the php files inside or scan with available antivirus(clamav inside that directory)

clamscan -i -r Directory-Name


This will list the vulnerable php files. You just need to delete those files first.

After you find the files which caused the spamming you might need to run a full system scanning on the server using clamav antivirus to find out any other suspicious files are residing on the server.


clamscan -i -r /


Below are the steps to make the system more secure against spamming

1)First install a antivirus like clamav on the server and then scan whole the server and automate it to run daily or weekly using crontab.

2)Install CSF firewall on the server and enable lfd on it

3)Install chrootkit or RK hunter on the server and automate the scanning of those using cron jobs

4)Disable  shell access for users  on the Cpanel servers unless it is required.

5)Disable any unanonymous FTP uploads on the Cpanel server.

6)Disable variables like open_basedir and php exec_shell and register_globals of php on the server

Regards
Syamkumar.M





Sunday, 6 April 2014

How to change Outgoing IP of exim in a Cpanel server

Hi All,

Some times the IP of a cpanel server may got black listed due to spamming and hence we shouldn't be able to send emails to gmail or yahoo etc. This would affect whole customers of a server as no email communication is not possible.  A work around or temperory solution for this issue was to change the outgoing email IP of the cpanel server. Below is the steps to change the ip of a outgoing exim email server in Cpanel.

1)First you need to stop the email service exim through command line.

root@server [~]# /etc/init.d/exim stop

2)Now Login to your WHM control panel and do the changes on the section Exim configuration Manager on WHM.

Reference /etc/mailips for outgoing SMTP connections [?]
Send outgoing mail from the IP address that matches the domain name in /etc/mailips (more information)
Make the above settings to on.
3)Now login to the server as root and then open the configuration file /etc/mailips

add the new outgoing ip adress for exim as 

*:X.X.X.X

Where x.x.x.x is the ip adress you need to change. Save the configuration file and exit.


4)Restart the exim service

/etc/init.d/exim restart




Now the email will be sending from new fresh ip which is not black listed.


Regards
Syamkumar.M


Tuesday, 25 March 2014

psql: FATAL: parameter "listen_addresses" cannot be changed without restarting the server

Hi,

We faced an issue on one of the machine, where the postgresql commands are not runnning as root. Always getting the below error while executing any psql command

psql: FATAL:  parameter "listen_addresses" cannot be changed without restarting the server.

Initially I thought it was some thing to do with the settings on the pg_hba.conf file and postgresql.conf file where the variable listen_address is specified .The variable listen_adresses has been changed on postgresql.conf from

listen_addresses = '*'

to

listen_addresses = '10.11.16.112'

Then restarted the postgresql service. But still got the same error. One of the strange thing is that I am able to connect to postgresql command line from another machine to the machine having issue, but not from with in the machine as root.

Finally On checking, I found that there was a variable named PGOPTIONS was the issue.  Below is the steps I had done to resolve it.

Find the value of variable PGOPTIONS on the command line using the command

echo $PGOPTIONS
-i

SO I found out that the variable was defined in the server some where . I found out the variable on the environment file /etc/environment.

I changed the value from -i to Null value on /etc/environment

vi /etc/environment
PGOPTIONS=""


 Now the command echo $PGOPTIONS showed the null value

And now I am able to execute any psql command operations like pg_dump.

Regards
Syamkumar.M




Monday, 24 March 2014

/etc/rc.local not running on the boot

Hi,

   /etc/rc.local is the file which runs once the system boots up. If we need to run few commands immediately once the system starts up, we can do it by adding those commands in /etc/rc.local.

Last week I faced an issue in which the commands inside the rc.local was not working, once the system boot.  I tried starting and stopping the systems so many times and tried to change the settings of /etc/rc.local, but still it was not working.  Then I read in one of the Centos Forums that it was some issue with the first boot.

In my machine firstboot got hanged and init was not able to execute the content inside /etc/rc.local. Below is the steps to resolve it

check to see if firstboot is still running and kill it:


ps ax |grep firstboot
killall firstboot


This will kill the first boot .

Then switch the firstboot permenantly using chkconfig

chkconfig firstboot off


The first boot issue was caused by some of the software installations which may confuse the firstboot.

Regards
Syamkumar.M
 

Tuesday, 18 March 2014

How to change ulimit values permanently for a user in Centos

Hi,

ulimit is the parameter which defines the limits a process can use on a linux system.  It will provide control over the resources a user or a process in a shell can use.  You can list the current setting of ulimit values by login as your user and type the following commands

# ulimit -Hn
# ulimit -Sn


Default values should be 4096 and 1024 respectively.
 

So it will also determine the number of open files a user can open or edit. For increasing the ulimit, you need to change those paramentes in a configuration file called

/etc/security/limits.conf

If I need to change the ulimit value for my user on  a linux system. Then you should login to machine as root.

Open the above file in editor and then add the following content to it.

syam        soft nofile 9000
syam        hard nofile 65000



Now you should see the changes to the ulimit value for a user when you switch user from the root. But still the limit won't get reflected when user login as ssh with the password. We need to add the following steps to get the changes reflected for the user upon ssh login as user .


  1. In /etc/pam.d/sshd added the line
session required pam_limits.so
  1. In /etc/pam.d/login added the line
session required pam_limits.so
  1. In /etc/ssh/sshd_config added
UsePAM yes

Now restart the sshd service

4. /etc/init.d/sshd restart

Now the ulimit values will be changed permenantly and you can see the values once you ssh into the machine as user.


ulimit -Hn
65000

ulimit -Sn

9000

Regards
Syamkumar.M




Tuesday, 11 March 2014

How to Delete a line from gz file having huge size

Hi,

We got a task to delete a specific line from a 6Gb gzip file. Below is the steps followed to delete the line.

1)Use zgrep to search through the gzip files

zgrep is used to search a line or pattern from the gzipped file. The output will be same as that of grep command on a normal file. Here we use the command as below. There is a specific pattern on that line through which we need to find the line number and then delete the line from that file using sed.

zgrep -in pattern test1.gz

2)From the above command we got the line number which we need to delete. It is 5344402. Then we need to use sed command to delete line on that line number. But we can't use sed on a gzipped file. So we need to unzip the file

unzip test.gzsya

3)Now we can use sed command to delete that line from the test file

sed -i '5344402d' test

Above command will delete the line on that line number of the file.

4)Again zip the file

zip test






Thats all
Thanks

Monday, 3 March 2014

Switch off redirection from http to https in DirectAdmin

Hi,

Below is the steps to disable redirection from http to https in the direct admin Login page. Default Direct admin Login URL is http://domainname:2222, where 2222 is the port used by Direct admin.

The DirectAdmin configuration file is

/usr/local/directadmin/conf/directadmin.conf

Open it in a text editor like vi to view its content

It contains all the default configuration for the directadmin like port and ssl.

Search for ssl in the file

SSL=1
cacert=/usr/local/directadmin/conf/cacert.pem
cakey=/usr/local/directadmin/conf/cakey.pem


You will get the result as above which contains certificate file location for the self signed certificate the directadmin is using.

You can turn the ssl off so that it will no longer redirect from http to https.

 SSL=0

Save the file and exit

Similarly if you need to change another port for directadmin Admin url you can change it in the above  configuration file.


Regards
Syamkumar.M




Ad