Preparation and configuration of instructions for quicker and simpler starting project
You need at least one machine to run Ansible playbooks and Terraform, one to run Jenkins and last one for Tomcat service(or other java builder)
Create repositiry to put git project in
mkdir configuration_files
cd configuration_filesClone repository with config files
git clone https://github.com/bim22614/CICD_configFiles.gitGo to directory
cd configuration_filesGo to Terraform directory
cd TerraformConnect AWS keys
nano main.tfInput region you want to built instances; AccessKey and SecretKey of your user
provider "aws" {
access_key = ""
secret_key = ""
region = ""
}Init Terraform
terraform initRun Terraform
terraform applyYou will get outputing with public ip of instances
Save this addresses for Ansible configuration
Output:
instance_public_ip_jenkins = "3.86.116.52"
instance_public_ip_tomcat = "3.93.234.157"
It will create tfkey file - private key
Move this file to Key directory and change its permisions
mv tfkey ../Key
chmod 400 ../Key/tfkeyMove to Ansible directory
cd ../AnsibleOpen hosts.txt file
You need take ip addresses that was created by AWS and input it in file
[jenkins_main]
3.86.116.52
[tomcat]
3.93.234.157Checking connection to instances
ansible all -m pingRun playbook for installing Tomcat - tomcat instance
ansible-playbook playbook_tomcatRun playbook for installing Docker - jenkins instance
ansible-playbook playbook_dockerConnect to server
cd ../Key
ssh ubuntu@3.93.234.157 -i tfkeyLocation of JAVA
sudo update-java-alternatives -lOutput:
java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64Create the systemd service file and put way JAVA to JAVA_HOME
sudo nano /etc/systemd/system/tomcat.service[Unit]
Description=Apache Tomcat Web Application Container
After=network.target
[Service]
Type=forking
Environment=JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64/jre #<--------------------
Environment=CATALINA_PID=/opt/tomcat/temp/tomcat.pid
Environment=CATALINA_HOME=/opt/tomcat
Environment=CATALINA_BASE=/opt/tomcat
Environment='CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC'
Environment='JAVA_OPTS=-Djava.awt.headless=true -Djava.security.egd=file:/dev/./urandom'
ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh
User=tomcat
Group=tomcat
UMask=0007
RestartSec=10
Restart=always
[Install]
WantedBy=multi-user.targetReload daemon and start Tomcat
sudo systemctl daemon-reload
sudo systemctl start tomcatConnect to server
ssh ubuntu@3.86.116.52 -i tfkeyRun Docker
- port 8080 - for Jenkins
- port 50000 - for WebHooks
sudo docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:ltsIn output you find these rows
Save this password (Jenkins autorotation)
Jenkins initial setup is required. An admin user has been created and a password generated.
Please use the following password to proceed to installation:
7444ff4ecbd1495f84993487955c38cb <-------------------------------------
This may also be found at: /var/jenkins_home/secrets/initialAdminPasswordConnect to Jenkins:
Open browser and put your ip:8080
3.86.116.52:8080Put password (Jenkins autorotation) and put starting of configure jenkins by defoult Install
- Maven Plugin
- Deploy to container Plugin