Prequel:
I’m always setting up one-off dev instances and end-up googling all this information. I haven’t found a one-stop shop for doing this, so here’s my notes to myself and others.
I’m assuming the following has been completed: (1) Provisioned an instance in EC2 for a CentOS 7 box, (2) Have your SSH key for that instance, and (3) have converted your PEM formatted key into a PPK which is able to be used by Putty.
I’m setting this up using the AWS keys provided. No passwords.
Set an Elastic IP:
I usually turn off my instance while I’m not using it to save money. Unfortunately, this means the IP address will change each time I turn it on. I’ve set an elastic ip for it. The AWS EC2 T Series requires a “VPC” type elastic ip (not “ec2” type), otherwise you get a cryptic error when trying to attach it: “An error occurred while attempting to associate the address. The request must contain the parameter instance id.”
Connect to your account:
Putty into the server using your PPK.
The default username, for a CentOS 7 box in AWS, is: “centos”.
Set up your user account:
Add a non-default user account for yourself:
#useradd <username>
Add the user to the sudoers group:
#sudo gpasswd -a <username> wheel
The default settings in: /etc/sudoers does not allow password-less login. Since we aren’t using a password, we need to modify this file. Comment out the current wheel line, and uncomment the 2nd one. It should look this afterward:
Edit the /etc/sudoers file:
## Allows people in group wheel to run all commands
#%wheel ALL=(ALL) ALL
## Same thing without a password
%wheel ALL=(ALL) NOPASSWD: ALL
Install Java
I prefer to use the tar.gz version of Java and specifically link it in myself, versus using an rpm, or yum to manage that for me. Lots of pro’s and con’s here.
I downloaded java on my local workstation and scp’d it over to the server.
## Extract java into /opt
# sudo tar -xvf jdk-8u102-linux-x64.tar.gz
## Give it your permissions
# sudo chown -R <username>.<username> jdk*
## Symlink your current java install
# sudo ln -s jdk1.8.0_102 java
Add JAVA_HOME and JAVA_BIN to /home/<user>/.bashrc and to the PATH.
# vi /home/<user>/.bashrc
## Add the following:
# export JAVA_HOME=/opt/java
# export PATH=$PATH:$JAVA_HOME/bin
Either source your bashrc (source ~/.bashrc), or log out and log back in to pick up the new path.
Run the following to verify Java is installed properly:
# java -version
Output:
java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
Install Maven:
Like Java, I prefer to install Maven on my own.
Download the latest version using wget and install:
# wget http://mirrors.gigenet.com/apache/maven/maven-3/3.3.9/binaries/apache-maven-3.3.9-bin.tar.gz
## Extract maven into /opt
# sudo tar -xvf jdk-8u102-linux-x64.tar.gz
## Give it your permissions
# sudo chown -R <username>.<username> apache-maven*
## Symlink your current java install
# sudo ln -s apache-maven-3.3.9 maven
Add Maven to your .bashrc:
# vi /home/<user>/.bashrc
## Add the following:
# export PATH=/opt/maven/bin:$PATH
Either source your bashrc (source ~/.bashrc), or log out and log back in to pick up the new path.
Run the following to verify Maven is installed properly:
# mvn -v
Output:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T16:41:47+00:00)
Maven home: /opt/maven
Java version: 1.8.0_102, vendor: Oracle Corporation
Java home: /opt/jdk1.8.0_102/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "linux", version: "3.10.0-327.10.1.el7.x86_64", arch: "amd64", family: "unix"
There you have it! Up and running with Java and Maven on CentOS 7 EC2. Next step is to install your favorite ide, or maybe just git clone and compile something from github.
Sources: