Rabu, 13 Maret 2019

Installing MySQL Server 8.0 Community Edition on CentOS 7

This guide is to help you with Installing MySQL 8.0 Community Edition Server on CentOS 7

To start installing MySQL server on CentOS 7, you need to add the official MySQL community repository to your system. Run below commands to add it,

# cd
# wget https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
# yum localinstall mysql80-community-release-el7-1.noarch.rpm

Install MySQL 8 on CentOS

Now that repo is added, you can install MysQL 8 without editing repository content since repo for 8 is enabled by default.

# yum --enablerepo=mysql80-community install mysql-community-server

Start MySQL Service

For CentOS 7, use systemd to start mysql service:

# systemctl enable  mysqld
# systemctl start mysqld

Harden MySQL Server / Set MySQL root password

Installation of MySQL on CentOS 7 generates a temporary password for you. You can get it by running:

# grep 'temporary password' /var/log/mysqld.log

It will look like below:

temporary password is generated for root@localhost: si=R&3t#Buy7

Change mysql root user password and Harden MySQL

# mysql_secure_installation

You will be given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes to these options.

Configure Firewall

Firewalld:

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

Test your settings:

[root@webapps3 ~]# mysql -uroot -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 173142
Server version: 8.0.15 MySQL Community Server (GPL)

Copyright (c) 2000, 2019, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

Selasa, 12 Maret 2019

Create a New MySQL User and Database


Creating users and databases

The standard tool for interacting with MySQL is the mysql client which installs with the mysql-server package. The MySQL client is used through a terminal.

To create a MySQL database and user, follow these steps:

  1. At the command line, log in to MySQL as the root user: 

    # mysql -u root -p

  2. Type the MySQL root password, and then press Enter. 

  3. To create a database user, type the following command. Replace username with the user you want to create, and replace password with the user's password:

    mysql> create database testdb;
    mysql> create user 'testuser'@'localhost' identified by 'password';
    mysql> grant all privileges on testdb.* to 'testuser' identified by 'password';

    You can shorten this process by creating the user while assigning database permissions:

    mysql> GRANT ALL PRIVILEGES ON *.* TO 'username'@'localhost' IDENTIFIED BY 'password';

    Information This command grants the user all permissions. However, you can grant specific permissions to maintain precise control over database access. For example, to explicitly grant the SELECT permission, you would use the following command:

        GRANT SELECT ON *.* TO 'username'@'localhost';

    For more information about setting MySQL database permissions, please visit https://dev.mysql.com/doc/refman/8.0/en/grant.html.

  4. Type \q or exit to exit the mysql program.

  5. To log in to MySQL as the user you just created, type the following command. Replace username with the name of the user you created in step 3:

    mysql> mysql -u username -p

  6. Type the user's password, and then press Enter.

  7. To create a database, type the following command. Replace dbname with the name of the database that you want to create:

    mysql> CREATE DATABASE dbname;

  8. To work with the new database, type the following command. Replace dbname with the name of the database you created in step 7:

  9. You can now work with the database. For example, the following commands demonstrate how to create a basic table named example, and how to insert some data into it:

    mysql> CREATE TABLE example ( id smallint unsigned not null auto_increment, name varchar(20) not null, constraint pk_example primary key (id) );
    mysql>  INSERT INTO example ( id, name ) VALUES ( null, 'Sample data' );


Deleting tables and databases

To delete a table, type the following command from the mysql> prompt. Replace tablename with the name of the table that you want to delete:

mysql>  DROP TABLE tablename;

Information This command assumes that you have already selected a database by using the USE statement.

Similarly, to delete an entire database, type the following command from the mysql> prompt. Replace dbname with the name of the database that you want to delete:

mysql>  DROP DATABASE dbname;

Warning The mysql program does not ask for confirmation when you use this command. As soon as you press Enter, MySQL deletes the database and all of the data it contains..

Deleting users

To view a list of all users, type the following command from the mysql> prompt:

mysql>  SELECT user FROM mysql.user GROUP BY user;

To delete a specific user, type the following command from the mysql> prompt. Replace username with the name of the user that you want to delete:

mysql>  DELETE FROM mysql.user WHERE user = 'username';


Selasa, 05 Maret 2019

How do I turn off the mysql passowrd validation or Your Password does not Satisfy the Current Policy Requirements


Whenever the user tried to set any password in MySQL, he faced following error:

mysql> create user 'testuser'@'localhost' identified by 'password';
ERROR 1819 (HY000): Your password does not satisfy the current policy requirements

After a while, he really got frustrated by this Current Policy Requirements for a password.
You can check the current variables related to validating password by running the following command:

mysql> show global variables like 'validate%';
+---------------------------------------+-------------+
| Variable_name                         | Value       |
+---------------------------------------+-------------+
| validate_password.check_user_name     | ON          |
| validate_password.dictionary_file     |             |
| validate_password.length              | 8           |
| validate_password.mixed_case_count    | 1           |
| validate_password.number_count        | 1           |
| validate_password.policy              | MEDIUM      |
| validate_password.special_char_count  | 1           |
+---------------------------------------+-------------+
7 rows in set (0.01 sec)

Now let us see how we can resolve our error.

Method 1: Let us see how we can set the password_policy to low login to mysql as root:

mysql> SET GLOBAL validate_password.policy=LOW;
mysql> SET GLOBAL validate_password.length=6;

Method 2: You can also set the same variable in my.cnf file as well edit my.cnd like this.

[mysqld]
validate_password.policy=LOW
validate_password.length=6

Method 3: Uninstall Plugin which validates password if you use MySQL Ver 5.7 below
Run the following sql command:

mysql> uninstall plugin validate_password;

Senin, 04 Maret 2019

How to Install Percona Server for MySQL on CentOS 7


  1. Download the packages of the desired series for your architecture from the download page. The easiest way is to download bundle which contains all the packages. Following example will download Percona Server for MySQL 8.0.13-4 release packages for CentOS 7:

  2. # wget https://www.percona.com/downloads/Percona-Server-8.0/Percona-Server-8.0.13-4/binary/redhat/7/x86_64/Percona-Server-8.0.13-4-rf0a32b8-el7-x86_64-bundle.tar

  3. You should then unpack the bundle to get the packages:

  4. # tar xvf Percona-Server-8.0.13-4-rf0a32b8-el7-x86_64-bundle.tar

    After you unpack the bundle you should see the following packages when running

    # ls *.rpm
    percona-mysql-router-8.0.13-4.1.el7.x86_64.rpm
    percona-server-client-8.0.13-4.1.el7.x86_64.rpm
    percona-server-debuginfo-8.0.13-4.1.el7.x86_64.rpm
    percona-server-devel-8.0.13-4.1.el7.x86_64.rpm
    percona-server-rocksdb-8.0.13-4.1.el7.x86_64.rpm
    percona-server-server-8.0.13-4.1.el7.x86_64.rpm
    percona-server-shared-8.0.13-4.1.el7.x86_64.rpm
    percona-server-shared-compat-8.0.13-4.1.el7.x86_64.rpm
    percona-server-test-8.0.13-4.1.el7.x86_64.rpm
    percona-server-tokudb-8.0.13-4.1.el7.x86_64.rpm

  5. Now you can install Percona Server for MySQL 8.0 by running :

  6. # rpm -ivh percona-server-server-80-8.0.13-4-rf0a32b8.el7.x86_64.rpm \
       percona-server-client-80-8.0.13-4.1.el7.x86_64.rpm \
       percona-server-shared-80-8.0.13-4.1.el7.x86_64.rpm \
       percona-server-shared-compat-80-8.0.13-4.1.el7.x86_64.rpm

    # systemctl start mysqld
    # systemctl enable mysqld

Harden MySQL Server

  1. Run the mysql_secure_installation script to address several security concerns in a default MySQL installation.

  2. # mysql_secure_installation

    You will be given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases. It is recommended that you answer yes to these options.

    NOTE
     If MySQL 5.7 was installed, you will need the temporary password that was created during installation. This password is notated in the /var/log/mysql.log file, and can be quickly found using the following command.

    # grep 'temporary password' /var/log/mysqld.log


Rabu, 27 Februari 2019

CentOS 7 : How to setup yum repository using locally mounted iso


1. Copy iso file to some directory. For example /home/iso/

   
# cd /home
# mkdir iso
# cd iso

   Copy iso file to prepare directory, what ever methode you use
   list file on it

# ls
   

2. Mount the CentOS 7 installation media ISO to some directory. For example /media/CentOS

# mkdir -p /media/CentOS

   Edit file /etc/fstab make add line like this
  
/home/iso/CentOS-7-1810.iso    /media/CentOS iso9660    loop,ro        0 0

   Mount iso file to prepare directory

# mount -a

   if No Error you can check on folder /media/CentOS
  
# cd /media/CentOS
# ls

3. remove/backup all repo on /etc/yum.repo.d/

# cd /etc/yum.repo.d
# mv *.repo /root/

   copy back file CentoOS-Media.repo to /etc/yum.repo.d/

# cd
# cp CentOS-Media.repo /etc/yum.repo.d/

   edit fiel /etc/yum.repo.d/CentOS-Media.repo
  
# vi /etc/yum.repo.d/CentOS-Media.repo

   edit like this

[c7-media]
name=CenOS-$releasever - Media
baseurl=file:///media/CentOS/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7


4. Make sure you clear the related caches by yum clean all and subscription-manager clean once.
  
# yum clean all


Kamis, 31 Januari 2019

Deploy java API as service in linux CentOS 6


For sample i use uereka microservices

  1. Create user for running API

    # useradd api
    # passwd api

  2. login as api create directory eureka for put jar file, copy jar file to /home/api/eureka

    # mkdir eureka

  3. Create script wrapper for system V init in /home/api/eureka


    #!/bin/sh
    ### BEGIN INIT INFO
    # chkconfig: 345 98 01
    # description: Startup Script for Eureka API
    # Provides:          Eureka
    ### END INIT INFO

    SCRIPT="nohup java -jar -DSpring.profiles.active=cloud1 /home/api/eureka/eureka-service.jar"
    RUNAS=api

    PIDFILE=/home/api/eureka/eureka-api.pid
    LOGFILE=/home/api/eureka/eureka-api.log

    start() {
      if [ -f $PIDFILE ] && [ -s $PIDFILE ] && kill -0 $(cat $PIDFILE); then
        echo 'Eureka already running' >&2
        return 1
      fi
      cd /home/api/eureka
      echo 'Starting service… Eureka' >&2
      local CMD="$SCRIPT &> \"$LOGFILE\" & echo \$!"
      su -c "$CMD" $RUNAS > "$PIDFILE"
        
      # Try with this command line instead of above if not workable
      # su -s /bin/sh $RUNAS -c "$CMD" > "$PIDFILE"
      # or
      # nohup java -jar -DSpring.profiles.active=cloud1 /home/api/eureka/eureka.jar &> /home/api/eureka/eureka-api.log & echo $! > $PIDFILE

      PID=$(cat $PIDFILE)
        if pgrep -u $RUNAS -f eureka-service.jar > /dev/null
        then
          echo "API Eureka is now running, the PID is $PID"
        else
          echo ''
          echo "Error! Could not start Eureka !"
        fi
    }
      
    stop() {
      if [ ! -f "$PIDFILE" ] || ! kill -0 $(cat "$PIDFILE"); then
        echo 'Service Eureka not running' >&2
        return 1
      fi
      echo 'Stopping service…' >&2
      kill -15 $(cat "$PIDFILE") && rm -f "$PIDFILE"
      echo 'Service Eureka stopped' >&2
    }
      
    uninstall() {
      echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
      local SURE
      read SURE
      if [ "$SURE" = "yes" ]; then
        stop
        rm -f "$PIDFILE"
        echo "Notice: log file was not removed: $LOGFILE" >&2
        update-rc.d -f eureka remove
        rm -fv "$0"
      fi
    }
      
    status() {
        printf "%-50s" "Checking Eureka ..."
        if [ -f $PIDFILE ] && [ -s $PIDFILE ]; then
           PID=$(cat $PIDFILE)
                if [ -z "$(ps axf | grep ${PID} | grep -v grep)" ]; then
                    printf "%s\n" "The process appears to be dead but pidfile still exists"
                else  
                    echo "Running, the PID is $PID"
                fi
        else
            printf "%s\n" "Service Eureka not running"
        fi
    }
      
      
    case "$1" in
      start)
        start
        ;;
      stop)
        stop
        ;;
      status)
        status
        ;;
      uninstall)
        uninstall
        ;;
      restart)
        stop
        start
        ;;
      *)
        echo "Usage: $0 {start|stop|status|restart|uninstall}"
    esac
      

  4. Enable service in system V and start eureka

    # sudo ln -s /home/api/eureka/eureka /etc/init.d/eureka
    # sudo chkconfig --add eureka
    # sudo chkconfig eureka on
    # sudo service eureka start

  5. Firewall

    # iptables -I INPUT -p tcp --destination-port 8761 -j ACCEPT
    # service iptables save

Rabu, 30 Januari 2019

Install Tomcat 8 on a CentOS 6


In the following tutorial you will learn how to install and set-up Apache Tomcat 8 on your CentOS 6

What is Tomcat?

Apache Tomcat (before known as Jakarta Tomcat) is an application server developed by the Apache Software Foundation that executes Java servlets and renders Web pages that include Java Server Page coding.


UPDATE THE SYSTEM


Make sure you are in a your CentOS 6 based Linux Server is up-to-date by running:

# yum update


INSTALL JAVA 8


Download the latest JAVA 8 from  here or use the following command to download JAVA JDK

# wget --no-cookies \
--no-check-certificate \
--header "Cookie: oraclelicense=accept-securebackup-cookie" \
"https://download.oracle.com/otn-pub/java/jdk/8u201-b09/42970487e3af4f5aa5bca3f542482c60/jdk-8u201-linux-x64.rpm" \
-O /tmp/jdk-8u201-linux-x64.rpm

once the JAVA package has been downloaded, install it using rpm as follows:

# rpm -Uvh /tmp/jdk-8u201-linux-x64.rpm

CONFIGURE JAVA

configure the newly installed JAVA package using alternatives as in:

# alternatives --install /usr/bin/java java /usr/java/jdk1.8.0_201-amd64/jre/bin/java 20000
# alternatives --install /usr/bin/jar jar /usr/java/jdk1.8.0_201-amd64/bin/jar 20000
# alternatives --install /usr/bin/javac javac /usr/java/jdk1.8.0_201-amd64/bin/javac 20000
# alternatives --install /usr/bin/javaws javaws /usr/java/jdk1.8.0_201-amd64/jre/bin/javaws 20000
# alternatives --set java /usr/java/jdk1.8.0_201-amd64/jre/bin/java
# alternatives --set javaws /usr/java/jdk1.8.0_201-amd64/jre/bin/javaws
# alternatives --set javac /usr/java/jdk1.8.0_201-amd64/bin/javac
# alternatives --set jar /usr/java/jdk1.8.0_201-amd64/bin/jar

check the JAVA version running on your system:

# java -version

INSTALL TOMCAT 8

Create a separate user which will run the Tomcat server:

# useradd tomcat8

Download the latest Tomcat 8 version from here or use the following command to download Tomcat

# wget https://www-eu.apache.org/dist/tomcat/tomcat-8/v8.5.37/bin/apache-tomcat-8.5.37.tar.gz -P /tmp

Extract the contents of the Tomcat archive to /opt using the following command:

# tar zxf /tmp/apache-tomcat-8.5.37.tar.gz -C /opt

make symbolic link

# ln -s /opt/apache-tomcat-8.5.37 /opt/tomcat8

change permission

# chown -hR tomcat8: /opt/tomcat8 /opt/apache-tomcat-8.5.37
# cd /opt/tomcat8/bin
# chmod +x *.sh


START THE TOMCAT 8 SERVICE

Create the following init script in /etc/init.d/tomcat8

#!/bin/sh
### BEGIN INIT INFO
# chkconfig: 345 84 16
# description: Tomcat Jakarta JSP Server
# Provides: Tomcat
### END INIT INFO

JAVA_HOME=/usr/java/jdk1.8.0_201-amd64
export JAVA_HOME

## IF NEEDED 
#JAVA_OPTS="-Dfile.encoding=UTF-8 \
#  -Dnet.sf.ehcache.skipUpdateCheck=true \
#  -XX:+UseConcMarkSweepGC \
#  -XX:+CMSClassUnloadingEnabled \
#  -XX:+UseParNewGC \
#  -XX:MaxPermSize=128m \
#  -Xms512m -Xmx512m"
# export JAVA_OPTS

PATH=$JAVA_HOME/bin:$PATH
export PATH
CATALINA_HOME=/opt/tomcat8

STARTSCRIPT="/opt/tomcat8/bin/startup.sh"
STOPSCRIPT="/opt/tomcat8/bin/shutdown.sh"
RUNAS=tomcat8

PIDFILE=/opt/tomcat8/tomcat8.pid
LOGFILE=/opt/tomcat8/tomcat8.log

start() {

  TOMCATLIVE=$(pgrep -u tomcat8 -f bootstrap.jar | wc -l)
  if [ "$TOMCATLIVE" -eq 0 ]; then
    echo 'Starting Jakarta Tomact service …' >&2
    local CMD="$STARTSCRIPT &> \"$LOGFILE\" & echo \$!"
    su -l $RUNAS -c "$CMD" > "$PIDFILE"
  sleep 2
  PID=$(cat $PIDFILE)

    if pgrep -u $RUNAS -f bootstrap.jar > /dev/null
    then
      echo "Jakarta Tomcat is now running, the PID is $PID"
    else
      echo ''
      echo "Error! Could not start Jakarta Tomcat!"
    fi

  else
    echo 'Service Jakarta Tomcat all ready running' >&2
    return 1
  fi
  
}

stop() {

  TOMCATLIVE=$(pgrep -u tomcat8 -f bootstrap.jar | wc -l)
  if [ "$TOMCATLIVE" -eq 0 ]; then
    echo 'Service Jakarta Tomcat not running' >&2
    return 1
  fi
  echo 'Stopping Jakarta Tomcat service …' >&2
  su -l $RUNAS -c $STOPSCRIPT
  rm -f "$PIDFILE"
  echo 'Service Jakarta Tomcat stopped' >&2

}

uninstall() {
  echo -n "Are you really sure you want to uninstall this service? That cannot be undone. [yes|No] "
  local SURE
  read SURE
  if [ "$SURE" = "yes" ]; then
    stop
    rm -f "$PIDFILE"
    echo "Notice: log file was not removed: $LOGFILE" >&2
    update-rc.d -f tomcat8 remove
    rm -fv "$0"
  fi
}

status() {

TOMCATLIVE=$(pgrep -u tomcat8 -f bootstrap.jar | wc -l)
TOMCATPIDLIVE=$(pgrep -u tomcat8 -f bootstrap.jar )
if [ "$TOMCATLIVE" -eq 0 ]; then
  echo -n "Jakarta Tomcat Stopped"
  echo
else
  echo "Jakarta Tomcat Running, the PID is $TOMCATPIDLIVE "
fi

}


case "$1" in
  start)
    start
    ;;
  stop)
    stop
    ;;
  status)
    status
    ;;
  uninstall)
    uninstall
    ;;
  restart)
    stop
    start
    ;;
  *)
    echo "Usage: $0 {start|stop|status|restart|uninstall}"
esac

make the script executable using chmod

# chmod +x /etc/init.d/tomcat8

Add the Tomcat 8 service to system startup:

# chkconfig --add tomcat8
# chkconfig tomcat8 on

Start the Tomcat 8 server using:

# service tomcat8 start

Configuring Firewall

# iptables -I INPUT -p tcp --destination-port 8080 -j ACCEPT
# service iptables save
# ip6tables -I INPUT -p tcp --destination-port 8080 -j ACCEPT
# service ip6tables save

Access your newly installed Tomcat at http://YOUR_IP:8080

Minggu, 27 Januari 2019

How to Disable SELinux on CentOS


By default in CentOS 7, SELinux is enabled and in enforcing mode.

It is recommended to keep SELinux in enforcing mode, but in some cases, you may need to set it to permissive mode or disable it completely.

In this tutorial, we will show you how to disable SELinux on CentOS 7 systems.


Disable SELinux

You can temporarily change the SELinux mode from targeted to permissive with the following command:

# setenforce 0

However, this change will be valid for the current runtime session only.

To permanently disable SELinux on your CentOS 7 system, follow the steps below:

Open the /etc/selinux/config file and set the SELINUX mod to disabled:

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#       enforcing - SELinux security policy is enforced.
#       permissive - SELinux prints warnings instead of enforcing.
#       disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
#       targeted - Targeted processes are protected,
#       mls - Multi Level Security protection.
SELINUXTYPE=targeted

Save the file and reboot your CentOS system with:

# shutdown -r now

Once the system boots up, verify the change with the sestatus command:

# sestatus

The output should look like this:

SELinux status:                 disabled

Conclusion

In this tutorial, you learned how to permanently disable SELinux on a CentOS 7 machine.
You may wish to visit the CentOS SELinux guide and learn more about the powerful features of SELinux.


Kamis, 17 Januari 2019

Quit Bash Shell Without Saving Bash History


Sometimes it is very useful to delete / remove Bash history partially or completely when log out. Here is my favourite methods howto log out / quit / exit Bash shell without saving Bash history.

Remove Only Current Session Bash History and Leave Older History Untouched

  1. Quit Bash Shell Without Saving History: Unset HISTFILE

  2. # unset HISTFILE && exit

  3. Quit Bash by Killing you Current Consolel Without Saving History: Kill Console

  4. # kill -9 $$

  5. Quit Bash Shell Without Saving History: Clear History Option

  6. #history -c && exit

  7. Set your Bash Shelll history to Zero(0):  Set HISTSIZE 0

  8. #HISTSIZE=0 && exit


Remove/Delete Bash History Completely

  1. Quit Bash Shell Without Saving History: Delete HISTFILE and Unset HISTFILE

  2. #rm -f $HISTFILE && unset HISTFILE && exit


If you want make these commands more permanent then these commands could be added on ~/.bash_logout file or used with aliases.

echo "alias nohistory='history -c && exit'" >> ~/.bash_logout


Run the remote linux graphics application locally


Overview

The X Window System (also known as X11, or just X) is a software package and network protocol that lets you interact locally,
using your personal computer's display, mouse, and keyboard, with the graphical user interface (GUI) of an application running on a remote networked computer.

Requirements

For X forwarding in SSH to work your personal computer must be running an X server program.
The X server program manages the interaction between the remote application (the X client) and your computer's graphics hardware and input devices.

Most Linux distributions have the X server installed,
but if your personal computer is running Windows, you will most likely need to install and run an X server application, for example:

  • Xming, download and install Xming. For X forwarding to work, you'll need to start Xming before connecting to the remote system with your SSH client (for example, PuTTY).

  • MobaXTerm, download and install MobaXTerm

but now we will only focus Xming

Additionally, your personal computer's SSH terminal application must have X11 forwarding enabled:

  • In Linux, the SSH terminal supports X forwarding by default.

  • if not you can edit the sshd_config file

vi /etc/ssh/sshd_config

change for the lines below:

X11Forwarding yes
X11UseLocalhost yes

Restart the ssh srever, if you have made changes:

service sshd restart

  • In PuTTY for Windows, you can enable X forwarding new or saved SSH sessions by selecting Enable X11 forwarding in the "PuTTY Configuration" window ( Connection  > SSH > X11).
Also, the remote computer's SSH application must be configured to accept X server connections.


Use SSH with X forwarding

Linux

To use SSH with X forwarding from your Linux personal computer to run an X client application installed on remote server:

  1. Open the SSH terminal client.

  2. On the command line, enter (replacing username with your username):

  3. ssh -Y username@host

    note
    The -Y option turns on trusted X forwarding. You should use it only when connecting to secure systems.

  4. Log in with your password

  5. To test if X forwarding is working, try running xclock; on the command line, enter:

    xclock

    If X forwarding is working, the xclock graphical clock will appear on your personal computer's desktop.

PuTTY for Windows

To use SSH with X forwarding in PuTTY for Windows:

  1. Launch your X server application (for example, Xming).

  2. Make sure your connection settings for the remote system have Enable X11 forwarding selected; in the "PuTTY Configuration" window, see Connection > SSH > X11

     

  3. Open an SSH session to the desired remote system:

  4. Log in normally with your username and password.

To test if X forwarding is working, try running xclock; on the command line, enter:

If X forwarding is working, the xclock graphical clock will appear on your personal computer's desktop.

 How to start X application from SSH [simple way]
 
A short command

ssh -X username@host xapplication

note
The -X  is Enable X11 Forwarding.

Rabu, 18 Mei 2016

SymmetricDS

SymmetricDS

SymmetricDS adalah tools Open Source dalam hal Distributed database, replikasi dan/atau transformasi data.
Tools ini juga cross platform baik database maupun operatin System nya, jadi bisa di aplikasikan di Windows
maupun linux dan juga hampir semua mainstream database sudah di support.

OK tanpa berlama-lama lagi, ikuti saja langkah-langkahnya. dalam tutorial di bawah ini saya menggunakan
OS linux dan database oracle dengan asumsi 1 server sebagai HQ dan 1 lagi sebagai server store

* Download SymmetricDS dari Webnya
 
  http://www.symmetricds.org/download

  pada saat tutorial ini di buat symmetrcds sudah versi 3.7.33

* buat folder /opt/symds di kedua node (server HQ dan server Store)

* extract source symmetric DS kemudian move ke folder yg telah kita sediakan di kedua node (server HQ dan server Store)

* copy file /opt/symds/samples/corp-000.properties ke /opt/symds/engines/hq-0000.properties
  di node HQ

* edit hq-0000.properties sesuaikan dengan settinga database kita

    engine.name=hq-0000
    # The class name for the JDBC Driver
    db.driver=oracle.jdbc.driver.OracleDriver

    # The JDBC URL used to connect to the database
    db.url=jdbc:oracle:thin:@192.168.9.6:1521:orcl

    # The user to login as who can create and update tables
    db.user=symds

    # The password for the user to login as
    db.password=symds

    registration.url=
    sync.url=http://192.168.9.6:31415/sync/hq-0000

    # Do not change these for running the demo
    group.id=hq
    external.id=0000

    # Don't muddy the waters with purge logging
    job.purge.period.time.ms=7200000

    # This is how often the routing job will be run in milliseconds
    job.routing.period.time.ms=5000
    # This is how often the push job will be run.
    job.push.period.time.ms=10000
    # This is how often the pull job will be run.
    job.pull.period.time.ms=10000
    # Kick off initial load
    initial.load.create.first=true

* copy file /opt/symds/samples/store-001.properties ke /opt/symds/engines/store-0001.properties
  di node Store

* edit store-0001.properties sesuaikan dengan settinga database kita di server store

    engine.name=store-0001

    # The class name for the JDBC Driver
    db.driver=oracle.jdbc.driver.OracleDriver

    # The JDBC URL used to connect to the database
    db.url=jdbc:oracle:thin:@192.168.9.29:1521:orcl

    # The user to login as who can create and update tables
    db.user=symds

    # The password for the user to login as
    db.password=symds

    # The HTTP URL of the root node to contact for registration
    registration.url=http://192.168.9.6:31415/sync/hq-0000

    # Do not change these for running the demo
    group.id=store
    external.id=0001

    # This is how often the routing job will be run in milliseconds
    job.routing.period.time.ms=5000
    # This is how often the push job will be run.
    job.push.period.time.ms=10000
    # This is how often the pull job will be run.
    job.pull.period.time.ms=10000
* Siapkan database HQ di server, dan sesuaikan dengan setting di edit tadi, nama databasenya orcl
  di sini kita cretae schema dengan nama symds dan password symds, jika perlu kita juga boleh
  persiapkan table table yg akan kita gunakan nanti.

* Siapkan database Store di server, dan sesuaikan dengan setting di edit tadi, nama databasenya orcl
  di sini kita cretae schema dengan nama symds dan password symds, jika perlu kita juga boleh
  persiapkan table table yg akan kita gunakan nanti.

* jika kita ingin mencoba dengan sample yg di sediakan dari symmetricds kita bisa import ke system kita

    ../bin/dbimport --engine corp-000 --format XML --alter-case create_sample.xml

  perintah di atas jika kita menggunakan sample data dari symds dan engine kita bernama corp-000
  tapi karena kita pakai sample data sendiri bisa kita skip

* jalankan script import SymmedtricDS Tables

    ../bin/symadmin --engine hq-0000 create-sym-tables

* jalankam script import sample data HQ

    ../bin/dbimport --engine hq-0000 insert_config.sql

  file insert_config.sql

    delete from sym_trigger_router;
    delete from sym_trigger;
    delete from sym_router;
    delete from sym_channel where channel_id in ('sale_transaction', 'item');
    delete from sym_node_group_link;
    delete from sym_node_group;
    delete from sym_node_host;
    delete from sym_node_identity;
    delete from sym_node_security;
    delete from sym_node;

    insert into sym_channel 
    (channel_id, processing_order, max_batch_size, enabled, description,last_update_time,create_time)
    values('sales', 1, 100000, 1, 'sales transactional data from store',current_timestamp,current_timestamp);

    insert into sym_channel 
    (channel_id, processing_order, max_batch_size, enabled, description,last_update_time,create_time)
    values('master', 1, 100000, 1, 'master data to store',current_timestamp,current_timestamp);

    insert into sym_node_group (node_group_id,description,last_update_time,create_time)
    values ('hq','Server Group on HQ',current_timestamp,current_timestamp);
    insert into sym_node_group (node_group_id,description,last_update_time,create_time)
    values ('store','Node Group on Store',current_timestamp,current_timestamp);

    insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action)
    values ('hq', 'store', 'W');
    insert into sym_node_group_link (source_node_group_id, target_node_group_id, data_event_action)
    values ('store', 'hq', 'P');

    insert into sym_trigger 
    (trigger_id,source_table_name,channel_id,last_update_time,create_time)
    values('m_price','M_PRICE','master',current_timestamp,current_timestamp);

    insert into sym_trigger 
    (trigger_id,source_table_name,channel_id,last_update_time,create_time)
    values('m_item','M_ITEM','master',current_timestamp,current_timestamp);

    insert into sym_trigger 
    (trigger_id,source_table_name,channel_id,last_update_time,create_time)
    values('m_outlet_price','M_OUTLET_PRICE','master',current_timestamp,current_timestamp);

    insert into sym_trigger 
    (trigger_id,source_table_name,channel_id,last_update_time,create_time)
    values('t_pos_bill','T_POS_BILL','sales',current_timestamp,current_timestamp);

    insert into sym_trigger 
    (trigger_id,source_table_name,channel_id,last_update_time,create_time)
    values('t_pos_bill_item','T_POS_BILL_ITEM','sales',current_timestamp,current_timestamp);

    insert into sym_router 
    (router_id,source_node_group_id,target_node_group_id,router_type,create_time,last_update_time)
    values('hq_2_store', 'hq', 'store', 'default',current_timestamp, current_timestamp);

    insert into sym_router 
    (router_id,source_node_group_id,target_node_group_id,router_type,create_time,last_update_time)
    values('store_2_hq', 'store', 'hq', 'default',current_timestamp, current_timestamp);

    insert into sym_trigger_router 
    (trigger_id,router_id,initial_load_order,last_update_time,create_time)
    values('m_item','hq_2_store', 100, current_timestamp, current_timestamp);

    insert into sym_trigger_router 
    (trigger_id,router_id,initial_load_order,last_update_time,create_time)
    values('m_price','hq_2_store', 100, current_timestamp, current_timestamp);

    insert into sym_trigger_router 
    (trigger_id,router_id,initial_load_order,last_update_time,create_time)
    values('m_outlet_price','hq_2_store', 100, current_timestamp, current_timestamp);

    insert into sym_trigger_router 
    (trigger_id,router_id,initial_load_order,last_update_time,create_time)
    values('t_pos_bill','store_2_hq', 200, current_timestamp, current_timestamp);

    insert into sym_trigger_router 
    (trigger_id,router_id,initial_load_order,last_update_time,create_time)
    values('t_pos_bill_item','store_2_hq', 200, current_timestamp, current_timestamp);

    insert into sym_node
    (node_id,node_group_id,external_id,sync_enabled,sync_url,schema_version,symmetric_version,
    database_type,database_version,heartbeat_time,timezone_offset,batch_to_send_count,
    batch_in_error_count,created_at_node_id) 
    values ('0000','hq','0000',1,null,null,null,null,null,current_timestamp,null,0,0,'0000');

    insert into sym_node
    (node_id,node_group_id,external_id,sync_enabled,sync_url,schema_version,symmetric_version,
    database_type,database_version,heartbeat_time,timezone_offset,batch_to_send_count,
    batch_in_error_count,created_at_node_id) 
    values ('0001','store','0001',1,null,null,null,null,null,current_timestamp,null,0,0,'0000');

    insert into sym_node_security (node_id,node_password,registration_enabled,registration_time,
    initial_load_enabled,initial_load_time,created_at_node_id) 
    values ('0000','5d1c92bbacbe2edb9e1ca5dbb0e481',0,current_timestamp,0,current_timestamp,'0000');

    insert into sym_node_identity values ('0000');
  jika ingin menggunakan sample bawaan dari symmetricds

    ../bin/dbimport --engine corp-000 insert_sample.sql

* jika kita ingin mencoba dengan sample yg di sediakan dari symmetricds kita bisa import ke system kita

    ../bin/dbimport --engine store-001 --format XML --alter-case create_sample.xml

  perintah di atas jika kita menggunakan sample data dari symds dan engine kita bernama corp-000
  tapi karena kita pakai sample data sendiri bisa kita skip

* jalankan HQ service SymmetricDS

    ../bin/sym --engine hq-0000 --port 31415

* jalankan store 0001 service

    ../bin/sym --engine store-0001 --port 31415

* baca dan amati log di screen daemon

* Simulasikan registrasi node store-0001 di HQ

    ../bin/symadmin --engine hq-0000 open-registration store 0001

* simulasikan penulisan data di server Corp (pull). ini contoh data jika menggunakan sample bawaan symmetricds
  sedangkan sample data untuk table yg penulis buat (maaf bukan untuk konsumsi public)

    insert into "item" ("item_id", "name") values (110000055, 'Soft Drink');
    insert into "item_selling_price" ("item_id", "store_id", "price") values (110000055, '001', 0.65);
    insert into "item_selling_price" ("item_id", "store_id", "price") values (110000055, '002', 1.00);

  amati apakah ada perubahan baik di log maupun di database client

* simulasikan penulisan data di store 001 (push). ini contoh data jika menggunakan sample bawaan symmetricds
  sedangkan sample data untuk table yg penulis buat (maaf bukan untuk konsumsi public)

    insert into "sale_transaction" ("tran_id", "store_id", "workstation", "day", "seq")
    values (1000, '001', '3', '2007-11-01', 100);
    insert into "sale_return_line_item" ("tran_id", "item_id", "price", "quantity")
    values (1000, 110000055, 0.65, 1);

* Ada 3 table yg penting untuk memahami cara kerja symmetricds. di sisi pengirim perhatikan table berikut

    * sym_data
      table yg akan merekam semua perubahan data
       
        select * from sym_data order by data_id desc;

    * sym_data_event
      perubahn di eksekusi oleh bath bath yg ada pada table ini

        select * from sym_outgoing_batch where batch_id = x;    -- ganti x dengan angka

    * sym_outgoing_batch
      pastikan perubahan data terekam,terkirim dan terkonfirmasi di server
      gunakan batch id di table sebelumnya

        select * from sym_outgoing_batch where batch_id = ?;    -- ganti x dengan angka

      batch awalnya berstatus "NE" kalau belum terkirim. ketika node penerima mengkonfirmasi pengiriman,
      statusnya berganti "OK" atau "ER" kalau Error

* Disisi penerima, cek table ini
   
    * sym_incoming_batch
      periksa penerimaan data di tabel ini

        select * from sym_incoming_batch where batch_id = ?;    -- ganti x dengan angka

* Sedangkan untuk membuat suatu trigger berikut table yg harus di configurasi

    sym_channel   
    sym_node
    sym_node_group
    sym_node_group_link
    sym_router
    sym_trigger
    sym_trigger_router

* Encrypted Passwords

  properti db.users dan db.password bisa dalam bentuk encrypted text, ini untuk meningkatkan keamanan system.
  text yang di awali dengan enc: menandakan bahwa itu ter encrypt. untuk meng encrypt text ikuti command berikut

    symadmin -e {engine name} encrypt-text text-to-encrypt

  atau

    symadmin -p {properties file} encrypt-text text-to-encrypt

Sementara sekian dulu yah. kritik dan saran sangant saya harapkan