Labels

Wednesday, May 2, 2018

Install Puppet

 Install Puppet

This blog is a guide on how to install Puppet Master and Puppet Agent (Slave) on a CentOS machine. We will also look at a Puppet example, in which I will deploy Apache Tomcat using Puppet. I am using two CentOS virtual images, one for Puppet Master and other for Puppet Agent.
Following are the steps to install Puppet:-
  1. Install Puppet Master and Puppet Agent
  2. Edit hosts and Puppet configuration files in Puppet Master and Agent
  3. Establish a Secure Connection between Puppet Master and Puppet Agent
  4. Deploy Apache Tomcat using Puppet
Before we install Puppet, Let us look at some prerequisites.

Prerequisites

I am using two virtual images, so you can select any one of them as Puppet Master and other can be termed as Puppet Agent.
First, we need to delete all firewall rules from Puppet Master and Puppet Agent. Iptables is the default firewall available in the most Linux distributions by default.
Execute this:
1
iptables -F
Now we need to save these configurations.
Execute this:
1
service iptables save
We need to enable the official Puppet Labs collection repository in both Puppet Master and Puppet Agent. To get this repository go to a link yum.puppetlabs.com.
Puppet Repository - Install Puppet - EdurekaHere, copy the link location of the repository according to the version of CentOS that you are using. I am using CentOS 6.
Now to get this repository, execute the below command in both the virtual images:
Execute this: 
1
rpm -ivh http://yum.puppetlabs.com/puppetlabs-release-el-6.noarch.rpm
Enable Puppet Repository - Install Puppet - Edureka
Puppet Slave Repository - Install Puppet - Edureka
We are done with the prerequisites, now before moving to Puppet installation, check out this Puppet installation video.


1. Install Puppet Master and Puppet Agent

1.1. Install Puppet Master

To install Puppet Master execute the below command:
Execute this (on master): 
1
yum install puppet-server
 Install Puppet Master - Install Puppet - Edureka

1.2. Install Puppet Agent

To Install Puppet Agent execute the below command:
Execute this (on agent): 
1
yum install puppet
Install Puppet Agent - Install Puppet - Edureka

2. Edit hosts and Puppet configuration files in Puppet Master and Agent

2.1. Edit hosts and Puppet configuration files in Puppet Master

First, in Puppet Master virtual image I will edit the hosts file using vi editor. You can use any other editor like vim, gedit etc. as well.
Execute this (on master):
1
vi /etc/hosts
Puppet Slave Hosts File - Install Puppet - Edureka
Just type the IP address of your machine and give a domain name to it. In the above screenshot you can see that 192.168.1.182 is the IP address of my machine and I have assigned it a domain name puppet puppet.edureka.co.
In order to know the IP address of your machine use the below command:
Execute this (on master):
1
ifconfig

IP Address Of The Machine - Install Puppet - Edureka
Now we will edit the Puppet configuration file, I will use vi editor.
Execute this (on master): 
1
vi /etc/puppet/puppet.conf
Puppet Configuration File Puppet Master - Install Puppet - Edureka
Here in the Master section give the DNS name to which the server will respond to (type the domain name that you have given to your Puppet Master). DNS is an important element to ensure that nodes communicate using friendly names instead of IP addresses.
dns_alt_names = puppet,puppet.edureka.co
We need to give the certificate name as well
certname=puppet

2.2.Edit hosts and Puppet configuration files in Puppet Agent

Similar to Puppet Master here in the Puppet Agent virtual image we will first edit the hosts file by using vi editor.
Execute this (on agent): 
1
vi /etc/hosts
Puppet Agent Hosts File - Install Puppet - Edureka
Now type the IP address of your Puppet Agent and give a domain name to it, I have given ‘puppetagent’. You also need to give the IP address of your Puppet Master and the domain name attached to it.
192.168.1.119 puppetagent
192.168.1.182 puppet puppet.edureka.co
Let us now edit the Puppet configuration file.
Execute this (on agent):
1
vi /etc/puppet/puppet.conf
 Puppet Configuration File Puppet Agent - Install Puppetr - Edureka
Now in the agent section assign the server name.
Type the domain name of your Puppet Master. This is a very important step because once you give the domain name it will go to the hosts file and check the IP address attached to that domain name. Make sure you have typed the correct domain name.
server = puppet.edureka.co

3. Establish A Secure Connection Between Puppet Master and Puppet Agent

Puppet Agent requests Puppet Master for its certificate. Once Puppet Master sends its certificate Puppet Agent generates its own certificate. It then requests the Puppet Master to sign this certificate. Once Master has signed this certificate there is a secure connection established between Puppet Master and Puppet Agent.

3.1. Generate Puppet Master Certificate

In Puppet Master virtual image, in order to generate CA certificate and Puppet Master certificate in Puppet Master machine execute the below command:
Execute this (on master): 
1
sudo -u puppet puppet master --no-daemonize --verbose
This command will create the CA certificate and a Puppet Master certificate, with the appropriate DNS names included. Stop It once the version of Puppet is displayed by using ctrl+c because we cannot start the Puppet Master right now.
Puppet Master Certificate - Install Puppet - Edureka
Now I will start Puppet Master.
Execute this (on master): 
1
puppet resource service puppetmaster ensure=running
Start Puppet - Install Puppet - Edureka

3.2. Send Certificate signing request from Puppet Agent to Puppet Master

Here in Puppet Agent virtual image, I need to send the certificate signing request to Puppet Master.
Execute this (on agent): 
1
puppet agent -t
Certificate Signing Request - Install Puppet - Edureka

3.3. Sign Puppet Agent Certificate in Puppet Master

In Puppet Master virtual image, we need to sign the certificate requested by Puppet Agent. In order to get the list of certificates execute the below command:
Execute this (on master): 
1
puppet cert list
Puppet certificates - Install Puppet - Edureka
As you can see that there is a certificate signing request pending by the name puppetagent. In order to sign that certificate execute the below command:
Execute this (on master): 
1
puppet cert sign puppetagent
Sign Puppet Agent Certificate - Install Puppet - Edureka
Here the certificate signing request was sent by Puppet Agent so I have signed that particular certificate, refer the screenshot above.

3.4. Update Puppet Agent

First, we need to start the Puppet Agent.
Execute this (on agent): 
1
puppet resource service puppet ensure=running
Start Puppet Agent - Install Puppet - Edureka
Now we need to update the Puppet Agent with the changes made in the Puppet Master. Since the Master has recently signed the certificate so it will update that.
Execute this (on agent): 
1
puppet agent -t
Puppet Agent Update - Install Puppet - Edureka
Congratulations! Now there is a secure connection between Puppet Master and Puppet Agent. Let us now see a Puppet example, in which I will deploy Apache Tomcat using Puppet.

4. Deploy Apache Tomcat using Puppet

4.1. Define Configuration In Puppet Master

In Puppet Master virtual image, before installing Tomcat 9, I need to install Java 8 because Tomcat 9 is only compatible with Java 8 or versions of Java released after Java 8.

4.1.1. Install Java and Tomcat Module

To install Java I need to install Java module, this module automatically installs Java JDK and simplifies the installation of Java using Puppet.
Execute this (on master): 
1
puppet module install puppetlabs-java
This command will install the latest compatible version of Java module.
Java Module - Install Puppet - Edureka
Now, we will install the Tomcat module. It allows you to use Puppet to install Tomcat, manage its configuration files and deploy web apps to it.
To install latest compatible version of Tomcat Module:
Execute this (on master): 
1
puppet module install puppetlabs-tomcat
Tomcat Module - Install Puppet - Edureka

4.1.2. Edit site.pp File in Puppet Manifests

Edit site.pp file in Puppet Manifests using your favorite editor, I will use vi editor, to know more about Manifests refer my Puppet Tutorial blog.
Execute this (on master): 
1
vi /etc/puppet/manifests/site.pp
Here include the following:
1
2
3
4
5
6
7
8
9
10
class {  ‘java’ :
 package => ‘java-1.8.0-openjdk-devel’:
 }
 tomcat::install { ‘/opt/tomcat’:
 }
 tomcat::instance { ‘default’:
 catalana_home => ‘/opt/tomcat’,
 }
This is how site.pp file should look like:
Site.pp File For Tomcat - Install Puppet - Edureka
Save the file and quit from vi editor.

4.2. Update Puppet Agent

Puppet Agent pulls its configuration from the Master periodically (after every 30 minutes). It will evaluate the main manifest and apply the module that specifies Tomcat setup. If you want to try it out immediately, you need to run the following command on every Agent node:
Execute this (on agent): 
1
puppet agent -t
Updated Puppet Manifests - Install Puppet - Edureka
Let us see if Apache Tomcat is working in Puppet Agent. To confirm that open localhost:8080 in your browser on Puppet Agent virtual image (port 8080 is the default port for Apache Tomcat).
Apache Tomcat - Install Puppet - Edureka
We have successfully installed Apache Tomcat using Puppet. Similarly, large infrastructure with hundreds of Agents can be automatically managed using Puppet and plays a vital role in achieving DevOps.
Learn DevOps Now

4 comments:

  1. I‘d mention that most of us visitors are endowed to exist in a fabulous place with very many wonderful individuals with very helpful things.



    apple service center chennai | ipod service center in chennai | apple iphone service center in chennai | apple service center chennai

    ReplyDelete
  2. Such a nice blog, I really like what you write in this blog, I also have some relevant Information about Best HR Training In Hyderabad | Hr training institute in Hyderabad! if you want more information.
    Excellent blog I visit this blog it's really awesome. The important thing is that in this blog content written clearly and understandable. The content of information is very informative.
    oracle fusion financials classroom training
    Workday HCM Online Training
    Oracle Fusion Financials Online Training
    Oracle Fusion HCM Online Training
    Oracle Fusion SCM Online Training
    Oracle Fusion HCM Classroom Training

    ReplyDelete
  3. Appreciating the persistence you put into your blog and detailed information you provide.
    Data science training in chennai |Data science course in chennai

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete