Wednesday, June 8, 2022

AWS EC2 - SSH locked with UFW

Need to update the instance's user data:

1. Stop the instance

2. Right click (windows) or ctrl + click (Mac) on the instance to open a context menu, then go to Instance Settings -> Edit User Data or select the instance and go to Actions -> Instance Settings -> Edit User Data

If you're still on the old AWS console, select the instance, go to Actions -> Instance Settings -> View/Change User Data

3. Past following in: 


ontent-Type: multipart/mixed; boundary="//"
MIME-Version: 1.0
--//
Content-Type: text/cloud-config; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="cloud-config.txt"
#cloud-config
cloud_final_modules:
- [scripts-user, always]
--//
Content-Type: text/x-shellscript; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment; filename="userdata.txt"
#!/bin/bash
ufw disable
iptables -L
iptables -F

--//


4. Once added, restart the instance and ssh should work. 

The user-data disables ufw if enabled and also flushes any iptable rules blocking ssh access.

Friday, March 18, 2022

Nginx Virtual Hosts on Ubuntu

Nginx Virtual Hosts on Ubuntu


1. Create Root Directory

sudo mkdir -p /var/www/login.jordan.app/html

sudo chown -R $USER:$USER /var/www/login.jordan.app/html

sudo chmod -R 755 /var/www/login.jordan.app


2. Creating Sample Pages

vi /var/www/login.jordan.app/html/index.html

<html>
    <head>
        <title>Welcome to login.jordan.app!</title>
    </head>
    <body>
        <h1>Success! The jordan.app server block is working!</h1>
    </body>
</html>


3. Create Block Files

sudo cp /etc/nginx/sites-available/default /etc/nginx/sites-available/login.jordan.app

sudo vi /etc/nginx/sites-available/login.jordan.app

server {
        listen 80;
        listen [::]:80;

        root /var/www/login.jordan.app/html;
        index index.html index.htm index.nginx-debian.html;

        server_name jordan.app www.jordan.app login.jordan.app;

        location / {
                try_files $uri $uri/ =404;
        }
}

grep -R default_server /etc/nginx/sites-enabled/


4. Enabling Server Block

sudo ln -s /etc/nginx/sites-available/login.jordan.app /etc/nginx/sites-enabled/


5. Modify config file

sudo vi /etc/nginx/nginx.conf

Remove the # symbol to uncomment

server_names_hash_bucket_size 64;
    
sudo nginx -t
    

6. Restart 

sudo systemctl restart nginx
    
    
7. Modify host file 

sudo vi /etc/hosts
    
3.104.250.177 jordan.app www.jordan.app login.jordan.app


Friday, July 24, 2020

Weblogic 10.3.6 Installer Insufficient Disk Space

Weblogic 10.3.6 Installer fails with the insufficient disk space issue please use one of the following command to ignore disk space detection:


java -Dos.name=unix -jar wls1035_generic.jar

or

java -Xmx1024M -Dspace.detection=false -jar wls1035_generic.jar


Thursday, April 30, 2020

Disable Directory Listing Apache2

Edit the following file:

/etc/apache2/apache2.conf

Remove 'Indexes' from default root directory setting:

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Updated apache2.conf file:

<Directory /var/www/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>

Restart the apache2 server instance.

Thursday, March 5, 2020

SdkMan CLI

SDKMAN (Software Development Kit Manager CLI) is a tool for managing parallel Versions of multiple Software Development Kits on any Unix based system. It provides a convenient command line interface for installing, switching, removing and listing Candidates.

Installation:

 #curl -s "https://get.sdkman.io" | bash

 #source "$HOME/.sdkman/bin/sdkman-init.sh"

Check Version:

 #sdk versiokn

Development Kits
    Install:

     #sdk list <software> 
     #sdk list java

     #sdk install java 7.0.181-zulu
     #sdk install java 11.0.6.j9-adpt

     The installation could be find in: 
        <user.home>/.sdkman/candidates/

    Uninstall:
      #sdk uninstall java 7.0.181-zulu 
      
    User Version:
       #sdk use java 7.0.181-zulu 
      
    Default Version:
       #sdk default java 7.0.181-zulu 
    
    View Current Versions:
       #sdk current
    
    Upgrade Version:
       #sdk upgrade java
       #sdk upgrade
    
 for more reference http://sdkman.io


Thursday, January 2, 2020

Default Web Server on Mac

The web server can be started on my in any directory through the following command:

# python -m SimpleHTTPServer 8000

(port number can be changed) 

or the default apache server can also be started through: 

# sudo apachectl start

The default localhost folder located here: /Library/WebServer/Documents or as per
configuration in apache2 config files.

Default apache is installed in /etc/apache2/ with all
its configuration files (httpd.conf).

Sunday, December 1, 2019

Docker


1. docker container can be find / downloaded from docker hub / docker store.

    http://hub.docker.com
 
    i.e
        $docker run ansible
        $docker run mogodb
        $docker run redis
        $docker run nodejs
     
2. Docker have two addition
    i. Community Edition
    ii. Enterprise Edition
 
3. Community Edition are availble for mac/windows/cloud (AWS)

4. Install docker desktop for windows / mac from http://docs.docker.com/install

5.  It will be eaiser to install docker through convenience script, instruction must  be found on http://docs.docker.com/install

6. Download images/container from http://hub.docker.com

7. To test visit the hub.docker and search for whalesay image to test the docker installation.

 $sudo docker run docker/whalesay cowsay HelloWorld

 Docker will pull the image and runs it.

 8. Docker Command
    i. $docker run <<container-name>> : to run the image, the image will be downloaded if not available.
 
    ii. $docker ps : will list all the containers
             -a : show the status and other details
           
    iii. $docker stop <<container-name>>
 
    iv. $docker rm <<container-name>> : remove the installed docker.
 
    v. $docker images : list down the downloaded images.
 
    vi. $docker rmi <<image-name>> : to remove the downloaded image.
        a. Stop and delete all the dependent container to remove image.
     
    vii. $docker pull <<image-name>> : just to pull the image without running it.
 
    viii. $docker run ubuntu : to run the container
 
    ix. $docker ps -a : list down the running container.
 
    x. Why the containers are in Exited status?
        Containers are ment to run process / tasks /webserer / application server/database instance not operating system once the task / process is completed the container exists.
     
        $docker run ubuntu sleep 5 : the ubuntun imaghe will start and sleep for 5 seconds one the task is completed the ubuntu iamge will be in Existed.
     
    xi. $docker exec distracted_mcclintock cat /etc/hosts : execute command inside the container to display the file content.
 
    xii. Processes runs either on four ground / active mode.
        a. $docker run kodekloud/simple-webapp : Run the image on attached mode.
     
        b. $docker run -d kodekloud/simple-webapp : Run the image in detach mode (backgroundm ode).
 
        - $kdocker attach <<image-name>> / <<image-id>> : to connect the detach container run the following command

        - first five character of docker image id are enough to run any docker command.
     
    ix. $docker run redis : to run the latest redis server
        $docker run redis:4.0 : to run the older version redis use the tag, the tag can be used with any image.
     
    xx. The hub.docker.com listdown all the versions / tags for all the available images.
 
    xxi. $docker run -i my/simple-prompt-docker : where -i is for an interactive mode to receive command line input and pass as parameter in application.
         $docker run -it my/simple-prompt-docker : for more interactive mode where you will see the application asking for input and you need to type you value and application will process that input further.
       
    xxii. Port forwarding:
 
    $docker run my/webapp: to start the web application image, the webapp is running on 5000 port (i.e http://172.17.0.2:5000/). Every machine have default IP and only accessable from docker host and not accessable outside the host.
 
    $docker run -p 80:5000 my/webapp : Map the port to access docker webapp image instance running on 5000 port.
 
    - this way you can run multipule instance of application using different ports.
    i.e
      $docker run -p 8000:5000 my/webapp
      $docker run -p 9000:5000 my/webapp
   
      $docker run -p 3306:3306 mysql
      $docker run -p 8306:3306 mysql
      $docker run -p 9306:3306 mysql
   
      - all above host ports are forwarded to one post of docker image.
 
    xxiii. Volume Mapping
 
    i.e $docker run mysql
        $docker stop mysql
        $docker rm mysql
     
        Onec the container removed all the data inside mysql database will be removed as well to prevent this we need to map the mysql data files with host file path.
     
        $docker run -v /opt/datadir:/var/lib/mysql mysql
     
        one the container starts with volume mapping all the data will be stored in the host system. Removing the mysql container will not effect the stored data.
     
    xxiv. Inspect Container:
        $docker inspect <<container-name>> : will return the json contain the details about container.
     
    xxv. Container logs (Processing running in detach mode)
     
        $ docker logs <<container-name>>
     
    xxvi. Set Environment Variables:
        The environment varabiles can be used inside the application and to set those run the following command:
     
        $docker run -e APP_COLOR=blue myweb
        $docker run -e APP_COLOR=red myweb
        $docker run -e APP_COLOR=green myweb
     
        to view the envrionment variable of container use inspect command
     
        $docker inspect <<container-name>>
        You will find the list of ENV in config tag of josn returned by inspect command.
 
     
9. Free lab to prectise the lab and quiz http://kodekloud.com/p/docker-labs

10. Create your own docker image.
    - Task list
        i. Install OS (ubuntu)
        ii. Update apt repository
        iii. Install apt updates
        iv. Install the python and its dependencies
        v. Copy the source
        vi. Run the application
     
       
    - Process
        i. Create docker file 'Dockerfile' and put all the commands are you will execute on OS.
     
            i.e
            --------------------------------
            FROM Ubuntu

            RUN apt-get update
            RUN apt-get install python
            RUN pip install flask
            RUN pip install flask-mysql

            COPY ./opt/source-code

            ENTRYPOINT FLASK_APP=/opt/source-code/app.py flask run
            ----------------------------------
         
            - In the above file, everything on left (i.e FORM, RUN, COPY) are instruction and text on the right side are Argument.
         
            -FROM Ubuntu: deifne the base OS required for docker image.

        ii. Build you image with docker build command using Dockerfile as parameter.
     
        $docker build Dockerfile -t isyed/my-python-app

        or
     
        $docker build .
            - If you want to re-run / contine if the building image failed on any step.
     
        iii. Run the push command to push the newly created image to public hub docker repository.
     
        $docker push isyed/my-python-app
            - here isyed is my account name which is created on docker website.
     
        $docker history isyed/my-python-app
            - to know the history and size of container image.
        

AWS EC2 - SSH locked with UFW

Need to update the instance's user data: 1. Stop the instance 2. Right click (windows) or ctrl + click (Mac) on the instance to open a c...