Monday, 4 July 2016

[Ubuntu] Install and Setup NFS Client (NFS 클라이언트 설치 및 설정하기)

1. Install package

#> apt-get install nfs-common






2. Mount directory

#> mount -t nfs [NFS_SERVER_HOST]:[REMOTE_DIRECTORY] [LOCAL_DIRECTORY]





3. Register /etc/fstab

#> vi /etc/fstab

[NFS_SERVER_HOST]:[REMOTE_DIRECTORY] [LOCAL_DIRECTORY] nfs [OPTIONS]

[Ubuntu] Install and Setup NFS Server (NFS서버 설치 및 설정하기)

1. Install packages for NFS server

#> apt-get install nfs-common nfs-kerne-server rpcbind



2. Make directory for sharing

#> mkdir [DIRECTORY]



3. Setup directory and authority

#> vi /etc/exports

DirectoryAllowed IP(Options)

Options
roread only
rwread/write
root_squashPrevents root users connected remotely from having root privileges and assigns them the user ID for the user nfsnobody
no_root_squashTurns off root squashing
asyncAllows the server to write data at non-regular intervals. This setting works best if the exported file system is read-only
syncAll file writes are committed to the disk before the write request by the client is completed
wdelayImprove performance by reducing the number of times the disk must be accessed by separate write commands, reducing write overhead
no_wdelayTurns off this feature, but is only available when using the sync option.




4. Restart NFS Server

#> nfs-kernel-server restart






5. Restart rpcbind

#> rpcbind restart









[Linux] How to get processes id using named files, sockets, or filesystems (Named 파일, 파일시스템, 소켓을 사용중인 프로세스 ID 찾기)

Usage: fuser [ -a | -s | -c ] [ -n SPACE ] [ -SIGNAL ] [ -kimuv ] NAME...
             [ - ] [ -n SPACE ] [ -SIGNAL ] [ -kimuv ] NAME...
       fuser -l
       fuser -V
Show which processes use the named files, sockets, or filesystems.

    -a        display unused files too
    -c        mounted FS
    -f        silently ignored (for POSIX compatibility)
    -i        ask before killing (ignored without -k)
    -k        kill processes accessing the named file
    -l        list available signal names
    -m        show all processes using the named filesystems
    -n SPACE  search in this name space (file, udp, or tcp)
    -s        silent operation
    -SIGNAL   send this signal instead of SIGKILL
    -u        display user IDs
    -v        verbose output
    -V        display version information
    -4        search IPv4 sockets only
    -6        search IPv6 sockets only
    -         reset options

  udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]


[Linux] How to get process id using specific TCP/UDP port (특정 TCP/UDP 포트를 사용중인 프로세스 ID 찾기)

#> netstat -nap | grep [PORT]

Wednesday, 29 June 2016

[Ubuntu] Setup firewall using UFW

UFW is a default firewall. it is more easier than iptables. But iptables supports more various options and functions for building high-quality service.

1. Set UFW Enable/Disable

#> ufw enable

#> ufw disable

2. Check UFW status

#> ufw status verbose






3. Check default rule

#> ufw show raw



4. Allow/Deny default rule

#> ufw default allow

#> ufw default deny

5. Allow/Deny specific port and protocol

#> ufw allow [port]

#> ufw allow [port]/tcp

#> ufw allow [port]/udp

#> ufw deny[port]

#> ufw deny[port]/tcp

#> ufw deny[port]/udp



[Ubuntu] How to turn off coloring syntax in vi editor

#> vi /etc/vim/vimrc








remove if has("syntax") syntax on end if.

Friday, 24 June 2016

[CloudSQL] Getting Started Google Cloud SQL

1. Create new instance

I choose Cloud SQL generation 2. this is more fast and support more disk and more cheaper than generation 1. But, it is beta service yet.


2. Set up resource size



3. Set up options and add network allowed access



4. Set up other options



5. Finished creating instance







6. Set up root password



7. Connect DB using database tool





[Oracle] ORA-00845 : MEMORY TARGET not supported on this system

I used Oracle 11g in CentOS VM image. this image is allocated 16GB memory. But after reducing memory to 8GB, oracle instance was not started.



This error comes up because you tried to use the Automatic Memory Management (AMM) feature of Oracle 11g R2. It seems that your shared memory filesystem (shmfs) is not big enough. In this case, you should increase shmfs.


1. Check shared memory filesystem size

# df -h



2. Remount and increase size

# umount tmpfs
# mount -t tmpfs shmfs -o size=8192m /dev/shm



3. Startup database instance



4. Check parameter related with memory



[Oracle] How to increase line width in SQLPlus

set linesize [SIZE]

Wednesday, 22 June 2016

[Windows] How to check Main(Mother) Board model

C:\Users\Administrator>wmic baseboard

Caption ConfigOptions CreationClassName Depth Description Height HostingBoard HotSwappable InstallDate Manufacturer Model Name OtherIdentifyingInfo PartNumber PoweredOn Product Removable Replaceable RequirementsDescription RequiresDaughterBoard SerialNumber SKU SlotLayout SpecialRequirements Status Tag Version Weight Width
Base Board Win32_BaseBoard Base Board TRUE FALSE Dell Inc. Base Board TRUE 0D735T FALSE TRUE FALSE ..CN697029CK0163. OK Base Board A00

[Windows] How to check Memory model

C:\Users\Administrator>wmic momorychip


BankLabel Capacity Caption CreationClassName DataWidth Description DeviceLocator FormFactor HotSwappable InstallDate InterleaveDataDepth InterleavePosition Manufacturer MemoryType Model Name OtherIdentifyingInfo PartNumber PositionInRow PoweredOn Removable Replaceable SerialNumber SKU Speed Status Tag TotalWidth TypeDetail Version
BANK0 4294967296 Physical Memory Win32_PhysicalMemory 64 Physical Memory DIMM0 8 1 0 Samsung 1 Physical Memory M378B5273CH0-CH9 1 002D7AA2 1333 Physical Memory 0 64 128
BANK1 4294967296 Physical Memory Win32_PhysicalMemory 64 Physical Memory DIMM1 8 1 0 Samsung 1 Physical Memory M378B5273DH0-CH9 1 6468CE66 1333 Physical Memory 1 64 128
BANK2 4294967296 Physical Memory Win32_PhysicalMemory 64 Physical Memory DIMM2 8 1 0 Samsung 1 Physical Memory M378B5273DH0-CH9 1 00421459 1333 Physical Memory 2 64 128
BANK3 4294967296 Physical Memory Win32_PhysicalMemory 64 Physical Memory DIMM3 8 1 0 Samsung 1 Physical Memory M378B5273DH0-CH9 1 6555173D 1333 Physical Memory 3 64 128

[Utility] hiltie.me - Make code like Java, Shell, SQL, HTML etc to HTML code

hilite.me converts your code snippets into pretty-printed HTML format, easily embeddable into blog posts, emails and websites.

http://hilite.me/

[Java] What is difference between Class.forName() and Class.forName().newInstance()

In JavaDoc, calling Class.forName( String) returns the Class object associated with the class or interface with the given string name.
On the other hand, calling Class.forName( String).newInstance() creates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list.
In other words, Class.forName( String CLASS_NAME) is equivalent to new CLASS_NAME()
(Referenced by http://stackoverflow.com/questions/2092659/what-is-the-difference-between-class-forname-and-class-forname-newinstanc)


Class.forName( String) is not create instance, but call static block in class. On the other hand, newInstance() creates instance. The result of below code will make you more understandable.

Class pe.dorbae.test.Driver
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package pe.dorbae.test;

/*
 * ************************************************************************************
 *
 * Driver.java
 * 
 * ************************************************************************************
 * 
 * @version 1.0.00 2016-06-21 dorbae Initialize
 * @since 2016-06-21
 * @author dorbae
 * 
 * ************************************************************************************
 */
public class Driver {
 
 static {
  System.out.println( "Static Block");
 }

 public Driver() {
  System.out.println( "Constructure");
  
 }
 
 public void test() {
  System.out.println( "test");
 }
 
}


Calling Class.forName( String) Code and Result
1
2
3
4
5
6
public class Test {
 public static void main(String[] args) throws Exception {
  Class.forName( "pe.dorbae.test.Driver"); // equivalent to Class.forName( "pe.dorbae.test.Driver", true, this.getClass().getClassLoader())
  
 }
}




Calling Class.forName( String, false, ClassLoader) Code and Result
1
2
3
4
5
6
public class Test {
 public static void main(String[] args) throws Exception {
  Class.forName( "pe.dorbae.test.Driver", false, Thread.currentThread().getContextClassLoader());
  
 }
}



Calling Class.forName( String).newInstance()
1
2
3
4
5
6
public class Test {
 public static void main(String[] args) throws Exception {
  Class.forName( "pe.dorbae.test.Driver").newInstance(); // equivalent to Class.forName( "pe.dorbae.test.Driver", true, this.getClass().getClassLoader())
  
 }
}




Calling Class.forName( String, false, ClassLoader).newInstance()
1
2
3
4
5
6
public class Test {
 public static void main(String[] args) throws Exception {
  Class.forName( "pe.dorbae.test.Driver", false, Thread.currentThread().getContextClassLoader()).newInstance();
  
 }
}




When use JDBC driver, we usually call Class.forName( String driverClass). Class.forName( String) is not create JDBC Driver Object instance. If so, how to use driver object?

JDBC Driver generally make driver class that implements java.sql.Driver like this.
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
public final class <DriverClass> implements java.sql.Driver {

    static {
        try {
            DriverManager.registerDriver(new <DriverClass>());
        } catch (SQLException e) {
            throw new RuntimeException("Could not register driver", e);
        }
    }

    .
    .
    .
    
}

Therefore, if you call Class.forName( String driverClass), static block is called and it register new driver class instance.

However, it is different when JDBC Driver class is loaded in another. DriverManager.getConnection() finds driver object in Thread.current.getContextClassLoader().  DriverManager can't not find driver object, because it is actually loaded in another class loader.

In this case, you should like this.
1
2
java.sql.Driver driver = ( java.sql.Driver)Class.forName( DriverClassName, true, AnotherClassLoader).newInstance();
java.sql.Connection conn = driver.connect( <URL>, <Properties>);