How to install Docker on Ubuntu

Introduction

This tutorial explains how to install Docker on Ubuntu 21.04, highlighting Docker as an efficient open platform for building, testing, and deploying applications. Docker simplifies and accelerates the deployment process, making it less time-consuming to build and test applications. The guide is ideal for anyone looking to streamline their development workflow using Docker on the Ubuntu system.

How to install Docker on Ubuntu

To install Docker on Ubuntu, you can follow these steps:

Prerequisites

  • A system running Ubuntu 21.04
  • A user account with sudo privileges

Step 1: Update your system

Update your existing packages:

sudo apt update

Step 2: Install the curl package

sudo apt install curl -y

Step 3: Download the Latest Docker Version

curl -fsSL https://get.docker.com -o get-docker.sh

Step 4: Install Docker

sh get-docker.sh

Step 5: To make sure that the current user can access the docker daemon

To avoid using sudo for docker activities, add your username to the Docker Group

sudo usermod -aG docker $USER

Step 6: Check Docker Version

To verify the installation, check the Docker version by command below:

docker --version

Uninstall Docker on Ubuntu

Check the package installed docker on Ubuntu.

dpkg -l | grep -i docker

Use the apt remove command to uninstall Docker on Ubuntu.

sudo apt-get purge docker-ce docker-ce-cli docker-ce-rootless-extras docker-scan-plugin
sudo rm -rf /var/lib/docker

Remove Software Dependencies

sudo apt autoremove

Conclusion

How to install Docker on Ubuntu 21.04. After completing these steps, Docker should be successfully installed on your Ubuntu system, and you can start using Docker commands to manage containers and images. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Exploring the fd Command in Linux: A Powerful Find Alternative for Efficient File Searches

Introduction

In this tutorial, how to use the fd command in Linux. fd command-line tool to find files in the file system. this tool is very simple.

The “fd” command is not a standard command in Linux. It seems that you might be referring to a specific command that is not part of the core Linux utilities.

What is the ‘fd’ Command?

The ‘fd’ command is a powerful and user-friendly tool that facilitates file searches within the Linux file system.

Although not a native Linux command, it is often considered a better and more intuitive alternative to the ‘find’ command. ‘fd’ is built on Rust, which contributes to its speed and efficiency.

Install fd command

Before you can start using ‘fd’, you need to install it on your Linux system. In this section, we’ll cover how to install ‘fd’ using popular package managers like ‘apt’ and ‘yum’, as well as from source.

Using apt to install fd on Ubuntu Server.

sudo apt-get install fd-find

(Optional) Create an alias for fd that refers to fdfind.

alias fd=fdfind

(Optional) To make the alias permanent.

vi ~/.bashrc
#Add this entry to the bashrc file
alias fd=fdfind

Use the fd command in Linux

Before using the fd command in Linux, we need to read the help of the command.

# fd --help

The output terminal as below

Find all files and directories starting with “abc” followed by any number of digits, you can use the following command:

fd -e "^abc\d+"

find all files that were changed before a specified number of days

$ fd index /home/vagrant --changed-before 365d

Finding Files Inside a Specific Directory

$ fd password /etc

Finding Files Based on Extension

$ fd -e html

Finding Hidden Files

$ fd -H bash

More details information about fd command.

man fd

Conclusion

fd command is a simple command in Linux. It uses the number of lines of files. These are just a few examples of how you can use the “fd” command.

For more advanced usage and options, you can refer to the documentation or help of the specific “fd” implementation you have installed on your system, as there are multiple versions available. Thank you for reading the DevopsRoles page!

Step-by-Step: Create Docker Image from a Running Container

Introduction

In this tutorial, We will deploy a container Nginx server, modify it, and then create a new image from that running container. Now, let’s go to Create Docker Image from a Running Container.

What does docker mean?

Docker is a set of platform as a service products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries, and configuration files Quota from Wikipedia

Install Docker on Ubuntu

If you don’t already have Docker installed, let’s do so. I will install Docker on Ubuntu Server. I use Ubuntu version 21.04 to install Docker.

To install Docker on Your Ubuntu server command below

sudo apt-get install docker.io -y

Add your user to the docker group with the command below

sudo usermod -aG docker $USER

Logging out and logging back in to ensure the changes take effect.

Create Docker Image from a Running Container

Create the New Container

We will create the new container with the command below:

sudo docker create --name nginx-devops -p 80:80 nginx:alpine
  • Create a new container: nginx-devops
  • Internal port ( Guest ): 80
  • External ( host ) port: 80
  • Use image: nginx:alpine

The output terminal is the picture below:

Start the Nginx container with the command below

After creating a new container, you open a Web browser and point it. You see the NGINX welcome page.

Modify the Existing Container

We will create a new index.html page for Nginx.

To do this, create a new page with the command below

vi index.html

In that file, paste the content (you can modify it to say whatever you want):

<html>
    <h2>DevopsRoles.com</h2>
</html>

Save and close the file

We copy index.html to the document root on nginx-devops container with the command below:

sudo docker cp index.html nginx-devops:/usr/share/nginx/html/index.html

you refresh the page in your web browser, you see a new welcome as the picture below:

Create a New Image

How to create a new image that includes the changes. It is very simple.

  1. We will commit the changes with the command below:
sudo docker commit nginx-devops

we will list all current images with the command below

sudo docker images

2. We will tag for docker-base-image

sudo docker tag IMAGE_ID nginx-devops-container

Where IMAGE_ID is the actual ID of your new container.

you’ll see something like this:

sudo docker images

In the output terminal step, 1 and step 2 as in the picture below

You’ve created a new Docker image from a running container.

Let’s stop and remove the original container. we will remove nginx-devops container with the command below

sudo docker ps -a
sudo docker stop ID
sudo docker rm ID

Where ID is the first four digits of the original container.

You could deploy a container from the new image with a command like:

sudo docker create --name nginx-new -p 80:80 nginx-devops-container:latest

The output terminal as the command below

vagrant@devopsroles:~$ sudo docker ps -a
CONTAINER ID   IMAGE          COMMAND                  CREATED          STATUS         PORTS                               NAMES
fe3d2e383b80   nginx:alpine   "/docker-entrypoint.…"   11 minutes ago   Up 8 minutes   0.0.0.0:80->80/tcp, :::80->80/tcp   nginx-devops
vagrant@devopsroles:~$ sudo docker stop fe3d2e383b80
fe3d2e383b80
vagrant@devopsroles:~$ sudo docker rm fe3d2e383b80
fe3d2e383b80
vagrant@devopsroles:~$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
vagrant@devopsroles:~$ sudo docker create --name nginx-new -p 80:80 nginx-devops-container:latest
91175e61375cf86fc935c55081be6f81354923564c9c0c0f4e5055ef0f590600
vagrant@devopsroles:~$ sudo docker ps -a
CONTAINER ID   IMAGE                           COMMAND                  CREATED              STATUS    PORTS     NAMES
91175e61375c   nginx-devops-container:latest   "/docker-entrypoint.…"   About a minute ago   Created             nginx-new
vagrant@devopsroles:~$ sudo docker start 91175e61375c
91175e61375c
vagrant@devopsroles:~$

What is the difference between docker commit and docker build?

docker commit creates an image from a container’s state, while docker build creating an image from a Dockerfile, allowing for a more controlled and reproducible build process.

Refresh your web browser and you should, once again, see the DevopsRoles page, New Stack! Welcome page.

YouTube: Create Docker Image from a Running Container

Conclusion

Create Docker Image from a Running Container is a powerful feature that enables you to capture the exact state of an application at any given moment. By following the steps outlined in this guide, you can easily commit a running container to a new image and use advanced techniques to add tags, commit messages, and author information. Whether you’re looking to back up your application, replicate environments, or share your work with others, this process provides a simple and effective solution. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Git Revert Commit already pushed to a remote repository

In this tutorial, How to Git Revert Commit is already pushed to a remote repository. Sometimes I recover wrong changes (commits) in a coding project.

For example, File Vagrantfile on the remote repository with the content below

I have to change the content of this file as below

How do you see the last commit?

Use the git log command to see the hash of each Git commit, the message associated with each commit, and more metadata.

git log

You can see the last commit simplify the output terminal as command below

git log --oneline

How to undo this commit?

git revert <commit hash>
  • This command will create a new commit with the “Revert” word at the beginning of the message.
  • Check your repository status
  • After this, I will be pushed to the remote repository with the git push command

I will revert to with content not comment out in file Vagrantfile

PS C:\MyData\Vagrant_VMS\Projects\Vagrant\Rocky-LEMP> git revert 850e78a
[master d0fca2b] Revert "Edit file Vagrantfile"
 1 file changed, 1 deletion(-)
PS C:\MyData\Vagrant_VMS\Projects\Vagrant\Rocky-LEMP> cat .\Vagrantfile
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "rockylinux/8"
  config.ssh.insert_key = false

  config.vbguest.auto_update = false

  config.vm.define "webserver" do |webserver|
    webserver.vm.hostname = "devopsroles.com"
    webserver.vm.network "private_network", ip: "192.168.4.4"
    webserver.vm.network "forwarded_port", guest: 80, host: 8888
    webserver.vm.provision "shell",
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-LEMP\\shell\\web-lemp-rocky.sh"

  end

end
PS C:\MyData\Vagrant_VMS\Projects\Vagrant\Rocky-LEMP> git push
Enumerating objects: 9, done.
Counting objects: 100% (9/9), done.
Delta compression using up to 16 threads
Compressing objects: 100% (5/5), done.
Writing objects: 100% (5/5), 530 bytes | 530.00 KiB/s, done.
Total 5 (delta 2), reused 0 (delta 0), pack-reused 0
To gitlab.com:huupv/project.git
   850e78a..d0fca2b  master -> master
PS C:\MyData\Vagrant_VMS\Projects\Vagrant\Rocky-LEMP>

Final, Git Revert Commit already pushed to a remote repository

Show git log command to see message Revert it.

Conclusion

You have to Git Revert Commit already pushed to a remote repository. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Vagrant install Nodejs on Rocky Linux

Introduction

Welcome to this tutorial, where we’ll guide you through the process of install Nodejs on Rocky Linux or RHEL Linux using Vagrant. Node.js is a powerful runtime that allows you to run JavaScript on the server side, making it a crucial component for various web applications and development projects. With the help of Vagrant, we’ll simplify the installation process and ensure a smooth setup on your Rocky Linux or RHEL Linux environment.

What does Nodejs mean?

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser. quote from Wikipedia.

My Setup for Installing Node.js with Vagrant

  • Host OS: Window 11
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell

The structure of the Vagrant directory and files will appear as follows:

C:\MYDATA\VAGRANT_VMS\PROJECTS\VAGRANT\ROCKY-NODEJS
│   Vagrantfile
│
├───sample-app
└───shell
        init-nodejs.sh

I created an init-nodejs.sh script to Install Node.JS from Nodesource Repositories or Install Node.JS from Rocky Linux AppStream Repositories.

The script content is as follows:

#!/bin/bash

# Update your system
sudo yum update -y
#Tools
sudo dnf install -y git unzip net-tools

# Install Node.JS from Rocky Linux AppStream Repositories
#sudo dnf module list nodejs -y 
#sudo dnf module install nodejs:14
#sudo dnf install nodejs
#node -v
#npm -v

# Install Node.JS from Nodesource Repositories
# curl -fsSL https://deb.nodesource.com/setup_16.x | sudo -E bash -   # For ubuntu Server
curl -sL https://rpm.nodesource.com/setup_16.x | sudo bash -
sudo dnf install nodejs -y 
# Check version
node -v
npm -v


echo "##########################"
echo "Run npm install and then run app..."
echo "##########################"
#mkdir sample-app
#cd sample-app
#sudo npm install
#sudo forever start server.js


echo "##########################"
echo "Success! Navigate to localhost..."
echo "##########################"

Set Up a Virtual Machine

Navigate to my working directory

cd Rocky-Nodejs
vagrant init rockylinux/8

Configure the Virtual Machine

Edit the Vagrantfile and paste the content below

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "rockylinux/8"
  config.ssh.insert_key = false  

  config.vbguest.auto_update = false
  # Uncomment this if you want to link to a shared folder (e.g. if you are running source control and want to link it to Vagrant)
  config.vm.synced_folder "./sample-app", "/home/vagrant/sample-app", create: true, group: "vagrant", owner: "vagrant"
  
  config.vm.define "nodeserver" do |nodeserver|
    nodeserver.vm.hostname = "devopsroles.com"
    nodeserver.vm.network "private_network", ip: "192.168.4.4"
    nodeserver.vm.network "forwarded_port", guest: 3000, host: 3000
    nodeserver.vm.provision "shell", 
      path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-Nodejs\\shell\\init-nodejs.sh"

  end

end

Use Vagrant install Nodejs on Rocky Linux

vagrant up

To connect to Node Server.

vagrant ssh nodeserver

The output terminal is below

Check the Nodejs version that you have installed with the help of the following picture.

After you don’t use it, You delete Node Server.

Conclusion

To install Node.js on Rocky Linux, utilize Vagrant. I hope you find this information helpful. Thank you for visiting the DevopsRoles page!

A Step-by-Step Guide Vagrant install Redis server

Introduction

In this tutorial, How to use Vagrant install Redis server. Vagrant, a powerful open-source tool, allows developers to create and manage lightweight, reproducible, and portable virtual machines effortlessly.

My Environment for Vagrant install Redis server

  • Host OS: Windows 11
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell
  • Installed VirtualBox

The vagrant directory and files will look like as below:

C:\MYDATA\VAGRANT_VMS\PROJECTS\VAGRANT\ROCKY-REDIS
│   Vagrantfile
│
├───conf
│       redis.conf
│
└───shell
        init-redis.sh

I created an “init-redis.sh” script to install Redis Server on Rocky Linux. I use the provisioning shell of Vagrant to deploy Redis Server on Rocky Linux.

The content script is as below:

#!/bin/bash

# Install Redis
sudo dnf install -y git unzip net-tools
sudo dnf module install redis -y

sudo sysctl vm.overcommit_memory=1
echo never > sudo  /sys/kernel/mm/transparent_hugepage/enabled

#Configure Redis
sudo cp /etc/redis.conf /etc/redis.conf.orig
sudo cp /vagrant/conf/redis.conf /etc/redis.conf

sudo systemctl start redis
sudo systemctl enable redis
sudo systemctl status redis

For example, the File “redis.conf” configures Redis Server as below:

bind 0.0.0.0
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile /var/log/redis/redis.log
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
requirepass devosroles.com

Create a Virtual Machine

I will navigate to my working directory. For example, the “Rocky-Redis” folder and create initialized Vagrantfile vagrant as the command below.

cd Rocky-Redis
vagrant init rockylinux/8

Configure the Virtual Machine

Edit the Vagrantfile and paste the content below

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "rockylinux/8"
  config.ssh.insert_key = false  

  config.vbguest.auto_update = false
  
  config.vm.define "redisserver" do |redisserver|
    redisserver.vm.hostname = "devopsroles.com"
    redisserver.vm.network "private_network", ip: "192.168.4.4"
    redisserver.vm.network "forwarded_port", guest: 6379, host: 6379
    redisserver.vm.provision "shell", 
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-Redis\\shell\\init-redis.sh"

  end

end

Deploy Redis Server on Rocky Linux

Use the command below to create and configures guest machines according to your Vagrantfile.

vagrant up

Finally, we will connect to the Redis server.

vagrant ssh redisserver

The output terminal as below

Conclusion

You’ve successfully installed the Redis server on a virtual machine using Vagrant. With this setup, you can now develop and test your Redis-dependent applications in an isolated and portable environment.

Vagrant’s ease of use and versatility make it an invaluable tool for any developer’s toolkit. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Vagrant LEMP stack: A Comprehensive Guide from Basic to Advanced

Introduction

In this tutorial, I wrote deploy Vagrant LEMP stack. I will install and configure the LEMP stack for this web application.

Vagrant is a powerful tool for managing virtual development environments, and the LEMP stack (Linux, Nginx, MySQL, PHP) is a popular choice for web developers due to its performance and flexibility. Combining Vagrant with a LEMP stack allows developers to create a consistent and reproducible environment, making development and collaboration more efficient.

What does lemp stand for?

Linux operating system, and Nginx (pronounced engine-x, hence the E in the acronym) webserver. MySQL database and dynamic content processed by PHP.

My Environment for Vagrant LEMP stack

  • Host OS: Window 11
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell

Vagrant directory and files will look like as below:

C:\MYDATA\VAGRANT_VMS\PROJECTS\VAGRANT\ROCKY-LEMP
│   Vagrantfile
│
├───Files

│       index.html
│       info.php
│
└───shell

        web-lemp-rocky.sh

Files Folder contains test Nginx and PHP with index.html and info.php files.

The content index.html and info.php files

# index.html file

<html>
    <h2>DevopsRoles.com</h2>
</html>

# info.php file

<?php
phpinfo();
?>

I created a web-lemp-rocky.sh script to install Nginx, MySQL, and PHP on Rocky Linux. I use the provisioning shell of Vagrant to deploy LEMP on Rocky Linux.

The content script is as below:

#!/bin/bash


#Tools
sudo dnf install -y git unzip net-tools

#Apache
sudo dnf install -y nginx

#chkconfig --add nginx
sudo systemctl enable nginx
sudo systemctl stop nginx

sudo systemctl start nginx

#PHP
sudo dnf install php php-fpm php-gd php-mysqlnd php-cli php-opcache
sudo systemctl enable php-fpm
sudo systemctl start php-fpm

#MySQL
sudo dnf install -y mysql mysql-server mysql-devel
sudo systemctl enable mysqld.service
sudo systemctl start mysqld

mysql -u root -e "SHOW DATABASES";

# content
# sudo rm -rf /var/www/html/*
sudo cp -rf /vagrant/Files/{index.html,info.php} /usr/share/nginx/html/
# cd /vagrant
#sudo -u vagrant wget -q https://raw.git.....

sudo systemctl restart nginx

Create a Virtual Machine

Navigate to my working directory

cd Rocky-LEMP
vagrant init rockylinux/8

Configure the Virtual Machine

Edit the Vagrantfile and paste the content below

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "rockylinux/8"
  config.ssh.insert_key = false  

  config.vbguest.auto_update = false
  
  config.vm.define "webserver" do |webserver|
    webserver.vm.hostname = "devopsroles.com"
    webserver.vm.network "private_network", ip: "192.168.4.4"
    webserver.vm.network "forwarded_port", guest: 80, host: 8888
    webserver.vm.provision "shell", 
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\Rocky-LEMP\\shell\\web-lemp-rocky.sh"

  end

end

Deploy LEMP on Rocky Linux

vagrant up

To connect to Web Server.

vagrant ssh webserver

The output terminal is below

Opens a browser that can access your Server’s IP address.

Testing PHP

FAQs

What is Vagrant used for?

Vagrant is used for creating and managing virtual development environments, allowing developers to work in a consistent and isolated environment.

Why choose the LEMP stack over LAMP?

The LEMP stack uses Nginx instead of Apache, offering better performance and scalability for handling high-traffic websites.

How do I access the Vagrant VM’s web server?

You can access it using the IP address assigned to the VM or using a private network setup.

Can I use a different operating system for the Vagrant box?

Yes, Vagrant supports various operating systems, and you can specify a different box in the Vagrantfile.

Conclusion

Setting up a Vagrant LEMP stack is a powerful way to streamline your development process. By following this guide, you can create a consistent, isolated, and easily reproducible environment for your web development projects. Whether you’re a beginner or looking to implement advanced configurations, Vagrant provides the flexibility and control needed to optimize your workflow.

You have to use the Vagrant LEMP stack on Rocky Linux. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Run Multiple Ansible Versions using Python 3 Virtual Environments

#Introduction

In this tutorial, How to Run Multiple Ansible Versions using Python 3 Virtual Environments. You can install multiple versions for Ansible

The benefits of using a virtual environment run Multiple Ansible Versions

  • Each project its isolated environment and modules
  • The base system is not affected
  • Does not require root access as virtual environments

Install Python 3

CentOS 7

sudo yum -y install epel-release
sudo yum -y install python36 python36-pip

Ubuntu

Check the python version

python3 --version

If python is not installed by default, you can install it

sudo apt install python3.9 python3.9-venv

check the python version.

python3 -V

The output terminal is as below:

vagrant@devopsroles:~$ python3 -V
Python 3.9.5

Create Virtual Environments

First, we will need to create a folder that we’ll use to store the virtual environments. You do not create inside your project folder.

mkdir ~/python-environment

For example, I create two environments for different versions of Ansible using venv modules

cd ~/python-environment
python3.9 -m venv ansible2.7.0
python3.9 -m venv ansible2.8.0

The output terminal as below

Activate an environment ansible version 2.7.0

source ansible2.7.0/bin/activate

Use pip install ansible 2.7.0

pip install --upgrade pip setuptools
pip install ansible==2.7.0
ansible --version

The output terminal as below

List of Python packages that have been installed in this environment

pip list

deactivate the environment

deactivate

The output terminal as below

Set up the second environment for ansible version 2.8.0

cd ~/python-environment
source ansible2.8.0/bin/activate
pip install --upgrade pip setuptools
pip install ansible==2.8.0
ansible --version
pip list
deactivate

You have the environments set up and use pip to install any packages without risk the base system packages.

Conclusion

You have Run Multiple Ansible Versions using Python 3 Virtual Environments. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Docker deploy a Bitwarden server

#Introduction

In this tutorial, How to deploy an in-house password manager server.

Bitwarden is an integrated open source password management solution for individuals, teams, and business organizations.

Install Docker on Ubuntu

sudo apt install apt-transport-https ca-certificates curl gnupg-agent software-properties-common -y
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt update
sudo apt install docker-ce docker-compose

Obtain Bitwarden’s Installation key and ID

you via Bitwarden page get key and ID as the picture below

The display picture as below as below

Create the Bitwarden user

sudo mkdir /opt/bituser
sudo adduser bituser
sudo chmod -R 700 /opt/bituser
sudo chown -R bituser:bituser /opt/bituser
sudo usermod -aG docker bituser

Change to the Bitwarden user with the command below

su bituser
cd
pwd

Download the script and deploy Bitwarden

Download the script with the command below

curl -Lso bitwarden.sh https://go.btwrdn.co/bw-sh && chmod 700 bitwarden.sh

Bitwarden use on port 80, If you start apache/Nginx then stop it.

sudo systemctl stop apache2
# Redhat
sudo systemctl stop httpd
# Stop Nginx
sudo systemctl stop nginx

Installer Bitwarden

./bitwarden.sh install

The output terminal as below

Finally, we need to configure the SMTP server that Bitwarden will use it.

After installing Bitwarden, open the configuration file with:

nano /home/bituser/bwdata/env/global.override.env

You will replace every REPLACE with your SMTP Server.

globalSettings__mail__smtp__host=REPLACE
globalSettings__mail__smtp__port=REPLACE
globalSettings__mail__smtp__ssl=REPLACE
globalSettings__mail__smtp__username=REPLACE
globalSettings__mail__smtp__password=REPLACE
adminSettings__admins= ADMIN_EMAIL

Start the Bitwarden server.

./bitwarden.sh start

Access your Bitwarden server

Open a web browser and point it to https://SERVER

The display picture as below as below

Note: Create a new account to login into Bitwarden

Conclusion

You have to deploy a Bitwarden server. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Vagrant multiple servers

Introduction

In this tutorial, How to deploy multiple servers using Vagrant. I will deploy LAMP multiple servers. I create more VMs, each VM can have its own and different configuration.

My Environment

  • Host OS: Window 11
  • Vagrant version: 2.2.18
  • Vagrant provider: VirtualBox
  • Boxes Vagrant: rockylinux/8
  • Terminal/PowerShell

LAMP server architecture

Vagrant directory and files will look like as below:

C:\MYDATA\VAGRANT_VMS\PROJECTS\VAGRANT\VM-MULTI-SERVER
│   Vagrantfile

│
└───shell
        common-rocky.sh
        database-rocky.sh
        web-rocky.sh

I created common-rocky.sh script to deploy the common packages as below

#!/bin/bash

#Update OS
# sudo yum update -y --exclude=kernel

#Tools
sudo yum install -y git unzip nc telnet

web-rocky.sh script to install the package Apache, PHP as below

#!/bin/bash

#Apache
sudo dnf install -y httpd httpd-devel httpd-tools

#chkconfig --add httpd
sudo systemctl enable httpd.service
sudo systemctl stop httpd

sudo systemctl start httpd

#PHP
sudo dnf install -y php php-cli php-gd php-curl php-zip php-mbstring php-opcache php-intl php-mysqlnd

database-rocky.sh script to install MySQL server as below

#!/bin/bash

#MySQL
sudo yum install -y mysql mysql-server mysql-devel
sudo systemctl enable mysqld.service
sudo systemctl start mysqld

mysql -u root -e "SHOW DATABASES";

Create a Virtual Machine

Navigate to my working directory

cd Rocky-LAMP
vagrant init rockylinux/8

Configure the Virtual Machine

Edit the Vagrantfile and paste the content below

# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure("2") do |config|

  config.vm.box = "rockylinux/8"
  config.ssh.insert_key = false  
  config.vm.provision "shell", 
   path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\VM-multi-server\\shell\\common-rocky.sh"

  config.vbguest.auto_update = false
  
  config.vm.define "webserver" do |webserver|
    webserver.vm.hostname = "devopsroles.com"
    webserver.vm.network "private_network", ip: "192.168.4.4"
    webserver.vm.network "forwarded_port", guest: 80, host: 8888
    webserver.vm.provision "shell", 
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\VM-multi-server\\shell\\web-rocky.sh"

  end

  config.vm.define "databases" do |databases|
    databases.vm.hostname = "database-server"
    databases.vm.network "private_network", ip: "192.168.4.5"
    databases.vm.provision "shell", 
     path: "C:\\MyData\\Vagrant_VMS\\Projects\\Vagrant\\VM-multi-server\\shell\\database-rocky.sh"

  end

end

Deploy LAMP on Rocky Linux

vagrant up

To connect to Web Server.

vagrant ssh webserver

To connect to the database server.

vagrant ssh databases

Opens a browser that can access your Server’s IP address

Conclusion

You have to use Vagrant to install LAMP for multiple servers. I hope will this your helpful. Thank you for reading the DevopsRoles page!

Devops Tutorial

Exit mobile version