2016년 5월 18일 수요일

Raspberry Pi - Button을 이용한 GPIO 입력 테스트

Raspberry Pi의 GPIO를 이용하여 버튼이 눌러졌을 때 LED를 켜는 테스트를 해 보자. 테스트를 위해서는 기본적으로 wiringPi가 설치되어 있어야 한다.

테스트 회로는 그림과 같이 Push Button을 눌렀을 때 1번 Pin에 High가 인가 되도록 5V를 연결하였으며 10kΩ의 Pull-down 저항을 연결하였다. LED는 버튼이 눌러진 것을 확인하기 위해 연결하였다.

※ LED의 극성을 반대로 연결하면 LED가 고장 나므로 주의해서 연결한다. 길이가 짧은 쪽이(-), 긴 쪽이 (+)이다. 

회로 및 구성

  • Raspberry Pi 2 Model B
  • Push Button
  • LED (동작 전압: 1.8V ~ 2.3V)
  • 저항 250Ω, 10kΩ




테스트를 위해 buttonTest.c 코드를 다음과 같이 작성한다.

#include <wiringPi.h>

#define LED 4
#define BUTTON 1

int main(void)
{
  if(wiringPiSetup() == -1)
    return 1;

  pinMode(LED, OUTPUT);
  pinMode(BUTTON, INPUT);

  digitalWrite(LED, 0);
  int input = 0;

  for(;;)
  {
    if(digitalRead(BUTTON))
      digitalWrite(LED, 1);
    else
      digitalWrite(LED, 0); 

    delay(100);
  }

  return 0;
}

코드를 컴파일 하고 실행 시킨다.

pi@raspberrypi ~$ gcc -o buttonTest buttonTest.c -lwiringPi
pi@raspberrypi ~$ sudo ./buttonTest


버튼을 누르면 LED에 불이 들어오는 것을 확인할 수 있다.

Raspberry Pi - GPIO output test with LED

Let's turn on LED using a Raspberry Pi GPIO port. Before the test, wiringPi must be installed. 

※ Be careful!!. If LED is connected to reverse polarity, it will be broken. Long leg is positive(+) and short leg is negative(-).

Component
  • Raspberry Pi 2 Model B
  • LED (Operating Voltage: 1.8V ~ 2.3V)
  • Resistor 250Ω





In order to test, make a simple code which is ledtest.c

#include <wiringPi.h>

#define LED1 1

int main(void)
{
  if(wiringPiSetup() == -1)
    return 1;

  pinMode(LED1, OUTPUT);
  digitalWrite(LED1, 1);

  return 0;
}

Complie and run the program.

pi@raspberrypi ~$ gcc -o ledtest ledtest.c -lwiringPi
pi@raspberrypi ~$ sudo ./ledtest


After run the program, LED will be turned on.

2016년 5월 17일 화요일

Raspberry Pi - LED를 이용한 GPIO 출력 테스트

Raspberry Pi의 GPIO를 이용하여 간단한 LED를 켜는 테스트를 해 보자. 테스트에 앞서 wiringPi가 설치되어 있지 않다면 wiringPi를 먼저 설치하도록 한다.

테스트 회로는 다음과 같이 발광 다이오드의 (+)를 1번에 연결하고 (-)를 GND에 연결하였으며 (+)와 1번 사이에 250Ω의 저항을 연결하였다.

※ LED의 극성을 반대로 연결하면 LED가 고장 나므로 주의해서 연결한다. 길이가 짧은 쪽이(-), 긴 쪽이 (+)이다. 

회로 및 구성

  • Raspberry Pi 2 Model B
  • LED (동작 전압: 1.8V ~ 2.3V)
  • 저항 250Ω




테스트를 위해 다음과 같이 코드를 작성한다.
#include <wiringPi.h>

#define LED1 1

int main(void)
{
  if(wiringPiSetup() == -1)
    return 1;

  pinMode(LED1, OUTPUT);
  digitalWrite(LED1, 1);

  return 0;
}

코드를 컴파일 하고 실행 시킨다.

pi@raspberrypi ~$ gcc -o ledtest ledtest.c -lwiringPi
pi@raspberrypi ~$ sudo ./ledtest

프로그램이 실행되면 LED에 불이 들어오는 것을 확인할 수 있다.

2016년 5월 16일 월요일

Debian에서 Glassfish 설치


Glassfish를 설치하기 전 Java 버전을 먼저 확인한다. Glassfish V3는 JDK 1.7.0, Glassfish V4는 JDK 1.8.0 이상 설치되어 있어야 한다.


scwook@debian:~/Download# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

JAVA 설치 방법은 다음 Post를 참고한다.

http://scwook.blogspot.kr/2016/05/debian-jessie-java.html


Glassfish V3 설치

Glassfish V3은 Oracle 홈페이지에서 받을 수 있다. 다운로드 페이지에서 Linux/Unix/Mac Installer 파일을 다운 받는다.


다운받은 파일을 관리자 권한으로 실행한다.

root@debian:/Downloads# bash ogs-3.1.2.2-unix.sh

설치 화면이 나타나면 Next를 누른다.



Typical Installation을 선택한 후 Next를 누른다.



설치 위치를 /opt/glassfish3로 변경한 후 Next를 누른다.



Next를 누른다.



Install을 누르면 설치가 시작된다.



설치가 완료되면 설정 메뉴가 나타난다. 기본 설정으로 두고 Username과 Password를 입력한 후 Next를 누른다.



설치가 완료되면 Exit를 누른다.


테스트를 위해 다음 주소록 접속한다.

http://localhost:4848 또는 http://[Server IP Address]:4848

Glassfish V4 설치

Glassfish 사이트에 접속하여 Java EE 7 Full Platform 파일을 다운 받는다.




다운 받은 파일의 압축을 풀고 daemon을 실행한다.

root@debian:~# unzip glassfish-4.1.1.zip -d /opt/
root@debian:~# cd /opt/glassfish4/bin/
root@debian:/opt/glassfish4/bin# ./asadmin start-domain
Waiting for domain1 to start ...
Successfully started the domain : domain1
domain  Location: /opt/glassfish4/glassfish/domains/domain1
Log File: /opt/glassfish4/glassfish/domains/domain1/logs/server.log
Admin Port: 4848
Command start-domain executed successfully.

다음 주소로 접속한다.


필요한 경우 change-admin-password 명령으로 관리자 암호를 설정한다.

root@debian:/opt/glassfish4/bin# ./asadmin change-admin-password

Enter admin user name [default: admin]>admin

Enter the admin password> [아무것도 입력하지 않음]
Enter the new admin password> [새로 설정할 암호] 
Enter the new admin password again> [새로 설정할 암호]

자동 실행
create-service 명령을 사용하면 /etc/init.d/ 폴더에 GlassFish_domain1 실행 스크립트가 생성된다.

root@debian:/opt/glassfish4/bin# ./asadmin create-service

update-rc 명령으로 GlassFish_domain1을 등록한다.

root@debian:/etc/init.d# update-rc GlassFish_domain1 default


2016년 5월 15일 일요일

Olog Mysql Database Schema

This is a schema for MySQL Olog database. Just copy and make a file such as "olog.sql". following command can load the file.

mysql> source olog.sql;

-- MySQL dump 10.13  Distrib 5.5.49, for debian-linux-gnu (x86_64)
--
-- Host: localhost    Database: olog
-- ------------------------------------------------------
-- Server version 5.5.49-0+deb7u1

/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */;
/*!40103 SET TIME_ZONE='+00:00' */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;

--
-- Current Database: `olog`
--

CREATE DATABASE /*!32312 IF NOT EXISTS*/ `olog` /*!40100 DEFAULT CHARACTER SET latin1 */;

USE `olog`;

--
-- Table structure for table `attributes`
--

DROP TABLE IF EXISTS `attributes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `attributes` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `property_id` int(11) unsigned NOT NULL,
  `name` varchar(200) NOT NULL,
  `state` enum('Active','Inactive') NOT NULL DEFAULT 'Active',
  PRIMARY KEY (`id`),
  KEY `attributes_property_id_fk` (`property_id`),
  CONSTRAINT `attributes_property_id_fk` FOREIGN KEY (`property_id`) REFERENCES `properties` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=19 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `attributes`
--

LOCK TABLES `attributes` WRITE;
/*!40000 ALTER TABLE `attributes` DISABLE KEYS */;
/*!40000 ALTER TABLE `attributes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `entries`
--
This is a schema of MySQL for 


DROP TABLE IF EXISTS `entries`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `entries` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `created` datetime NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `entries`
--

LOCK TABLES `entries` WRITE;
/*!40000 ALTER TABLE `entries` DISABLE KEYS */;
/*!40000 ALTER TABLE `entries` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `logbooks`
--

DROP TABLE IF EXISTS `logbooks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `logbooks` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(45) NOT NULL,
  `is_tag` int(1) unsigned NOT NULL DEFAULT '0',
  `owner` varchar(45) DEFAULT NULL,
  `state` enum('Active','Inactive') NOT NULL DEFAULT 'Active',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=12 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `logbooks`
--

LOCK TABLES `logbooks` WRITE;
/*!40000 ALTER TABLE `logbooks` DISABLE KEYS */;
INSERT INTO `logbooks` VALUES (1,'Operations',0,NULL,'Active'),(2,'Electronics Maintenance',0,NULL,'Active'),(3,'Mechanical Technicians',0,NULL,'Active'),(4,'LOTO',0,NULL,'Active'),(5,'Inverpower Power Supplies',1,NULL,'Active'),(6,'RF Area',1,NULL,'Active'),(7,'Kicker',1,NULL,'Active'),(8,'Bumps',1,NULL,'Active'),(9,'Septums',1,NULL,'Active'),(10,'Large Power Supplies',1,NULL,'Active'),(11,'Timing Systems',1,NULL,'Active');
/*!40000 ALTER TABLE `logbooks` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `logs`
--

DROP TABLE IF EXISTS `logs`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `logs` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `modified` datetime NOT NULL,
  `source` varchar(80) NOT NULL DEFAULT '',
  `owner` varchar(32) NOT NULL,
  `description` mediumtext NOT NULL,
  `md5entry` varchar(32) NOT NULL DEFAULT '',
  `state` enum('Active','Inactive') NOT NULL DEFAULT 'Active',
  `level` enum('Info','Problem','Request','Suggestion','Urgent') NOT NULL DEFAULT 'Info',
  `entry_id` int(11) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `entry_id_fk` (`entry_id`),
  CONSTRAINT `entry_id_fk` FOREIGN KEY (`entry_id`) REFERENCES `entries` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `logs`
--

LOCK TABLES `logs` WRITE;
/*!40000 ALTER TABLE `logs` DISABLE KEYS */;
/*!40000 ALTER TABLE `logs` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `logs_attributes`
--

DROP TABLE IF EXISTS `logs_attributes`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `logs_attributes` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `log_id` int(11) unsigned NOT NULL,
  `attribute_id` int(11) unsigned NOT NULL,
  `value` varchar(200) NOT NULL,
  `grouping_num` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `logs_attributes_attribute_id_fk` (`attribute_id`),
  KEY `logs_attributes_log_id_fk` (`log_id`),
  CONSTRAINT `logs_attributes_attribute_id_fk` FOREIGN KEY (`attribute_id`) REFERENCES `attributes` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `logs_attributes_log_id_fk` FOREIGN KEY (`log_id`) REFERENCES `logs` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB AUTO_INCREMENT=179 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `logs_attributes`
--

LOCK TABLES `logs_attributes` WRITE;
/*!40000 ALTER TABLE `logs_attributes` DISABLE KEYS */;
/*!40000 ALTER TABLE `logs_attributes` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `logs_logbooks`
--

DROP TABLE IF EXISTS `logs_logbooks`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `logs_logbooks` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `log_id` int(11) unsigned NOT NULL,
  `logbook_id` int(11) unsigned NOT NULL,
  PRIMARY KEY (`id`),
  KEY `log_id_fk` (`log_id`),
  KEY `logbook_id_fk` (`logbook_id`) USING BTREE,
  CONSTRAINT `log_id_fk` FOREIGN KEY (`log_id`) REFERENCES `logs` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION,
  CONSTRAINT `logbook_id_fk` FOREIGN KEY (`logbook_id`) REFERENCES `logbooks` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `logs_logbooks`
--

LOCK TABLES `logs_logbooks` WRITE;
/*!40000 ALTER TABLE `logs_logbooks` DISABLE KEYS */;
/*!40000 ALTER TABLE `logs_logbooks` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `properties`
--

DROP TABLE IF EXISTS `properties`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `properties` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `name` varchar(200) NOT NULL,
  `state` enum('Active','Inactive') NOT NULL DEFAULT 'Active',
  PRIMARY KEY (`id`),
  UNIQUE KEY `name` (`name`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `properties`
--

LOCK TABLES `properties` WRITE;
/*!40000 ALTER TABLE `properties` DISABLE KEYS */;
/*!40000 ALTER TABLE `properties` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `schema_version`
--

DROP TABLE IF EXISTS `schema_version`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `schema_version` (
  `version_rank` int(11) NOT NULL,
  `installed_rank` int(11) NOT NULL,
  `version` varchar(50) NOT NULL,
  `description` varchar(200) NOT NULL,
  `type` varchar(20) NOT NULL,
  `script` varchar(1000) NOT NULL,
  `checksum` int(11) DEFAULT NULL,
  `installed_by` varchar(100) NOT NULL,
  `installed_on` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
  `execution_time` int(11) NOT NULL,
  `success` tinyint(1) NOT NULL,
  PRIMARY KEY (`version`),
  KEY `schema_version_vr_idx` (`version_rank`),
  KEY `schema_version_ir_idx` (`installed_rank`),
  KEY `schema_version_s_idx` (`success`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `schema_version`
--

LOCK TABLES `schema_version` WRITE;
/*!40000 ALTER TABLE `schema_version` DISABLE KEYS */;
INSERT INTO `schema_version` VALUES (1,1,'1.00','Base version','INIT','Base version',NULL,'root','2016-05-13 05:23:05',0,1),(2,2,'2.00','ALTER logbooks status to state','SQL','V2.00__ALTER_logbooks_status_to_state.sql',-1775352058,'root','2016-05-13 05:23:05',15,1),(3,3,'2.01','ALTER logs status to state','SQL','V2.01__ALTER_logs_status_to_state.sql',104011789,'root','2016-05-13 05:23:05',11,1),(4,4,'2.02','ALTER properties status to state','SQL','V2.02__ALTER_properties_status_to_state.sql',-680189563,'root','2016-05-13 05:23:05',19,1),(5,5,'2.03','ALTER attributes status to state','SQL','V2.03__ALTER_attributes_status_to_state.sql',-207252449,'root','2016-05-13 05:23:05',12,1),(6,6,'2.04','ALTER logs logbooks drop columns','SQL','V2.04__ALTER_logs_logbooks_drop_columns.sql',-2067581210,'root','2016-05-13 05:23:05',5,1),(7,7,'2.05','CREATE entries','SQL','V2.05__CREATE_entries.sql',-16098960,'root','2016-05-13 05:23:05',3,1),(8,8,'2.06','ALTER logs md5recent','SQL','V2.06__ALTER_logs_md5recent.sql',-1367573323,'root','2016-05-13 05:23:05',4,1),(9,9,'2.07','DROP statuses','SQL','V2.07__DROP_statuses.sql',-1470090610,'root','2016-05-13 05:23:05',2,1),(10,10,'2.08','ALTER logs level to ENUM','SQL','V2.08__ALTER_logs_level_to_ENUM.sql',-308002669,'root','2016-05-13 05:23:05',11,1),(11,11,'2.09','DROP levels','SQL','V2.09__DROP_levels.sql',-352522219,'root','2016-05-13 05:23:05',2,1),(12,12,'2.10','ALTER logs','SQL','V2.10__ALTER_logs.sql',-16433912,'root','2016-05-13 05:23:05',14,1),(13,13,'2.11','ALTER fix all fkeys','SQL','V2.11__ALTER_fix_all_fkeys.sql',-340063373,'root','2016-05-13 05:23:05',51,1);
/*!40000 ALTER TABLE `schema_version` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table `subscriptions`
--

DROP TABLE IF EXISTS `subscriptions`;
/*!40101 SET @saved_cs_client     = @@character_set_client */;
/*!40101 SET character_set_client = utf8 */;
CREATE TABLE `subscriptions` (
  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
  `tag_id` int(11) unsigned NOT NULL,
  `email` varchar(250) NOT NULL DEFAULT '',
  `webhook` varchar(250) DEFAULT NULL,
  `level_id` int(11) NOT NULL,
  PRIMARY KEY (`id`),
  KEY `subscriptions_tag_id_fk` (`tag_id`),
  CONSTRAINT `subscriptions_tag_id_fk` FOREIGN KEY (`tag_id`) REFERENCES `logbooks` (`id`) ON DELETE NO ACTION ON UPDATE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
/*!40101 SET character_set_client = @saved_cs_client */;

--
-- Dumping data for table `subscriptions`
--

LOCK TABLES `subscriptions` WRITE;
/*!40000 ALTER TABLE `subscriptions` DISABLE KEYS */;
/*!40000 ALTER TABLE `subscriptions` ENABLE KEYS */;
UNLOCK TABLES;
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;

/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;

-- Dump completed on 2016-05-16  9:36:30

2016년 5월 11일 수요일

Debian Jessie에서 Java 설치

update-alternatives 명령을 사용하면 새로운 버전의 Java를 추가 및 변경할 수 있다. 우선 현재 사용하고 있는 Java 버전을 확인한다.


scwook@debian:~$ java -version
openjdk version "1.8.0_72-internal"
OpenJDK Runtime Environment (build 1.8.0_72-internal-b15)
OpenJDK 64-Bit Server VM (build 25.72-b15, mixed mode)


새로 설치할 Java 를 다운받은 후 원하는 위치에 압축을 해제한다.

http://www.oracle.com/technetwork/java/javase/downloads/index.html


root@debian:~/Download# tar xvf jdk-8u91-linux-x64.tar.gz -C /opt/

--install 옵션으로 새로운 Java를 등록한다.

root@debian:~/Download# update-alternatives --install /usr/bin/java java /opt/jdk1.8.0_91/bin/java 1
root@debian:~/Download# update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_91/bin/javac 1

--config 옵션으로 새로 등록된 Java로 변경한다.

root@debian:~/Download# update-alternatives --config java
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1069      auto mode
  1            /opt/jdk1.8.0_91/bin/java                        1         manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1069      manual mode

Press enter to keep the current choice[*], or type selection number: 1

Java 버전을 확인해 보면 새로 설치된 Java로 변경된 것을 확인할 수 있다.

root@debian:~/Download# java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

2016년 5월 10일 화요일

Olog Service Module 설치

Olog는 REST 기반의 Web Service Module로 가속기 운영 중 발생하는 다양한 Event에 대한 기록 및 검색을 사용자에게 제공해 주는 모듈이다. Olog는 크게 Servie를 제공하는 Server와 Log를 작성하는 Client로 구성되어 있다.

기본적인 Olog 설치 및 파일은 다음 사이트에서 받을 수 있다.

http://olog.github.io/2.2.7-SNAPSHOT/


시스템 구성
  • Debain Jessie 64bit Kernel 3.16.0
  • Glassfish Application Server v3.1.2.2
  • MySql 5.5
  • Olog Service v2.2.6
Olog Service는 Web application ARchive(WAR)파일로 제공되므로 이를 Deploy할 수 있는 Application Server가 필요하다. 현재 가장 많이 사용되고 있는 서버 프로그램으로는 Glassfish와 Apache Tomcat이 있으며, 여기서는 Glassfish v3.1.2.2를 사용하였다. Glassfish 설치는 다음 포스트를 참고하기 바란다.

Debian에서 Glassfish 설치


1. MySql 설치


MySql은 Debian 기본 Package에 포함되어 있으며 aptitude 명령으로 설치 할 수 있다.

root@debian:~# aptitude install mysql-server-5.5

MySQL에 사용할 root 패스워드를 설정하고 Ok를 누른다.


Olog Database 추가

Olog Service에서 사용되는 SQL 테이블은 다음과 같다.
  • attributes
  • entries
  • logbooks
  • logs
  • logs_attributes
  • logs_logbooks
  • properties
  • schema_version
  • subscriptions
테이블 생성을 위한 Schema 파일은  다음 포스트를 참고한다.

Olog Mysql Database Schema

MySql에 로그인 한 후 Databases를 만든다.

scwook@debain:~$ mysql -u root -p
Enter password: 

mysql> source /home/scwook/Downloads/olog_scheme.sql;

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| olog               |
| performance_schema |
+--------------------+
4 rows in set (0.00 sec)

mysql> use olog;
Database changed
mysql> show tables;
+-----------------+
| Tables_in_olog  |
+-----------------+
| attributes      |
| levels          |
| logbooks        |
| logs            |
| logs_attributes |
| logs_logbooks   |
| properties      |
| statuses        |
| subscriptions   |
+-----------------+
9 rows in set (0.01 sec)

mysql> exit

MySql Connector Java 설치


TAR Archive 파일을 다운 받는다.



다운 받은 파일의 압축을 해제하고 connector 파일을 glassfish library 폴더에 복사한다.

root@debain:~/Downloads# tar xvf mysql-connector-java-5.1.38.tar.gz
root@debain:~/Downloads# cd mysql-connector-java-5.1.38
root@debain:~/Downloads# cp mysql-connector-java-5.1.38-bin.jar /opt/glassfish3/glassfish/lib


2. Glassfish 설정

JDBC Connection Pool 생성

- Common Tasks - Resources - JDBC - JDBC Connection Pools 메뉴 선택
- New 버튼을 눌러 다음과 같이 설정한다.
  • Pool Name: OlogPool
  • Resource Type: javax.sql.ConnectionPoolDataSource
  • Datasource Classname:  com.mysql.jdbc.jdbc2.optional.MysqlConnectionPoolDataSource
-  Additional Properties 에 다음 속성을 추가한다. 
  • databaseName - olog
  • serverName - localhost
  • user - [mysql user]
  • password - [mysql password]





JDBC Resource 생성

- Common Tasks - Resources - JDBC - JDBC Resources 메뉴 선택
- New 버튼을 눌러 다음과 같이 설정한다.
  • JNDI Name: jdbc/olog
  • Pool Name: OlogPool




Realm  추가

- Common Tasks - Configurations - Server-config - Security - Realms 선택
- New 버튼을 눌러 다음과 같이 설정한다.
  • Name: olog
  • Class Name: com.sun.enterprise.security.auth.realm.file.FileRealm
  • JAAS Context: fileRealm
  • Key File: ${com.sun.aas.instanceRoot}/config/olog_keyfile

- Common Tasks - Configurations - Server-config - Security - Realms - olog 선택
- Manage Users 를 클릭하여 사용자를 추가한다.
  • User ID: [사용자 ID]
  • Group List: [사용자가 속한 그룹]
- Group List는 다음 중 하나로 설정한다.

  • olog-admins:  Logbook 및 Tag 생성, 삭제, Log 작성
  • olog-logs: Log 작성





Depoly

다음 주소에 접속하여 Olog 2.2.6 버전을 받는다.

압축을 해제한다.
scwook@debian:~/olog$ tar xvf Olog_2-2-6.tar.gz
scwook@debian:~/olog$ ls
OlogAPI-2.2.6.jar          OlogAPI-2.2.6-sources.jar
OlogAPI-2.2.6-javadoc.jar  olog-service-2.2.6.war

- Common Tasks - Applications 선택
- Deploy 버튼을 눌러 다음과 같이 설정한다.
  • Location: olog-service-2.2.6.war
  • Type: Web Application
  • Context Root: olog
  • Application Name: olog-service-2.2.6