Wednesday, December 08, 2021

SSH access with key

Create Public & Private Key

$ ssh-keygen -t rsa

$ ls -l
id_rsa  <-- private key
id_rsa.pub  <-- public key

Create .ssh directory. Change ownership
$ mkdir /home/<user>/.ssh
$ cat id_rsa.pub >> /home/<user>/.ssh/authorized_keys

$ chmod 700 /home/<user>/.ssh
$ chmod 600 /home/<user>/.ssh/authorized_keys

Copy id_rsa private key file to Windows computer.
Use Puttygen.exe to convert from id_rsa.private to id_rsa.ppk
Configure Putty.exe to use SSH key id_rsa.ppk to access server (instead of password)


Sunday, May 24, 2020

Python - send message to Slack channel

Requirement:
$ sudo apt install python-pip
$ pip install requests

$ cat sendmsg.py
--
import requests
import json

webhook = 'https://hooks.slack.com/services/T02Bxxxxx/BHL1xxxxx/RxtkmKBo0xxxxxxx'
slack_data = {
    'channel': '#yourchannelname',
    'text': 'Hello apa khabar'
}

response = requests.post(webhook, data=json.dumps(slack_data), headers={'Content-Type':'application/json'})

print('Response: ' + str(response.text))
print('Status code: ' + str(response.status_code))
--
$ python sendmsg.py



Wednesday, May 13, 2020

First Electron Desktop Application

FIRST ELECTRON DESKTOP APP PROJECT

Electron - framework to easily build desktop app using html, javascript, css.
Example of popular desktop app using electron - whatsapp desktop, atom editor, slack messenger

Install Nodejs
$ sudo apt-get update
$ sudo apt-get install nodejs

Install npm
$ sudo apt-get install npm

Install Electron
$ npm install --save-dev electron

Create work directory
$ mkdir -p /home/mzadmin/NODEJS/first_electron
$ cd /home/mzadmin/NODEJS/first_electron

---
$ npm init -y

For normal nodejs app:
$ cat package.json
{
  "name": "first_electron",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node ."
  }
}

Change to electron app:
  "scripts": {
    "start": "electron ."
  }

Electron app
$ cat index.js
const { app, BrowserWindow } = require('electron')
function createWindow () {
  let win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      nodeIntegration: true
    }
  })
  win.loadFile('index.html')
}
app.whenReady().then(createWindow)

HTML appfile 
$ cat index.html
<html>
<body bgcolor="beige">
Hello electron world
</body>
</html>

RUN APP
$ npm start

LIST OF FILES
node_modules (directory 199mb)
package.json
index.js
index.html

PACKAGE app as exe
Install electron-packager (for use in npm scripts)
$ npm install electron-packager --save-dev

$ electron-packager <sourcedir> <appname> --platform=win32 --arch=x64


Friday, September 13, 2019

Setting up APACHE DERBY DB

(1) Create user myderby
# useradd -m -c "Derby Admin" myderby
# passwd myderby
Password: password

(2) Install Java
# yum install java-1.8.0-openjdk -y

(3) Download Derby file
https://db.apache.org/derby/releases/release-10.14.2.0.cgi
# mkdir /opt/derbydata
# chown myderby:myderby /opt/derbydata
# su - myderby
$ cd /opt/derbydata

$ tar -zxvf db-derby-10.14.2.0-bin.tar.gz
$ mv db-derby-10.14.2.0-bin /opt/

(4) Setup home path
$ vi /home/myderby/.bashrc
 export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.181-7.b13.el7.x86_64/jre
 export DERBY_HOME=/opt/db-derby-10.14.2.0-bin
 export PATH=$JAVA_HOME/bin:$DERBY_HOME/bin:$PATH

(5) Create Derby DB & Table
$ java -jar /opt/db-derby-10.14.2.0-bin/lib/derbyrun.jar ij

ij> connect 'jdbc:derby:/opt/derbydata/dbphone;create=true';

ij> create table tphone (id int primary key, name varchar(15), phone varchar(10));

ij> insert into tphone values (1,'Romeo','0193830000');
ij> insert into tphone values (2,'Juliet','0123490000');

ij> select * from tphone;
ID         |NAME           |PHONE
--------------------------------------
1          |Romeo          |0193830000
2          |Juliet         |0123490000
2 rows selected

(6) Start DB Derby to listen to port 1527
# /opt/db-derby-10.14.2.0-bin/bin/startNetworkServer -h 0.0.0.0 &
Thu Nov 23 20:19:49 MYT 2017 : Apache Derby Network Server - 10.14.1.0 - (1808820) started and ready to accept connections on port 1527

# netstat -an|grep 1527
tcp6       0      0 0.0.0.0:1527          :::*                    LISTEN

(7) Connect to Derby from your application
DB Type: Derby
DB Name: /opt/derbydata/dbphone
DB Host/IP: <server ip>
Port no: 1527
Username: myderby
Password: password




Friday, April 19, 2019

GIT with bitbucket.org

Login to bitbucket.org
>create new repository name "bitstamp"

git config --global user.name "rayrosliabas"
git config --global user.email "rayrosliabas@gmail.com"
git config -l

git clone https://rayrosliabas@bitbucket.org/rayrosliabas/bitstamp.git
Enter password:

cd bitstamp
git pull

git add bitstamp-avg.js bitstamp.js
git commit -a -m 'add bitstamp.js & bitstamp-avg.js'
git push -u origin master

git status
git log

git checkout -b mynewbranch
git branch -av  (list branches)
git checkout master (back to master)
git push origin branch (push branch to repo)

git diff master mynewbranch
git merge mynewbranch  (merge branch to master)
git push origin master (push merged branch+master to repo)







Wednesday, October 24, 2018

Build Own Image with Dockerfile

Create Dockerfile
> mkdir mywork

> vi Dockerfile
# Build own ubuntu with Dockerfile

FROM ubuntu
MAINTAINER rayrosliabas@gmail.com

RUN apt-get install -y mlocate
# RUN ["/bin/bash"]

CMD ["echo","Welcome to my Ubuntu"]

Build image name as "my_ubuntu",  dockerfile location c:\mywork\
> docker build -t my_ubuntu c:\mywork\

List images created
> docker images
REPOSITORY                 TAG                 IMAGE ID            CREATED              SIZE
my_ubuntu                 ver.1          6cee799c3ba7        About a minute ago   110MB
ubuntu                     latest              ea4c82dcd15a        5 days ago           85.8MB

Test Run
>docker run -it my_ubuntu
Welcome to my Ubuntu

Notes:
-if using CMD, image will run, execute echo, then terminated.
-if using RUN /bin/bash, image will login into container server

Tuesday, October 23, 2018

DOCKER

Install docker on Windows 10 laptop/pc
https://docs.docker.com/docker-for-windows/install/

Disable ipv6 in Network Settings - to avoid slow response during running docker commands

C:\ docker search centos
NAME                               DESCRIPTION                                   
centos                             The official build of CentOS.

C:\ docker pull centos

C:\ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
centos              latest              75835a67d134        13 days ago         200MB

C:\ docker ps
List running docker containers

C:\ docker ps -a
List running & exited containers

C:\ docker run -it -d --privileged=true -h "SERVER01" -p 9000:9000 -p 222:22 --name mycentos centos:latest
(Run in detached mode centos image, as name mycentos, hostname SERVER01, expose port 9000 and 22 (for ssh), give root access privileged. If connect with ssh, use ip 127.0.0.1 port 222).

>can also expose port range. Eg: -p 600-700:600:700

C:\ docker exec -it mycentos bash
(Connect to detached container cmd line)

C:\ docker stop mycentos
(Stop/shutdown server)

C:\ docker start mycentos
(Start server, that is status 'Exited'. No need to rerun using cmd 'docker run')

C:\ docker commit mycentos myserver1:monday
(Save container in status running or exited to image file. If not once removed, changes is lost. Check in 'docker images')

C:\ docker save -o myserver.tar mycentos
(Backup/Save container to file)

C:\ docker load -i myserver.tar
(Restore from tar file to image. Do not use import/export/restore for correct result)

C:\ docker tag <oldname or id> <newname>

C:\docker rm mycentos
(delete container from running, stop, exited status)

C:\ docker rmi centos
(permanently delete docker server from images pulled or saved)

C:\docker stats
>shows cpu & memory usage. Ctrl+c to exit



Other notes:
To enable systemctl
--privileged=true + centos /sbin/init

*require docker run centos /sbin/init

Share Folder With Host C:\share & Docker Image /opt/share
$ docker run -v /c/share:/opt/share centos /sbin/init

yum install openssh-clients openssh-server -y
> vi sshd_config --> UsePAM no

yum install sudo mlocate net-tools -y



Wednesday, August 01, 2018

LINUX COMMANDS

Mail commands

send email
$ mail -s 'email subject' myname@gmail.com < /tmp/myemail.txt

mail queue
$ mailq
$ postqueue -p

delete mail from queue
$ sudo postsuper -d <queue id>


Monday, July 23, 2018

PostgreSQL

INSTALL Redhat/Centos

# yum install postgresql postgresql-contrib postgresql-server -y
# postgresql-setup initdb
Initializing database ... OK

# vi /var/lib/pgsql/data/pg_hba.conf
    82  host    all             all             127.0.0.1/32            ident <-change to md5
    84  host    all             all             ::1/128                 ident  <-change to md5

# systemctl start postgresql
# systemctl enable postgresql
# systemctl status postgresql


CREATE DB
From linux prompt (Server KL-Test)
$ su - postgres
Pwd: postgres

$ cd /usr/lib/postgresql/9.5/bin  (ubuntu only)
createdb dbphone

ENTER SQL
$ psql dbphone

CREATE TABLE

# \l = list databases
# create table tphone (id int, name varchar(25),phone varchar(15));
# \d = display tables

INSERT DATA
dbphone=# insert into tphone values(1,'Romeo','019-3836031');
INSERT 0 1

DISPLAY DATA
dbphone=# select * from tphone;
 id | name  |    phone
----+-------+-------------
  1 | Romeo | 019-3836031
(1 row)

OTHER NOTES
\c dbphone --connect to db
\q -- quit sql
\d tphone --describe table design

# alter table tphone add email varchar(15);

Network connection info
dbphone=# \conninfo
You are connected to database "dbphone" as user "mzadmin" via socket in "/var/run/postgresql" at port "5432".

Thursday, July 05, 2018

RHEL 7 - Extend root filesystem (type xfs)

# fdisk -l
Disk /dev/sdb: 5368 MB, 5368709120 bytes

# fdisk /dev/sdb
Command (m for help): n (new)
Select (default p): p (primary)
Partition number (1-4, default 1): 1 (choose default 1)
Partition 1 of type Linux and of size 5 GiB is set
Command (m for help): t (change type)
Hex code (type L to list all codes): 8e
Changed type of partition 'Linux' to 'Linux LVM'
Command (m for help): w
The partition table has been altered!

# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

# vgextend rhel /dev/sdb1
  Volume group "rhel" successfully extended

# vgdisplay rhel
  Free  PE / Size       1279 / <5.00 GiB

# pvscan
  PV /dev/sda2   VG rhel            lvm2 [<7.00 GiB / 0    free]
  PV /dev/sdb1   VG rhel            lvm2 [<5.00 GiB / <5.00 GiB free]
  Total: 2 [11.99 GiB] / in use: 2 [11.99 GiB] / in no VG: 0 [0   ]

# lvextend /dev/rhel/root /dev/sdb1
  Size of logical volume rhel/root changed from <6.20 GiB (1586 extents) to 11.19 GiB (2865 extents).
  Logical volume rhel/root successfully resized.

# xfs_growfs /dev/rhel/root
data blocks changed from 1624064 to 2933760

# df -h /
Filesystem             Size  Used Avail Use% Mounted on
/dev/mapper/rhel-root   12G  5.6G  5.6G  50% /


Friday, June 01, 2018

RHEL 7 - Add static route persistent/permanently

Check current route
# ip route show
default via 10.1.1.1 dev enp0s3  proto static  metric 1024
10.0.0.0/8 dev enp0s3  proto kernel  scope link  src 10.1.1.110

Add to persistent route
To add destination 15.15.0.0/24 via ip 10.1.1.110 using interface enp0s3
# cat /etc/sysconfig/network-scripts/route-enp0s3
15.15.0.0/24 via 10.1.1.110 dev enp0s3

Restart network & verify

Sunday, May 20, 2018

Redhat/CentOS systemd service

Creating new systemd service that starts & stops automatically on every reboot & shutdown

# cat /etc/systemd/system/sayhello.service
[Unit]
Description=Mediation Zone Platform, EC1 service
After=network.target

[Service]
Type=simple    #one-shot,forking
User=rayrosli
WorkingDirectory=/home/rayrosli
ExecStart=/home/rayrosli/bin/sayhello.sh
ExecStop=/home/rayrosli/bin/saybye.sh

[Install]
WantedBy=multi-user.target

# systemctl daemon-reload
# systemctl status sayhello.service
# systemctl enable sayhello.service
# systemctl start sayhello.service
# systemctl stop sayhello.service


NOTE:
>For mediationzone application, use Type=forking.
>ExecStart, ExecStop configured & runs successfully 

Monday, May 07, 2018

Couchbase NoSQL DB Installation

Couchbase  Installation Steps
>on ubuntu server 16.04
>Couchbase Server 5.1.0 Enterprise for Ubuntu 16.04 (size 100mb)
>Choose download package from:
https://www.couchbase.com/downloads

INSTALL
$ sudo apt-get update
$ sudo apt-get autoclean
$ sudo apt-get -f install
$ sudo apt-get -f install python-httplib2

$ curl -O https://packages.couchbase.com/releases/5.1.0/couchbase-server-enterprise_5.1.0-ubuntu16.04_amd64.deb

$ sudo dpkg -i couchbase-server-enterprise_5.0.0-ubuntu14.04_amd64.deb
Done.
You have successfully installed Couchbase Server.
Please browse to http://localhost:8091/ to configure your server.

INITIALISE CLUSTER - via couchbase Web Console
Open browser to http://localhost:8091/
choose [Setup New Cluster]

Cluster Name : MyCouchDB
Admin user: Administrator
Pwd: xxx

CONFIGURE
Hostname/IP : 127.0.0.1
Data Disk Path : /opt/couchbase/var/lib/couchbase/data
Index Disk Path: /opt/couchbase/var/lib/couchbase/data
Memory Quota : xx MB

START/STOP SERVICE
>startup script auto installed in Ubuntu/Redhat/CentOS
> /etc/init.d/couchbase-server stop|start
>manual (redhat/centos):
$ sudo systemctl start couchbase-server

Wednesday, April 25, 2018

RHEL Notes

INDEX

Reset root password
NFS normal, secure
Samba

Postfix
DNS unbound

Mariadb
Bash script

Storage
HTTP webserver

Shell
Firewall

Other: Firewall, Network teaming, ip address

Add new disk


CONTENT

Reset root password
-boot server, press any key, press "e" to edit
-linux 16 --> rd.break
-ctrl x to boot
mount -o remount, rw /sysroot
chroot /sysroot
passwd
touch /.autorelabel
exit 

NFS


SAMBA
yum install samba -y
yum install samba-client -y
yum install cifs-utils -y

systemctl start/enable smb
systemctl start/enable nmb

firewall-cmd --permanent --add-service=samba
firewall-cmd --reload

mkdir /sharesamba
semanage fcontext -a -t samba_share_t '/sharesamba(/.*)?'

useradd -s '/sbin/nologin' fred
smbpasswd -a fred

vi /etc/samba/smb.conf
--
workgroup = asiapacific.asiacorp.net
hosts allow = 127. 16.189.16
[mysamba]
comment = my samba
path = /sharesamba
browserable = yes
writeable = yes
guest ok = yes
valid users = fred, @admin
--
testparm
smbclient -L 127.0.0.1 -U fred
smbstatus

POSTFIX

*rimnet orideslo*
vi /etc/postfix/main.cf
--
relayhost = smtp2.example.com
inet_interfaces = loopback-only
mynetworks = 127.0.0.1/8 [::1]/128
myorigin = wani7
mydestinations =
local_transport=error:local delivery disabled
--
postconf -e "myorigin=wani7"
postconf relayhost

Unbound DNS
yum install unbound -y
*inac dofo*

vi /etc/unbound/unbound.conf
interface = loop-back only
access-control = 127.0.0.1/8 [::1]/128
domain-insecure = "asiapacific.asiacorp.net"
forward-zone:
  name: .
  forward-addr: 16.189.16.254

Mariadb
yum groupinstall mariadb-client -y
yum groupinstall mariadb -y

systemctl start mariadb.service
systemctl enable mariadb.service

firewall-cmd --permanent --add-service=mysql
firewall-cmd --reload

mysql -u root
show databases;
create database dbphone;
use dbphone;

create table tphone (name char(10), phonenum int );
describe tphone;
insert into tphone values ('emma', 5551234);
show tables;
select * from tphone;

CREATE USER 'mary@'%' IDENTIFIED BY 'mary123';
grant select on dbphone.* to mary@'%'
flush priveleges;
exit;

Dump table data into db
mysql -u root < /tmp/data.sql dbphone
mysqldump -root dbphone > /tmp/mydata.sql

Show table data from linux cmd line
mysql -u root -p -e 'select * from tphone' dbphone

Other notes:
-create user must use caps
-


BASH SCRIPT
vi myscript.sh
#!/bin/bash

if [ $# -eq 0 ]; then
 echo "need input"
fi

case $1 in
 one)
   echo "satu"
 ;;
 *)
   exit;
 ;;
esac

for i in {1..5}; do
 echo $i;
done

STORAGE
cdialupo -- fw mudo -- dislogses - xfs blkid

install targetcli, iscsi-initiator-utils
start/enable target
fw port 3260

fdisk /dev/sda. new partition sda1
targetcli
>create disk - iscsi - acls -luns - portals
(disk, server, desktop, disk, port)

vi iscsi initiator (desktop)
isciadm >discovery - logins - session

mkfs -t xfs /dev/sda1
blkid /dev/sda1
/etc/fstab --> UUID /mnt/z  xfs  _netdev 0 2

--

FIREWALL

# firewall-cmd --list-all-zones
# firewall-cmd --get-default-zone
# firewall-cmd --zone=work --list-services
# firewall-cmd --permanent --zone=public --add-service=http
success

# firewall-cmd --list-services

# firewall-cmd --list-ports

# firewall-cmd --permanent --add-port=2222/tcp

# systemctl restart firewalld

HTTP WEBSERVER

(A) Web PHP
install --> httpd --- php --- php-mysql
start/en  --> httpd.service
fw --> http, https

ls -lZ /var/www/html/index.php
restorecon -Rv /var/www/
...
(B) Web Vir + SSL
install --> httpd  --- mod_ssl --- mod_wsgi



OTHER

NETWORK IP Config
CLI
ip addr add 192.168.0.35/24 dev eth0
ip route add 192.168.0.1 dev eth0
DNS -> vi /etc/resolv.conf
8.8.8.8

Check:
ip addr
ip route

PERMANENT
vi /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=none
ONBOOT=yes
PREFIX=24
IPADDR=192.168.0.35

vi /etc/sysconfig/network  (gateway)
192.168.0.1

systemctl restart network

NETWORK TOOLS
-no yum install required

yum install net-tools (for basic networking tools)
ifconfig
netstat -rn

NETWORK TEAMING

nmcli con add
 type team
 con-name team0
 ifname team0
 config 'runner:name:roundrobin'

--> '{runner: {name: roundrobin}}'
--> '{"runner":{"name":"activebackup"}}'

nmcli con mod team0
 ipv4.address '192.168.0.15/24'

nmcli con mod team0
 ipv4.method manual

nmcli con add
 type team-slave
 con-name team0-port1
 ifname eth0
 master team0
--> repeat for team0-port2 + eth1

teamdctl team0 state
nmcli dev dis/con team0-port1
nmcli con delete team0-port2
nmcli con delete team0


*notes:
forgot-> config ' ', mod team0, master team0


Add new disk
# fdisk -l
> /dev/sdb = 2GB

# fdisk /dev/sdb
n=new
p=primary partition
t=change type
83=linux
8e=linux LVM
p=print current setting
w= write & quit

# pvcreate /dev/sdb1
  Physical volume "/dev/sdb1" successfully created.

Create new filesystem /opt/mz using new disk

# vgcreate vgopt /dev/sdb1

# lvcreate -L 2G -n lvopt vgopt
# lvdisplay

# mkfs.ext4 /dev/vgopt/lvopt

# mkdir /opt/mz
# mount /dev/vgopt/lvopt  /opt/mz
# df -h /opt/mz

>edit /etc/fstab to mount as persistence
/dev/mapper/vgopt-lvopt      /opt/mz    ext4    defaults  0 0


Monday, April 16, 2018

NMON monitoring in Cron

Runs NMON monitoring tool via CRON at 12.00midnight
Runs on 1st & 15th every month and deletes files after 30 days

0 0 * * * /usr/bin/nmon -ft -l 64 -s 600 -c 144 -m /tmp/nmon
0 0 1,15 * * /usr/bin/find /tmp/nmon/* -mtime +30 -exec rm {} \;

Convert nmon file to html chart with nmon chart tool
Usage: nmonchart input01.nmon output01.html

Download: http://nmon.sourceforge.net/pmwiki.php?n=Site.Nmonchart

Ubuntu & MySQL

Ubuntu & MySQL

# apt-get update
(download/refreshes package informations from configured sources)

Configured sources
$ cat /etc/apt/sources.list

# apt-get install mysql-server
# /usr/bin/mysql_secure_installation
>to create root user & password

# service mysql start
# /usr/sbin/update-rc.d mysql defaults
>to set autostart after every reboot

>Note: network access port = 3306

# mysql -u root -p
mysql>

> show databases
> grant all privileges on *.* to 'mzadmin'@'localhost';
> create database dbphone;
> use dbphone;
> show tables;
> create table tphone (id int, name varchar(25), phone varchar(10));
> insert into tphone values (1,'Rosli','0123335555');
> select * from tphone;
> describe tphone;
> quit;

UBUNTU INSTALL PACKAGE
Install/upgrade oracle java in Ubuntu

$ sudo apt-get update
$ sudo apt-cache search jre
$ sudo apt-get install default-jre

$ java -version

Monday, April 02, 2018

RESET WINDOWS USER PWD FROM UBUNTU LINUX

RESET WINDOWS USER PWD FROM UBUNTU LINUX

Boot with Ubuntu Desktop Linux

Software sources - Enable universe repo. Use sudo if required
# add-apt-repository universe
# apt-get update
# apt-get install chntpw -y

**or download chntpw from https://pkgs.org/download/chntpw **

# fdisk -l
(if shown as microsoft basic data, means bitlocker encrypted. unable to reset)

# mkdir /mnt/windows
# ntfs-3g /dev/sda3 /mnt/windows -o force

# ls /mnt/windows
# cd /mnt/windows/Windows/System32/config
# chntpw -l SAM
# chntpw -u Administrator SAM
# chntpw -u romeo SAM
>choose clear pwd, unlock, promote to admin, quit etc
>save yes

Other:
Lightweight Slitaz Linux, install chntpw using tazpkg
http://www.slitaz.org/en/get/flavors.php  (29MB)
Download with browser http://distro.ibiblio.org/slitaz/packages/cooking/chntpw-140201.tazpkg
$ su
Pwd: root
# tazpkg install chnt*.tazpkg
(will require internet to install dependency openssl package)


Monday, March 26, 2018

INSTALL ORACLE XE 11g on UBUNTU SERVER LINUX 16.04

INSTALL ORACLE XE 11g on UBUNTU SERVER LINUX 16.04

Download oracle installation file
http://www.oracle.com/technetwork/database/database-technologies/express-edition/downloads/index.html

Convert from rpm file to deb for Ubuntu
# alien --scripts -d oracle-xe-11.2.0-1.0.x86_64.rpm
oracle-xe_11.2.0-2_amd64.deb generated

# ls -l
-rw-rw-r-- 1 mzadmin admin 317320273 Aug 28  2011 oracle-xe-11.2.0-1.0.x86_64.rpm
-rw-r--r-- 1 root    root  275903388 Mar 26 11:08 oracle-xe_11.2.0-2_amd64.deb

# vi /sbin/chkconfig
     1  #!/bin/bash
     2  # Oracle 11gR2 XE installer chkconfig hack for Ubuntu
     3  file=/etc/init.d/oracle-xe
     4  if [[ ! `tail -n1 $file | grep INIT` ]]; then
     5  echo >> $file
     6  echo '### BEGIN INIT INFO' >> $file
     7  echo '# Provides: OracleXE' >> $file
     8  echo '# Required-Start: $remote_fs $syslog' >> $file
     9  echo '# Required-Stop: $remote_fs $syslog' >> $file
    10  echo '# Default-Start: 2 3 4 5' >> $file
    11  echo '# Default-Stop: 0 1 6' >> $file
    12  echo '# Short-Description: Oracle 11g Express Edition' >> $file
    13  echo '### END INIT INFO' >> $file
    14  fi
    15  update-rc.d oracle-xe defaults 80 01
    16  #EOF

# ll /sbin/chkconfig
-rw-r--r-- 1 root root 553 Mar 26 11:19 /sbin/chkconfig
# sudo chmod 755 /sbin/chkconfig
--
# vi /etc/sysctl.d/60-oracle.conf
# Oracle 11g XE kernel parameters
fs.file-max=6815744
net.ipv4.ip_local_port_range=9000 65000
kernel.sem=250 32000 100 128
kernel.shmmax=536870912

# service procps restart

# sysctl -q fs.file-max
fs.file-max = 6815744

# ln -s /usr/bin/awk /bin/awk
# mkdir /var/lock/subsys
# touch /var/lock/subsys/listener

INSTALL

# dpkg --install oracle-xe_11.2.0-2_amd64.deb

Run configure script

# /etc/init.d/oracle-xe configure

Port for Oracle Application Express (default 8080): 8081
(using 8081 because 8080 already exist for other app)

Port for databaselistener [1521]: <Enter>

Specify password: oracle
Confirm pwd: oracle

Oracle to start on boot : y

Starting Oracle Net Listener...Done
Configuring database...Done
Starting Oracle Database 11g Express Edition instance...Done
Installation completed successfully.
---

# cat /etc/passwd
oracle:x:1004:1004::/u01/app/oracle:/bin/bash

# id oracle
uid=1004(oracle) gid=1004(dba) groups=1004(dba)

Change oracle id password or else sudo to oracle id
# passwd oracle

Setup oracle variables

# vi /etc/bash.bashrc

# ORACLE ENV VARIABLES
export ORACLE_HOME=/u01/app/oracle/product/11.2.0/xe
export ORACLE_SID=XE
export NLS_LANG=`$ORACLE_HOME/bin/nls_lang.sh`
export ORACLE_BASE=/u01/app/oracle
export LD_LIBRARY_PATH=$ORACLE_HOME/lib:$LD_LIBRARY_PATH
export PATH=$ORACLE_HOME/bin:$PATH

Load changes
# source /etc/bash.bashrc
Check
# echo $ORACLE_HOME
/u01/app/oracle/product/11.2.0/xe

Start Oracle

# service oracle-xe start

# service oracle-xe status
  oracle-xe.service - LSB: Oracle 11g Express Edition
   Loaded: loaded (/etc/init.d/oracle-xe; bad; vendor preset: enabled)
   Active: active (exited) since Mon 2018-03-26 13:10:41 +08; 22s ago
     Docs: man:systemd-sysv-generator(8)
  Process: 24839 ExecStart=/etc/init.d/oracle-xe start (code=exited, status=0/SUCCESS)

Mar 26 13:10:41 KL-TEST systemd[1]: Starting LSB: Oracle 11g Express Edition...
Mar 26 13:10:41 KL-TEST oracle-xe[24839]: Oracle Database 11g Express Edition instance is already started
Mar 26 13:10:41 KL-TEST systemd[1]: Started LSB: Oracle 11g Express Edition.
--

Make getting started link on desktop executable
$ cd ~/Desktop
$ chmod a+x oraclexe-gettingstarted.desktop

REFERENCE
http://blog.whitehorses.nl/2014/03/18/installing-java-oracle-11g-r2-express-edition-and-sql-developer-on-ubuntu-64-bit/


EXAMPLE:
$ id
oracle
$ sqlplus
Enter username: mzadmin
Enter password: xxxx
SQL>
SQL> conn / as sysdba
Connected.
SQL> create user mzadmin identified by dba;
SQL> grant dba to mzadmin;
SQL> conn mzadmin as sysdba;
Password: dr

>Create table & insert data using SQL Developer Client
>Check data from sql*plus cmd line

SQL> SELECT * FROM MZADMIN.TPHONE;

        ID NAME                      PHONE
---------- ------------------------- ---------------
         1 AINA                0193831234

CHECK SESSION PARAMETER & CURRENT USAGE
SQL> select name, value from v$parameter where name='sessions';
NAME
--------------------------------------------------------------------------------
VALUE
--------------------------------------------------------------------------------
sessions
172

SQL> select count(*) from v$session;
  COUNT(*)
----------
        35


Wednesday, November 08, 2017

Mediation Zone 7.3 Installation Guide

Virtualbox - UBUNTU SERVER

-Storage disk - 10GB
-Boot from ubuntu iso file
-Install Ubuntu 16.04

Network Configurations
NAT - Advance - Port Forwarding
127.0.0.1--447--10.0.2.15--22
127.0.0.1--6790--10.0.2.15--6790
127.0.0.1--6791--10.0.2.15--6791

--
Putty connect to 127.0.0.1 port 447
Id: mzadmin Pwd: xx
==

Create User
# useradd -m -g sudo -c "MZ Admin" mzadmin
# passwd mzadmin
passwd: xx

Install JAVA - JRE, JDK
# apt-get install default-jre
# apt-get install default-jdk

# ln -s /usr/lib/jvm/java-1.8.0-openjdk-amd64 /opt/java

# mkdir /opt/mz
chown mzadmin:mzadmin /opt/mz

# mkdir /opt/3pp
chown mzadmin:mzadmin /opt/3pp

==
# vi /home/mzadmin/.bashrc
# To set environment home
export MZ_HOME=/opt/mz
export JAVA_HOME=/opt/java
export PATH=$JAVA_HOME/bin:$MZ_HOME/bin:$PATH

Download oracle jdbc & save to /opt/3pp/
# ls -l /opt/3pp/ojdbc6.jar


INSTALL MZ SERVER PLATFORM

>require 2GB disk space
>extract MZ73 installation to /home/mzadmin/installer/

$ su - mzadmin
$ cd /home/mzadmin/installer/MZ73

$ ./setup.sh prepare
Follow installation instructions (doc/installation.pdf) to configure install.xml for your environment
When done, execute ./setup.sh create

$ vi install.xml
<property name="install.security" value="true"/>
<property name="mz.home" value="/opt/mz"/>
<property name="mz.container" value="mz73"/>
<property name="pico.rcp.platform.host" value="10.0.2.15"/>
<property name="pico.rcp.server.host" value="10.0.2.15"/>

$ ./setup.sh create
Follow installation instructions (doc/installation.pdf) to configure install.xml for your environment
When done, execute ./setup.sh install
BUILD SUCCESSFUL
Total time: 19.751 secs

$ ./setup.sh install
Administrator password: xxx

$ mzsh status
$ mzsh startup platform

**NOTE: /opt/mz need to be empty, no installer files or any files**

INSTALL MZ CLIENT

Install Java JRE in Windows computer/laptop

Run from command line
> java -jar desktop-installer*.jar

MZ8 or MZ7 Client Launcher Ports Issue
Issue: Unable to correctly launch MZ8 client from my laptop. Success if run from linux desktop gui in the server. Also caused by firewalld need to be stop/disabled.
Cause: Conflict with existing MZ7.4 ports installation in Virtualbox.
Solution:
Virtualbox, port forward default ports 9000,6790,6791 to 9002, 6795, 6796.
Fwd port SSH default 22 to 448.
Connect using 127.0.0.1 + new port number

*NOTE: Issue found to be also caused by firewalld on Centos/RHEL 7*
# systemctl stop firewalld
# systemctl disable firewalld

DISABLE HYPER-V VIRTUALIZATION
-in windows 10, need to disable/remove tick in Add/Remove Windows Features - Hyper V




Monday, November 06, 2017

Virtualbox - Use WIFI

To enable usage of WIFI adapter in Virtualbox
Setting - Network - NAT - Advance - PCNET Fast III

IP will be 10.0.2.15
>shared from host wifi. able to access internet















To enable own IP and setting directly from your internet Router, use Bridged Network
-harder to configure for WIFI. easier for LAN connection















VIRTUALBOX HOST ONLY ADAPTER
>Redhat 7.5 not able to get ip automatically. Need to setup manually

>Boot vbox Redhat75. Set ip manually 192.168.81.10.
>Laptop as host having ip 192.168.81.1

$ cat /etc/sysconfig/network-scripts/ifcfg-enp0s8
TYPE=Ethernet
BOOTPROTO=static
NAME=enp0s8
UUID=440295b1-0cc1-41f5-b439-66e4b7819d7c
DEVICE=enp0s8
ONBOOT=yes
IPADDR=192.168.81.10
NETWORK=192.168.81.0
GATEWAY=192.168.81.1
DNS=8.8.8.8 192.168.81.1
NM_CONTROLLED=no

>Restart network service. Verify able to ping laptop pc. P/S: not able to ping internet
# systemctl restart network.service

2018/7/23
Virtualbox -Redhat 7.5 -NAT network adapter & DHCP

$ cat /etc/sysconfig/network-scripts/ifcfg-enp0s8
TYPE=Ethernet
BOOTPROTO=dhcp
NAME=enp0s8
UUID=fa06c7d8-db0e-4e0a-b5f1-59aa6bfa2bc6
DEVICE=enp0s8
ONBOOT=yes

$ sudo systemctl restart network

$ sudo dhclient

$ ip addr
enp0s3:
    inet 192.168.120.3/24 brd 192.168.120.255 scope global dynamic enp0s3
enp0s8: 
    inet 10.0.3.15/24 brd 10.0.3.255 scope global noprefixroute dynamic enp0s8

$ ping www.yahoo.com
PING atsv2-fp.wg1.b.yahoo.com (124.108.103.104) 56(84) bytes of data.
64 bytes from media-router-fp2.prod1.media.vip.tp2.yahoo.com (124.108.103.104): icmp_seq=1 ttl=55 time=71.2 ms

--
NAT=10.0.3.15
Host-Only=192.168.120.3

Sunday, November 05, 2017

Ubuntu Linux Notes

ADD CDROM AS REPOSITORY
mkdir /mnt/cdrom
mount -t iso9660 /dev/cdrom /mnt/cdrom
apt-cdrom -m -d /mnt/cdrom add
cat /etc/apt/sources.list|grep cdrom
apt-get update

SEARCH PACKAGES
# apt-cache search find-utils

SERVER TO INSTALL MINIMAL DESKTOP
# apt-get --no-install-recommends install ubuntu-desktop
# reboot

ps: require internet connection to download packages

FULL REMOVE DESKTOP
# apt-get remove ubuntu-desktop^

Monday, July 24, 2017

Test VI and Linux commands

Test VI and Linux commands online.
-able to run vi, bash script, linux basic commands

https://www.tutorialspoint.com/unix_terminal_online.php

Monday, May 15, 2017

Access bitlocker drive from Linux live usb

1. Download deft-zero live linux iso -- http://www.deftlinux.net/
Burn to usb drive using Rufus
Boot laptop using deft-zero

2. Run from linux command line
# fdisk -l
# mkdir /media/temp
# mkdir /media/mydrive

# dislocker -V /dev/sda5 -p12345-00000-000000 -- /media/temp
(change -pxxx with bitlocker key. -r for readonly)

# ls -l /media/temp
# mount -o loop /media/temp/dislocker-file /media/mydrive
OR
# mount -o loop,umask=0,uid=nobody /media/temp/dislocker-file /media/mydrive

# ls -l /media/mydrive
(your bitlocker drive files will be listed here)

Friday, January 13, 2017

Backup whole linux root filesystem

# cd /root
# tar -cvpzf backup.tar.gz --exclude=/root/backup.tar.gz --one-file-system /

To restore, may need to login from single user mode
# cd /
# tar -xzvf /root/backup.tar.gz --exclude=/root

Monday, October 24, 2016

CentOS yum repository setting

# cat /etc/yum.repos.d/centos.repo
[centosbase]
name=CentOS
baseurl=http://mirror.centos.org/centos/6/os/$basearch/
gpgcheck=0
enabled=1
--
# yum search nmap

# yum install nmap -y

====
DVD as CentOS repo

# mkdir /mnt/cdrom
# mount -t iso9660 /dev/cdrom /mntcdrom

# cat /etc/yum/repos.d/mydvd.repo
[centosdvd]
name=CentOS7DVD
baseurl=file:///mnt//cdrom/
gpgcheck=0
enabled=1

# yum search locate
# yum install mlocate

===
Redhat/Centos Install EPEL Repository
Eg: for package nmon tool

# wget https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
# yum install ./epel-release-latest-7.noarch.rpm
# yum repolist
# yum search nmon
# yum install nmon -y

===
Install Gnome GUI desktop
# yum -y groups install "GNOME Desktop"
# reboot or startx

Sunday, January 03, 2016

Python - send facebook message

# Download & install https://github.com/carpedm20/fbchat

import fbchat

#Login
client = fbchat.Client("yourid-or-email", "fbpassword")

#Show user info
tinfo = client.getUsers("rayromeoabas")
print tinfo

# send message to id number 1282668763 (rayromeoabas). From facebook, look at friends profile photo, info below your browser
client.send(1282668763,"Hello to facebook from python")


Python - take snapshot from webcam

#Need to install pygame & download videocapture file "vidcap.pyd"
#from http://videocapture.sourceforge.net/ and save into your Python DLLs folder
#Example for Win7

import pygame
import pygame.camera
from pygame.locals import *

pygame.init()
pygame.camera.init()

cam = pygame.camera.Camera(0,(640,480),"RGB")
cam.start()
img = pygame.Surface((640,480))
cam.get_image(img)
pygame.image.save(img, "webcam.jpg")
cam.stop()

Tuesday, December 09, 2014

Simple Java Program

1. Open Notepad, type these lines and save as MyName.java

import java.util.*;

public class MyName {
 
 public static void main (String[] args) {
   Scanner s=new Scanner(System.in);

   System.out.print ("Enter name: ");
   String tname=s.nextLine();
   System.out.println ("Hello " + tname);
 }
}

2.  Compile from cmd line. Output program will be named MyName.class
javac MyName.java

3.  Run the program. Output is shown as below
java MyName

Enter name: Ray
Hello Ray

Tips : Download NetBeans from https://netbeans.org/ to get graphical tool for coding instead of simple notepad

Wednesday, January 15, 2014

Run command in gnu screen at startup

Place this command in file /etc/rc.local
For example running 'top' command in screen name 'mywin' at every bootup.
---
screen -dm -S mywin top

Sunday, July 21, 2013

Update computer time

Run this in command prompt or create a file (eg:mytime.bat) and configure to run at startup
---
w32tm /config /syncfromflags:manual /manualpeerlist:time.windows.com
w32tm /config /update

Note : useful when your system bios battery is dead and unable to keep accurate computer time. Require internet connection