Friday, December 10, 2021

First Angular Program

 first check whether machine has Angularjs install

 ng --version



ng new hello-world
this will create new project

 

load this web site

ng serve

 

 




Tuesday, September 14, 2021

react js ui and Microsoft Rest api connection

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.app</groupId>
<artifactId>highmaturity</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>highmaturity</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-active-directory-spring-boot-starter</artifactId>
<version>2.1.5</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20180813</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>

<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz</artifactId>
<version>2.2.1</version>
</dependency>
<dependency>
<groupId>org.quartz-scheduler</groupId>
<artifactId>quartz-jobs</artifactId>
<version>2.2.1</version>
</dependency>

<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.5.15</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.0.1</version>
</dependency>
<dependency>
<groupId>org.springframework.session</groupId>
<artifactId>spring-session-core</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>jul-to-slf4j</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>log4j-over-slf4j</artifactId>
</dependency>
</dependencies>

<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<includes>
<include>ui/build/**</include>
<include>static/**</include>
<include>application.properties</include>
<include>logback.xml</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
</configuration>
</plugin>

<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>

<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<nodeVersion>v14.16.0</nodeVersion>
<npmVersion>6.14.11</npmVersion>
<!--<npmDownloadRoot>http://registry.npmjs.org/npm/-/</npmDownloadRoot>-->
<!--<npmRegistryURL>http://registry.npmjs.org/</npmRegistryURL>-->
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
<configuration>
<workingDirectory>src/main/resources/ui</workingDirectory>

</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>

<executions>
<execution>
<id>Copy my react frontend to the static folder of my spring application</id>
<phase>process-resources</phase>

<configuration>
<target>
<copy todir="target/classes/static">
<fileset dir="src/main/resources/ui/build"/>
</copy>
</target>
</configuration>
<goals>
<goal>run</goal>
</goals>

</execution>
</executions>
</plugin>


</plugins>
</build>

</project>

Thursday, July 15, 2021

Create a SSL Certificate on Nginx for Ubuntu

1.  create ssl folder

sudo mkdir /etc/nginx/ssl

 

 

 2. go to nginx /ssl folder using below command

cd /etc/nginx/ssl
 
3.
The first file that we need to create is the private key. While creating the key, we will be asked for a passphrase. We must make sure to remember the passphrase since we will not be able to access the certificate without it.
 
 sudo openssl genrsa -des3 -out server.key 1024
 

 4.
Once we have the key created, we will use the key on order to create Certificate Signing Request.
 
5.We have to run below command to create certification
sudo openssl req -new -key server.key -out server.csr 
It will ask your old pass pharse value and Company Name,City like wise Questions.
you may refer screenshot.

 
6.If we have a passphrase it has to be typed in manually, so if there is not person available to do it, the website will be offline for a long time. That is why we are going to remove the passphrase from the key file, using the following command 
# sudo cp server.key server.key.org
# sudo openssl rsa -in server.key.org -out server.key
 

 
7.Now we are ready to create and sign our certificate by below command
 sudo openssl x509 -req -days 365 -in server.csr -signkey server.key 

 8.
It will be valid for 1 year (365 days). That is something that can be 
changed if needed. Now we can use the certificate and assign to a 
virtual host. We can copy the Nginx sample configuration file in a new 
file and use that.
 
9.most important part to be change are as follows
server {
  listen 443;
  server_name our-domain.com;

  root /var/www;
  index index.html index.htm;

  ssl on;
  ssl_certificate /etc/nginx/ssl/server.crt;
  ssl_certificate_key /etc/nginx/ssl/server.key;
} 
 

After making the changes and saving the file, we should copy the virtual host configuration file into /etc/nginx/sites-enabled/default file.

Before change it ,please take a backup of it.

and then restart Nginx.

# sudo service nginx restart
  

Install Intellij IDEA IDE on Ubuntu 18.04

 1. go to https://www.jetbrains.com/idea/download/#section=linux 

and Download Linux version Community one.

you may refer screenshot.



2. go to download ideaIC-2019.1.4.tar.gz file and run the below command

sudo tar -zxvf ideaIC-2019.1.4.tar.gz -C /opt/

3. go to install location

cd /opt/idea-IC-191.8026.42/bin/


4. run the below command

./idea.sh


5. you will received below popup window and continue rest of the installation process.


6. Now your installation process completed 



 




Tuesday, July 6, 2021

setup react js on ubuntu 18

 1. run the below command to install nodejs


sudo apt install nodejs
 
2. run the below command to install npm (node package manager)
 
sudo apt install npm

 
3.  Next install Visual Studio code with below commands
 
wget -q https://packages.microsoft.com/keys/microsoft.asc -O- | sudo apt-key add - 
sudo add-apt-repository "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" 
 sudo apt install code
 
4. After that open Visual STudio Code IDE
Then Add Simple React Snippets  Extension
5. Then Add Prettier
Extension
 

 Now you can run reactjs project on your Ubuntu machine.Good luck

Monday, June 28, 2021

Install tomcat 8 on Ubuntu 18.04

 1. install jdk 8 or open jdk 8

2. create tomcat user account

sudo groupadd tomcat


3. run below command

sudo useradd -s /bin/false -g tomcat -d /opt/tomcat tomcat




4. move to tmp folder

5. run the below command to download tomcat tar file

wget ftp://apache.cs.utah.edu/apache.org/tomcat/tomcat-8/v8.5.68/bin/apache-tomcat-8.5.68.tar.gz
 

 

6. create folder on /opt/tomcat

cd /opt/

sudo mkdir /opt/tomcat
 

 

7. run below command - to extract tar file to /opt/tomcat

cd /tmp/

sudo tar xzvf apache-tomcat-8*tar.gz -C /opt/tomcat --strip-components=1
 

 8.tomcat extract to below folder
 

 

9.give the tomcat user control of the entire directory and make all the scripts in the bin location executable

 

sudo chown -R tomcat: /opt/tomcat
sudo sh -c 'chmod +x /opt/tomcat/bin/*.sh'
 

 

 10.run below command

sudo vi /opt/tomcat/conf/tomcat-users.xml

add the below lines

11. add below line to 

sudo vi /etc/systemd/system/tomcat.service

==============================

[Unit]
Description=Tomcat servlet container
After=network.target

[Service]
Type=forking

User=tomcat
Group=tomcat

Environment="JAVA_HOME=/usr/lib/jvm/default-java"
Environment="JAVA_OPTS=-Djava.security.egd=file:///dev/urandom"

Environment="CATALINA_BASE=/opt/tomcat"
Environment="CATALINA_HOME=/opt/tomcat"
Environment="CATALINA_PID=/opt/tomcat/temp/tomcat.pid"
Environment="CATALINA_OPTS=-Xms512M -Xmx1024M -server -XX:+UseParallelGC"

ExecStart=/opt/tomcat/bin/startup.sh
ExecStop=/opt/tomcat/bin/shutdown.sh

[Install]
WantedBy=multi-user.target
 
12. After that, run the commands below to reload systemd profiles and enable tomcat service
sudo systemctl daemon-reload 
--- not working below two line ---------- 
sudo systemctl start tomcat.service
sudo systemctl enable tomcat.service
 
13. run the tomcat using the below commands
sudo -s
cd /opt/tomcat/bin/ 
./startup.sh 
  

14. on the web browser run below command

http://localhost:8080




Thursday, June 24, 2021

create Elastic Search Database backup


1.Make a zip from elasticsearch folder by executing, `tar -czvf backup.tar.gz elasticsearch`

 =========


Existing database table values display as follows.



2. Stop elastic search db

3. rename it's db data folder to different name


4. extract previously taken db backup using below command

tar -xvf backup.tar.gz
 

 5. Now you can see the extract elasticsearch data folder as follows

 6.start elastic search db using below command
sudo service elasticsearch start
7. recheck the data using the postman

 



Wednesday, June 23, 2021

Uninstall MySQL On Ubuntu OS

 1. open Terminal and execute below command

sudo systemctl stop mysql

this command will stop mysql service

2. Next run below command

sudo apt-get purge mysql-server mysql-client mysql-common mysql-server-core-* mysql-client-core-*

3.Below command will remove MySQL configuration and data.

sudo rm -rf /etc/mysql /var/lib/mysql

 


4.

(Optional) Remove unnecessary packages.

sudo apt autoremove

(Optional) Remove apt cache.

sudo apt autoclean


MySQL Database DB Bakup from Ubuntu OS

MySQL DB back can be taken as below Terminal command

 

sudo mysqldump -p mailhub >/home/pasindu/a.sql




restore mysql DB using the below command


mysql -u username -p database_name < backup_name.sql

 

Below commands are used to stop mysql service

sudo service mysql stop

or 

sudo systemctl stop mysql
 

Below command is used to start mysql service

sudo service mysql start
 

Create mysql user for MySQL database

 Create new mysql user 

CREATE USER 'sunny'@'localhost' IDENTIFIED BY 'sunny';


GRANT ALL PRIVILEGES ON *.* TO 'sunny'@'localhost' WITH GRANT OPTION;


This user has all privileges

username : sunny

password: sunny

Install MySQL on Ubuntu 18.04

 Install mysql database on the Ubuntu OS.

1. open terminal

 execute below command

sudo apt-get update
2. sudo apt-get install mysql-server

3.sudo systemctl status mysql - check status of mysql db

4.sudo mysql_secure_installation
It's asking for Root new password
5.For all the other asking questions  enter 'y'
 

 
6.Next enter mysql -u root -p
Then it's ask for password
After that It's giving below error message.
7.
 Then enter sudo mysql command


8. After that enter below sql query

SELECT user,authentication_string,plugin,host FROM mysql.user;

you can see output as follows


then I change Root password as follows.

 ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '257F257f';



9.then press below sql query.

FLUSH PRIVILEGES;

10. next see below sql query.

SELECT user,authentication_string,plugin,host FROM mysql.user;


Now output will be as follows.

You can see in this example output that the root MySQL user now authenticates using a password. Once you confirm this on your own server,
you can exit from mysql shell using exit command.
Next login to my sql you have to do following command
 
mysql -u root -p
 



Sunday, June 20, 2021

Elastic Search Database

 Elastic Search database is no-sql database.

Below are the comparison with Elastic Search Database items with Relation Database Item.


create index using below command line


If below http://localhost:9200/_cat/indices  on brower contains yellow one,you have to run below command

curl -XPUT 'http://localhost:9200/_settings' -H 'Content-Type: application/json' -d '
{
    "index" : {
        "number_of_replicas" : 0
    }
}'



Tuesday, June 15, 2021

setup nginx Server reverse proxy on Windows 10

 Nginx is famous server to do a reverse proxy.

 Here I am setting up how to setup Nginx