Server 1: Git Server
Customer Clone Git codes and MOdify here, After they will push it to Github
Server 2: Jenkins Server
Install Git - yum install git
Java - yum install java-11 java-11-openjdk.x86_64
vi /root/.bash_profile
JAVA_HOME=/usr/lib/jvm/java-11
PATH=$PATH:$HOME/bin:$JAVA_HOME
INstall jenkins
wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
yum install jenkins -y
service jenkins start
Manage Jenkins > Global Tool Configuration > JDK > Add Jadk > unselect auto install > Paste the Jave home directory
> git > automatically execute git exe
> Maven > AddMaven > unselect auto install > Paste the Maven home directory >
Maven -
Ansible
Create an ansible server and setup SSH key and install ansible
Create two more ansible clients.
From ansible server "ssh-copy-id ansible@host1ip" to copy SSH keys to client machines
Connect Ansible servers to Jenkins
Login to Jenkins> Manage Jenkins> ManagePlugins > "publish over SSH"
Manage Jenkins > Configure systems > at bottom "SSH Servers" > paste ansible server details "Us private IP address"
New Item > Deploy-on -ansible > copy from > "My First ansible Job" > Ok > Description: PAste any > Post build action > Send build artifact over ssh > Source file = webapp/target/*.war > Remove Prefix=webapp/target > remote directory=//home//ansible > Apply> Save
Create 2 ansible client servers
Install tomcat on both ansible servers
find / -name context.xml
vi ..../host-managet/META-INF/context.xml
comment 2 lines "<Value Class name="org......................................
allow="127....................................."
vi .../manager/META-INF/context.xml
comment 2 lines "<Value Class name="org......................................
allow="127....................................."
tomcat/bin/# ./sutdown.sh
tomcat/bin/# ./startup.sh
Now we can access tomcat page, but accessing manager asks for password which we didn't set so far. To set user access,
vi conf/tomcat-users.xml
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
cd tomcat/bin
tomcat/bin/# ./sutdown.sh
tomcat/bin/# ./startup.sh
Now create a playbook in ansible server to sync war file
---
hosts all
become yes
tass
-- name "Deploy war file into tomcat VMs of ansible hosts"
copy srcc=./webapp.war dest=/root/tomcat/webapps
ansible-playbook -i hosts playbookname.
Create New Project > "Deploy on container using ansible" > go down "Exec Command" = ansible-playbook -i hosts playbookname.yml >
Jenkins > Select Project > configuration >
Integrate Docker conteiner
yum install docker -y
service docker start
docker pull tomcat:latest //Pull OS images
docker run -td --name tomcat-container -p 8080:8080 tomcat:8.0
docker exec -it tomcat-container/bin/bash
cp -pr /usr/local/tomcat/webapps.dist/* /usr/local/tomcat/webapps/
My Practice
Git Server
Build EC2 server to install git server
Created an account at Github
Create a repository in Git
yum -y update
yum install git -y
git config --global user.name "Sherin"
git config --global user.email "sherinsha1@gmail.com"
git config --list
git init
git status
git commit -m "Test Git connection"
git remote add origin https://github.com/sherinsha1/Project2.git
git push -u origin master
Jenkins Server
CReate a new EC2 for Jenkins server
yum install java-11* //Setupbash profile
yum install git -y
yum install jenkins -y
Manage Jenkins > Global Tool Configuration > JDK > Add Jadk > Name=any, unselect auto install > Paste the Jave home directory > Apply> SAVE
Manage Jenkins > Manage Plugins > Available = "GitHub plugin "
Manage Jenkins > Global Tool Configuration > Git installations > Path to Git executable = /usr/bin/git > Apply > SAVE
Create a Job and try to build.
Setup Maven
cd /opt
wget https://dlcdn.apache.org/maven/maven-3/3.8.6/binaries/apache-maven-3.8.6-bin.tar.gz
tar -xvzf apache-maven-3.8.6-bin.tar.gz
mv apache-maven-3.8.6 maven
vi /root/.bash_profile
M2_HOME=/opt/maven
M2=/opt/maven/bin
PATH=$PATH:$HOME/bin:$JAVA_HOME:$M2_HOME
Manage Jenkins > Manage Plugins > Available = "Maven integration plugin "
Manage Jenkins > Global Tool Configuration >Maven > Name = Maven > MAVEN_HOME = /opt/maven > Apply > SAVE
Setup Ansible
yum install python python-pip
pip nstall ansible // In this method we cannot find ansible configuration file
useradd ansible
passwd ansible
visudo //or vi /etc/sudoers
Ansible ALL=(ALL) NOPASSWD: ALL
su ansible
ssh-keygen
Setup 2 ansible hosts
Run following in both servers:
yum -y update
useradd ansible
Password
visudoers
Ansible All=(All) NOPasswd:All
vi /etc/ssh/sshd_config
Password authentication: yes
service sshd restarrt
at ansible server::
ssh-keygen
ssh-copy-id ansible@ansiblehost-IP
ssh-copy-id ansible@ansiblehost2-IP
vi /etc/ansible/hosts
Paste hosts server IPs
#ansible all -m ping
INstall Tomcat in Ansible SLaves
yum install java-11* -y
wget https://dlcdn.apache.org/tomcat/tomcat-8/v8.5.83/bin/apache-tomcat-8.5.83.tar.gz
tar -xvzf apache-tomcat-8.5.83.tar.gz
mv apache-tomcat-8.5.83 tomcat
cd tomcat/bin
./startup.sh
Now we can access tomcat page using http://ip:8080 , but we cannoit access the manager page to get it modify following files
cd tomcat/
find ./ -name context.xml
vi ./webapps/host-manager/META-INF/context.xml and ./webapps/manager/META-INF/context.xml // Comment following lines
<!-- <Valve className="org.apache.catalina.valves.RemoteAddrValve"
allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" /> -->
vi tomcat/conf/tomcat-users.xml //Add following lines at the bottom
<role rolename="manager-gui"/>
<role rolename="manager-script"/>
<role rolename="manager-jmx"/>
<role rolename="manager-status"/>
<user username="admin" password="admin" roles="manager-gui, manager-script, manager-jmx, manager-status"/>
<user username="deployer" password="deployer" roles="manager-script"/>
<user username="tomcat" password="s3cret" roles="manager-gui"/>
now we can access tomcat Manager *****