Setting up a Centos server

Following this post, we will set up a Centos server from scratch, with some basic features:

  • Updating ┬áthe server
  • Creating a user (other that root)
  • Installing Nginx web server, serving HTTP requests
  • Automation!

Let’s connect to out server (you can skip this step if you are working locally). In this tutorial we will be working with a Centos server from Amazon Web Services (How to get a Server from AWS?)

$ ssh -i devops-notes-keypair.pem ec2-user@ec2-35-160-173-17.us-west-2.compute.amazonaws.com
Last login: Sun Oct 30 09:41:07 2016 from ...

 __| __|_ )
 _| ( / Amazon Linux AMI
 ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2016.09-release-notes/
3 package(s) needed for security, out of 10 available
Run "sudo yum update" to apply all updates.
$ sudo yum update -y

Users

Let’s create a working user (protecting us from ourselves) and give it sudo privileges. For our demonstration, we will name the user anikan.

$ sudo adduser anikan
$ sudo bash -c 'echo "%anikan ALL = (ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo)'

Nginx

Let’s install Nginx web server, and verify it is up and running:

$ sudo yum install nginx -y
$ sudo service nginx start
$ # a way to see nginx is up:
$ ps -ef | grep nginx # run a few times to see the pid doesn't change

$ # we will see a better way later

To see our Nginx server response in the browser, we need to play with our instance’s Security Group – select the instance in the AWS dashboard, and in the Description tab, click the security group, and edit it: open inbound connection type of HTTP, port 80.

Then, grab the public DNS (the same one used to ssh), and paste it in the browser. This is what you are expected to see:

ngnix_welcome

If you see the above – then that’s it! you have a Linux server, running Nginx as a server.

Automation! Let’s have it all in one script:

#!/bin/bash

sudo yum update -y

sudo adduser anikan
sudo bash -c 'echo "%anikan ALL = (ALL) NOPASSWD: ALL" | (EDITOR="tee -a" visudo)'

sudo yum install nginx -y
sudo service nginx start

if [ `curl -sL -w "%{http_code}\\n" "http://localhost/" -o /dev/null` -ne 200 ]; then 
 echo "ERROR: nginx not up" 
else 
 echo "nginx is up"
fi

[link-to-git]

Advertisements
This entry was posted in Centos and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s