Tuesday, June 23, 2015

Remotly Manage Linux Servers In Azure with Webmin

To managing Linux servers in Azure is not that easy some times the server SSH sessions are dropped and cant connect to server to manage. To this we can use "Webmin" this tools is Like a c panel for managing Linux servers.

  • Install dependency packagers for for Webmin.
# sudo apt-get install perl libnet-ssleay-perl openssl libauthen-pam-perl libpam-runtime libio-pty-perl apt-show-versions python
  • Download Webmin.
# wget http://sourceforge.net/projects/webadmin/files/webmin/1.760/webmin_1.760_all.deb
  • Install webmin
#  sudo dpkg --install webmin_1.760_all.deb
  • Open firewall ports for Webmin
# sudo ufw allow 10000
  • Create a endpoint with following configuration.
       
  • Now access  the webmin portal with  http://name.cloudapp.net:10000
  • Login with root and root password.

How to Automate MySQL Backup - Ubuntu

Recently i want to backup some MySQL Database  to this i have used Automysqlbackup tool.
this tool backup the Databases daily weekly and Monthly.

  • To Install the automysqlbackup
         # sudo apt-get install automysqlbackup
  • Start the Service
        # sudo automysqlbackup
  • Config Files are stored in /etc/default/automysqlbackup
       # sudo nano /etc/default/automysqlbackup
  •  uncomment the Following Lines. 
Note : From this it will create a seprate folders daly , weekly , Monthly and have separate folders for DB in /var/lib/automysqlbackup.

 # Username to access the MySQL server e.g. dbuser
USERNAME=`grep user /etc/mysql/debian.cnf | tail -n 1 | cut -d"=" -f2 | awk '{print $1}'`
# Username to access the MySQL server e.g. password
PASSWORD=`grep password /etc/mysql/debian.cnf | tail -n 1 | cut -d"=" -f2 | awk '{print $1}'`

# Host name (or IP address) of MySQL server e.g localhost
DBHOST=localhost

# reading the mysql folder content. Feel free to replace by something else.
DBNAMES=`find /var/lib/mysql -mindepth 1 -maxdepth 1 -type d | cut -d'/' -f5 | grep -v ^mysql\$ | tr \\\r\\\n ,\ `

# This one does a list of dbs using a MySQL statement.

DBNAMES=`mysql --defaults-file=/etc/mysql/debian.cnf --execute="SHOW DATABASES" | awk '{print $1}' | grep -v ^Database$ | grep -v ^mysql$ | grep -v ^performance_schema$ | grep -v ^information_schema$ | tr \\\r\\\n ,\ `

# root, with Unix rights 0600.
BACKUPDIR="/var/lib/automysqlbackup"

# List of DBBNAMES for Monthly Backups.
MDBNAMES="mysql $dbname "

Monday, June 22, 2015

Cant SSH to Linux VM - Azure



Did you encounter that the SSH connection is suddenly not working with Azure Linux machine.
This happens to me quit a lot with Azure Ubuntu VM. and there were not much help in the internet about this and had to call the Microsoft support,
This are the steps what we have done to resolve this issue.

  • First we can try to reset the remote session form the portal.
  • Log in to https://portal.azure.com/
  • Then go to Browse All and select Virtual Machines.
 
  • Then select the vm and  click Reset Remote Access.
 
  • If this didn't work ( in my case this didn't work) there is a script to run.
  • Open  Microsoft Azure Command Shell
  • Then first remove the All the saved azure accounts form the computer.
 # Get-AzureAccount | %{Remove-AzureAccount -Name $_.Id} Clear-AzureProfile
  • Add the Azure account to Powershell.
# Add-azureaccount
  • Then run the following script to reset the SSH
  • Replace the  red colourd with the details of the your Azure VM
$subname = "Subscription name"     #Set subscription details
$subid = "Subscription id"         #Subscription id

Set-AzureSubscription -SubscriptionName $subname
Select-AzureSubscription -SubscriptionName $subname
Get-AzureSubscription

#Sample script to reset the SSH configuration on your VM
#Identify the VM

$vm = Get-AzureVM -ServiceName 'CLOUD_SERVICE_NAME_WITHOUT_cloudapp.net'  ' -Name 'VM_Name'
##Get-AzureVMExtension -VM $Vm | Select ExtensionName, Publisher, Version
$vm.GetInstance().ProvisionGuestAgent = $true
Get-AzureVMExtension -VM $Vm | Select ExtensionName, Publisher, Version
#Set-AzureVMExtension -ExtensionName 'CustomScriptForLinux' -VM $vm -Publisher 'Microsoft.OSTCExtensions' -Version '1.2' | Update-AzureVM -Verbose
$TimeStamp = (Get-Date).Ticks

$PrivateConfig = '{"reset_ssh": "True", "timestamp": "' + $TimeStamp + '"}'

# Begin execution
$ExtensionName = 'VMAccessForLinux'
$Publisher = 'Microsoft.OSTCExtensions'
$Version =  '1.*'
Set-AzureVMExtension -ExtensionName $ExtensionName -VM  $vm -Publisher $Publisher -Version $Version -PrivateConfiguration $PrivateConfig | Update-AzureVM
  • Now try to log in the Azure with SSH Using the first account you used to connect to Azure. 
( eg : azureuser and the Password )

Saturday, June 20, 2015

Configure Https In apache - Ubuntu server - Azure

To Configure https In Apache ( Ubuntu )
  •  First need to enable  https
          $ sudo a2enmod ssl
  • Create a Folder to store SSL certificate
         $ sudo mkdir /etc/apache2/ssl/
  •  Next copy the following certificate to above folder
    1. SSL CertificateFile (.crt)
    2. SSL Certificate Key File (.key)
    3. Certificate Chain file (.crt)
Note : 
  • This certificates can be downloaded form the Certificate authority.
  • Also can Self Signed SSL Certificate form following command.
" $ sudo openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /etc/apache2/ssl/apache.key -out /etc/apache2/ssl/apache.crt "
This was copied form https://www.digitalocean.com/community/tutorials/how-to-create-a-ssl-certificate-on-apache-for-ubuntu-12-04
  •    Next open the SSL configuration file.
$ sudo nano /etc/apache2/sites-available/default-ssl.conf
  • Make sure SSL on
    # SSLEngine on
  • And change the  following with the certificate name.
 # SSLCertificateFile    /etc/apache2/ssl/SSL CertificateFile.crt
          #  SSLCertificateKeyFile /etc/apache2/ssl/SSL Certificate Key File.key
 # SSLCertificateChainFile /etc/apache2/ssl/Certificate Chain file.crt
  • Save the file.
  •  Next Open the 443 port from the Firewall
$ sudo ufw allow 443
  • Restart the Apache service.
$ sudo service apache2 restart
  •  In azure to work this also need to open the 443 from Azure port. 
  # log in the portal and select the Virtual Machine  and go to Endpoint and create a endpoint with following config.

Saturday, June 13, 2015

Can't Delete Blob - ''There is Currently a lease on the blob and no lease ID was specified in the request."

If you got following error when your deleting a storage contaner.

'' There is Currently a lease on the blob and no lease ID was specified in the request ''

this mainly because when you deleting vm some times it dosen't  the disks.
to resolve this.

  • Go to Virtual Machines and select Images. and delete the image.


  •  Then go to Disks and delete the disk that was attached to the deleted Virtual machine.
  •  now you wll able to delete the blob storage.



Upload VHD file to Azure


Azure has many good feature and one thing I loved is that we can attached VHD files and run the Virtual machines.

  • First we need to Prepare the VHD files to Upload to the Azure. To do that we need to run sysprep tool
  • When the machine is powered on go to  windows/system32/sysprep and run the sysprep.exe
  •  Next we need to create  a storage
  • Sign in to the Azure Management Portal
  •  On the command bar, click New. 
  •  Click Data Services > Storage > Quick Create. And give a name and create a new storage. 
  •  Next open the storage  and go to containers. And create  a new container 

  • Enable Debug mode so it will give more detials about the process. 
          # DebugPreference='Continue'
  • Login to Windows Azure subscription
          # Add-AzureAccount
  •  Get Azure publisher settings
          # Get-AzurePublishSettingsFile
  •  Import azure publisher Files 
          # Import-AzurePublishSettingsFile –PublishSettingsFile Pay-As-You-Go-6-11-2015-credentials.publishsettings

   EG :  #Import-AzurePublishSettingsFile –PublishSettingsFile C:\Users\user\Downloads\Pay-As-You-Go-6-11-2015-credentials.publishsettings

  •  Upload the VHD files
            # add-AzureVhd –LocalFilePath /Filepath/vhdfileneame.vhd -NumberOfUploaderThreads 36 -Destination "blobspace "

            # add-AzureVhd -LocalFilePath F:\Virtual_Hard_Disks\2012R3A_OS.vhd -NumberOfUploaderThreads 36 -Destination https://rir.blob.core.windows.net/vhds/2012R3A_OS.vhd

Thursday, June 4, 2015