Saturday, May 14, 2016

Elasticsearch first met



Change cluster name to unique name on same network


D:\Elasticsearch\config\elasticsearch.yml:

cluster.name: nutthaphon


D:\Elasticsearch\start.bat
** Version 1.7.5 support jdk 1.7 only





Ease use on Chrome browser + Sense plugins




Test JSON document via JSON Parser


For thai language, use analyzer=thai
** default thai analyzer from Java, but can be another such as IBM or NECTEC LexTo etc.


POST _search
{
   "query": {
      "match_all": {}
   }
}
GET _aliases
DELETE twitter
PUT twitter
PUT twitter/tweet/1
{
"name": "meo",
"text" : "สวัสดีชาวโลก"
}
PUT twitter/tweet/2
{
    "name":"meo2",
 "text":"สวัสดีชาวโลก อีกครั้ง"
}
PUT twitter/tweet/3
{
    "name":"meo3",
 "text":"สวัสดีชาวโลก อีกครั้งแล้วเหรอ"
}
GET twitter
GET twitter/_search
PUT twitter/tweet/2
{
"name" : "somsak",
"email" : "somsak@gmail.com",
"address" : {
"road" :"roadtosomsak",
"province": "bangkok"
}
}
GET twitter/tweet/_search?q=meo
POST /_search
{
"query": {
"query_string": {
"query": "สวัสดีชาวโลก"
}
}
}
GET twitter/_search
{
"query": {
"query_string": {
"query": "สวัสดีชาวโลก"
}
}
}
POST /_search
{
    "query": {
        "query_string": {
            "query": "สวัสดีชาวโลก อีกครั้งแล้วเหรอ",
        "default_operator":"AND"
        }
    }
}
POST /_search
{
    "query": {
        "query_string": {
            "query": "meo",
        "fields": ["name"]
        }
    }
}
POST /_search
{
    "query": {
        "match": {
            "name": "meo"
        }
    }
}
GET movie_db/_search
GET movie_db/_search
{
"query": {
"match": {
"genre": "Action"
}
}
}
GET movie_db/_search
{
    "query": {
        "match": {
            "genre": "Drama"
        }
    }
}
GET movie_db/_search
{
    "query": {
        "query_string": {
            "query": "drama"
        }
    }
}
GET movie_db/_search
{
"query": {
"filtered": {
"query": {
"query_string": {
"query": "Action"
}
},
"filter": {
"range": { "release_year": {"gte":2001}}
}
}
}
}
GET products/_search
POST products/_search
{
"query": {
"filtered": {
"query": {
"match": {
"department_name": "Books"
}
},
"filter": {
"range": {
"price": {
"gte": 10000
}
}
}
}
}
}
DELETE twitter
PUT twitter
{
"mappings":{
"tweet": {
"properties": {
"name": {
"type": "string"
},
"text": {
"type": "string",
"analyzer":"thai"
},
"value": {
"type": "long"
}
}
}
}
}
GET twitter
PUT twitter/tweet/1
{
    "name":"meo",
    "text":"สวัสดีชาวโลก",
 "value": 10
}
PUT twitter/tweet/2
{
    "name":"meo2",
 "text":"สวัสดีชาวโลก อีกครั้ง",
 "value": 20
}
PUT twitter/tweet/3
{
    "name":"meo3",
 "text":"สวัสดีชาวโลก อีกครั้งแล้วเหรอ",
 "value": 30
}
GET twitter/_search
{
"query": {
"query_string": {
"query": "text:สวัสดี",
"analyzer": "thai"
}
}
}
GET twitter_db/_search
GET  twitter_db/_search
{
    "query": {
        "query_string": {
          
           "query": "สวัสดี" 
          
        }
    }
}


Kibana

Home = D:\kibana
run start.bat



http://localhost:5601/













Wednesday, May 11, 2016

Systemd Boot Manager


Installation


# add-apt-repository ppa:pitti/systemd
# apt-get update
# apt-get install systemd libpam-systemd systemd-ui

Boot loader configuration


Edit /etc/default/grub :

GRUB_CMDLINE_LINUX_DEFAULT="quiet splash init=/lib/systemd/systemd"

*** For an emergency boot without any services use
init=/lib/systemd/systemd systemd.unit=emergency.service


*** Previous Ubuntu use upstart like
init=/sbin/upstart

After any modifies then
# update-grub

Controlling service after booted

systemctl list-units - List all units (where unit is the term for a job/service)
systemctl start [NAME...] - Start (activate) one or more units
systemctl stop [NAME...] - Stop (deactivate) one or more units
systemctl enable [NAME...] - Enable one or more unit files
systemctl disable [NAME...] - Disable one or more unit files
systemctl reboot - Shut down and reboot the system
systemctl list-dependencies [NAME...] - Lists all dependency of service

Remote file system mount after networking ready

Old style use /etc/fstab  but can not check services dependency.

Create file /lib/systemd/system named <mount-unit-name>.mount and has a content

[Unit]
Description=<mountpoint>
Wants=network.target statd.service   // Network Status Monitor service
After=network.target statd.service

[Mount]
What=<server>:<share>
Where=<mountpoint>
Type=nfs
StandardOutput=syslog
StandardError=syslog

Where

  • <mount-unit-name> = Remote shared directory like "/usr/local" then file name is "user-local.mount"
  • <mountpoint>  = Local mount point
  • <server:share> = same manner in /etc/fstab







Tuesday, May 10, 2016

Ubuntu fix broken package

For 12.04 and newer:


You can delete the lock file with the following command:

sudo rm /var/lib/apt/lists/lock

You may also need to delete the lock file in the cache directory

sudo rm /var/cache/apt/archives/lock

Monday, May 9, 2016

VirtualBox Boot Guest VM from USB



Open Disk Management


Remember disk number see blue arrow ( i.e. It's PhysicalDrive1 )


Run command windows with Administrator

C:\Program Files\Oracle\VirtualBox>VBoxManage internalcommands createrawvmdk -filename "E:\Virtual Machine\VirtualBox\Ubuntu Xenial\usb.vmdk" -rawdisk \\.\PhysicalDrive1
RAW host disk access VMDK file E:\Virtual Machine\VirtualBox\Ubuntu Xenial\usb.vmdk created successfully.

Finally, open VirtualBox with Administrator


Monday, May 2, 2016

Manage data volume in Docker container



Possible way to keep data in container:

  1. Storing data within the container
  2. Store your data outside Docker’s Union Filesystem
  3. Mounting a volume within the Docker host’s filesystem
  4. Storing data on a network-attached block device. Docker volume plugins allow you to provision and mount shared storage, such as iSCSI, NFS, or FC


Case 1: It 's normal case, you can store any data to guest OS file system. When run container and show your filesystem with 'df' command, show you like this


docker@default:~$
docker@default:~$ docker run -it --name oel-guest1 --rm oraclelinux:7.2 bash
[root@acbc5894fa52 /]#
[root@acbc5894fa52 /]#
[root@acbc5894fa52 /]# df -m
Filesystem     1M-blocks  Used Available Use% Mounted on
none               18306  1808     15532  11% /
tmpfs                498     0       498   0% /dev
tmpfs                498     0       498   0% /sys/fs/cgroup
/dev/sda1          18306  1808     15532  11% /etc/hosts
shm                   64     0        64   0% /dev/shm
[root@acbc5894fa52 /]#


Case  2: Create or run container as volume container. This volume container can share among containers in same Docker host


docker create -v /orahome --name orahome oraclelinux:7.2 /bin/true
docker run -it --volumes-from orahome --name db1 oraclelinux:7.2 bash
[root@b5c9355faefb /]#
[root@b5c9355faefb /]# df -k
Filesystem     1K-blocks    Used Available Use% Mounted on
none            18745336 1850824  15903788  11% /
tmpfs             509888       0    509888   0% /dev
tmpfs             509888       0    509888   0% /sys/fs/cgroup
/dev/sda1       18745336 1850824  15903788  11% /orahome
shm                65536       0     65536   0% /dev/shm

exit
docker inspect db1

...
 "Mounts": [
            {
                "Name": "8b552ab768be1f3d7ddc73059dbab62d82a0c316fc7c5303e6833377fcbdb937",
                "Source": "/mnt/sda1/var/lib/docker/volumes/8b552ab768be1f3d7ddc73059dbab62d82a0c316fc7c5303e6833377fcbdb937/_data",
                "Destination": "/orahome",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            }
        ],

...


Mount multiple volume

docker create -v /oradata --name oradata oraclelinux:7.2 /bin/true

docker run -it --rm  --volumes-from=oradata --volumes-from=orahome --name db1 oraclelinux:7.2 bash

-- add host share folder
docker run -it --rm --privileged -v /cygdrive/d/TEMP:/test --volumes-from=oradata --volumes-from=orahome --name db1 oraclelinux:7.2 bash

docker inspect db1


"Mounts": [
            {
                "Name": "1def11f59155cd3e02bb2b1f94dbe84e0c3b8aff6834e3146da1f21d9ce25c70",
                "Source": "/mnt/sda1/var/lib/docker/volumes/1def11f59155cd3e02bb2b1f94dbe84e0c3b8aff6834e3146da1f21d9ce25c70/_data",
                "Destination": "/oradata",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Name": "8b552ab768be1f3d7ddc73059dbab62d82a0c316fc7c5303e6833377fcbdb937",
                "Source": "/mnt/sda1/var/lib/docker/volumes/8b552ab768be1f3d7ddc73059dbab62d82a0c316fc7c5303e6833377fcbdb937/_data",
                "Destination": "/orahome",
                "Driver": "local",
                "Mode": "",
                "RW": true,
                "Propagation": ""
            },
            {
                "Source": "/cygdrive/d/TEMP",
                "Destination": "/test",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],


Case 3: Mounting host file system (Boot2Docker linux)


docker@default:~$ docker run -it --name hostdir --privileged -v /cygdrive/d/TEMP:/test oraclelinux:7.2 bash
[root@ea3d6181c614 /]# df -k
Filesystem     1K-blocks      Used Available Use% Mounted on
none            18745336   1355072  16399540   8% /
tmpfs             509888         0    509888   0% /dev
tmpfs             509888         0    509888   0% /sys/fs/cgroup
temp           439887868 211736176 228151692  49% /test
/dev/sda1       18745336   1355072  16399540   8% /etc/hosts
shm                65536         0     65536   0% /dev/shm
[root@ea3d6181c614 /]# exit
exit
docker@default:~$ docker inspect hostdir
...
 "Mounts": [
            {
                "Source": "/cygdrive/d/TEMP",
                "Destination": "/test",
                "Mode": "",
                "RW": true,
                "Propagation": "rprivate"
            }
        ],

...

Case 4: Use Docker volume plugin

..... coming soon .....



Oracle 12c docker container



open VirtualBox and goto settting, in Shared folders

add folder, permission and naming

Press OK and finish in VirtualBox

To ensure shared folder can access by Docker container restarting

docker-machine stop default
docker-machine start default

Babun shell:

docker-machine ssh default

sudo mkdir -p /cygdrive/d/TEMP
sudo mount -t vboxsf temp /cygdrive/d/TEMP

docker@default:~$ df -k
Filesystem                Size      Used Available Use% Mounted on
tmpfs                   896.3M    164.5M    731.8M  18% /
tmpfs                   497.9M         0    497.9M   0% /dev/shm
/dev/sda1                17.9G    807.9M     16.1G   5% /mnt/sda1
cgroup                  497.9M         0    497.9M   0% /sys/fs/cgroup
/dev/sda1                17.9G    807.9M     16.1G   5% /mnt/sda1/var/lib/docker/aufs
temp                    419.5G    200.0G    219.5G  48% /cygdrive/d/TEMP


 docker run -it --privileged -v /cygdrive/d/TEMP:/test oraclelinux:7.2 bash

Install database
/vagrant/database/runInstaller -silent -showProgress -ignorePrereq -responseFile /vagrant/db_install.rsp

Listener configuration
netca -silent -responseFile $ORACLE_HOME/assistants/netca/netca.rsp

Database creation
dbca -silent -createDatabase -responseFile /vagrant/dbca.rsp