Showing posts with label Ubuntu. Show all posts
Showing posts with label Ubuntu. Show all posts

Thursday, November 14, 2024

How to install oracle database on Ubuntu system with Docker

In this tutorial, we are going to learn how to install the Oracle database on the Ubuntu system.

- Prerequisites

Docker needs to be installed on the system to verify it use the following command

docker --version

This will list the docker version installed

elint@elint:~$ docker --version
Docker version 27.0.2, build 912c1dd

- Download the Oracle docker image

Next, download or clone the oracle docker image from the repo oracle/docker-image Unzip it.

Navigate to the Oracle database docker files; in our case, it's inside /opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles. Here, you can see all the dockerfiles version. Select and navigate the desired version to install

- Download the Oracle database binary file

Download the database zip file from the Oracle website This will require the Oracle login so, create the account login and download the file. Once downloaded copy that file under the Oracle database selected dockerfile version. In our case, we are using docker file version 19.3.0

The overall folder structure looks like below

- Build the Oracle docker image

Note: You need to have at least 8-15Gb storage space on your system

Navigate to the folder

cd /opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0

Using the following command to build

docker build -t oracle/database:19.3.0-ee --build-arg DB_EDITION=ee .

Here oracle/database:19.3.0-ee is the image name, you can give any name

or you can use the following command

../buildContainerImage.sh -v 19.3.0 -e

-v specifies the docker image version and -e for the enterprise edition

Note: this will take some time to build the image

- Run the Oracle container

docker run --name oracle19.3c --network host -p 1521:1521 -p 5500:5500 -v /opt/oracle:/home/oracle oracle/database:19.3.0-ee

This will take some time to complete according to your system's RAM and CPU. Once completed the output looks similar as below

You can close the terminal after this.

- Start the container

To start the container run the below command

docker start oracle19.3c

oracle19.3c is the container name; you can find it using the command: docker ps -a

elint@elint:/opt/oracle/docker-images/OracleDatabase/SingleInstance/dockerfiles/19.3.0$ docker ps -a 
CONTAINER ID   IMAGE                       COMMAND                  CREATED       STATUS                 PORTS     NAMES
767c0a92e087   oracle/database:19.3.0-ee   "/bin/bash -c 'exec …"   11 days ago   Up 11 days (healthy)             oracle19.3c

This process will set the default username and password for the system user to change it, use the command

docker exec oracle19.3c ./setPassword.sh yourPassword

Where oracle19.3c is the container name

Now, login into the container

docker exec -it oracle19.3c bash

To connect to the database use the below command

sqlplus system/yourPassword@orclpdb1

Here orclpdb1 is the default database SID created

If you are having trouble running queries with sqlplus might be due to the export path issue that can resolved by exporting the environment variable. Note: enter into the container first with the command: docker exec -it oracle19.3c bash

export ORACLE_HOME=/opt/oracle/product/19c/dbhome_1
export PATH=$ORACLE_HOME/bin:$PATH

Verify the path for sqlplus

bash-4.2$ cd /opt/oracle/product/19c/dbhome_1 
bash-4.2$ ls
OPatch	 addnode     cfgtoollogs  css  data    deinstall    drdaas   has      instantclient  jdbc  ldap  md	  nls	opmn	     ord  owm	 precomp  relnotes     root.sh.old.1  runInstaller   slax      sqlplus	utl
QOpatch  assistants  clone	  ctx  dbjava  demo	    dv	     hs       inventory      jdk   lib	 mgw	  odbc	oraInst.loc  oss  perl	 racg	  root.sh      root.sh.old.2  schagent.conf  sqlj      srvm	wwg
R	 bin	     crs	  cv   dbs     diagnostics  env.ora  install  javavm	     jlib  log	 network  olap	oracore      oui  plsql  rdbms	  root.sh.old  root.sh.old.3  sdk	     sqlpatch  usm	xdk

Now you can create a new sid/database and connect to the users.

With suitable database connector; you can connect the database using the url: jdbc:oracle:thin:@127.0.0.1:1521/orclpdb1

Share:

Wednesday, November 13, 2024

How to remove docker containers and images

In this tutorial, we are going to learn how to remove the docker containers and images

Initially, list all the containers that use the docker images. To see all the running containers on your machine use the following command

docker ps -a

This will show all the running containers on your machine. The sample output looks like as below:

Here, we do have one running container with container ID: 767c0a92e087 and container name: oracle19.3c

Stop a running container

docker stop <container_id>

Use your own container ID in our case it is 767c0a92e087 to stop it

Now, let's delete the container

docker rm <container_id>

To force to remove the running container in one command use the following command

docker rm -f <container_id>

If you want to remove all the containers(not recommended)

docker container prune

Let's look into deleting the docker images

List all the available docker images

docker image ls

The sample output looks like

elint@elint:~$ docker image ls
REPOSITORY        TAG         IMAGE ID       CREATED       SIZE
oracle/database   19.3.0-ee   dd6c130762a3   11 days ago   6.54GB

To delete the specific image

docker rmi <image_id>

Use your own docker image ID in our case it is dd6c130762a3

To remove the docker image forcefully

docker rmi -f <image_id>

To remove unused images. The unused or dangling images are those images which are not associated with docker images

docker image prune

Note: the deleted images need to re-download if we need it later

These are the overall commands to clean up the docker containers and images.

Share:

Tuesday, November 12, 2024

How to install and start Redis server for Ubuntu system

If the Redis server is not installed on the system install it. For the Ubuntu system use the following command

sudo apt-get update
sudo apt-get install redis-server

Once the Redis server is installed, open the terminal and start it using the following command

redis-server

This will start the Redis server. Note: with this redis server will start on default port 6379.

To customize the configuration create a custom file redis.conf add the proper configuration and start the server

redis-server /etc/redis/redis.conf

The above command to run the server will require the terminal to open so to run in the background use the following command

redis-server --daemonize yes

To test whether the Redis is running successfully ping using the Redis cli command

redis-cli ping

This will return the response PONG if it's running successfully

Share:

Tuesday, August 23, 2022

How to setup auto renewable free SSL certificate using Lets Encrypt and Nginx on Ubuntu machine

In this tutorial, we are going to set up free SSL auto-renewable Let's Encrypt along with Nginx.

Prerequisites:

Before we start setup, first make sure your domain e.g. example.com is pointed to the server's public IP address. You can set up and point this configuration from the dashboard of your domain service provider.

Connect to the remote server:

First SSH into the remote server where we want to set up the SSL.

If you are using a server password to connect, use the following command

sudo ssh server_username@ip_address

Here use your server username and server IP address to connect. For example ubuntu@34.344.56

If you are using a .pem file or other private keys to connect to a server then use the following command

sudo ssh -i path_to_pem_file server_username@ip_address

Install Nginx:

First, let's install Nginx on the server using the following commands.

sudo apt-get update
sudo apt-get install nginx

If nginx got successfully installed, then use the following command to verify.

nginx -v
nginx version: nginx/1.18.0 (Ubuntu)

Or we can verify by checking the status

sudo systemctl status nginx

Setup Nginx Configuration:

Now let's configure the Nginx for our domain. For this navigate to the Nginx directory

cd /etc/nginx/sites-available

Here, if we use the ls command we can see the default file for configuration. We will create a new file for our domain to configure for e.g 360learntocode.com, you can create using your domain name.

sudo vim 360learntocode.com

Now the new empty file is open lets edit and inserts the configuration by entering Shift + i

server {
      server_name 360learntocode.com;

      location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass              http://568.19.34.63:8080;
      }
}

Make sure to replace 360learntocode.com with your domain name and http://568.19.34.63:8080 with your IP address and the port in which your application is running.

Now save the configuration. Enter Esc and type :wq and hit Enter.

Now, symlink this file with the directory “sites-available” in our Nginx for this navigate to sites-available

cd /etc/nginx/sites-enabled/
sudo ln -s /etc/nginx/sites-available/360learntocode.com /etc/nginx/sites-enabled/

To check the Nginx configuration use the following command

sudo nginx -t

We are supposed to see the output as below

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

Reload the Nginx to reflect the changes:

sudo systemctl reload nginx

If we try to open our domain, we can see the Nginx 502 Bad Gateway if our application is not running otherwise we will see the running application.

Setup SSL Certificate:

For the SSL certificate, we are using the let's encrypt and certbot client. For more detail check let's Encrypt and Certbot

- Install Certbot client

Use the following commands to install certbot client

sudo apt-get update
 sudo apt-get install python3-certbot-nginx

Now, the certbot is successfully installed on our server. Let's create an SSL certificate for our domain

sudo certbot --nginx -d 360learntocode.com

Note: use your own domain name. Follow the steps asked afterward.

Here are some sample examples screens.

Now, let's reload the Nginx so that our configuration changes will reflect.

sudo systemctl reload nginx

If we load our domain URL then it will open over HTTPS.

If you want to see the overall configuration setup, please open the file that we created previously i.e 360learntocode.com inside /etc/nginx/sites-available/, there we can see all the setup done. The sample file looks like as below.

server {
      server_name 360learntocode.com;

      location / {
        proxy_set_header   X-Forwarded-For $remote_addr;
        proxy_set_header   Host $http_host;
        proxy_pass              http://568.19.34.63:8080;
      }


    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/360learntocode.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/360learntocode.com/privkey.pem; # managed by Certbot
    include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
    ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot

}
server {
    if ($host = 360learntocode.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


      server_name 360learntocode.com;
    listen 80;
    return 404; # managed by Certbot


}

Here, the auto-renew script is managed by certbot client so we don't have to worry about the SSL expiration. To verify the auto-renew scripts navigate to the script file.

cd /etc/cron.d/
sudo vi certbot

In the certbot file, we can see the auto-renew script as below added by cerbot client

0 */12 * * * root test -x /usr/bin/certbot -a \! -d /run/systemd/system && perl -e 'sleep int(rand(43200))' && certbot -q renew

Thanks for following the tutorial, Happy coding !!

Share:

Wednesday, July 27, 2022

Install Docker on Ubuntu 20.04

In this tutorial, we will learn how to install docker on Ubuntu Linux.

Install docker using the repository:

For this, first set up the repository. Use the following command.

sudo apt-get update
sudo apt-get install \
    ca-certificates \
    curl \
    gnupg \
    lsb-release

Now, add docker's GPG key

sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

Now give sufficient permission

sudo chmod a+r /etc/apt/keyrings/docker.gpg

In order to set up the repository, use the following command

echo \
  "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Now for installing Docker use the following command, which will install the latest docker.

sudo apt-get update & sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

Install Docker using .deb package:

If we might have a problem with installing the docker with the above or wants to install a specific version of the docker then using .deb package is a good solution.

Download the desired version of .deb from here

In order to test the ubuntu version use the following command

lsb_release -a

we can get the output as below

No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.3 LTS
Release:	20.04
Codename:	focal

Here, the codename is focal so We chose the same as above. Then browse to pool/stable/, choose amd64, armhf, arm64, or s390x, and download the .deb file

In order to test the CPU available use the following command

lscpu

Go to the download folder and execute the deb package using the following command

sudo dpkg -i docker-ce-cli_18.09.0_3-0_ubuntu-bionic_amd64.deb

Note: make sure to use your own version of the .deb package. Now start the docker

Now, we successfully install docker.

Check the Docker Version:

docker --version

Uninstall Docker:

Uninstall docker, CLI, Containerd, and Docker Compose packages using the following command

sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin

Now, delete all images, containers, and volumes

sudo rm -rf /var/lib/docker
 sudo rm -rf /var/lib/containerd

Share:

Thursday, June 30, 2022

Install Mysql Specific Version on Ubuntu/Linux using debian package

In this tutorial, we are going to install MySQL version 5.7 using the Debian package(.deb)

Step 1. Add the MySQL Apt Repository

First download the Debian(.deb) package from MySQL Apt Repo. Here we are using the wget to download as below:

wget https://dev.mysql.com/get/mysql-apt-config_0.8.12-1_all.deb

Step 2. Configure the .deb file

sudo dpkg -i mysql-apt-config_0.8.12-1_all.deb

You can see the below prompt screen

If somehow we are unable to see the prompt screen then either dpkg is interrupted or broken. Use the below command to clean the config after that use the previous dpkg command, now we can see the screen

apt-get purge mysql-apt-config

Select the ubuntu bionic option and the second screen will pop up as below. Now select the first option to select the MySQL version

Now select the desired version of MySQL, Here we are selecting the MySQL 5.7

Once selected the desired version of MySQL then select ok to configure.

Now the configure suppose to get successful and we can see the output as below:

Selecting previously unselected package mysql-apt-config.
(Reading database ... 36242 files and directories currently installed.)
Preparing to unpack mysql-apt-config_0.8.12-1_all.deb ...
Unpacking mysql-apt-config (0.8.12-1) ...
Setting up mysql-apt-config (0.8.12-1) ...
Warning: apt-key should not be used in scripts (called from postinst maintainerscript of the package mysql-apt-config)
OK

Step 3. Install the MySQL Server

Now update the MySQL repository

sudo apt-get update

Install the MySQL using the following command:

sudo apt install -f mysql-client=5.7* mysql-community-server=5.7* mysql-server=5.7*

If you chose the latest version of MySQL then no need to specify the package.

Next, the screen will pop up to enter the root password. Enter the password and press ok. After that MySQL is installed and running successfully. Test the MySQL version and MySQL status by using the below command:

mysql --version
sudo systemctl status mysql

Step 4. Secure MySQL Installation

Use the following command to secure MySQL installation:

sudo mysql_secure_installation

Enter your MySQL root password and answer all of the security questions.

Now, log in using the root credential

mysql -u root -p

Step 5. Create a New Mysql User

Before creating new users we need to first log in with the root user as mentioned above. Now, create the user using the following command:

CREATE USER 'username'@'localhost' IDENTIFIED BY 'password';

Here, use your own username and password and localhost as we are working on the same machine.

For example:

CREATE USER 'testuser'@'localhost' IDENTIFIED BY 'testpassword';

If we want to create a user that can be connected from any machine then use the following command

CREATE USER 'username'@'%' IDENTIFIED BY 'password';

Now, let's grant the permission to the newly created user.

GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost';

Here, user have full access to the database with ALL PRIVILEGES and for all the databases as we are using *.*

However, we can grant privileges for specific databases as

GRANT ALL PRIVILEGES ON database_name.* TO 'testuser'@'localhost';

After grant privileges to user, we need to flush the privileges

FLUSH PRIVILEGES;

We can revoke privileges using the following command:

GRANT ALL PRIVILEGES ON *.* TO 'testuser'@'localhost';

Remove User:

DROP USER 'testuser'@'localhost';

Step 6: Some commands for MySQL server:

Stop the MySQL server:

sudo systemctl stop mysql

Start the MySQL server:

sudo systemctl start mysql

Check the status of MySQL server:

sudo systemctl status mysql

Restart MySQL server

sudo systemctl restart mysql

Step 7: Completly remove/uninstall MySQL server

sudo apt-get remove --purge mysql*
sudo apt-get autoremove
sudo apt-get autoclean
Share:

Tuesday, January 25, 2022

Install OpenCv in Linux/Ubuntu for Java Application.


1. Introduction:

In this blog post, we are going to install and set up OpenCV in ubuntu os for the java applications. OpenCV is a widely used great computer vision library. You can learn more about the OpenCV tutorial from here. For documentation, you can follow here. We will also cover some tutorials for Java bindings too.
 



2. Download OpenCV:

You can download OpenCV from the public Github repository of OpenCV or from their official website from here.  Select the desired version and click "Sources", which will download the zip file. Unzip the file.
unzip opencv-4.3.0.zip

 
3. Build OpenCV:

In order to build OpenCV, go to the OpenCV path in my case it's under "/opt/opencv-4.3.0" so I will use the same.

Create a directory to build.
mkdir build
  cd build
Now, if you don't have installed cmake software please install it using the below command
sudo apt-get  install cmake
Next, is to generate and configure with cmake for building executables in our system.
cmake -DBUILD_SHARED_LIBS=OFF ..
Note: When OpenCV is built as a set of static libraries (-DBUILD_SHARED_LIBS=OFF option) the Java bindings dynamic library is all-sufficient, i.e. doesn’t depend on other OpenCV libs, but includes all the OpenCV code inside. 

Make sure the output of the above command looks like below:


If it doesn't find the ant and java then you may get the following output: 
Java:
   ant:                         NO
   JNI:                         NO
   Java tests:                 YES
For this, install and setup your java and install ant
sudo apt install openjdk-8-jdk
sudo apt-get install ant

If you are still getting ant as NO then try the following command to install ant
sudo snap install ant --classic
Now start the build
make -j4
Note: Be careful not to run out of memory during the build. We need 4GB of memory per core. For example, if we compile with 4 cores (e.g. make -j4) we need a machine with at least 16GB of RAM.

The output look likes this and it will take some time.


If everything is fine, you successfully build OpenCV. Make sure the following files are packaged in the corresponding directory.
/opt/opencv-4.3.0/build/lib/libopencv_java430.so
/opt/opencv-4.3.0/build/bin/opencv-430.jar
The path of those files is created according to your OpenCV version and directory. You need to make sure the so and jar file must be created. This jar file contains the java wrapper code which we will used in the sample example.

 



4. Run Sample Example:

Now we are going to add the compiled jar file in our project library.

For IntelliJ Idea:

Go to : File >> Project Structure >> Libraries (under project settings)

you can see the + icon at the top left, to add a new project library click on it, and select java and add the path of previously created jar file i.e opencv-430.jar. 

It's time to run a sample test example.
import org.opencv.core.CvType;
import org.opencv.core.Mat;

public class SampleTest {

    public static void main(String[] args) {
        System.load("/opt/opencv-4.3.0/build/lib/libopencv_java430.so");
        Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
        System.out.println("mat = " + mat.dump());
    }
}
Make sure that you loaded your corresponding .so file.

Output:
mat = [  1,   0,   0;
   0,   1,   0;
   0,   0,   1]
For those who are running OpenCV in an existing project, you can set up with Gradle project as below:

For Gradle:

Copy the jar file in your project directory package for e.g "libs" and add following inside dependencies in build.gradle file.
dependencies {
//other dependencies

compile fileTree(dir: 'libs', include: '*.jar')
}
Share:

Wednesday, January 5, 2022

How to record GIF on Ubuntu Linux

This is a quick tutorial on how we can record the animated GIF on a Linux Ubuntu machine.

 For this, there is a software called Peek, a simple screen recorder with an easy to use interface

Peek is very easy to create short screencasts of specific screen areas. We can simply place the Peek window over the area where we want to record and start recording.

Although it is optimized for recording and generating animated GIFs, we can also record WebM and MP4 videos too.

Let's look at how we can install it. For this open your terminal and type the following command

For Ubuntu:

sudo add-apt-repository ppa:peek-developers/stable
sudo apt update
sudo apt install peek

Here, we are adding PPA repositories required, while doing so use enter key to allow. Now, after running the above command you can simply open the peek recorder and start recording the GIFs animation.

The sample recording screen looks as below:



For Debian:

sudo apt install peek

For ElementaryOS:

sudo apt install software-properties-common
sudo add-apt-repository ppa:peek-developers/stable
sudo apt update
sudo apt install peek

For Arch Linux:

sudo pacman -S peek
Share: