Thursday, 13 October 2022

Docker and kubernetes


Docker Containerization



Containerization is a lightweight virtualization technology alternative to hypervisor virtualization.
any application can be bundled in a container that can run without any worries about dependencies, Libraries, and binaries.
containers are designed to run on any physical server, virtual machine, and cloud instance.


Virtualization Vs Containerization



Virtualization technology allows us to have multiple operating systems to share a single hardware processor.

Containerization is application-specific virtualization, because it provides applications with dedicated environments in the form of containers to run on, which can be deployed and run anywhere without a dedicated virtual machine with the operating system for each application.

also, the container was designed to solve modern problems and application management issues. so it is not a replacement for virtualization, but it is complementary to it.


Advantages of Containerization




Containers are isolated, don't require an operating system, and share a host kernel. so containers run on the same server and use the same resource. they do not interact with each other because its isolated, if one application crashes, other containers with the same application will keep running without any issues.

It's a portable and lightweight operating system and it contains only the required binaries, dependencies, and libraries to run the application. so it can be moved anywhere easily and run without worrying about compatibility, or dependencies kind of issue.

faster and resource efficient it's very fast to boot because containers are lightweight and start in less than a second since they do not require an operating system boot.

improving scalability and lower costs by allowing more containers in the environment without the need for more servers, containerization increases scalability anywhere from 10 to 100 times that of traditional VM environments.


Introduction to Docker - What is Docker on Containers






Docker is an open-source platform tool designed to manage containers, which allows us to build the application in a container with required libraries, binaries, and dependencies to run the application, ship the contained, and run it anywhere.


                      Docker Architecture and Components



 

     Docker Installation


A few quick notes about Docker:docker-installation-on-ubuntu-article

Multiple containers run on the same hardware

Maintains isolated applications

Enables high productivity

Quick and easy to configure

Before learning about this technology, the first step is to install it. In this article, you’ll learn how to install Docker on Ubuntu. 


Ubuntu:

#sudo apt-get update
#sudo apt-get install docker.io

Verify the docker version 

#docker -v
#lsb_release -a

CentOS/RHEL:

#sudo yum -y install docker
#sudo systemctl start docker;sudo systemctl enable docker

verify the docker version
#docker -v
 
       Open the terminal on Ubuntu.

 

                       sudo apt-get install docker.io


docker -v

sudo systemctl status docker




1, Install all the dependency packages using the following command:

    $ sudo snap install docker

2, Before testing Docker, check the version installed using the following command:

   $ docker --version

3, Pull an image from the Docker hub using the following command:

   $ sudo docker run httpd

      Here, httpd is the docker image present on the Docker hub.

4, Check if the docker image has been pulled and is present in your system using the following  cmd              
    $sudo docker images

5, To display all the containers pulled, use the following command:

   $ sudo docker ps -a

6, To check for containers in a running state, use the following command:

   $ sudo docker ps

    You’ve just successfully installed Docker on Ubuntu!

Necessary comment to operate docker.

sudo docker search httpd

sudo docker pull httpd

sudo docker pull docker.io/exasol/nagios-monitoring

sudo docker images

sudo docker rmi "image id" ( to remove images)

sudo docker system df

sudo docker ps

sudo docker run -d -it --name web httpd

sudo docker exec -it web /bin/bash

sudo docker run -d -it --name web  -p 80:80 httpd

sudo docker stop web

sudo docker stats web

sudo docker events

sudo docker rm web

sudo docker rm -f web

sudo docker top web

sudo docker save imange id > https-backup.tar  (to take image as backup)

scp https-backup.tar ranjith@192.168.2.133:/home/ranjith/ (for SCP)

sudo docker load -i https-backup.tar ( it will load the image from local not in internet)

sudo docker commit "container Id" ( it will commit the image)

sudo docker commit d16a51d08814 customimage:2.1 (to add tag for commited images)

sudo docker run -d -it --name test1 customimage:2.1 /bin/sh ( to login custome image)

sudo docker exec -it  0b4a4fca58d6 /bin/bash ( to exec the custome image and verify)

sudo docker network inspect ff8866d57f1d

sudo docker network ls

ip a

sudo docker port web5

Docker run -i -t centos (to mount os)

docker cp aaca4f3bedb6:/opt/nagios/etc/ /root/Desktop

docker cp /root/Desktop/etc/nagios.cfg aaca4f3bedb6:/opt/nagios/etc/





Saturday, 26 March 2022

Apache Guacamole 1.1.0 Install Guide

This guide is written assuming that you are logged in as root. You can do this from a non root account with sudo privileges, but sudo will need to be placed before each command.


1. Once we have a installed CentOS 7, we are going to set the hostname, update the OS and other packages, and enable the Enterprise Linux Repositories (EPEL):


hostnamectl set-hostname guac
yum install -y  epel-release
yum update -y

2. Guacamole requires ffmpeg-devel, and that package is not included with the base CentOS or EPEL repositories so we will need to enable/install a repository that includes ffmpeg-devel and its dependencies. For this tutorial we will be using RPM Fusion but other 3rd party repositories that have the necessary packages will work as well. Use this command to install RPM Fusion:

yum -y localinstall --nogpgcheck https://download1.rpmfusion.org/free/el/rpmfusion-free-release-7.noarch.rpm https://download1.rpmfusion.org/nonfree/el/rpmfusion-nonfree-release-7.noarch.rpm

3. Next we need to download and install several dependencies:

yum install -y cairo-devel libjpeg-turbo-devel libwebsockets-devel libpng-devel uuid-devel ffmpeg-devel freerdp-devel pango-devel libssh2-devel libvncserver-devel pulseaudio-libs-devel openssl-devel libvorbis-devel libwebp-devel libtool libtelnet-devel freerdp mariadb-server wget tomcat

4. Now download and extract the Guacamole server source code (.tar.gz) and download the Guacamole Web Application (.war)

wget https://downloads.apache.org/guacamole/1.1.0/source/guacamole-server-1.1.0.tar.gz
tar -xzf guacamole-server-1.1.0.tar.gz
wget https://downloads.apache.org/guacamole/1.1.0/binary/guacamole-1.1.0.war

5. Once the source code is downloaded and extracted, we need to prep it for compiling and installation.

cd guacamole-server-1.1.0
./configure --with-init-dir=/etc/init.d

If the required dependencies from the previous steps were installed correctly, all of the libraries, protocols, and services/tools should say yes except for wsock32. If you see any “no” items, go back to step 3 and verify all of the packages installed correctly.


6. We can now run make/install.

make install
ldconfig && cd ~

7. We need to enable tomcat, mariadb, and guacd to start each time our system starts or reboots.

systemctl enable tomcat && systemctl enable mariadb && systemctl enable guacd

8. The guacamole web application that we downloaded in step 4 needs to be copied to the correct directory

cp ~/guacamole-1.1.0.war /var/lib/tomcat/webapps/guacamole.war

9. The firewall needs to be opened to allow tomcat/guacamole to connect via port 8080.

firewall-cmd --permanent --add-port=8080/tcp
firewall-cmd --reload

10. To configure Guacamole to support multiple users and connections, we need to download and configure MySQL.

mkdir -p /usr/share/tomcat/.guacamole/{extensions,lib}
wget https://cdn.mysql.com//Downloads/Connector-J/mysql-connector-java-8.0.26.tar.gz
tar -xzf mysql-connector-java-8.0.26.tar.gz
cp mysql-connector-java-8.0.26/mysql-connector-java-8.0.26.jar /usr/share/tomcat/.guacamole/lib/
wget https://downloads.apache.org/guacamole/1.1.0/binary/guacamole-auth-jdbc-1.1.0.tar.gz
tar -xzf guacamole-auth-jdbc-1.1.0.tar.gz
cp guacamole-auth-jdbc-1.1.0/mysql/guacamole-auth-jdbc-mysql-1.1.0.jar /usr/share/tomcat/.guacamole/extensions/

11. Let’s now start mariadb and tomcat.

systemctl start mariadb  && systemctl start tomcat

12. Next we need to better secure our mysql/mariadb installation

mysql_secure_installation

13. Press enter when asked “Enter current password for root (enter for none):”


14. Enter “Y” to set your own root password. This should be different from your normal root user password. Make sure you save this password for future use. For this demo, we are going to use GuacDemo as our password.


15. Enter “Y” to remove anonymous users, and then “Y” again to disallow remote root login.


16. Enter “Y” to remove the test database, and finally “Y” again to reload the privilege tables.


17. Now we need to configure the tables and database scheme so that Guacamole can store connection and user information in the database. Log into mysql, you will be promoted to enter the password you created in step 14.

mysql -u root -p

18. Enter the following lines of SQL once you’ve been greeted with the MariaDB prompt.

CREATE DATABASE IF NOT EXISTS guacdb DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
GRANT SELECT,INSERT,UPDATE,DELETE ON guacdb.* TO 'guacuser'@'localhost' IDENTIFIED BY 'guacpass' WITH GRANT OPTION;
flush privileges;
quit

19. We now need to download and extract the guacamole client, and cat the .sql files to mysql from inside the jbdc folder.

wget https://downloads.apache.org/guacamole/1.1.0/source/guacamole-client-1.1.0.tar.gz
tar -xzf guacamole-client-1.1.0.tar.gz
cat guacamole-client-1.1.0/extensions/guacamole-auth-jdbc/modules/guacamole-auth-jdbc-mysql/schema/*.sql | mysql -u root -p guacdb

Note: You will be prompted for a password after this step. Use the MySQL password you created back in step 14.


20. Now we need to create the Guacamole configuration file.

mkdir -p /etc/guacamole/ && vi /etc/guacamole/guacamole.properties

Now paste the following into the file:

#----------------------------------Inset Into VI---------------------------------------
# MySQL properties
mysql-hostname: localhost
mysql-port: 3306
mysql-database: guacdb
mysql-username: guacuser
mysql-password: guacpass
#Additional settings
mysql-default-max-connections-per-user: 0
mysql-default-max-group-connections-per-user: 0
#----------------------------------End Inset Into VI---------------
--------------------

Note: To exit vi and save the file, press ESC, then the colon symbol ":", type wq, and press enter.


21. Now we fix some file permissions and create a symbolic link.

chmod 0400 /etc/guacamole/guacamole.properties
chown tomcat:tomcat /etc/guacamole/guacamole.properties
ln -s /etc/guacamole/guacamole.properties /usr/share/tomcat/.guacamole/
chown tomcat:tomcat /var/lib/tomcat/webapps/guacamole.war

22. In order for MySQL/MariaDB to communicate correctly with Guacamole, we have to specify our timezone in /etc/my.cnf Add the following to the [mysqld] block of the configuration file. I use -4:00 for EDT. You will need to look up the correct timezone value based on your location.

default-time-zone='-4:00'

23. Finally, we need to fix a permission issue with SELinux that will prevent Guacamole from working correctly.

setsebool -P tomcat_can_network_connect_db on
restorecon -R -v /usr/share/tomcat/.guacamole/lib/mysql-connector-java-8.0.26.jar

24. That should be it! Just reboot your machine, and with any luck you will be greeted with the guacamole login screen when you navigate to:

[yourip]:8080/guacamole

The default username is: guacadmin and the default password: guacadmin.

If you get a blank white screen, try step 23 again and reboot your computer. If you are still met with a blank white screen, try disabling SELinux.