Showing posts with label putty. Show all posts
Showing posts with label putty. Show all posts

Tuesday, January 3, 2012

Steps for creating automatic startup/shutdown scripts for Tomcat in Amazon EC2

After Tomcat is installed in EC2, it's time to create a startup/shutdown service script. Below are steps:
  1. login to EC2 instance with putty
  2. sudo su
  3. cd /etc/init.d
  4. vim tomcat
  5. put following into the file  
  6. #!/bin/bash
    # chkconfig: 234 20 80
    # description: Tomcat Server basic start/shutdown script
    # processname: tomcat
    JAVA_HOME=/usr/java/jdk1.6.0_24
    export JAVA_HOME
    TOMCAT_HOME=/usr/share/apache-tomcat-7.0.23/bin
    START_TOMCAT=/usr/share/apache-tomcat-7.0.23/bin/startup.sh
    STOP_TOMCAT=/usr/share/apache-tomcat-7.0.23/bin/shutdown.sh
    start() { echo -n "Starting tomcat: "
    cd $TOMCAT_HOME
    ${START_TOMCAT}
    echo "done." }
    stop() { echo -n "Shutting down tomcat: "
    cd $TOMCAT_HOME
    ${STOP_TOMCAT} echo "done." }
    case "$1" in
    start)
    start
    ;;
    stop)
    stop
    ;;
    restart)
    stop
    sleep 10
    start
    ;;
    *)
    echo "Usage: $0 {start|stop|restart}"
    esac
    exit 0
  7. Change permissions.  chmod 755 tomcat
  8. Add script to system services. chkconfig --add tomcat
  9. Test it out. service tomcat start, service tomcat stop.

Monday, January 2, 2012

Create Swap Space in Amazon EC2 instance

Just found out my Amazon EC2 micro instance does not have any swap space. The memory comes with the micro instance is enough for a regular PHP app, but not enough for any J2EE application. It's time to add a file system swap. Below are steps for creating a swapfile:
  1. login as ec2-user with putty.
  2. sudo su
  3. dd if=/dev/zero of=/swapfile bs=1024 count=1048576
  4. /sbin/mkswap /swapfile
  5. /sbin/swapon /swapfile
  6. /sbin/swapon -s

Sunday, January 1, 2012

Install Tomcat to Amazon EC2 instance

To install Tomcat, first we need to install a JDK. Steps to install JDK.
  1. Login to AWS EC2 instance with putty.
  2. sudo su
  3. Create a directory for Java installation. cd /usr/share, mkdir java, cd java.
  4. Download a JDK from Oracle.  wget http://download.oracle.com/otn-pub/java/jdk/7u2-b13/jdk-7u2-linux-i586.tar.gz 
  5. Install it. tar -xzf jdk-7u2-linux-i586.tar.gz
  6. Test it. /usr/share/java/ jdk1.7.0_02/bin/java -version.
Install Tomcat.
  1. Download Tomcat to /usr/share directory. wget http://www.trieuvan.com/apache/tomcat/tomcat-7/v7.0.23/bin/apache-tomcat-7.0.23.tar.gz
  2. Install Tomcat. tar -xzf apache-tomcat-7.0.23.tar.gz
  3. set JAVA_HOME $env in catalina.sh. cd /usr/share/apache-tomcat-7.0.23/bin,
    vi catalina.sh and add following line after the first line. JAVA_HOME=/usr/share/java-1.7.0/jdk1.7.0_02
  4. Start it. ./start.sh. Check log and fix errors if any.
Next I will talk about creating a startup/shutdown script.

Thursday, December 29, 2011

Install Wordpress over Amazon EC2 instance

 LAMP stack has been installed on my Amazon free EC2 instance, now it's time to get something up and running on it so that I test what an Amazon free micro EC2 instance is capable of. I started with a bare bone CentOS instance with and use it as my sandbox for experiencing things. Wordpress would be a good candidate to try. Below are steps I used to install Wordpress 3.3 to my EC2 instance.
  1. login into AWS Management Console and launch the instance (if it's not running).
  2. Connect to the instance with putty.
    • sudo su
  3. Start Apache and MySQL.
    • service httpd start
    • service mysqld start
  4. login into mysql and create a database for Wordpress
    • mysql> CREATE DATABASE wpdb;
      mysql> GRANT ALL PRIVILEGES ON wpdb.* TO wpuser@localhost
          -> IDENTIFIED BY "wpuser-password";
      mysql> FLUSH PRIVILEGES;
      mysql> exit
  5. Download Wordpress and unpack it.
    • cd /var/www/html
      wget http://wordpress.org/latest.zip
      unzip latest.zip
      rm -rf latest.zip
      cp wp-config-sample.php wp-config.php
  6. Change the ownership of all Wordpress file to Apache - chown -R apache:apache wordpress
  7. Open a browser and type in the Wordpress URL. Following the on screen instruction and Wordpress is up and running in no time.
Of course there is an even quicker way to get Wordpress. There are a number of community AMIs that come with Wordpress pre-loaded and you only need to change wp-config.php to get it up and running.

Wednesday, December 28, 2011

Set up an FTP server on Amazon AWS EC2

You really don't need to set up an FTP server if you simply want to tranfer files between your EC2 instance and your local machine. You can use PSFTP (coming with putty package) with a saved putty session for your EC2 conection. Open a command window, type in psftp your_saved_putty_session_name. Type ec2-user for  login as and you are connected.


If you don't like commandline tool, you can use Filezilla instead. Download and install Filezilla client.  Lauch Filezilla. Click Edit -> Settings and select SFTP under Connction. Click Add Keyfile to add the private key file you use for putty connection. Click OK.


Click File -> Site Manager, Click New Site, enter your AWS EC2's public DNS or IP in Host field. Choose SFTP, enter ec2-user in User field and click Connect.

Now you are connected to your EC2 instance with FileZilla.


If you still want to set up an FTP server on your AWS EC2. Below are steps to install VSFTP.
  1. login to  your AWS management console.
    • Go to EC2 and click the Security Groups link.
    • Then choose the default group and switch to the inbound tab (at the bottom of the page)
    • Add the port ranges as above (20-21 and 40000-41000) and apply the rule changes
  2. connect to your instance with putty.
  3. login as ec2-user
  4. sudo su
  5. yum vsftpd
  6. change the conf file. vim /etc/vsftpd/vsftpd.conf. Add
    write_enable=YES 
    pasv_max_port=41000
    pasv_min_port=40000
    port_enable=YES
    pasv_enable=YES
  7. Add an FTP user (see instruction here)
  8. Start the FTP server. service vsftpd start

Thursday, December 15, 2011

Add a new user to Amazon EC2 instance

After connecting to your Amazon EC2 instance, you can add a new user with sudo privilege with following steps:
  1. Open a putty session, log in with the default user, ec2-user
  2. sudo su
  3. useradd new_user_name
  4. passwd new_user_name, give a password for the new user
  5. vim /etc/sudoers, insert line "new_user_name ALL = NOPASSWD: ALL" at the end of the file
  6. cd /home/new_user_name
  7. mkdir .ssh
  8. cp ../ec2-user/.ssh/authorized_keys .ssh/authorized_keys
  9. chown -R new_user_name:new_user_name .ssh
  10. chmod 700 .ssh
  11. chmod 600 .ssh/*
Open another putty session and log in with the same private key you use for ec2-user.

Tuesday, December 13, 2011

Amazon EC2: Install LAMP stack to it

I have talked about creating an Amazon EC2 account, defining access credentials, launching an instance and connecting to it with putty. Now what? The most logical step next is to load some software to it and start experimenting with it. A very practical way is to configure it as a standalone LAMP stack.
  • Connecting to you instance with putty. Run command sudo su
Install Apache with command: yum install httpd
          


Install mySQL server with command: yum install mysql-server mysql


Install PHP with command: yum install php php-mysql


Install other optional php packages if you want.

Start Apache server with command: service httpd start.

To test your Apache and PHP install, go to /var/www/html/ directory and create a file index.php with one line of code:
<?php phpinfo(); ?>
In your favorate browser, enter your instance's public DNS name, something like ec2-##-##-##-###.compute-#.amazonaws.com.

Monday, December 12, 2011

Amazon Elastic Compute Cloud (EC2) : Part 4: Connect to an Instance with Putty

In Part 3 I talked about launching an instance. I will discuss how to connect to an Amazon EC2 instance with Putty via SSH  step by step.

First import the private key and save it as putty format.
  • Open PUTTYGEN.EXE


  • Click the Load button, select the private key of the key pair you created before and click Open.


  • You will get the Key import successful message.



  • Click OK, then click Save private Key.



  • You will get a warning message about saving the key without a passphrase, click Yes.



 Next launch Putty to open an SSH session.

Configure Putty to use the PPK file you just saved. Click connection, SSH, and select Auth. Click the browse button next to the Private Key File for authentication field, and select the .PPK file you just created with Puttygen.


Copy your EC2 instance Public DSN to your putty session and click open. Log in with user name ec2-user.