Junjao

Programming, Software Engineering

วิธีการสร้างไฟล์ Certificate Signing Request เพื่อขอ Certificate key ธันวาคม 30, 2011

Filed under: Uncategorized — จั่น @ 9:40 am

http://www.ssl.in.th/index.php/main/public/action/view/page/Generate_CSR

 

อันนี้เป็นวิธีการสร้างไฟล์ CSR  สำหรับผู้ทีใช้  openssl  ในการสร้าง CSR

https://knowledge.geotrust.com/support/knowledge-base/index?page=content&id=AR876

 

jboss multidatasource ธันวาคม 25, 2011

Filed under: Uncategorized — จั่น @ 2:26 am

ในไฟล์  XX-ds.xml ที่ deploy ลงใน  <server_instance_name>/deploy/…

 

    <connection-url>jdbc:mysql://localhost:3306/test|jdbc:mysql://172.20.14.106:3306/test</connection-url>
    <url-delimiter>|</url-delimiter>

ระหว่างที่ database แรก ล่มแล้วย้ายไปสร้าง connection กับ database ตัวที่สอง จะมีการล่มเกิดขึ้น ดังนั้นก่อนที่ application จะได้ connection ไปจึงต้องมีการ check ก่อนว่า connection นั้นใช้ได้หรือไม่ ด้วย tag

   <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.MySQLValidConnectionChecker</valid-connection-checker-class-name>

 

**อ้างอิง http://jagadesh4java.blogspot.com/2011/09/jboss-database-failover-high.html

 

http://javabrains.koushik.org ธันวาคม 17, 2011

Filed under: Uncategorized — จั่น @ 5:14 pm

http://javabrains.koushik.org

 

แปลงจากไฟล์ที่เข้ารหัสเป็น UTF-8 เป็น TIS-620 ตุลาคม 3, 2011

Filed under: Uncategorized — จั่น @ 7:53 pm

เป็นตัวอย่าง code การแปลงจากไฟล์ที่มีภาษาไทย เข้ารหัสด้วย UTF-8 (ภาษาไทยแต่ละตัวใช้พื้นที่ 3 bytes)
—-> แปลงเป็นไฟล์ที่มีภาษาไทย เข้ารหัสด้วย TIS620  โดยภาษาไทยแต่ละตัวใช้พื้นที่เหลือ 1 byte

static String readInput() {

    StringBuffer buffer = new StringBuffer();
    try {
        FileInputStream fis = new FileInputStream("test.txt");
        InputStreamReader isr = new InputStreamReader(fis,"UTF8");
        Reader in = new BufferedReader(isr);
        int ch;
        while ((ch = in.read()) > -1) {
                buffer.append((char)ch);
        }
        in.close();
        return buffer.toString();
    } catch (IOException e) {
        e.printStackTrace();
        return null;
    }
}
static void writeOutput(String str) {

    try {
        FileOutputStream fos = new FileOutputStream("test2.txt");
        Writer out = new OutputStreamWriter(fos, "TIS620");
        out.write(str);
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

วิธีการทดสอบ
1.สร้างไฟล์ test.txt ที่มีภาษาไทย เข้ารหัสด้วย UTF-8  แล้วเปิดดูแบบ hex viewer ด้วย EditPlus จะเห็นว่าภาษาไทยแต่ละตัวใช้ 3 bytes
2.รันโปรแกรม ทดสอบ
3.แล้วเปิด test2.txt แบบ hex viewer ด้วย EditPlus จะเห็นว่าภาษาไทยแต่ละตัวใช้ 1 byte

อ้างอิง

http://download.oracle.com/javase/tutorial/i18n/text/stream.html

 

SSL ด้วย openSSL สิงหาคม 11, 2011

Filed under: Uncategorized — จั่น @ 5:01 pm

1) ที่ Linux

#yum install mod_ssl เพื่อที่จะได้คำสั่ง openssl

 

 

แบบ Self-Signed
=============
2)Create a RSA private key for your server (will be Triple-DES encrypted and PEM formatted):
$ openssl genrsa -des3 -out server.key 1024

3) Create a self-signed Certificate (X509 structure) with the RSA key you just created (output will be PEM formatted):

$ openssl req -new -x509 -nodes -sha1 -days 365 -key server.key -out server.crt

*****จากนั้นนำ server.key กับ server.crt ไปใช้งาน โดยระบุใน apache configuration file (ssl.conf)

 

 

แบบส่ง Public key ไป Sign กับ ROOT CA  (cacert.org)

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

2) Create a RSA private key for your Apache server (will be Triple-DES encrypted and PEM formatted):

$ openssl genrsa -des3 -out server.key 1024

3) Create a Certificate Signing Request (CSR) with the server RSA private key (output will be PEM formatted):

$ openssl req -new -key server.key -out server.csr

เมื่อได้ไฟล์ server.csr แล้วจึงนำไปสร้าง Certificate ที่ website cacert.org   จะได้เนื้อหาของไฟล์ server.crt 

****จากนั้นนำ server.key กับ server.crt ไปใช้งาน โดยระบุใน apache configuration file (ssl.conf)

****ข้อจำกัดคือจะได้ Certificate ที่มีอายุเพียง 6 เดือน

 

 

อ้างอิง

http://httpd.apache.org/docs/2.0/ssl/ssl_faq.html

http://www.cacert.org

 

Ubuntu พฤษภาคม 18, 2011

Filed under: Uncategorized — จั่น @ 12:57 am

มีทั้งแบบ Desktop (default เป็น GUI Mode เมื่อติดตั้งเสร็จแล้ว)

http://www.ubuntu.com/download/ubuntu/download

กับแบบ Server (default เป็น Text mode เมื่อติดตั้งเสร็จแล้ว)

http://www.ubuntu.com/download/server/download

 

ติดตั้ง apache บน Fedora พฤษภาคม 11, 2011

Filed under: Uncategorized — จั่น @ 11:47 am

เมื่อ download apache2.2.XX.tar.gz มาแล้ว  ให้แตกออกแล้วเข้าไปเพื่อ compile apache source ใหม่ดังนี้

เก็บ apache ที่ Compile แล้วไว้ที่  /exec/apache2  (ซึ่ง /exec/apache2 ก็คือ $APACHE_HOME)
# ./configure –prefix=/exec/apache2 –enable-rewrite –enable-proxy=http –enable-module=so –enable-ssl

#make

#make install

ทดสอบโดยการ Start

#cd /exec/apache2/bin

#./apachectl start

ตรวจสอบว่ามี process httpd ทำงานอยู่ในระบบ

#ps -aef|grep httpd

 

ลง Postgresql ด้วย yum บน FedoraCore13 พฤษภาคม 9, 2011

Filed under: Uncategorized — จั่น @ 6:42 pm

ติดตั้ง Postgresql Server และตัว Dependencies อื่นๆ
1. #yum install postgresql-server
2. #chkconfig postgresql on

Initialize database ด้วย user root

3. #service postgresql initdb

จากข้างบนจะสร้าง user postgres มาให้เราทันทีในระบบ

มาถึงตรงนี้เราสามารถ Start postgresql Server ได้แล้ว ด้วยคำสั่ง

#/etc/rc.d/init.d/postgresql restart

———————
ทดสอบด้วย user postgres
4. #su – postgres

สร้างฐานข้อมูลทดสอบชื่อ “mydb”
5. $createdb mydb
6. $psql mydb
7. mydb=#select version();
8. mydb=#\q

อ้างอิง

http://wiki.postgresql.org/wiki/YUM_Installation

http://yum.pgrpms.org/

 

apache ที่เราลงมีคุณสมบัติอย่างไร พฤษภาคม 9, 2011

Filed under: Uncategorized — จั่น @ 6:33 pm

1. เข้าไปที่ $APACHE_HOME/bin  เช่นสมมติลง apache ไว้ที่ /opt/apache2
#cd /opt/apache2
2. เข้าไปที่ bin
#cd bin
3. Output a list of modules compiled into the server:
#httpd -l
4. dump a list of loaded Static and Shared Modules
#httpd -M
5. Print the version and build parameters of httpd, and then exit
#httpd -V

อ้างอิง

http://www.cyberciti.biz/faq/find-out-apache-version/

 

ตรวจดูว่า java application หรือ java web app ใช้ memory ไปเท่าไหร่ พฤษภาคม 2, 2011

Filed under: Uncategorized — จั่น @ 2:17 pm

ใช้ jconsole ซึ่งอยู่ใน $JAVA_HOME/bin/jconsole ตรวจสอบได้
ดังภาพด้านล่าง  ทดสอบด้วยการ

  1. เปิดเล่น web application นั้นๆโดยการ Start tomcat
  2. พิมพ์คำสั่ง #jconsole  ที่ command prompt ของ windows เพื่อเปิดโปรแกรม jconsole  (จริงๆแล้วตำแหน่งของ program jconsole จะอยู่ที่ $JAVA_HOME/bin)
  3. จากข้อ 2  จะแสดง java process pID ทั้งหมดในระบบ  ให้เชื่อมไปที่  org.apache.catalina.startup.Bootstrap java process
  4. ไปที่ tab  “memory” ดังภาพด้านล่าง จะเห็นว่า web application ที่เราพัฒนาขึ้นมีการใช้  memory (java Heap) ไปประมาณ 60-70MB

คำถามต่อมาคือแล้วจะรู้ไปทำไม  ก็คือทำให้เรารู้ว่ามีการใช้ resources ของเครื่องไปเท่าไหร่  เพื่อที่เราจะได้จัดสรรให้เหมาะสม เช่น อย่างกรณีนี้เราอาจปรับ JVM parameter ให้เหมาะสม เช่นเป็น -Xms128M  -Xmx256M  เพราะ web application ของเราใช้เพียง 60-70MB  เท่านั้น

**หมายเหตุ  ในกรณีที่นำ web application นี้ไปใช้งานจริงๆซึ่งมี data เก็บมากขึ้นในฐานข้อมูล  เราควรจะต้องใช้ jconsole ตรวจสอบอีกครั้งว่า  web application มีการใช้ memory เพิ่มขึ้นหรือไม่ จะได้กำหนด -Xms และ -Xmx ใหม่ให้เหมาะสมต่อไป

อ้างอิง

http://download.java.net/jdk7/docs/technotes/guides/management/jconsole.html

 

 
Follow

Get every new post delivered to your Inbox.