Thursday, April 20, 2017

Extending disk space in linux


https://tecadmin.net/resize-root-ebs-volume-on-aws-linux-instance/

I have created a new CentOS Linux instance. I had selected 50GB of root volume during creating of instance but when system comes online it was showing only 8GB of disk is usable. I tried to resize root disk using resize2fs, I get the following message
root@tecadmin [~]# resize2fs /dev/xvda1 

The filesystem is already 16775167 blocks long.  Nothing to do!
So, I have following below steps and able to successfully resize volume to its ful size selected during instance creation

Step 1. Take Backups

We strongly recommended to take full backup (AMI) of your instance before doing any changes. Also create a snapshot of root disk.

Step 2. Check Current Partitioning

Now check the disk partitioning using following command. You can see that /dev/xvda is 53GB in size but
root@tecadmin [~]# df -h 

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       8G  3.7G   4.2G  45% /
tmpfs           1.8G     0  1.8G   0% /dev/shm
/usr/tmpDSK     485M  111M  349M  25% /tmp
root@tecadmin [~]# fdisk -l

Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *           1        1045     8387584   83  Linux

Step 3. Increase Size of Volume

Now start with the disk re partitioning using set of following commands. Execute all the commands carefully.
root@tecadmin[~]# fdisk /dev/xvda 

WARNING: DOS-compatible mode is deprecated. It's strongly recommended to
         switch off the mode (command 'c') and change display units to
         sectors (command 'u').
Now change the display units to sectors using u switch.
Command (m for help): u 
Changing display/entry units to sectors
Now print the partition table to check for disk details
Command (m for help): p 

Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1   *        2048    16777215     8387584   83  Linux
Now delete the first partition using following command.
Command (m for help): d
Selected partition 1
Now create a new partition using following commands. For the first sector enter 2048 (as shows in above command output) and for last second just press enter to select all partition.
Command (m for help): n
Command action
   e   extended
   p   primary partition (1-4)
p
Partition number (1-4): 1
First sector (63-104857599, default 63): 2048 
Last sector, +sectors or +size{K,M,G} (2048-104857599, default 104857599): [PRESS ENTER]
Using default value 104857599
Print the partition table again. You will see that new partition has occupied all disk space.
Command (m for help): p 

Disk /dev/xvda: 53.7 GB, 53687091200 bytes
255 heads, 63 sectors/track, 6527 cylinders, total 104857600 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x00098461

    Device Boot      Start         End      Blocks   Id  System
/dev/xvda1            2048   104857599    52427776   83  Linux
Now set the bootable flag on partition 1.
Command (m for help): a 
Partition number (1-4): 1
Write disk partition permanently and exit.
Command (m for help): w 
The partition table has been altered!

Calling ioctl() to re-read partition table.

WARNING: Re-reading the partition table failed with error 16: Device or resource busy.
The kernel still uses the old table. The new table will be used at
the next reboot or after you run partprobe(8) or kpartx(8)
Syncing disks.
Lets reboot your system after making all above changes.
root@tecadmin [~]# reboot
Lets resize file system using resize2fs command. Remember that you are resizing filesystem not formatting.
root@tecadmin [~]# resize2fs /dev/xvda1 

resize2fs 1.41.12 (17-May-2010)
Filesystem at /dev/xvda1 is mounted on /; on-line resizing required
old desc_blocks = 1, new_desc_blocks = 4
Performing an on-line resize of /dev/xvda1 to 13106944 (4k) blocks.
The filesystem on /dev/xvda1 is now 13106944 blocks long.

Step 4. Verify Upgraded Disk

At this point your root volume has been resized successfully. Just verify your disk has been resizes properly
root@tecadmin[~]# df -h 

Filesystem      Size  Used Avail Use% Mounted on
/dev/xvda1       50G  6.7G   40G  15% /
tmpfs           1.8G     0  1.8G   0% /dev/shm
/usr/tmpDSK     485M  111M  349M  25% /tmp

Thursday, June 30, 2016

Remove the contents of a folder in linux

  1. To remove the folder with all its contents(including all interior folders): rm -rf /path/to/directory.
  2. To remove all the contents of the folder(including all interior folders) but not the folder itself: rm -rf /path/to/directory/*

Thursday, June 2, 2016

Address already in use tomcat


I also had the same issue. Tried all the options suggested in this thread. But didnt help. Then just did ran:
ps -awwef | grep tomcat
and found some stale process running. I killed it using (-15 instead of -9)
sudo kill -15 <tomcat pid from previous command>
And woot! it worked. Restarted tomcat without any issue.

http://stackoverflow.com/questions/8040640/tomcat-startup-8080-address-already-in-use

Tuesday, May 10, 2016

Self signed certificate

1. Generate keystore using Java keystore tool
2. Modify server xml to enable htts, chnage port to 443, chnage http redirect port to 443


https://dzone.com/articles/setting-ssl-tomcat-5-minutes

This tutorial will walk you through how to configure SSL (https://localhost:8443 access) onTomcat in 5 minutes.
For this tutorial you will need:
  • Java SDK (used version 6 for this tutorial)
  • Tomcat (used version 7 for this tutorial)
The set up consists in 3 basic steps:
  1. Create a keystore file using Java
  2. Configure Tomcat to use the keystore
  3. Test it
  4. (Bonus ) Configure your app to work with SSL (access through https://localhost:8443/yourApp)

1 – Creating a Keystore file using Java

Fisrt, open the terminal on your computer and type:
Windows:
cd %JAVA_HOME%/bin
Linux or Mac OS:
cd $JAVA_HOME/bin
The $JAVA_HOME on Mac is located on “/System/Library/Frameworks/JavaVM.framework/Versions/{your java version}/Home/
You will change the current directory to the directory Java is installed on your computer. Inside the Java Home directory, cd to the bin folder. Inside the bin folder there is a file named keytool. This guy is responsible for generating the keystore file for us.
Next, type on the terminal:
keytool -genkey -alias tomcat -keyalg RSA
When you type the command above, it will ask you some questions. First, it will ask you to create a password (My password is “password“):
loiane:bin loiane$ keytool -genkey -alias tomcat -keyalg RSA
Enter keystore password:  password
Re-enter new password: password
What is your first and last name?
  [Unknown]:  Loiane Groner
What is the name of your organizational unit?
  [Unknown]:  home
What is the name of your organization?
  [Unknown]:  home
What is the name of your City or Locality?
  [Unknown]:  Sao Paulo
What is the name of your State or Province?
  [Unknown]:  SP
What is the two-letter country code for this unit?
  [Unknown]:  BR
Is CN=Loiane Groner, OU=home, O=home, L=Sao Paulo, ST=SP, C=BR correct?
  [no]:  yes
 
Enter key password for
    (RETURN if same as keystore password):  password
Re-enter new password: password
It will create a .keystore file on your user home directory. On Windows, it will be on: C:Documents and Settings[username]; on Mac it will be on /Users/[username] and on Linux will be on /home/[username].

2 – Configuring Tomcat for using the keystore file – SSL config

Open your Tomcat installation directory and open the conf folder. Inside this folder, you will find theserver.xml file. Open it.
Find the following declaration:
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS" />
-->
Uncomment it and modify it to look like the following:
Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
    disableUploadTimeout="true" enableLookups="false" maxThreads="25"
    port="8443" keystoreFile="/Users/loiane/.keystore" keystorePass="password"
    protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
    secure="true" sslProtocol="TLS" />
Note we add the keystoreFilekeystorePass and changed the protocol declarations.

3 – Let’s test it!

Start tomcat service and try to access https://localhost:8443. You will see Tomcat’s local home page.
Note if you try to access the default 8080 port it will be working too: http://localhost:8080

4 – BONUS - Configuring your app to work with SSL (access through https://localhost:8443/yourApp)

To force your web application to work with SSL, you simply need to add the following code to yourweb.xml file (before web-app tag ends):
 
<security-constraint>
    <web-resource-collection>
        <web-resource-name>securedapp</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>
The url pattern is set to /* so any page/resource from your application is secure (it can be only accessed with https). The transport-guarantee tag is set to CONFIDENTIAL to make sure your app will work on SSL.
If you want to turn off the SSL, you don’t need to delete the code above from web.xml, simply changeCONFIDENTIAL to NONE.


https://coolestguidesontheplanet.com/redirecting-http-https-tomcat/


Redirect HTTP to HTTPS on Tomcat

You’ve bought your SSL secure certificate and successfully installed on Tomcat with thekeytool but how do your redirect the entire site to go HTTPS and redirect any HTTPconnection straight over to HTTPS.
You need to edit the 2 Tomcat configuration files; server.xml and web.xml and then when edited restart the tomcat service.
Open server.xml typically found in tomcat/conf and change:
Connector port="80?
 enableLookups="false"
 redirectPort="8443?
to
Connector port="80?
 enableLookups="false"
 redirectPort="443?
Then openweb.xml (same directory) and add this snippet before the closing tag of /web-app:
<security-constraint>
 <web-resource-collection>
 <web-resource-name>Protected Context</web-resource-name>
 <url-pattern>/*</url-pattern>
 </web-resource-collection>
 <!-- auth-constraint goes here if you requre authentication -->
 <user-data-constraint>
 <transport-guarantee>CONFIDENTIAL</transport-guarantee>
 </user-data-constraint>
 </security-constraint>
Restart Tomcat and all pages should redirect to https.

serach files in linux

$ find / -name 'program.c' 


/
Start searching from the root directory (i.e / directory)
-name
Given search text is the filename rather than any other attribute of a file


http://www.codecoffee.com/tipsforlinux/articles/21.html

Wednesday, May 4, 2016

MySQl Database backup command

mysqldump --user=root --result-file=/home/cwdrappier/sumesh/anp.sql anp

mysqldump --user=root --result-file=/home/centos/ileads_organization_157.sql ileads_organization_157

Thursday, March 3, 2016

Accessing a JSP Page without .jsp suffix

http://stackoverflow.com/questions/20326451/hide-jsp-extension-or-change-display-name-on-url


<servlet>
  <servlet-name>pub</servlet-name>
  <jsp-file>/publications.jsp</jsp-file>
</servlet>
<servlet-mapping>
  <servlet-name>pub</servlet-name>
  <url-pattern>/publications</url-pattern> <!-- Use this URL -->
</servlet-mapping>