Python : Print() method
Day 1-
Hi, Everyone
Today I learned about the print() method
Print () is the simplest used to display a string or a number. Here are some basic examples:
print("Hello world")
Day 1-
Hi, Everyone
Today I learned about the print() method
Print () is the simplest used to display a string or a number. Here are some basic examples:
print("Hello world")
$ vim user_input.py
roll_num = int(input("Enter your roll no.:"))
message = "Hello user your roll number is " + str(roll_num)
print(message)
:x
or
$ vim user_input.py
roll_num = int(input("Enter your roll no.:"))
print("Hello user your roll number is " + str(roll_num))
:x
$ python user_input.py
$ vim user_input.py
username = input("Enter username:")
print(username + " welcome to python")
:x
$ python user_input.py
syntax:
print(object(s), sep=separator, end=end, file=file, flush=flush)
$ print("Hello, Python!")
$ print('Hello, World!')
$ print("Hello","Dhana")
$ vim print.py
x = ("python", "php", "c", "c++")
print(x)
:x
$ python print.py
create directory postgres and navigate
$ mkdir postgres && cdβpostgres
create main.tf file
$ vim main.tf
provider "aws" {
}
resource "aws_security_group" "rds_sg" {
name = "rds_sg"
ingress {
from_port = 5432
to_port = 5432
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_db_instance" "myinstance" {
engine = "postgres"
identifier = "myrdsinstance"
allocated_storage = 20
engine_version = "14"
instance_class = "db.t3.micro"
username = "myrdsuser"
password = "myrdspassword"
parameter_group_name = "default.postgres14"
vpc_security_group_ids = ["${aws_security_group.rds_sg.id}"]
skip_final_snapshot = true
publicly_accessible = true
}
output "rds_endpoint" {
value = "${aws_db_instance.myinstance.endpoint}"
}
save and exit
$ terraform init
$ terraform plan
$ terraform apply -auto-approve
Install postgres client in local machine
$ sudo apt install -y postgresql-client
To access AWS postgresql RDS instance
$ psql -h <end_point_URL> βp=5432 βusername=myrdsuser βpassword βdbname=mydb
To destroy postgresql RDS instance
$ terraform destroy -auto-approve
create directory mysql and navigate
$ mkdir mysql && cdβmysql
create main.tf
$ vim main.tf
provider "aws" {
}
resource "aws_security_group" "rds_sg" {
name = "rds_sg"
ingress {
from_port = 3306
to_port = 3306
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_db_instance" "myinstance" {
engine = "mysql"
identifier = "myrdsinstance"
allocated_storage = 20
engine_version = "5.7"
instance_class = "db.t2.micro"
username = "myrdsuser"
password = "myrdspassword"
parameter_group_name = "default.mysql5.7"
vpc_security_group_ids = ["${aws_security_group.rds_sg.id}"]
skip_final_snapshot = true
publicly_accessible = true
}
output "rds_endpoint" {
value = "${aws_db_instance.myinstance.endpoint}"
}
save and exit
$ terraform init
$ terraform plan
$ terraform apply -auto-approve
install mysql client in local host
$ sudo apt install mysql-client
To access the mysql
$ mysql -h <end_point_URL> -P 3306 -u <username> -p
To destroy the mysql RDS instance
$ terraform destroy -auto-approve
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
bucket = "kaniyam-bucket"
acl = "private"
control_object_ownership = true
object_ownership = "ObjectWriter"
versioning = {
enabled = true
}
}
provider "aws" {
region = "ap-south-1"
}
resource "aws_s3_bucket" "example" {
bucket = "example-my"
}
resource "aws_s3_bucket_ownership_controls" "ownership" {
bucket = aws_s3_bucket.example.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_public_access_block" "pb" {
bucket = aws_s3_bucket.example.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_acl" "acl" {
depends_on = [aws_s3_bucket_ownership_controls.ownership]
bucket = aws_s3_bucket.example.id
acl = "private"
}
create directory s3-demo and navigate
$ mkdir s3-demo && cd s3-demo
create a demo file sample.txt andβcontents
$ echo βthis is sample object to store in demo-bucketβ > sample.txt
create main.tf file
$ vim main.tf
provider "aws" {
region = "ap-south-1"
}
resource "aws_s3_bucket" "example" {
bucket = "mydemo-bucket1"
}
resource "aws_s3_object" "object" {
bucket = aws_s3_bucket.example.bucket
key = "sample.txt"
source = "./sample.txt"
}
save and exit
$ terraform init
$ terraform plan
$ terraform apply -auto-approve
create directory s3 and navigate to the directory
$ mkdir s3 && cd s3
create main.tf file
$ vim main.tf
provider "aws" {
region = "ap-south-1"
}
resource "aws_s3_bucket" "my_bucket" {
bucket = "mydemo-bucket"
}
save and exit
$ terraform init
$ terraform plan
$ terraform apply -auto-approve
To destroy the bucket
$ terraform destroy -auto-approve
Install AWS CLI
$ sudo apt install awscli -y
To check for the version
$ aws βversion
To configure AWS account crdentials
copy the access and secret key from AWS account security credentials
$ aws configure
AWS Access Key ID [None]: *****************Β
AWS Secret Access Key [None]: ******************
Default region name [None]: ap-south-1
Default output format [None]: json or table or text
create directory ec2 and navigate to the directory
$ mkdir ec2 && cd ec2
create main.tf file
$ vim main.tf
provider "aws" {
region = "ap-south-1"
}
resource "aws_instance" "app_server" {
ami = "ami-03f4878755434977f"
instance_type = "t2.nano"
subnet_id = "subnet-0ccba3b8cfd0645e2"
key_name = "awskey"
associate_public_ip_address = "true"
tags = {
Name = "demo-server"
}
}
output "public_ip" {
description = "public ip of the instance"
value = aws_instance.app_server.public_ip
}
save and exit
initialize the terraform
$ terraform init
$ terraform plan
$ terraform apply -auto-approve
it will create the AWS EC2 instance with output the public ip of the instance
To destroy the instance
$ terraform destroy -auto-approve
Method1: Package manager
$ wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg βdearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
$ echo βdeb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) mainβ | sudo tee /etc/apt/sources.list.d/hashicorp.list
$ sudo apt update && sudo apt install terraform
$ terraform version
To get help options
$ terraform -h
Method2: Binary download
download the binary from wget https://developer.hashicorp.com/terraform/downloads
$ wget https://releases.hashicorp.com/terraform/1.6.6/terraform_1.6.6_linux_amd64.zip
extract using unzip
$ unzip terraform_1.6.6_linux_amd64.zip
$ mv terraform /usr/local/bin/
$ terraform version
$ terraform -h
To remove terraform binary method
$ sudo rm -f /usr/local/bin/terraform
To remove terraform package manager method
$ sudo apt remove terraform --purge
Β
step1: create EC2 instance step2: Create an IAM Role and attach it to EC2 instance IAM EC2 VPC CloudFormation Administrative access In the EC2 instance install kubectl and eksctl step3: install kubectl $ curl -LO "https://dl.k8s.io/release/$(curl -L -s https://dl.k8s.io/release/stable.txt)/bin/linux/amd64/kubectl" $ chmod +x ./kubectl $ sudo mv ./kubectl /usr/local/bin $ kubectl version --client step4: install eksctl $ 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 version step5: install aws-iam-authenticator $ curl -Lo aws-iam-authenticator https://github.com/kubernetes-sigs/aws-iam-authenticator/releases/download/v0.6.14/aws-iam-authenticator_0.6.14_linux_amd64 $ chmod +x ./aws-iam-authenticator $ mkdir -p $HOME/bin && cp ./aws-iam-authenticator $HOME/bin/aws-iam-authenticator && export PATH=$HOME/bin:$PATH $ echo 'export PATH=$HOME/bin:$PATH' >> ~/.bashrc step6: create clusters and nodes $ eksctl create cluster --name dhana-cluster --region ap-south-1 --node-type t2.small step7: Validate your cluster using by creating by checking nodes and by creating a pod $ kubectl get nodes $ kubectl run pod tomcat --image=tomcatΒ $ kubectl run pod nginx --image=nginx To delete the cluster dhana-cluster $ eksctl delete cluster dhana-cluster --region ap-south-1
To create postgres DB
$ aws rds create-db-instance --db-instance-identifier demo-postgresql --db-instance-class db.t3.micro --engine postgres --master-username postgres --master-user-password passcode123 --allocated-storage 20
To describe and get the endpoint url
$ aws rds describe-db-instances --db-instance-identifier demo-postgresql | grep Address
To access the remote postgresql
$ psql --host=<endpoint_url> --port=5432 --username=postgres
--dbname=postgres --password
To delete the db instance without final snapshot and automated backups
$ aws rds delete-db-instance --db-instance-identifier demo-postgresql
--skip-final-snapshot --delete-automated-backups
To create a mysql db
$ aws rds create-db-instance --db-instance-identifier demo-mysql --db-instance-class db.t3.micro --engine mysql --master-username admin --master-user-password passcode123 --allocated-storage 20
To describe and get the endpoint url
$ aws rds describe-db-instances --db-instance-identifier demo-mysql | grep Address
To access the remote mysql DB
$ mysql -h <endpoint_url> -P 3306 -u admin -p
To delete the db instance without final snapshot and automated backups
$ aws rds delete-db-instance --db-instance-identifier demo-mysql --skip-final-snapshot --delete-automated-backups
choose the EBS volume and click modify
give the desired size to extend the volume
in Linux terminal umount the volume
$ sudo umount /data
Β (where the ebs volume is mounted)
$ sudo e2fsck -f /dev/xvdf
$ sudo resize2fs /dev/xvdf
mount the volume again
$ sudo mount -a
$ df -Th
To start a new session
# tmux new -s zha
To login to a tmux session
# tmux a -t zha
or
# tmux attach-session -t zha
# tmux kill-session -t zha
or
# tmux kill-session -t 1
# tmux detach
# tmux attach
update the server
# apt update
install necessary packages
# apt-get install apache2 mariadb-server php libapache2-mod-php php-mail php-mail-mime php-mysql php-gd php-common php-pear php-db php-mbstring php-xml php-curl unzip wget -y
check the php version
# php -v
view versions of FreeRADIUS available
# apt policy freeradius
install freeradius
# apt -y install freeradius freeradius-mysql freeradius-utils
stop the freeradius service
# systemctl stop freeradius.service
To run FreeRADIUS debug mode
# freeradius -X
login to mariadb and create DB , DB user and password
# mysql -u root
> CREATE DATABASE radius;
> GRANT ALL ON radius.* TO radius@localhost IDENTIFIED BY "PASSWORD";
> FLUSH PRIVILEGES;
> QUIT;
check the DB created
# mysql -u root -p -e "show databases;"
download the daloradius webGUI package from github
# wget https://github.com/lirantal/daloradius/archive/refs/tags/1.3.zip
extract the package
# unzip 1.3.zip
rename the folder
mv daloradius-1.3/ daloradius
To populate the database with the daloRADIUS schema. The .sql file is located in the β/contrib/db/β folder.
we might have to change this path if you didnβt install it in the root destination.
# mysql -u root -p radius < contrib/db/fr2-mysql-daloradius-and-freeradius.sql
# mysql -u root -p radius < contrib/db/mysql-daloradius.sql
move the daloradius folder to /var/www/html
# mv daloradius /var/www/html/
rename the daloradius.conf.php.sample to daloradius.conf.php
# mv /var/www/html/daloradius/library/daloradius.conf.php.sample /var/www/html/daloradius/library/daloradius.conf.php
assign ownership of the daloRADIUS web configuration files to Apache
# chown -R www-data:www-data /var/www/html/daloradius/
configure the permissions of main configuration file to 664
# chmod 664 /var/www/html/daloradius/library/daloradius.conf.php
To allow the DaloRADIUS web interface to access FreeRADIUS,
to provide its database details in the configuration file for DaloRADIUS
add the database details(username, password and db name)
in the below file
# vim /var/www/html/daloradius/library/daloradius.conf.php
$configValues['CONFIG_DB_USER'] = 'radius';
$configValues['CONFIG_DB_PASS'] = 'PASSWORD';
$configValues['CONFIG_DB_NAME'] = 'radius';
:wq! save and exit
restart the freeradius and apache2 and check the status
# systemctl restart freeradius
# systemctl restart apache2
# systemctl status freeradius
# systemctl status apache2
access the daloradius
http://ip-address/daloradius/login.php
default username : administrator
default password : radius
To change the default password
config > operators > list operators > administrator > operator password and apply