Managing services on Linux

This article applies to Red Hat, Fedora, CentOS, AWS Linux distros.

For enabling, disabling and listing system services, use the script called chkconfig.

List all services

chkconfig --list

List a specific service

chkconfig --list httpd

Turn a service on for specific levels

chkconfig httpd on --level 2,3,5

Disable a service

chkconfig httpd off

For stopping, starting and restarting a service, use the script called service.

service httpd stop
service httpd start
service httpd restart

AWS EC2 Linux swap file creation

The Amazon EC2 Linux instances come without a swap file. The steps below show how to add a swap file to an EC2 Linux server.

dd if=/dev/zero of=/mnt/swapfile bs=1M count=4096
chown root:root /mnt/swapfile
chmod 600 /mnt/swapfile
mkswap /mnt/swapfile
swapon /mnt/swapfile
swapon -a

To make these changes permanent (reboot proof). Add the following line to /etc/fstab

vi /etc/fstab
/mnt/swapfile swap swap defaults 0 0

Java and Cassandra setup on an AWS Linux server

Java 7 Setup

# First verify the version of Java being used is not Oracle JDK.
java -version

# Get the latest JDK 7 from Oracle http://www.oracle.com/technetwork/java/javase/downloads/
wget http://download.oracle.com/otn-pub/java/jdk/XXXXXX/jdk-7u71-linux-x64.rpm
# Install Java
sudo rpm -i jdk-7u71-linux-x64.rpm
# Check if the default java version is set to Oracle jdk
java -version

# If not then lets create one more alternative for Java for Oracle JDK
sudo /usr/sbin/alternatives --install /usr/bin/java java /usr/java/jdk1.7.0_71/bin/java 20000
# Set the Oracle JDK as the default java
sudo /usr/sbin/alternatives --config java

# Verify if change in SDK was done.
java -version

Cassandra Setup

Download Cassandra from http://cassandra.apache.org/download/

  • Unzip/Untar the file apache-cassandra-2.1.0-bin.tar.gz
    • Copy the Cassandra folder apache-cassandra-2.1.0 to /usr/share
  • Edit the file /usr/share/apache-cassandra-2.1.0/conf/cassandra.yaml if necessary
  • Make sure /var/lib/cassandra has sufficient space

Start cassandra using the command:

/usr/share/apache-cassandra-2.1.o/bin/cassandra

Uploading GoDaddy SSL cert on AWS Load Balancer

So you have purchased an SSL certificate from GoDaddy and now you want to deploy it on the Amazon Load Balancer. This article assumes you generated the CSR before buying the certificate following the steps described here

In the AWS web console, go the “Load Balancers” section. Select your ELB and click on the “Listeners” tab. Now add a new listener for HTTPS.

Screen Shot 2014-09-25 at 9.02.41 AM

Click on the “Change” link the “SSL Certificate” column. You will see the following screen.

Screen Shot 2014-09-25 at 9.07.06 AM

Certificate Name: Enter the name you want to give this certificate.

Private Key: This private key is the one you generated when generating the CSR. If you followed the steps here, it is called server.key. This file will now have to be altered to create an Amazon supported private key. This can be done using openssl as follows.

openssl rsa -in server.key -out decrypted-server-key.pem

Now copy the contents of the file decrypted-server-key.pem and paste them into the “Private Key” section.

Public Key Certificate: This is the file that you got from GoDaddy, it you look something like “yourdomain.crt”. You now must get it into the Amazon supported form. This can be done using openssl as follows.

openssl x509 -inform PEM -in yourdomain.crt

Copy the entire output of the command above and past it into the “Public Key Certificate” section.

Thats it. Click on “Save” and you are done.

Add EBS volume to a Linux EC2 Instance

  1. Create an EBS volume using the AWS console (WEB UI)
  2. Using the AWS console, attach the EBS volume to running instance. The attached volume may get assigned to /dev/sdf (EC2’s external name for this particular device number).
  3. Format file system /dev/xvdf (Ubuntu’s internal name for this particular device number):
    sudo mkfs.ext4 /dev/xvdf
    
  4. Mount file system (with update to /etc/fstab so it stays mounted on reboot):
    sudo mkdir -m 000 /vol
    echo "/dev/xvdf /vol auto noatime 0 0" | sudo tee -a /etc/fstab
    sudo mount /vol
    

For more info: http://stackoverflow.com/questions/11535617/add-ebs-to-ubuntu-ec2-instance