Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

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


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.
        

Monday, February 15, 2016

LTSP(Linux Terminal Server project)

Introduction.
The Linux Terminal Server Project adds thin-client support to Linux servers.

Prerequisited for Installation
            Before installing LTSP we need DHCP  that must be already installed & configured on your
system.

Installation

DHCP (Dynamic Host Configuration Protocol)

apt-get install dhcp3-server dhcp3-common

After installation just you have to edit a file dhcpd.conf
vi /etc/dhcp3/dhcpd.conf

ddns-update-style none;
option domain-name "domain.com";

option domain-name-servers IP[i.e =192.168.3.1];
next-server IP[i.e=192.168.3.2];

default-lease-time 600;
max-lease-time 7200;

#log-facility local7;

subnet [i.e=192.168.3.0] netmask 255.255.255.0 {
# range [starting]  [ending]
   range 192.168.3.10  192.168.3.100;
   option subnet-mask 255.255.255.0;
   option routers 192.168.3.1;

#  option broadcast-address 10.5.5.31;
}
NFS
apt-get install nfs-kernel-server

After installation add permissions on any directory to any user. For this open
vi  /etc/exports
[Folder name]  [Client-IP/Complete Network] / [Netmask](permissions)
/home  192.168.1.0/255.255.255.0(rw)

LTSP
apt-get install ltsp-server
Note : If you find i386 [/opt/ltsp/i386] in your system than remove that.
rm -fr /opt/ltsp/i386

apt-get install atftpd


There are two ways to take all the packges to complete the LTSP installation.
ONE if you have all the updates download as a tar file or second if you have to connect
with the internet and download the updates. It's may be take two or three hours depending on your
internet speed.

If you want to download form internet or for apt server than

ltsp-build-client –mirror http://apt-proxy.emergen.biz:1010/kubuntu
ltsp-build-client  uses  the ubuntu archive mirrors in order to build an ltsp client for use with the ltsp server.

ltsp-update-sshkeys
ltsp-update-sshkeys  updates  the current ltsp servers sshkeys in the client chroot.  This is required for example if the ltsp server changes ip address.

After performing all these step you have to edit the dhcpd.conf file
Add this line

option-root-path “/opt/ltsp/i386”;
And in the body where you are defining range add this line
filename “/ltsp/pxelinux.0”

After editting dhcpd.conf you have to add two line in exports file.

vi /etc/exports
/opt/ltsp   *(ro,no-root-squash,sync)
/var/opt/ltsp/swapfiles *(rw,no-root-squash,sync)

Some times there is some error related with xdmcp bcoz of  xdmcp is not enabled bcoz of that you are unable to boot GUI on thin-clients.
for enabling xdmcp
vi /etc/kde3/kdm.kdmre

 [xdmcp]
 Enable=true  ( It was false before)

After this restart
/etc/init.d/nfs-kernel-server  restart
/etc/init.d/portmap  restart
/etc/init.d/inetd  restart

After this execute commad

showmount -e
showmount  queries  the  mount  daemon  on a remote host for information about the state of the NFS server on that machine.  With no options showmount lists the set of clients who are mounting from that  host.


After this Open
vi /etc/kd3/kdm/xaccess
Find line like
# *       #Any host can get a login windows
remove 1st hash (number sign)  from this line.

After removing the hash sign restart kdm and execute
netstat -anp| grep 177
you should see line like
udp      0          00        6716/kdm       

After this restart DHCP & bootup client.
this client'll boot up :)

SECOND If we have downloaded updates as i iso on CD than run
  ltspadmin
one menu is appear

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

Thin Client deployment on SuSe Enterprise 9

This document details the deployment and maintenance using LTSP on Suse Linux Enterprise Server 9.

Introduction
LTSP is an add-on package for Linux that allows you to connect lots of low-powered thin client terminals to a Linux server. Applications typically run on the server, and accept input and display their output on the thin client display.

Prerequisites for Installation of LPST
Before Installing LTSP you need LWP Pearl already installed on your system.
Also you need a TFTP server for LTSP.

Installation
There are two ways to  install LTSP 4.1 .

1.    LTSP Installer
You can download the LTSP installer, and use that to download the rest of the packages.
2.    ISO image
Download the ISO image and use the LTSP Installer to install from that.

We use second method in this document . Download ISO image but you need to run it on Apache or any other web server because it needs an web URL and mount the ISO directory to apache default web folder .

server #  mount -o loop /home/noman/LTSP4.1/ltsp-4.1-1.iso   /srv/www/htdocs/  

Now you have LTSP installer in htdocs folder. Install it first .

server #  rpm -ivh ltsp-utils-0.10-0.noarch.rpm

Now Run ltspadmin for LTSP package installation.

server # ltspadmin
Selection main menu is appered.

Select Install and update LTSP package.

LTSP installer Configuration wizard appears.
give your local apache web address for file to retrieve from there else it go on internet to get packages from there.

Specify directory for LTSP client Configuration to place all client files there.
/opt/ltsp

Select All packages to install.

Now select Configure LTSP.

1.    Runlevel
2.    Interface selection
3.    DHCP Configuration
4.    TFTP Configuration
5.    Portmapper Configuration
6.    NFS Configuration
7.    XDMCP Configuration
8.    Create /etc/hosts entries
9.    Create /etc/hosts.allow entries
10.              Create /etc/exports entries
11.              Create lts.conf files


1.    Run Level
Enter run level 5 for GUI Login Mode.
2.    Interface selection
Select the Network Interface for clients to connect if you have only one its select .
3.    DHCP Configuration
             # Sample configuration file for ISC dhcpd
            #
            # Make changes to this file and copy it to /etc/dhcpd.conf.sample
            #
ddns-update-style            none;

default-lease-time           21600;
max-lease-time               21600;
option ntp-servers 192.168.2.254;
option domain-name "emergen.biz”;
option domain-name-servers 192.168.2.254;

option subnet-mask           255.255.255.0;
option broadcast-address     192.168.2.255;
option routers               192.168.2.249;
option domain-name-servers   192.168.2.249;
option domain-name           "ltsp";          # <--Fix this domain name

option root-path             "192.168.2.249:/opt/ltsp/i386";

option option-128 code 128 = string;
option option-129 code 129 = text;

subnet 192.168.2.0 netmask 255.255.255.0 {
    use-host-decl-names      on;
    range 192.168.2.60 192.168.2.240;
    filename             "lts/2.4.26-ltsp-3/pxelinux.0";
    option log-servers       192.168.2.249;
}         
#
            # Add these two lines to the host entry that needs kernel parameters
            #
            #        option option-128     e4:45:74:68:00:00;       # NOT a mac address
            #        option option-129     "NIC=ne IO=0x300";
            #

4.    TFTP Configuration
      Enable TFTP.

5. Portmapper Configuration
Enable Poet Mapping (By default its on)

6.    NFS Configuration
     Enable NFS (By default its on)

7.    XDMCP Configuration
     Enable XDMCP (By default its XDM and its on)           

8. Create /etc/hosts entries
     Create hosts with LTSP installer. Then no need to modify it.

9.    Create /etc/hosts.allow entries
Create hosts with LTSP installer. Then no need to modify it.

10.              Create /etc/exports entries
Create export list with LTSP installer. Then no need to modify it.

12.              Create lts.conf files
     Create lts.conf with LTSP installer           
USB mount on LTSP

1. vi /opt/ltsp/i386/etc/lts.conf            //insert HOTPLUG entry.
        SERVER             = 10.0.2.51
        XSERVER            = auto
        X_MOUSE_PROTOCOL   = "PS/2"
        X_MOUSE_DEVICE     = "/dev/psaux"
        X_MOUSE_RESOLUTION = 400
        X_MOUSE_BUTTONS    = 3
        HOTPLUG            = Y
        USE_XFS            = N
        SCREEN_01          = startx


2.    Next, download the following two scripts and put them in /usr/local/bin










Installing the NodeManager service


1.    Open the Command Prompt
2.    Run %WL_HOME%\wlserver_10.3\server\bin\setWLSEnv.cmd to set Weblogic Environment variables like WL_HOME, JAVA_HOME, PATH, CLASSPATH etc.
3.    Edit the installNodeMgrSvc.cmd to bind to a hostname for remote starts 
set NODEMGR_HOST=localhost
4.    Now run the %WL_HOME%\wlserver_10.3\server\bin\installNodeMgrSvc.cmd Validate the service from the services list as well using the services.msc utility.


5.    Start the NodeManager service named as above “Oracle WebLogic NodeManager…”
6.    Make sure starting the NodeManager service should create a  nodemanager.properties file under %WL_HOME%\wlserver_10.3\common\nodemanager.

Setup NodeManager to restore servers to their last known state after a reboot

1.   
Open nodemanager.properties located at %WL_HOME%\wlserver_10.3\common\nodemanager
2.    Set CrashRecoveryEnabled property value to true CrashRecoveryEnabled=true 
3.    Set StartScriptEnabled property value to true to invoke the startWeblogic script StartScriptEnabled=true
4.    Set StopScriptEnabled property value to true to invoke the stopWeblogic script and get the managed servers to shutdown cleanly StopScriptEnabled=false
5.    Set ListenAddress property value ListenAddress=localhost
6.    Set SecureListener property value (In case you selected plan for as communication type) SecureListener=false
7.    Restart of NodeManager service for each change to this nodemanager.properties file



Setup the machine

1.    Login to the AdminServer console

2.    Navigate through Domain Structure to %DOMAIN_NAME% -> Environment -> Machines

3.    Create a new machine Name : localhost, OS : Other - as my operating system is Windows Node Manager - Type: Plan

4.    Create one machine for each instance of OS for a different host.

5.    Assign the ManagedServer to machines based on which machine the ManagedServer is hosted. Take Lock & Edit and navigate through %DOMAIN_NAME% -> Environment -> Machines -> %MACHINE_NAME% -> Configuration tab -> Servers tab

6.    Do not forget to save and Activate the changes.

Enrolling the domain with NodeManager      

1.    Open command prompt

2.    Run %DOMAIN_HOME%\bin\setDomainEnv.cmd to set domain specific environment variables

3.    Start WLST using java weblogic.WLST

4.    At WLS prompt connect to AdminServer using connect ('weblogic','weblogic','t3://localhost:7001')

5.    Run nmEnroll(domainDir='C:/oracle/Middleware/user_projects/domains/base_domain',nmHome='C:/oracle/Middleware/common/nodemanager'). Make sure that you use forward slashes "/" instead of backward "\" as WLST does not recognize forward slashes. If you use backward slashes "\" you get the following error.



6.    Once the domain is successfully enrolled with NodeManager the nodemanager.domains should be updated too with below values.

#Thu Apr 28 11:54:41 MDT 2014
            base_domain=C\:\\Oracle\\Middleware\\user_projects\\domains\\base_domain 
            Also NodeManager should be reachable in AdminServer console. To validate this,

a)    Login to AdminServer console

b)   Navigate through %DOMAIN_NAME% -> Environment -> Machines -> %MACHINE_NAME% -> Monitoring -> Node Manager Status it should be Reachable (If not please check the nodemanager.log in  C:\Oracle\Middleware\wlserver_10.3\common\nodemanager)
               


Server Startup Configuration

1.    Login to the AdminServer console
2.    Navigate through Domain Structure to %DOMAIN_NAME% -> Environment -> Servers -> ManagedServer_1 -> Configuration tab -> Server Start tab
3.    Take Lock & Edit and input values as appropriate.
Java Home - C:\oracle\Middleware\jdk160_14_R27.6.5-32
Java Vendor - Sun - As I am using Sun JDK 
Weblogic Home - C:\oracle\Middleware
Root Directory -C:\oracle\Middleware\user_projects\domains\base_domain 
Classpath - Can be left blank as we have configured the nodemanager.properties to use startWeblogic script in  Setup nodeManager to restore servers to their last known state after a reboot  step 3 and you can setup necessary values in that script.
Arguments - Can be left blank as we have configured the nodemanager.properties to use startWeblogic script in  Setup NodeManager to restore servers to their last known state after a reboot  step 3 and you can setup necessary values in that script. But i am using memory arguments as input here "-Xms64m -Xmx128m" 
Security Policy - File - C:\oracle\Middleware\wlserver_10.3\server\lib\weblogic.policy
User Name – weblogic
Password – weblogic
Confirm Password – weblogic
4.    Save and activate the changes
5.    Repeat steps 1-4 for each ManagedServer in the domain.



NodeManager Domain Username and password

1.    Login to the AdminServer console

2.    Click on Domain name in the Domain Structure and navigate through %DOMAIN_NAME% (cs_domain) -> Security tab -> General tab -> Advanced link

3.    Take Lock & Edit  and input the NodeManager username/password/confirm passwords fields and these could be unique from your weblogic console password. I have chosen to input same as my console credentials username: weblogic & password: weblogic. This setup would help user who use WLST to connect to NodeManager via nmConnect()

4.    Save and Activate the changes


Complete Setup

Finally the setup is complete and now its time to start your ManagedServer in Admin console using NodeManager.
Starting the ManagedServer using the NodeManager setup
1.    Login to the AdminServer console
2.    Navigate through Domain Structure to %DOMAIN_NAME% -> Environment -> Servers -> ManagedServer_1 -> Control tab -> Start/Stop tab
3.    Under the Server Status section select the ManagedServer and click on start button
4.    When prompted to confirm the Action to be performed, click yes button.
5.    Monitor the server logs and after a while the server should be in RUNNING state


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...