Posts

How To Reset Root Password in CentOS 7

Image
  In the boot grub menu select option to edit (Hit Enter or Shift key to enter Grub menu). Grub Menu select option to edit 2 — Select Option to edit (Press e for edit). Change in line no 16(may vary system to system) replace ro 3 — Go to the line of Linux 16 and change ro with rw init=/sysroot/bin/sh. And more than one tty console available then remove extra tty console exept One. 4 — Now press Control+x to start on single user mode. Go to Single user mode 5 — Now access the system with this command. mount –o remount,rw /sysroot chroot /sysroot 6 — Reset the password. passwd root 7 – Update selinux information touch /.autorelabel 8 — Exit chroot exit 9 — Reboot your system reboot That’s it. Enjoy.

How to set Grub Password in UBUNTU 18.03 (Password protect Boot Loader)

Image
  First, open a terminal from Ubuntu’s applications menu Take backup of two files :  cp /etc/grub.d/40_custom /etc/grub.d/40_custom.old and  cp /boot/grub/menu.lst /boot/grub/menu.lst.bkp Generating a Password Hash :  Just type  grub-mkpasswd-pbkdf2  and press Enter Generating a Password Hash 4.  Setting a Password:  Type  sudo vi /etc/grub.d/40_custom  to open the 40_custom file in the Nano text editor. This is the place where you should put your own custom settings. They may be overwritten by newer versions of Grub if you add them elsewhere. Save password in /etc/grub.d/40_custom scroll down to the bottom of the file and add a password entry in the following format: set superusers=”name” password_pbkdf2 <superusers_name>[long string from earlier] password Entry in /etc/grub.d/40_custom file 5. Open /boot/grub/menu.lst file and follow the below steps a. Generate md5 password :  echo -n <password> | md5sum b. Ope...

THE ULTIMATE DOCKER CHEAT SHEET

  1. RUN a CONTAINER (I) Start new container from an image:  docker run IMAGE_NAME (II) And assign it a name:  docker run --name CONTAINER _NAME IMAGE_NAME (III) To map a port:  docker run -p HOST_PORT:CONTAINER_PORT IMAGE (IV) To MAP all port:  docker run -P IMAGE_NAME (V) And Start a Container in background:  docker run -d IMAGE_NAME (VI) And Assign it a HOST NAME:  docker run --hostname HOSTNAME IMAGE_NAME (VII) And add a DNS entry or HOST entry in /etc/hosts file:  docker run  --add-host  HOSTNAME:IP IMAGE (VIII) And map a local directory (volume) to a container:  docker run -v HOST_DIR:TARGET_DIR IMAGE_NAME (IX)   ALL IN ONE Example :  docker run --name my_container -p 80:80 -v /home/data/:/var/www/html/--add-host test.ac.in:10.246.10.6 --hostname nginx_host -d nginx 2. MANAGE CONTAINERS (I) Show List of all running containers :  docker ps (II) Show List of all running and stop containers :  docker p...

ADVANCED DOCKER COMMAND CHEAT SHEET

  Remove all images : docker rmi $(docker images -q) Remove all running containers: docker rm -f $(docker ps -q) Remove all Containers: docker rm -f $(dcoker ps -aq) Remove all dangling (unused) container and images: docker system prune -a Create volume : docker volume create List volume: docker volume ls Remove Volume: docker volume rm Inspect Volume: docker volume inspect Remove Stop Containers: docker rm $(docker ps -q -f “status=exited”) Push an image to a registry: docker push [registry]/[username]/<image-name>:[tag] Run a detached container in a previously created container network: $ docker network create mynetwork & $ docker run — name mywildfly-net -d — net mynetwork \ -p 8080:8080 jboss/wildfly Push an image to a registry: docker push [registry]/[username]/<image-name>:[tag] Build Image with diffrent dockerfile name: docker build -t test -f DockerfileTest .

Backup/Restore a Dockerized PostgreSQL Database

  Enter in PostgreSQL container and View database list: docker exec -it <container-id> psql -W -U db_user DB_name  (IF DB_USER_NAME and DB_NAME is not same) docker exec -it <container-id> psql -U postgres  (If DB_USER_NAME and DB_NMAE is same as postgres) To list database : \l To use database: \c <database-name> To list tables: \d Now Exit from PostgreSQL: \q Backup Your Database: a. Command to backup a local or remote PostgreSQL database: docker exec -i <PostgreSQL-container-id> pg_dump -U postgres -d <database-name> > prod_db_dump_`date +%d-%m-%Y”_”%H_%M_%S`.sql  (Ask for postgres password) or echo -n "password" | docker exec -i 323f6ab197b1 pg_dump -U dbuser -d db_name > /home/prod_db_dump_`date +%d-%m-%Y”_”%H_%M_%S`.sql  (Never Ask for Password) b. Command to backup multiple PostgreSQL databases : docker exec -i <PostgreSQL-container-id> pg_dumpall -U postgres -d <database-name> > prod_db_dump_`date ...

Script to take Last 7 Days containerized PostgreSQL Database Backup

  Create a directory script and create script.sh file : mkdir -p /home/script vi /home/script/script.sh C opy below script: #!/bin/sh #For taking backup # create dir db_backup: mkdir -p /home/db_backup/ DIR=/home/db_backup/ DATESTAMP=$(date +%d-%m-%y-%H-%M) # remove backups older than $DAYS_KEEP DAYS_KEEP=7 find ${DIR}* -mtime +$DAYS_KEEP -exec rm -f {} \; 2> /dev/null # Find Container ID where PostgreSQL is running with ancestor=<image name with tag> CONTAINER_ID=$(docker ps -q --filter ancestor=postgres:10.1) # DATABBASE name want to take backup DB=middleware_production_db # Destination Path FILENAME=${DIR}${DB}-${DATESTAMP}.sql #echo $FILENAME #echo $CONTAINER_ID docker exec -t ${CONTAINER_ID} pg_dump -U postgres -d ${DB} > ${FILENAME} SET CRON JOB FOR THIS SCRIPT Edit Cron job: crontab -e Copy the fol l owing command: 0 8 * * * bash -l /home/script/script.sh

SCRIPT TO TAKE MYSQL DATABASE BACKUP FOR LAST 7 DAYS

  a. create a directory for database backup   and script:      mkdir /home1/db_backup b.  Create Directory and file:      mkdir /home1/script      cd /home1/script      touch dbbackup.sh c. Login to MYSQL console and run below commands     To Create read only  user: GRANT LOCK TABLES, SELECT ON *.* TO 'backup'@'localhost' IDENTIFIED BY 'readonly'; flush privileges; d. vi dbbackup.sh Copy Below Script #!/bin/sh #For taking backup DIR=/home/db_backup/ DATESTAMP=$(date +%d-%m-%y-%H-%M) DB_USER=backup DB_PASS='readonly' HOST=localhost # remove backups older than $DAYS_KEEP DAYS_KEEP=7 find ${DIR}* -mtime +$DAYS_KEEP -exec rm -f {} \; 2> /dev/null # create backups securely umask 006 # list MySQL databases and dump each DB_LIST=`mysql -h $HOST -u $DB_USER -p"$DB_PASS" -e'show databases;'` DB_LIST=${DB_LIST##Database} for DB in $DB_LIST; do FILENAME=${DIR}${DB}-${DATESTAMP}.sql.gz mysqldump -h ...