diff --git a/cloudwatch b/cloudwatch new file mode 100644 index 0000000..802defd --- /dev/null +++ b/cloudwatch @@ -0,0 +1,106 @@ +vi metric_data_queries + + +[ + { + "Id": "m1", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "BytesUploaded", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m2", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "BytesDownloaded", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m3", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "Requests", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m4", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "TotalErrorRate", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m5", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "4xxErrorRate", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + } +] + + + +this query get metrics over 7-day intervals. + + + +******************************************************************************************************************************************************************************************************* + + + +run command:- + +aws cloudwatch get-metric-data \ + --start-time "2023-08-01T00:00:00Z" \ + --end-time "2023-08-11T23:59:59Z" \ + --metric-data-queries file:///home/ubuntu/metric_data_queries \ + --output json | jq '.MetricDataResults[] | select(.Label == "BytesDownloaded").Values |= map(. / (1024*1024*1024) | "\(round) GB")' + + + diff --git a/cloudwatch shell scripting b/cloudwatch shell scripting new file mode 100644 index 0000000..a0a0052 --- /dev/null +++ b/cloudwatch shell scripting @@ -0,0 +1,222 @@ +vi cloudfront_metrics.sh + + + +#!/bin/bash + +# Update packages and install required tools +sudo apt-get update +sudo apt-get install awscli jq -y + +# Create a JSON file with metric data queries +cat < metric_data_queries.json +[ + { + "Id": "m1", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "BytesUploaded", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m2", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "BytesDownloaded", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m3", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "Requests", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m4", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "TotalErrorRate", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m5", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "4xxErrorRate", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + } +] +EOF + +# Configure AWS CLI +aws configure + +# Retrieve metric data and process it using jq +aws cloudwatch get-metric-data \ + --start-time "2023-08-01T00:00:00Z" \ + --end-time "2023-08-11T23:59:59Z" \ + --metric-data-queries file://metric_data_queries.json \ + --output json | jq '.MetricDataResults[] | select(.Label == "BytesDownloaded").Values |= map(. / (1024*1024*1024) | "\(round) GB")' + + + + + +chmod +x cloudfront_metrics.sh +./cloudfront_metrics.sh + + + +********************************************************************************************************************************************************************************************************** + +******************************************************************************************* with json veriable ***************************************************************************************** + + +nano metrics.sh + +#!/bin/bash + +# JSON data ko direct variable mein store karna +json_data='[ + { + "Id": "m1", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "BytesUploaded", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m2", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "BytesDownloaded", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m3", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "Requests", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m4", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "TotalErrorRate", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + }, + { + "Id": "m5", + "MetricStat": { + "Metric": { + "Namespace": "AWS/CloudFront", + "MetricName": "4xxErrorRate", + "Dimensions": [ + { "Name": "Region", "Value": "Global" }, + { "Name": "DistributionId", "Value": "E3CWZ2DCBC7S0C" } + ] + }, + "Period": 604800, + "Stat": "Sum" + }, + "ReturnData": true + } +]' + +# Configure AWS CLI +aws configure + +# Retrieve metric data and process it using jq +echo "$json_data" | aws cloudwatch get-metric-data \ + --start-time "2023-08-01T00:00:00Z" \ + --end-time "2023-08-11T23:59:59Z" \ + --metric-data-queries file:///dev/stdin \ + --output json | jq '.MetricDataResults[] | select(.Label == "BytesDownloaded").Values |= map(. / (1024*1024*1024) | "\(round) GB")' + + + +chmod +x metrics.sh +./metrics.sh diff --git a/ubuntu/ansible installation + configuration.txt b/ubuntu/ansible installation + configuration.txt new file mode 100644 index 0000000..dc21359 --- /dev/null +++ b/ubuntu/ansible installation + configuration.txt @@ -0,0 +1,37 @@ +***************************************** MASTER *************************************** +apt upadte +apt install -y ansible +cd .ssh +vim ansible_key +chmod 700 -R /home/ubuntu/.ssh +chmod 600 -R /home/ubuntu/.ssh/* +chown 700 -R /home/ubuntu/.ssh +chown 700 -R /home/ubuntu/.ssh/* +ssh -i /home/ubuntu/.ssh/ansible_key ubuntu@****ip***** ***exit*** +cat /etc/ansible/hosts ******No such file or directory******* +cd /home/ubuntu +mkdir ansible +cd ansible +vim hosts + ****************************************** + [servers] + server1 ansible_host=13.127.182.178 + + + [all:vars] + ansible_python_interpreter=/usr/bin/python3 + **************** SAVE ********************* + +ansible-inventory --list -y -i /home/ubuntu/ansible/hosts +ansible all -m ping + ******[WARNING]: No inventory was parsed, only implicit localhost is available + ******[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' + +ansible all -m ping -i /home/ubuntu/ansible/hosts --private-key=/home/ubuntu/.ssh/ansible_key -u ubuntu + + + + + +*************************************** NODE ******************************************* + diff --git a/ubuntu/kubernates k8s.txt b/ubuntu/kubernates k8s.txt new file mode 100644 index 0000000..fdaf073 --- /dev/null +++ b/ubuntu/kubernates k8s.txt @@ -0,0 +1,64 @@ + kubernates - kubeadm* + + +Step1: +On Master & worker node +sudo su +apt-get update +apt-get install docker.io -y +service docker restart +sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/kubernetes-archive-keyring.gpg +echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list +apt-get update +apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y + + + +Step2: +On Master: + kubeadm init --pod-network-cidr=192.168.0.0/16 +****************** Copy the token and paste it into the worker node.********************************** + + + + +Step3: +On Master: + exit + mkdir -p $HOME/.kube + sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config + sudo chown $(id -u):$(id -g) $HOME/.kube/config + + + + + +sudo apt-get update +sudo apt-get install -y ca-certificates curl +sudo apt-get install -y apt-transport-https +sudo apt-get update +sudo apt-get install -y kubectl=1.20.0-00 +curl -Ls "https://sbom.k8s.io/$(curl -Ls https://dl.k8s.io/release/stable.txt)/release" | grep "SPDXID: SPDXRef-Package-registry.k8s.io" | grep -v sha256 | cut -d- -f3- | sed 's/-/\//' | sed 's/-v1/:v1/' + + + + + + + + + + + + +step4: +Deploy Pod Network to Cluster ( ON MASTER) +sudo kubectl apply -f https://raw.githubusercontent.com/coreos/flannel/master/Documentation/kube-flannel.yml + + OR + +On Master: +kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/calico.yaml +kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.49.0/deploy/static/provider/baremetal/deploy.yaml + + diff --git a/ubuntu/sonarqube-jenkins-maven-rest-cmd-download cmd's.txt b/ubuntu/sonarqube-jenkins-maven-rest-cmd-download cmd's.txt new file mode 100644 index 0000000..dfdd9d2 --- /dev/null +++ b/ubuntu/sonarqube-jenkins-maven-rest-cmd-download cmd's.txt @@ -0,0 +1,209 @@ +************************************************************************************************ + +************************************* ANSIBLE ************************************************ + + +***************************************** MASTER *************************************** +apt upadte +apt install -y ansible +cd .ssh +vim ansible_key +chmod 700 -R /home/ubuntu/.ssh +chmod 600 -R /home/ubuntu/.ssh/* +chown 700 -R /home/ubuntu/.ssh +chown 700 -R /home/ubuntu/.ssh/* +ssh -i /home/ubuntu/.ssh/ansible_key ubuntu@****ip***** ***exit*** +cat /etc/ansible/hosts ******No such file or directory******* +cd /home/ubuntu +mkdir ansible +cd ansible +vim hosts + ****************************************** + [servers] + server1 ansible_host=13.127.182.178 + + + [all:vars] + ansible_python_interpreter=/usr/bin/python3 + **************** SAVE ********************* + +ansible-inventory --list -y -i /home/ubuntu/ansible/hosts +ansible all -m ping + ******[WARNING]: No inventory was parsed, only implicit localhost is available + ******[WARNING]: provided hosts list is empty, only localhost is available. Note that the implicit localhost does not match 'all' + +ansible all -m ping -i /home/ubuntu/ansible/hosts --private-key=/home/ubuntu/.ssh/ansible_key -u ubuntu + + + + + +*************************************** NODE ******************************************* +***************************************************************************************************************************************************************** +***************************************************************************************************************************************************************** + + + +-------------------------------------------- jenkins --------------------------------------------- +apt-get -y update +apt install -y openjdk-17-jre +java -version + + +curl -fsSL https://pkg.jenkins.io/debian-stable/jenkins.io-2023.key | sudo tee \ + /usr/share/keyrings/jenkins-keyring.asc > /dev/null + + + + + echo deb [signed-by=/usr/share/keyrings/jenkins-keyring.asc] \ + https://pkg.jenkins.io/debian-stable binary/ | sudo tee \ + /etc/apt/sources.list.d/jenkins.list > /dev/null + + + + sudo apt-get -y update + sudo apt-get install -y fontconfig openjdk-11-jre + sudo apt-get install -y jenkins + +************************************************************************************************ + + + + +-------------------------------------------- sonarqube-9.9.0.65466 ---------------------------- + + +java -version + + "openjdk-17" + + +apt install unzip wget +wget https://binaries.sonarsource.com/Distribution/sonarqube/sonarqube-9.9.0.65466.zip +unzip sonarqube-9.9.0.65466.zip -d /opt +adduser sonar +chown -R sonar:sonar /opt/sonarqube-9.9.0.65466 +su sonar +cd /opt/sonarqube-9.9.0.65466/bin/linux-x86-64 +./sonar.sh console + + +************************************************************************************************ + + + + +------------------------------------------- maven-3.6.3 ---------------------------------------- + + +apt-get update +apt-get install maven +mvn -v + + +********************************************************************************************************** + + +**************************************** kubernates ******************************************************************************************************************* + + + + kubernates - kubeadm* + + +Step1: +On Master & worker node +sudo su +apt-get update +apt-get install docker.io -y +service docker restart +sudo curl -s https://packages.cloud.google.com/apt/doc/apt-key.gpg | gpg --dearmor | sudo tee /usr/share/keyrings/kubernetes-archive-keyring.gpg +echo "deb [signed-by=/usr/share/keyrings/kubernetes-archive-keyring.gpg] https://apt.kubernetes.io/ kubernetes-xenial main" | sudo tee /etc/apt/sources.list.d/kubernetes.list +apt-get update +apt install kubeadm=1.20.0-00 kubectl=1.20.0-00 kubelet=1.20.0-00 -y + + + +Step2: +On Master: + kubeadm init --pod-network-cidr=192.168.0.0/16 +****************** Copy the token and paste it into the worker node.********************************** + + + + +Step3: +On Master: + exit + mkdir -p $HOME/.kube + sudo cp -i /etc/kubernetes/admin.conf $HOME/.kube/config + sudo chown $(id -u):$(id -g) $HOME/.kube/config + + + + + +step4: +On Master: +kubectl apply -f https://raw.githubusercontent.com/projectcalico/calico/v3.26.1/manifests/calico.yaml +kubectl apply -f https://raw.githubusercontent.com/kubernetes/ingress-nginx/controller-v0.49.0/deploy/static/provider/baremetal/deploy.yaml + + +****************************************************************************************************end + + + +----------------------------------------- jenkins pipeline ------------------------------------------ + + +pipeline { + agent any + + stages { + stage('Git CheckOut') { + steps { + checkout([$class: 'GitSCM', branches: [[name: '*/master']], extensions: [], userRemoteConfigs: [[url: 'https://github.com/prajeet1000/utk-mehtabsir.git']]]) + } + } + stage('Clean and Install') { + steps { + sh 'mvn clean install' + } + } + stage ('Code Quality'){ + steps { + withSonarQubeEnv('sonarqube server') { + sh 'mvn sonar:sonar' + } + } + } + + } +} + + + + +****************************************************************************************************************************************************************************** + +------------------------------------------------------------------ reset ubuntu machine ---------------------------------------------------------------------------------- + + +sudo apt update +sudo apt upgrade +sudo apt autoremove +sudo apt clean + + + +****************************************************************************************************************************************************************************** + + + + + + + + +