Devops - All Installations Kit
Note: Whole Credit, Thanx, Copy Rights of the below blog content goes to Shri Atiq Rahman....here iam just put all together into single blog for easily accessing
Task-1:
# Install Apache Maven on Amazon Linux2:
sudo yum update -y
sudo wget https://repos.fedorapeople.org/repos/dchen/apache-maven/epel-apache-maven.repo -O /etc/yum.repos.d/epel-apache-maven.repo
sudo sed -i s/\$releasever/6/g /etc/yum.repos.d/epel-apache-maven.repo
sudo yum install -y apache-maven
Task-2:
# Install Jenkins on Amazon Linux2:
sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key
sudo yum install jenkins
sudo systemctl start jenkins
sudo systemctl status jenkins
sudo systemctl status jenkins
Task-3:
# Send Email through AWS SES with Python Automation Code:
To use this script, you will need to have the AWS SDK for Python (Boto3) installed in your Lambda function’s environment.
You will also need to have the necessary permissions to send emails using SES.
import boto3
import json
def lambda_landler( event, context ):
#grab the to, from , subject and body
to_address = event['to_address']
subject = event['subject']
body = event['body']
from_address = event['from_address']
#load the ses client
client = boto3.client('ses')
response = client.send_email(
Source= from_address,
Destination={
'ToAddresses':[
to_address
]
},
Message={
'Subject': {
'Data': subject
},
'Body':{
'Text':{
'Data': body
}
}
}
)
return {'status': 200, 'body': json.dumps( response ) }
Task-4:
# How To Run a NodeJS application in Ubuntu 22 with SSL via Letsencrypt
sudo apt update -y
sudo apt install nginx -y
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.37.2/install.sh | bash
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
command -v nvm
nvm install 16
sudo vi /etc/nginx/conf.d/nodejs.conf
server {
listen 80;
server_name atiqur.xyz;
location / {
proxy_pass http://127.0.0.1:3000;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_cache_bypass $http_upgrade;
}
}
sudo systemctl restart nginx
sudo vi index.js
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => {
res.send('Hello World!')
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
sudo vi package.json
{
"name": "atiq-app",
"version": "1.0.0",
"description": "A simple Node.js Express application",
"main": "index.js",
"scripts": {
"start": "node index.js"
},
"dependencies": {
"express": "^4.17.1"
},
"author": "Your Name",
"license": "MIT"
}
npm install pm2 -g
pm2 start index.js --name "atiq-app"
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo certbot --nginx
sudo crontab -e
0 3 * * * sudo certbot renew >/dev/null 2>&1
Task-5:
# create an Nginx ingress controller with aws classic load balancer
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl create cluster
aws eks update-kubeconfig --region {aws-region-name} --name {eks-cluster-name}
kubectl create serviceaccount nginx-ingress-controller
kubectl create clusterrolebinding nginx-ingress-controller --clusterrole=cluster-admin --serviceaccount=default:nginx-ingress-controller
kubectl create namespace ingress-nginx
helm repo add ingress-nginx https://kubernetes.github.io/ingress-nginx
helm repo update
helm install nginx-ingress ingress-nginx/ingress-nginx --namespace ingress-nginx --set controller.service.annotations."service\.beta\.kubernetes\.io/aws-load-balancer-type"=classic
kubectl get pods -n ingress-nginx
# checking for pods with the name nginx-ingress-controller-*.
# Here is one sample deployment file which will create one service and
# link it with the Nginx ingress in a path.
apiVersion: apps/v1
kind: Deployment
metadata:
name: test-app
labels:
app: test-app
spec:
replicas: 3
selector:
matchLabels:
app: test-app
template:
metadata:
labels:
app: test-app
spec:
containers:
- name: test-app
image: nginx:latest
ports:
- containerPort: 80
resources:
limits:
cpu: 100m
memory: 128Mi
requests:
cpu: 50m
memory: 64Mi
---
apiVersion: v1
kind: Service
metadata:
name: atiq-service
spec:
type: NodePort
ports:
- port: 80
selector:
app: test-app
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: test-app-ingress
annotations:
nginx.ingress.kubernetes.io/ssl-redirect: "false"
kubernetes.io/ingress.class: 'nginx'
nginx.ingress.kubernetes.io/use-regex: "true"
nginx.ingress.kubernetes.io/rewrite-target: /$2
spec:
rules:
- http:
paths:
- path: /atiq(/|$)(.*)
pathType: Prefix
backend:
service:
name: atiq-service
port:
number: 80
Task-7
# Install MongoDB 6.0 in Ubuntu Inside AWS
wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo systemctl start mongod
sudo systemctl status mongod
sudo systemctl enable mongod
mongosh
use erpdatabase # erpdatabase is DB Name
db.users.insertOne(
{ firstName : "Atiqur",
lastName : "Rahman",
username : "randomuser0298",
age : 35 ,
gender : "Male",
}
)
db.users.find(
{
username: "randomuser0298"
}
).limit( 10 )
Task-8:
# setup WordPress in AWS Eks using Helm
curl --silent --location "https://github.com/weaveworks/eksctl/releases/latest/download/eksctl_$(uname -s)_amd64.tar.gz" | tar xz -C /tmp
sudo mv /tmp/eksctl /usr/local/bin
eksctl create cluster
sudo yum install openssl -y
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh
oidc_id=$(aws eks describe-cluster --name my-cluster --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
aws iam list-open-id-connect-providers | grep $oidc_id | cut -d "/" -f4
eksctl utils associate-iam-oidc-provider --cluster my-cluster --approve
eksctl create iamserviceaccount \
--name ebs-csi-controller-sa \
--namespace kube-system \
--cluster my-cluster \
--attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
--approve \
--role-only \
--role-name AmazonEKS_EBS_CSI_DriverRole
eksctl create addon --name aws-ebs-csi-driver --cluster my-cluster --service-account-role-arn arn:aws:iam::111122223333:role/AmazonEKS_EBS_CSI_DriverRole --force
helm repo add bitnami https://charts.bitnami.com/bitnami
helm install my-release --set wordpressUsername=admin --set wordpressPassword=defaultpass bitnami/wordpress
Task-9:
# install nginx in Amazon Linux 2023
sudo dnf update -y
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl status nginx
sudo systemctl enable nginx
sudo vi /etc/nginx/conf.d/sameple.com.conf
server {
listen 80;
server_name gcptips.com;
root /var/www/wordpress;
index index.html;
charset UTF-8;
}
sudo dnf install python3 augeas-libs
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
sudo /opt/certbot/bin/pip install certbot certbot-nginx
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
sudo certbot --nginx
sudo dnf install cronie -y
sudo systemctl start crond.service
sudo systemctl enable crond.service
sudo crontab -e
0 3 * * * sudo certbot renew >/dev/null 2>&1
Task-10:
# install Apache php on Amazon Linux 2023
sudo dnf update -y
sudo dnf install httpd mod_ssl php php-mysqlnd -y
sudo systemctl start httpd
sudo systemctl status httpd
sudo systemctl enable httpd
sudo nano /var/www/html/info.php
<?php
phpinfo();
?>
sudo dnf install python3 augeas-libs
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
sudo /opt/certbot/bin/pip install certbot certbot-apache
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
sudo certbot --apache
Task-11
# SSL Setup on Amazon Linux 2023 with Apache
SSL Setup on Amazon Linux 2023 with Apache
sudo dnf install httpd mod_ssl
sudo systemctl start httpd
sudo systemctl enable httpd
sudo systemctl status httpd
sudo dnf install python3 augeas-libs
sudo python3 -m venv /opt/certbot/
sudo /opt/certbot/bin/pip install --upgrade pip
sudo /opt/certbot/bin/pip install certbot certbot-apache
sudo ln -s /opt/certbot/bin/certbot /usr/bin/certbot
sudo certbot --apache
Task-12
# Install Java on Amazon Linux 2023
sudo dnf update -y
sudo dnf install java-17-amazon-corretto-devel
java -version
nano HelloWorld.java
public class HelloWorld {
public static void main(String[] args) {
System.out.println("Hello, World!");
}
}
javac HelloWorld.java
java HelloWorld
Task-13:
# Install Java in Ubuntu 22
sudo apt update
sudo apt install default-jdk
java -version
Task-14:
# Install MySQL 8 on Ubuntu 22.04
sudo apt update
sudo apt install mysql-server
systemctl start mysql
systemctl enable mysql
mysql -u root -p
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'new_password';
sudo mysql_secure_installation
mysql -uroot -p
# we can now create databases, tables, and users. For more information on how to use MySQL
Task-15:
# Install MySQL on Amazon Linux 2023
sudo wget https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm
sudo ls -lrt
sudo dnf install mysql80-community-release-el9-1.noarch.rpm
dnf repolist enabled | grep "mysql.*-community.*"
sudo dnf install mysql-community-server
sudo systemctl start mysqld
sudo mysql -V
sudo mysql_secure_installation
sudo mysql -uroot -p
sudo vi /etc/my.cnf ---> skip-grant-tables
sudo systemctl restart mysqld
sudo mysql_secure_installation
mysql -uroot -p
CREATE schema my_database;
Task-16:
# setup MongoDB using docker in Amazon Linux 2023 (Fedora)
sudo dnf update
sudo dnf install docker
sudo systemctl start docker
sudo systemctl enable docker
sudo docker pull mongo
mkdir ~/mongodb_data
sudo docker run -d -p 27017:27017 -v ~/mongodb_data:/data/db --name mongodb mongo
sudo docker ps
docker exec -it mongodb mongosh
db.runCommand(
{
hello: 1
}
)
Task-17:
# Install COMPOSER in AWS EC2 (Amazon Linux 2 )
sudo yum update -y
sudo amazon-linux-extras enable php8.0
sudo yum clean metadata
sudo yum install php-cli php-mbstring php-zip php-xml unzip -y
cd ~
sudo curl -sS https://getcomposer.org/installer | sudo php
sudo mv composer.phar /usr/local/bin/composer
sudo ln -s /usr/local/bin/composer /usr/bin/composer
#then you can run (optional)
sudo composer install
sudo vi composer.json
{
"require": {
"phpunit/phpunit": "^9.0"
}
}
# Alternate command
composer require aws/aws-sdk-php
Kubernetes Tasks:
# Task-1: Set Up Prometheus and Grafana in EKS
eksctl create cluster
oidc_id=$(aws eks describe-cluster --name xxxx --query "cluster.identity.oidc.issuer" --output text | cut -d '/' -f 5)
aws iam list-open-id-connect-providers | grep $oidc_id | cut -d "/" -f4
eksctl utils associate-iam-oidc-provider --cluster xxxx --approve
eksctl create iamserviceaccount \
--name ebs-csi-controller-sa \
--namespace kube-system \
--cluster my-cluster \
--attach-policy-arn arn:aws:iam::aws:policy/service-role/AmazonEBSCSIDriverPolicy \
--approve \
--role-only \
--role-name AmazonEKS_EBS_CSI_DriverRole
eksctl create addon --name aws-ebs-csi-driver --cluster my-cluster --service-account-role-arn arn:aws:iam::111122223333:role/AmazonEKS_EBS_CSI_DriverRole --force
sudo yum install openssl -y
curl https://raw.githubusercontent.com/helm/helm/master/scripts/get-helm-3 > get_helm.sh
chmod 700 get_helm.sh
./get_helm.sh
# add prometheus Helm repo
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
# add grafana Helm repo
helm repo add grafana https://grafana.github.io/helm-charts
kubectl create namespace prometheus
helm repo add prometheus-community https://prometheus-community.github.io/helm-charts
helm install prometheus prometheus-community/prometheus \
--namespace prometheus \
--set alertmanager.persistentVolume.storageClass="gp2" \
--set server.persistentVolume.storageClass="gp2"
kubectl get all -n prometheus
kubectl port-forward -n prometheus deploy/prometheus-server 8080:9090
mkdir ${HOME}/environment/grafana
cat << EoF > ${HOME}/environment/grafana/grafana.yaml
datasources:
datasources.yaml:
apiVersion: 1
datasources:
- name: Prometheus
type: prometheus
url: http://prometheus-server.prometheus.svc.cluster.local
access: proxy
isDefault: true
EoF
kubectl create namespace grafana
helm install grafana grafana/grafana \
--namespace grafana \
--set persistence.storageClassName="gp2" \
--set persistence.enabled=true \
--set adminPassword='EKS!sAWSome' \
--values ${HOME}/environment/grafana/grafana.yaml \
--set service.type=LoadBalancer
export ELB=$(kubectl get svc -n grafana grafana -o jsonpath='{.status.loadBalancer.ingress[0].hostname}')
echo "http://$ELB"
jasvfkasdf,
hsavfkdsbgksf
sajfdkg
ajfdsgsgn
sbjfdgn
kjsafakds
Note: