Sunteți pe pagina 1din 17

1) One VM having two containers GIT & Jenkins.

Puppet master on same


VM.(puppet)
2) One VM for Nagios(nagiosserver)
3) One VM for Elasticsearch(elasticserver)
4) One Production Server(spproduction)

Puppet Master
Docker Setup
1) sudo apt-get install -y docker.io
2) sudo usermod -aG docker smehta26
3) sudo docker info
4) docker -v
5) sudo docker version
6) sudo service docker restart

Setup GIT container


1) Create Dockerfile with following name
#dockerfile_gitserver
--------------------------------------------------------FROM ubuntu:14.04

RUN apt-get -y update


RUN apt-get -y install ssh
RUN apt-get -y install git
# Setting openssh
RUN mkdir /var/run/sshd
# Adding git user
RUN groupadd dev
RUN useradd -G dev -d /home/gituser -m -s /bin/bash gituser
RUN echo "gituser:gituser" | sudo chpasswd
RUN mkdir -p /home/gituser/.ssh
# Clearing and setting authorized ssh keys
RUN touch /home/gituser/.ssh/authorized_keys && chown -R gituser:dev
/home/gituser/.ssh && chmod 700 /home/gituser/.ssh && chmod 600 \
/home/gituser/.ssh/authorized_keys
ENV USER gituser
RUN mkdir -p /home/gituser/app.git && chmod -R 777 /home/gituser/app.git &&
cd /home/gituser/app.git && git --bare init && chmod -R g+ws * \
&& chgrp -R dev * && git config --global core.sharedRepository true
RUN mkdir -p /home/gituser/appDeploy.git && chmod -R 777
/home/gituser/appDeploy.git && cd /home/gituser/appDeploy.git && git --bare \
init && chmod -R g+ws * && chgrp -R dev * && git config --global
core.sharedRepository true
# Port Setting
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
------------------------------------------------------------------------------------2) sudo docker build -f dockerfile_gitserver -t gitserver .
3) sudo docker images
4) sudo docker run -p 22:22 -d --name gitserver gitserver

5) sudo docker ps -a
6) sudo docker inspect gitserver [[ Get IP Address ]]
7) Add below line in /etc/hosts
IPAddress of GIT

gitserver

8) Switch to Developer User Directory on base machine==>


a) git config --global user.name "Sagar Mehta"
b) git config --global user.email "sagar.mehta@atgensoft.com"
c) git config --global core.editor vim
d) git config --list
e) ssh-keygen
f) ssh-copy-id -i ~/.ssh/id_rsa.pub gituser@gitserver
g) mkdir -p ~/app ; cd ~/app
app
le
Hello.c
touch file
vi Hello.c
#include <stdio.h>
void main()
{
printf("Hello World!\n");
return 0;
}
h) git init ; git add .
i) git commit -m "Initial Commit" -a
j) git log
k) git remote add origin gituser@gitserver:app.git
l) git push origin master

m) mkdir -p ~/appDeploy ; cd ~/appDeploy


appDeploy/
les
Hello
manifests
init.pp
tests
init.pp
appDeploy -- Puppet code to deploy Hello executable
n) git init ; git add .
o) git commit -m "Initial Commit" -a
p) git log
q) git remote add origin gituser@gitserver:appDeploy.git
r) git push origin master

Setup Jenkins-#dockerfile_jenkins
-------------------------------------------------------------------------------------------FROM java:8-jdk
RUN apt-get update && apt-get install -y git curl zip gcc && rm -rf
/var/lib/apt/lists/*
#RUN wget https://apt.puppetlabs.com/puppetlabs-release-trusty.deb && dpkg -i
puppetlabs-release-trusty.deb && apt-get update && apt-get \
#
install -y puppet
ENV JENKINS_HOME /var/jenkins_home
ENV JENKINS_SLAVE_AGENT_PORT 50000

ENV user=jenkins
ENV group=jenkins
ENV uid=1000
ENV gid=1000
# Jenkins is run with user `jenkins`, uid = 1000
# If you bind mount a volume from the host or a data container,
# ensure you use the same uid
RUN groupadd -g ${gid} ${group} \
&& useradd -d "$JENKINS_HOME" -u ${uid} -g ${gid} -m -s /bin/bash ${user}
# Jenkins home directory is a volume, so configuration and build history
# can be persisted and survive image upgrades
VOLUME /var/jenkins_home
# `/usr/share/jenkins/ref/` contains all reference configuration we want
# to set on a fresh new installation. Use it to bundle additional plugins
# or config file with your custom jenkins Docker image.
RUN mkdir -p /usr/share/jenkins/ref/init.groovy.d
ENV TINI_SHA 066ad710107dc7ee05d3aa6e4974f01dc98f3888
# Use tini as subreaper in Docker container to adopt zombie processes
RUN curl -fsSL https://github.com/krallin/tini/releases/download/v0.5.0/tinistatic -o /bin/tini && chmod +x /bin/tini \
&& echo "$TINI_SHA /bin/tini" | sha1sum -c -

ENV JENKINS_VERSION=2.0
ENV JENKINS_SHA=da06f963edb627f0ced2fce612f9985d1928f79b

# could use ADD but this one does not check Last-Modified header

# see https://github.com/docker/docker/issues/8331
RUN curl -fsSL http://repo.jenkins-ci.org/public/org/jenkins-ci/main/jenkinswar/${JENKINS_VERSION}/jenkins-war-${JENKINS_VERSION}.war -o /usr/s
hare/jenkins/jenkins.war \
&& echo "$JENKINS_SHA /usr/share/jenkins/jenkins.war" | sha1sum -c ENV JENKINS_UC https://updates.jenkins-ci.org
RUN chown -R ${user} "$JENKINS_HOME" /usr/share/jenkins/ref
# for main web interface:
EXPOSE 8080
# will be used by attached slave agents:
EXPOSE 50000
ENV COPY_REFERENCE_FILE_LOG $JENKINS_HOME/copy_reference_file.log
USER ${user}
COPY jenkins.sh /usr/local/bin/jenkins.sh
ENTRYPOINT ["/bin/tini", "--", "/usr/local/bin/jenkins.sh"]
# from a derived Dockerfile, can use `RUN plugins.sh active.txt` to setup
/usr/share/jenkins/ref/plugins from a support bundle
COPY plugins.sh /usr/local/bin/plugins.sh
--------------------------------------------------------------------------------------#jenkins.sh
-------------------------------------------------------------------------------------------#! /bin/bash
set -e

# Copy files from /usr/share/jenkins/ref into $JENKINS_HOME


# So the initial JENKINS-HOME is set with expected content.
# Don't override, as this is just a reference setup, and use from UI
# can then change this, upgrade plugins, etc.
copy_reference_file() {
f="${1%/}"
b="${f%.override}"
echo "$f" >> "$COPY_REFERENCE_FILE_LOG"
rel="${b:23}"
dir=$(dirname "${b}")
echo " $f -> $rel" >> "$COPY_REFERENCE_FILE_LOG"
if [[ ! -e $JENKINS_HOME/${rel} || $f = *.override ]]
then
echo "copy $rel to JENKINS_HOME" >>
"$COPY_REFERENCE_FILE_LOG"
mkdir -p "$JENKINS_HOME/${dir:23}"
cp -r "${f}" "$JENKINS_HOME/${rel}";
# pin plugins on initial copy
[[ ${rel} == plugins/*.jpi ]] && touch "$JENKINS_HOME/${rel}.pinned"
fi;
}
: ${JENKINS_HOME:="/var/jenkins_home"}
export -f copy_reference_file
touch "${COPY_REFERENCE_FILE_LOG}" || (echo "Can not write to
${COPY_REFERENCE_FILE_LOG}. Wrong volume permissions?" && exit 1)
echo "--- Copying files at $(date)" >> "$COPY_REFERENCE_FILE_LOG"
find /usr/share/jenkins/ref/ -type f -exec bash -c "copy_reference_file '{}'" \;
# if `docker run` first argument start with `--` the user is passing jenkins launcher
arguments
if [[ $# -lt 1 ]] || [[ "$1" == "--"* ]]; then
eval "exec java $JAVA_OPTS -jar /usr/share/jenkins/jenkins.war $JENKINS_OPTS
\"\$@\""

fi
# As argument is not jenkins, assume user want to run his own process, for
sample a `bash` shell to explore this image
exec "$@"
-------------------------------------------------------------------------------------------------------#plugins.sh
---------------------------------------------------------------------------------------------------------#! /bin/bash
# Parse a support-core plugin -style txt file as specification for jenkins plugins to
be installed
# in the reference directory, so user can define a derived Docker image with just :
#
# FROM jenkins
# COPY plugins.txt /plugins.txt
# RUN /usr/local/bin/plugins.sh /plugins.txt
#
set -e
REF=/usr/share/jenkins/ref/plugins
mkdir -p $REF
while read spec || [ -n "$spec" ]; do
plugin=(${spec//:/ });
[[ ${plugin[0]} =~ ^# ]] && continue
[[ ${plugin[0]} =~ ^\s*$ ]] && continue
[[ -z ${plugin[1]} ]] && plugin[1]="latest"
echo "Downloading ${plugin[0]}:${plugin[1]}"
if [ -z "$JENKINS_UC_DOWNLOAD" ]; then
JENKINS_UC_DOWNLOAD=$JENKINS_UC/download

fi
curl -sSL -f
${JENKINS_UC_DOWNLOAD}/plugins/${plugin[0]}/${plugin[1]}/${plugin[0]}.hpi -o
$REF/${plugin[0]}.jpi
unzip -qqt $REF/${plugin[0]}.jpi
done < $1
----------------------------------------------------------------------------------------------1) sudo docker build -f dockerfile_jenkins -t jenkins .
2) sudo docker run --name jenkins -u root -p 9090:8080 -d jenkins
3) sudo docker inspect jenkins [[ Get IP Address ]]
4) Add below line in /etc/hosts
IPAddress of Docker

jenkinsserver

5) Login to URL with base machineip http://<IP>:9090


6) Use Password from below steps:
docker exec -it jenkins bash
more /var/jenkins_home/secrets/initialAdminPassword
7) Install Default Plugins
8) cd /var
9) chown -R jenkins:jenkins jenkins_home/
10) echo "<IP of GIT SERVER> gitserver" >> /etc/hosts
11) ssh-keygen
12) ssh-copy-id -i ~/.ssh/id_rsa.pub gituser@gitserver
13) su - jenkins

14) ssh-keygen
15) ssh-copy-id -i ~/.ssh/id_rsa.pub gituser@gitserver
16) Create Free Style Build Job (appBuild)
GIT URL --> gituser@gitserver:app.git
BUILD Environment -- Delete Workspace before BUILD starts
BUILD --> Execute Shell (gcc -Wall -o Hello Hello.c )

17) Create Free Style Deployment Job (appDeploy)


GIT URL --> gituser@gitserver:appDeploy.git
BUILD TRIGGER -- Build After project " appBuild"
BUILD Environment -- Delete Workspace before BUILD starts
BUILD -->
cd /var/jenkins_home/workspace/appDeploy ; mv
/var/jenkins_home/workspace/appBuild/Hello files/Hello ; date >>
metadata.json ; git config --global user.email "jenkins@atgensoft.com" ; git
config --global user.name "Jenkins" ; git add . ; git commit -m "jenkins" -a ;
git push origin HEAD:master --force

Puppet Master
1) Create new Ubuntu 14.04 LTS Machine
2) Modify /etc/hostname to have machine name as "puppet"
3) Execute command "hostname puppet"
4) Modify hostname in /etc/hosts and line
<IP Address> puppet
<IP Address> spproduction
5) Execute "sudo apt-get update"
6) sudo apt-get install ssh
7) vi /etc/ssh/sshd_config
PermitRootLogin yes

8) sudo service ssh restart


9) Transfer & Extract Puppet Package.
10) Execute command with "root".
./puppet-enterprise-installer -a answers/all.in.one
11) Once installation is finished successfully, change directory
to /etc/puppetlabs/code/environments/production
12) Execute mkdir modules ; cd modules

Puppet Agent
1) Create new Ubuntu 14.04 LTS Machine
2) Modify /etc/hostname to have machine name as
"spproduction"
3) Execute command "hostname spproduction "
4) Modify hostname in /etc/hosts and line
<IP Address> spproduction
<Puppet Master IP Address> puppet
5) Transfer & Extract Puppet Package.
6) Execute command
./puppet-enterprise-installer -a answer.agent.install
7) Run below command on Puppet Master
puppet cert sign spproduction

8) Make Puppet Console Browser Class/Group entry


9) Run below command on Puppet Agent(spproduction)
puppet agent -t

Nagios Core Server


1) apt-get install nagios3 nagios-nrpe-plugin
2) htpasswd /etc/nagios3/htpasswd.users nagiosadmin
3) Configuration Overview
There are a couple of directories containing Nagios configuration and check files.
/etc/nagios3: contains configuration files for the operation of the nagios daemon, CGI files,
hosts, etc.
/etc/nagios-plugins: houses configuration files for the service checks.
/etc/nagios: on the remote host contains the nagios-nrpe-server configuration files.
/usr/lib/nagios/plugins/: where the check binaries are stored. To see the options of a check use
the -h option.

4) sudo cp /etc/nagios3/conf.d/localhost_nagios2.cfg /etc/nagios3/conf.d/appserver.cfg


5) Next, edit /etc/nagios3/conf.d/appserver.cfg:
define host{
use
host_name
alias
address
}

generic-host ; Name of host template to use


appserver
Application Server
172.18.100.101

# check DNS service.


define service {
use
generic-service
host_name
appserver
service_description
DNS
check_command
check_dns!172.18.100.101
}

6) sudo service nagios3 restart

7) Lastly configure NRPE to check the disk space on appserver.


On nagiosserver add the service check to /etc/nagios3/conf.d/appserver.cfg:
# NRPE disk check.
define service {
use
generic-service
host_name
appserver
service_description nrpe-disk
check_command
check_nrpe_1arg!check_all_disks!172.18.100.101
}

8) sudo service nagios3 restart

Nagios Remote
1) apt-get install nagios-nrpe-server
2)Now on Agent edit /etc/nagios/nrpe.cfg changing:
allowed_hosts=NagiosServer IP
command[check_all_disks]=/usr/lib/nagios/plugins/check_disk -w
20% -c 10% -e
3) service nagios-nrpe-server restart

Elastic Search Server


1) sudo apt-get update
2) sudo apt-get install openjdk-7-jre
3) wget https://download.elastic.co/elasticsearch/elasticsearch/elasticsearch-1.7.2.deb
4) sudo dpkg -i elasticsearch-1.7.2.deb
5) sudo update-rc.d elasticsearch defaults
6) sudo service elasticsearch start
7) curl -X GET 'http://localhost:9200'
8) curl -X POST 'http://localhost:9200/tutorial/helloworld/1' -d '{
"message": "Hello World!" }'
9) curl -X GET 'http://localhost:9200/tutorial/helloworld/1'
10) curl -X PUT 'localhost:9200/tutorial/helloworld/1?pretty' -d '
{
"message": "Hello People!"
}'

11) curl -X PUT 'localhost:9200/tutorial/helloworld/1?pretty' -d '


>{
> "message": "Hello People!"
> }'

12) curl -X GET 'http://localhost:9200/tutorial/helloworld/1?pretty'


{
"_index" : "tutorial",
"_type" : "helloworld",
"_id" : "1",
"_version" : 2,
"found" : true,
"_source":

{
"message": "Hello People!"
}
}

S-ar putea să vă placă și