Monday, January 27, 2014

Puppet Agent to be seen by PM



Now We will configure our puppet agent to fetch configuration(although we do not have any configuration to be applied as of now) from our puppet master server(slashroot1). We have already started puppet master on the machine slashroot1. Our master server is listening connections on the port 8140.
the first step i will suggest doing is to edit the /etc/hosts file of your puppet agent server(slashroot2 in our case), and add puppet master server's ip and hostname(if you have your DNS entry configured for the master server then its well and fine.).
I believe that you have already installed the packages puppet & facter on your agent server as shown in the post "installing puppet agent and master".
Now lets connect our puppet agent to puppet master server for the first time. And see what happens.
?
1
2
3
4
5
6
7
8
9
10
11
12
13
[root@slashroot2 ~]# puppet agent --server slashroot1.slashroot.in --no-daemonize --verbose
info: Creating a new SSL key for slashroot2.slashroot.in
warning: peer certificate won't be verified in this SSL session
info: Caching certificate for ca
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
info: Creating a new SSL certificate request for slashroot2.slashroot.in
info: Certificate Request fingerprint (md5): 59:7A:AE:2C:7B:15:DA:E5:A8:14:7D:FF:1F:5B:7A:66
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
warning: peer certificate won't be verified in this SSL session
notice: Did not receive certificate
As shown in the above example you can see that, an SSL key is made for this agent machine and is waiting for the corresponding certificate to be signed by the puppet master server.
An Important fact to note here is a notice shown in the above command result, which says that "notice: Did not receive certificate".
--server in the above command specifies the puppet master server hostname
--no-daemonize tells the puppet agent to not to run as a daemon, and also output the messages to the screen. If you run puppet agent without this option, then you will not get the messages on the screen.
Note: If you do not specify the option --server, puppet agent will look for a host named "puppet". This is the main reason of keeping the puppet master hostname as puppet.
The ssl certificate signing is done only the first time an agent connects to the server.
The notice message(notice: Did not receive certificate)will keep on coming on the screen until the certificate request is signed by the puppet master.

 

How to Sign the SSL certificate from puppet Master?

Now as the client node (slashroot2) is waiting for its certificate to be signed, lets go and sign the certificate request from slashroot1(our puppet master server)
On your puppet master run the below command to show the certificate signing requests.
[root@slashroot1 ~]# puppetca --list
  slashroot2.slashroot.in (59:7A:AE:2C:7B:15:DA:E5:A8:14:7D:FF:1F:5B:7A:66)
[root@slashroot1 ~]#

#puppetca --list command will show you the agent certificate requests that are waiting to be signed.
#puppet cert list command will also show you the same thing
Now lets sign the certificate by the following method.
[root@slashroot1 ~]# puppetca --sign slashroot2.slashroot.in
notice: Signed certificate request for slashroot2.slashroot.in
notice: Removing file Puppet::SSL::CertificateRequest slashroot2.slashroot.in at '/var/lib/puppet/ssl/ca/requests/slashroot2.slashroot.in.pem'


Now from the above output you can clearly see that the puppet master server signed the certificate and also removed the old certificate signing request.
Now as soon as the certificate gets signed from the master server you will get the below message on the puppet agent's screen(because we ran puppet agent command with --no-daemonize option on our agent).

notice: Did not receive certificate
warning: peer certificate won't be verified in this SSL session
notice: Did not receive certificate
warning: peer certificate won't be verified in this SSL session
info: Caching certificate for slashroot2.slashroot.in
notice: Starting Puppet client version 2.7.9
info: Caching certificate_revocation_list for ca
info: Caching catalog for slashroot2.slashroot.in
info: Applying configuration version '1355395673'
info: Creating state file /var/lib/puppet/state/state.yaml
notice: Finished catalog run in 0.14 seconds


Now what does that message mean?
 
It means that our puppet agent got a signed certificate and the certificate is cached. Also the agents tells us that its applying a configuration version number "1355395673" based on the catalog given by the master server.

From now onwards we can restart and stop our puppet agent whenever required.
 
Note: Keep all the client nodes and the puppet server synchronized with one single ntp source. Because ssl connection rely heavily on time being synchronized.

We ran the command #puppet agent --server slashroot1.slashroot.in --no-daemonize --verbose, just for showing the output on the screen as example.In normal cases you can add the puppet server address in the puppet.conf file of your agent machine.
 
So on our agent we will add server address in the [main] section as shown below.

server=slashroot1.slashroot.in

After adding this server option in puppet.conf file simply restarting puppet agent will start it as a daemon. Which will periodically fetch data from the master server.
 
You can start/restart your puppet agent using the below commands.
 
/etc/init.d/puppet start
 
or
 
puppet agent

puppet master

Puppet.conf is the main configuration file of puppet. On most of the distribution this file is located under, /etc/puppet/ directory. Most of the times this file (/etc/puppet/puppet.conf) is automatically created during the installation. But if it is not there, you can easily create it by the following command.
[root@slashroot1 ~]# puppetmasterd --genconfig > /etc/puppet/puppet.conf
Puppet.conf file is easier to understand, and is very much self explanatory. Its divided into different sections as the following.

[agent] -- this section is for mentioning agent specific parameters.
[master] -- this section is for specifying options for puppet master.
[main] -- this section will contain all global configuration options.

Main section will contain options like the log directory,pid directory etc.(don't worry we will go ahead and configure all those, be patientsmiley)
The first step is to configure the /etc/hosts file and DNS entries with the ip of puppet master and its FQDN(Fully Qualified Domain Name).
Am keeping my puppet master name as puppet.slashroot.in. So my host entries will be something like the below.
[root@slashroot1 ~]# cat /etc/hosts
# Do not remove the following line, or various programs
# that require network functionality will fail.
127.0.0.1               slashroot1.slashroot.in slashroot1 localhost.localdomain localhost
::1             localhost6.localdomain6 localhost6
192.168.0.102 slashroot1.slashroot.in puppet puppet.slashroot.in

Also don't forget to add the same DNS entry in DNS server for your infra.
Now lets configure the [master] section of our puppet.conf file.
We will only be adding certname parameter in [master] section as of now. If you don't have the master section in your puppet.conf file then create it. My master section looks like the below.
[master]
certname=puppet.slashroot.in
Now lets configure an important file in puppet master configuration. Its the site.pp file. This is the file which tells what are the configurations that needs to be applied to the clients(agents).
We will be placing this site.pp file in /etc/puppet/manifests/ directory. Just create a file called site.pp there with no content. We will be adding configuration content inside this file later.

 

What are manifests in puppet?

manifest is nothing but a name that puppet calls those files which contain the configuration options for the clients.
An important fact to note is that all manifest files will also have a .pp extension just the same as site.pp file
You can alter the location of manifests and site.pp file with the help of manifestdir and manifest options in puppet.conf file.
As i have mentioned in my post How does Puppet Work Puppet does all its communication through SSL. And the default directory for SSL certificates is /var/lib/puppet.
[root@slashroot1 ~]# ls /var/lib/puppet/
bucket        client_data  facts  reports  server_data  state
clientbucket  client_yaml  lib    rrd      ssl          yaml

Now lets start puppetmaster, which will start master server listening on the port 8140. Starting puppet master server will also create a self signed certificate for the master server which can be found at /var/lib/puppet/ssl/ca/signed/
[root@slashroot1 signed]# /etc/init.d/puppetmaster start
Starting puppetmaster:
[root@slashroot1 signed]# ls /var/lib/puppet/ssl/ca/signed/
puppet.slashroot.in.pem
[root@slashroot1 signed]# lsof -i :8140
COMMAND    PID   USER   FD   TYPE DEVICE SIZE NODE NAME
puppetmas 3552 puppet    7u  IPv4   9583       TCP *:8140 (LISTEN)
[root@slashroot1 signed]#

As shown in the above example we have started puppet master, which inturn created a signed certificate for our puppet master, (note the fact that the certificate name is exactly the same as the certname in puppet.conf file).

 

What methods can be used to start puppet master server?

Puppet master can be started by the below methods.
#/etc/init.d/puppetmasterd start
OR
#puppetmasterd
OR
#puppet  master
For troubleshooting purposes you can run puppet master as the following.
#puppet master --verbose --no-daemonize

Thursday, January 23, 2014

Install puppet agent

https://github.com/moviepilot/puppet/blob/master/tools/install-puppet-agent.sh

#!/bin/bash
if [ "$(id -u)" != "0" ]; then
echo "This script must be run as root" 1>&2
   exit 1
fi
# refresh package list
apt-get update
# bootstrap ruby env
apt-get -y install irb libopenssl-ruby libreadline-ruby rdoc ri ruby ruby-dev git-core augeas-lenses augeas-tools libaugeas-ruby
# get a working gem version and update it to the most recent one
cd /usr/local/src
wget http://production.cf.rubygems.org/rubygems/rubygems-1.5.2.tgz
tar -xzf rubygems-1.5.2.tgz
cd rubygems-1.5.2
ruby setup.rb
update-alternatives --install /usr/bin/gem gem /usr/bin/gem1.8 1
gem update --system
# install puppet itself
gem install puppet -v 2.6.8 --no-ri --no-rdoc

aws auto-scale


Eric Lucas




Once Pre-Requisites are in place - this is the command.
54.243.63.144




Part 1
as-create-launch-config jvcauto --image-id ami-e447c38d --instance-type m1.medium -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --region us-east-1 --group jukin-security-1




Results
root@matrix:/# as-create-launch-config jvcauto --image-id ami-e447c38d --instance-type m1.medium -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --region us-east-1 --group jukin-security-1
OK-Created launch config




Part 2
root@matrix:/# as-create-auto-scaling-group jukinscale --launch-configuration jvcauto -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --availability-zones us-east-1b --min-size 2 --max-size 10 --load-balancers MainLoadJV --health-check-type ELB --grace-period 300
OK-Created AutoScalingGroup




Part 2-A Modify
Create new launch-configuration
as-create-launch-config jvcm1 --image-id ami-e447c38d --instance-type m1.medium -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --region us-east-1 --group jukin-security-1




Update-scaleing group
root@matrix:/home/macross# as-update-auto-scaling-group jukinscale --launch-configuration jvm1 -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y
OK-Updated AutoScalingGroup






2B modify max size
as-update-auto-scaling-group jukinscale --launch-configuration jvm1 -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --availability-zones us-east-1b --min-size 0 --max-size 3




Part 3
root@matrix:/# as-put-scaling-policy --auto-scaling-group jukinscale -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --name scale-up --adjustment 1 --type ChangeInCapacity --cooldown 300
arn:aws:autoscaling:us-east-1:838069323424:scalingPolicy:4186cee9-06cd-4bf0-968a-e99359e86f58:autoScalingGroupName/jukinscale:policyName/scale-up




Part 4
root@matrix:/# as-put-scaling-policy --auto-scaling-group jukinscale -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --name scale-dn "--adjustment=-1" --type ChangeInCapacity --cooldown 300
arn:aws:autoscaling:us-east-1:838069323424:scalingPolicy:53389773-a8f6-4c54-850d-7b797a9e8529:autoScalingGroupName/jukinscale:policyName/scale-dn




Part 5
mon-put-metric-alarm --alarm-name auto-scale-up -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --alarm-description "Scale up at 80% load" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average  --period 60 --threshold 80 --comparison-operator GreaterThanThreshold --dimensions InstanceId=i-52a36c2d --evaluation-periods 3  --unit Percent --alarm-actions arn:aws:autoscaling:us-east-1:838069323424:scalingPolicy:4186cee9-06cd-4bf0-968a-e99359e86f58:autoScalingGroupName/jukinscale:policyName/scale-up
OK-Created Alarm




mon-put-metric-alarm --alarm-name auto-scale-dn -I AKIAJEJVKDX6WSEOAZRQ -S mVKWOxwnKDmH5j0QOrYW8YkAAh1Y13eb63+s7v7Y --alarm-description "Scale down at 20% load" --metric-name CPUUtilization --namespace AWS/EC2 --statistic Average --period 60 --threshold 20 --comparison-operator LessThanThreshold --dimensions InstanceId=i-52a36c2d --evaluation-periods 3 --unit Percent --alarm-actions arn:aws:autoscaling:us-east-1:838069323424:scalingPolicy:4186cee9-06cd-4bf0-968a-e99359e86f58:autoScalingGroupName/jukinscale:policyName/scale-up