Friday, 16 August 2013

Amazon EC2 (Amazon Elastic Compute Cloud)



To see AWS free tier

750 hours Linux/UNIX or RHEL EC2 Micro Instance is free

To check AWS EC2 pricing

Creating New Instances
Login to AWS management console
We can create instances from
EC2 Dashboard > instances

Launch Instance > Create new instances

Choose an AMI (Amazon Machine Image ) for instance


Select the  Instance Type: (T1 micro)
Create the key pair. These key pair are required to login to the EC2 instance

Continue the next steps and create the instance.
  

Need to add rules in Security Groups. There will be a default security group in AWS or there is option to add new security group

We need to add the inbound rules to enable access to the different ports.
ie – the port numbers 21,22, 80,3306 etc.

By default there will no static IP configured in EC2. The server will be only accessible using the public DNS name
for eg :  ec2-23-20-98-110.compute-1.amazonaws.com

IF we want to configure a static IP there is option to add ELASTIC IP in AWS.  This is required at the time of pointing the domain name to EC2 server.



Login to the server

We require the key pair to login to EC2. Download the key pair to your local computer and authenticate with the key.

The default user of EC2 instance will be “ec2-user
login method
# ssh -i /home/domain.pem  ec2-24-25-97-150.compute-1.amazonaws.com
(domain.pem   is key pair name)


Reset the root password using sudo
# sudo passwd root
Enter new password.

By default there will be no software installed in the server. We need to install the softwares manually.  Ie we need to install Apache, PHP, MySQL, FTP manually.

We have an option to use Amazon RDS(Amazon Relational Database Service) for databases
http://aws.amazon.com/rds/

# su -
enter the password to switch to root user and install the required software.
 

 

Sunday, 14 July 2013

PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in Unknown on line 0


When you try to find some configuration values used while compiling php or checking the php.ini location, you might get the following error.

php -i | grep config

PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in Unknown on line 0
Configure Command => './configure' '--prefix=/usr/local/php53' '--with-layout=GNU' '--enable-libxml' '--with-libxml-dir=/usr/local' '--with-apxs=/usr/local/sbin/apxs' '--with-regex=php' '--with-zend-vm=CALL' '--disable-ipv6' '--mandir=/usr/local/man' '--infodir=/usr/local/info/' '--build=i386-portbld-freebsd7.2' '--with-curl' '--enable-ftp' '--with-gd' '--enable-mbstring' '--with-mcrypt' '--with-mysql' '--with-mysqli' '--with-openssl' '--enable-pcntl' '--with-pcre-regex' '--enable-soap' '--with-zlib' '--enable-cgi' '--enable-ctype' '--enable-dom' '--enable-xml' '--enable-simplexml'
PHP Warning: Unknown: It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'America/New_York' for 'EDT/-4.0/DST' instead in Unknown on line 0

To fix this error, add date.timezone in php.ini

php -i | grep php.ini # to find the location of php.ini

Then, 

echo 'date.timezone = "America/New_York"' >> /path/to/php.ini

Friday, 5 July 2013

Setup Local YUM Server in Centos

Yellowdog updater, Modified (Yum) is a software package manager that installs, updates and removes packages on RPM-based Linux distributions. Yum uses an online repository by default, but you can also configure it to use a local repository of packages.
Mount the contents of your CentOS 6.3 DVD in the /mnt directory or wherever you want. In the Terminal window, type the following command:

[root@ns2 Packages]# mount /dev/cdrom /mnt/
mount: block device /dev/sr0 is write-protected, mounting read-only

Install vsftpd package, so that we can use this as a FTP server to share our repository in the client systems.
Change to the directory where you mounted CentOS DVD. In our example we have mounted the CentOS DVD in /mnt directory.

    # cd /mnt/Packages
    # rpm -ivh vsftpd-2.2.2-11.el6.i686.rpm

Start the FTP Service:

    # service vsftpd start

Install createrepo package if it is not installed. This is package is used to create our local repository.

[root@ns2 Packages]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm
error: Failed dependencies:
    deltarpm is needed by createrepo-0.9.8-4.el6.noarch
    python-deltarpm is needed by createrepo-0.9.8-4.el6.noarch

It shows us the dependency problem. Let us the install missing dependencies first:

[root@ns2 Packages]# rpm -ivh deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:deltarpm               ########################################### [100%]
[root@ns2 Packages]# rpm -ivh python-deltarpm-3.5-0.5.20090913git.el6.x86_64.rpm
Preparing...                ########################################### [100%]
   1:python-deltarpm        ########################################### [100%]

Now install the createrepo package:
[root@ns2 Packages]# rpm -ivh createrepo-0.9.8-4.el6.noarch.rpm
Preparing...                ########################################### [100%]
   1:createrepo             ########################################### [100%]


Create a folder called localyumserver (You can use your own) in /var/ftp/pub directory to save all the packages from the CentOS DVD. Copy all the files in the Packages folder from the DVD to /var/ftp/pub/localyumserver folder:

[root@ns2 Packages]# mkdir /var/ftp/pub/localyumserver
[root@ns2 Packages]# cp -ar *.* /var/ftp/pub/localyumserver/

After all packages are copied, create a repo file called localyumserver.repo in /etc/yum.repos.d/ directory.

[root@ns2 Packages]# vi /etc/yum.repos.d/localyumserver.repo

and Type the following entries and save the file

[localyumserver]
name="local yum repository"
baseurl=file:///var/ftp/pub/localyumserver
gpgcheck=0
enabled=1

Where,
[localyumserver] ==> Name of the Local Repository.
comment ==> Information about the Repository.
baseurl ==> Path of the Repository (i.e where we had copied the contents from CentOS DVD)
gpgcheck ==> Authentication of the Repository, which is disabled in our case.

Now it is time to create our repository. Enter the following command in the Terminal:

[root@ns2 Packages]# createrepo -v /var/ftp/pub/localyumserver

Delete or rename all the other repo files except the newly created repo file i.e in our example it is localyumserver.repo.

Next update the repository:

        * yum clean all
        * yum update

Client side configuration:

Create a repo file in your client system as mentioned above in the /etc/yum.repos.d/ directory and remove or rename the existing repositories. Then modify the baseurl as mentioned below:

[localyumserver]
name="local yum repository"
baseurl=ftp://<IP>/pub/localyumserver
gpgcheck=0
enabled=1

Monday, 24 June 2013

Dovecot Installation

# yum install dovecot

Then edit the dovecot configuration file nd uncommet the line,  protocols = imap pop3 lmtp

# vi /etc/dovecot/dovecot.conf
protocols = imap pop3 lmtp



Then Open the file /etc/dovecot/conf.d/10-mail.conf and uncomment the line

# vi /etc/dovecot/conf.d/10-mail.conf
mail_location = maildir:~/Maildir



Open the /etc/dovecot/conf.d/10-auth.conf and edit

# vi /etc/dovecot/conf.d/10-auth.conf
disable_plaintext_auth = no  ## uncomment and change from yes to no.
auth_mechanisms = plain login


Then,
Open the /etc/dovecot/conf.d/10-master.conf and edit

# vi /etc/dovecot/conf.d/10-master.conf
unix_listener auth-userdb {
    #mode = 0600
    user = postfix  ## uncomment and enter postfix
    group = postfix  ## uncomment and enter postfix


Then,  start the dovecot service.

# service dovecot start
Starting Dovecot Imap:                                     [  OK  ]

# chkconfig dovecot on


Testing dovecot:

[root@ns2 postfix]# telnet localhost pop3
Trying ::1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user user1
+OK
pass user1
+OK Logged in.
list
+OK 1 messages:
1 424
.
retr 1
+OK 424 octets
Return-Path: <user1@ranjithkr.com>
X-Original-To: user1
Delivered-To: user1@ranjithkr.com
Received: from localhost (localhost [IPv6:::1])
    by ns2.ranjithkr.com (Postfix) with ESMTP id D01B1101E0D
    for <user1>; Sat, 22 Jun 2013 06:17:01 +0530 (IST)
Message-Id: <20130622004822.D01B1101E0D@ns2.ranjithkr.com>
Date: Sat, 22 Jun 2013 06:17:01 +0530 (IST)
From: user1@ranjithkr.com
To: undisclosed-recipients:;

test
.
quit
+OK Logging out.
Connection closed by foreign host.
[root@ns2 postfix]#

Installing Mail Server Using Postfix in Centos

Before proceeding with the postfix installation, please make sure,

    * The mail server should contain a valid MX record in the DNS server. Navigate to this link how to setup DNS server.
    * Firewall and SELinux should be disabled.

    #service iptables stop
    #vi /etc/selinux/config
    and set SELINUX=disabled


Then install postfix via, yum

# yum install postfix

And update your postfix configuration file, /etc/postfix/main.cf

# vi /etc/postfix/main.cf

and change the below values.

myhostname = ns2.example.com ## uncomment and enter your host name
mydomain = example.com  ## uncomment and enter your domain name
myorigin = $mydomain  ## uncomment
inet_interfaces = all  ## change to all
mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain  ## add $domain at the end
mynetworks = 192.168.1.0/24, 127.0.0.0/8  ## uncomment and add your network range
home_mailbox = Maildir/  ## uncomment



Now start the postfix service by,

# service postfix start


and enable postfix auto start at startup by,

# chkconfig postfix on


now the Postfix installation is over. We can test whether it is working fine by sending a test mail.

For that first create a test user called user1.

# useradd user1
# passwd user1


And the incoming mails to this user will be stored in the location /home/user1/Maildir/new

For testing we can use the telnet command, if it is not installed please install telnet via yum,

# yum install telnet

Then enter,

# telnet localhost smtp
Trying ::1...
Connected to localhost.
Escape character is '^]'.
220 ns2.ranjithkr.com ESMTP Postfix

Now please enter,

ehlo localhost

250-ns2.ranjithkr.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN

Now enter the below command,

mail from:<user1>
250 2.1.0 Ok

then,

rcpt to:<user1>
250 2.1.5 Ok

and,

data
354 End data with <CR><LF>.<CR><LF>

finally enter the mail body contents,

test
.
250 2.0.0 Ok: queued as D01B1101E0D

and hit quit,

quit
221 2.0.0 Bye
Connection closed by foreign host.


Now check the user1 maildir location and you will be able to see the new mail.


[root@ns2 postfix]# cd /home/user1/Maildir/
[root@ns2 Maildir]# ll
total 12
drwx------. 2 user1 user1 4096 Jun 22 06:18 cur
drwx------. 2 user1 user1 4096 Jun 22 06:18 new
drwx------. 2 user1 user1 4096 Jun 22 06:18 tmp
[root@ns2 Maildir]# cd new/
[root@ns2 new]# ll
total 4
-rw-------. 1 user1 user1 412 Jun 22 06:18 1371862122.Vfd00I3795M419578.ns2.ranjithkr.com
[root@ns2 new]# cat 1371862122.Vfd00I3795M419578.ns2.ranjithkr.com
Return-Path: <user1@ranjithkr.com>
X-Original-To: user1
Delivered-To: user1@ranjithkr.com
Received: from localhost (localhost [IPv6:::1])
    by ns2.ranjithkr.com (Postfix) with ESMTP id D01B1101E0D
    for <user1>; Sat, 22 Jun 2013 06:17:01 +0530 (IST)
Message-Id: <20130622004822.D01B1101E0D@ns2.ranjithkr.com>
Date: Sat, 22 Jun 2013 06:17:01 +0530 (IST)
From: user1@ranjithkr.com
To: undisclosed-recipients:;

test
[root@ns2 new]#

So postfix works fine now.

Sunday, 23 June 2013

DNS Installation and configuration in Centos

The DNS resolves hostname into ip address and vice versa. For example if we type http://www.google.com in browser, the DNS server translates the domain name into its corresponding ip address. So it makes us easy to remember the domain names instead of its ip address.

Setup primary Master DNS Server

Step 1:

yum install bind* -y

Step 2:

Configure DNS Server

The main configuration of the DNS will look like below.

[root@ns1 ~]# vi /etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
      listen-on port 53 { 127.0.0.1; 192.168.198.140;};                      ## Master DNS IP ##
      listen-on-v6 port 53 { ::1; };
      directory   "/var/named";
      dump-file   "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
      allow-query     { any; 192.168.198.0/24; };                      ## IP Range ##
      allow-transfer    { localhost; 192.168.198.141; };                        ## Slave DNS IP ## 
      recursion yes;
      dnssec-enable yes;
      dnssec-validation yes;
      dnssec-lookaside auto;
      /* Path to ISC DLV key */
      bindkeys-file "/etc/named.iscdlv.key";
      managed-keys-directory "/var/named/dynamic";
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
zone "." IN {
      type hint;
      file "named.ca";
};
zone  "example.com" IN {
      type master;
      file "fwd.example.com";
      allow-update { none; };
};
zone  "198.168.192.in-addr.arpa" IN {
      type master;
      file "rev.example.com";
      allow-update { none; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";


Step 3:

Create Zone files

Now we should create forward and reverse zone files which we mentioned in the ‘/etc/named.conf’ file.

Create Forward Zone:

[root@masterdns ~]# vi /var/named/fwd.example.com
$TTL 86400
@   IN  SOA     ns1.example.com. root.example.com. (
        2011071001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)
@     IN  NS      ns1.example.com.
@     IN  NS          ns2.example.com.
           
ns1     IN  A       192.168.198.140
ns2   IN  A     192.168.198.141

Create Reverse Zone:

[root@masterdns ~]# vi /var/named/rev.example.com
$TTL 86400
@   IN  SOA     ns1.example.com. root.example.com. (
        2011071001  ;Serial
        3600        ;Refresh
        1800        ;Retry
        604800      ;Expire
        86400       ;Minimum TTL
)
@     IN  NS      ns1.example.com.
@     IN  NS      ns2.example.com.
ns1   IN  A           192.168.198.140
ns2   IN  A           192.168.198.141
200     IN  PTR     ns1.example.com.
201   IN  PTR         ns2.example.com.


Step 4:

Start the bind service

[root@ns1 ~]# service named start
Generating /etc/rndc.key:                                  [  OK  ]
Starting named:                                            [  OK  ]
[root@ns1 ~]# chkconfig named on

Step 5:

Allow DNS Server through iptables

Add the lines shown below in ‘/etc/sysconfig/iptables’ file. This will allow all clients to access the DNS server.

-A INPUT -p udp -m state --state NEW --dport 53 -j ACCEPT
-A INPUT -p tcp -m state --state NEW --dport 53 -j ACCEPT

Then,

Restart iptables to save the changes

[root@ns1 ~]# service iptables restart




Test syntax errors of DNS configuration and zone files:

Checking DNS Config file

[root@ns1 ~]# named-checkconf /etc/named.conf
[root@ns2 ~]# named-checkconf /etc/named.rfc1912.zones

Checking zone files

[root@ns1 ~]# named-checkzone example.com /var/named/fwd.example.com
[root@ns2 ~]# named-checkzone example.com /var/named/rev.example.com


Test DNS Server

[root@ns1 ~]# dig ns1.example.com

[root@ns2 ~]# dig -x 192.168.198.140





Setup Secondary(Slave) DNS Server

Step 1:

[root@ns2 ~]# yum install bind* -y

Step 2:

Configure Slave DNS Server

[root@ns2 ~]# vi /etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
      listen-on port 53 { 127.0.0.1; 192.168.198.141; };                    ## NS2 DNS IP ##     
      listen-on-v6 port 53 { ::1; };
      directory   "/var/named";
      dump-file   "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
      allow-query     { localhost; 192.168.198.0/24; };                     ## IP Range ##  
      recursion yes;
      dnssec-enable yes;
      dnssec-validation yes;
      dnssec-lookaside auto;
      /* Path to ISC DLV key */
      bindkeys-file "/etc/named.iscdlv.key";
      managed-keys-directory "/var/named/dynamic";
};
logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};
zone "." IN {
      type hint;
      file "named.ca";
};
zone  "example.com" IN {
      type slave;
      file "slaves/example.fwd";
      masters { 192.168.1.140; };
};
zone  "198.168.192.in-addr.arpa" IN {
      type slave;
      file "slaves/example.rev";
      masters { 192.168.1.140; };
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";

Step 3:

Start the DNS Service

[root@ns2 ~]# service named start
Generating /etc/rndc.key:                                  [  OK  ]
Starting named:                                            [  OK  ]
[root@ns2 ~]# chkconfig named on


Now the forward and reverse zones are automatically replicated from Master DNS server to Slave DNS server.
The forward and reverse zones are automatically replicated from Master DNS. Now check the zone files whether the correct zone files are replicated or not.


Step 4:

Add the DNS Server details to all systems

[root@slavedns ~]# vi /etc/resolv.conf
# Generated by NetworkManager
search example.com
nameserver 192.168.198.140
nameserver 192.168.198.141
nameserver 8.8.8.8

Step 5:


Test DNS Server

[root@ns2 ~]# dig ns2.example.com
[root@ns2 ~]# dig ns1.example.com