2017년 12월 22일 금요일

PHP Session handler Redis 설정

Ubuntu 12.04, PHP 5.x 기준

PhpRedis 설치

su
cd /tmp
git clone https://github.com/nicolasff/phpredis.git
cd phpredis
phpize
./configure
make && make install
echo extension=redis.so > /etc/php5/conf.d/redis.ini
php -i | grep -E 'Redis Support|Registered save handlers'
  • Redis Support => enabled 확인
  • Registered save handlers => redis 포함 확인

PHP Session handler 설정 변경

vi /etc/php5/apache2/php.ini
-----------------------------
...
;; 주석처리
;session.save_handler = files
;; 아래 내용 추가
session.save_handler = redis
session.save_path = "tcp://레디스서버IP:포트?auth=패스워드"
...

  • Apache 재시작 후 Redis에 세션 데이터 생성 여부 확인
service apache2 restart



참고: https://github.com/phpredis/phpredis

2017년 12월 21일 목요일

Let’s Encrypt SSL 인증서 설치 경로 변경

(Let’s Encrypt config directory change)
(Let’s Encrypt certificate directory change)
(/etc/letsencrypt change)



* --config-dir 옵션으로 키파일 위치 변경 가능
$ certbot-auto certonly --webroot --webroot-path=/var/www --config-dir /변경할/디렉토리 -d 도메인 -d 추가도메인


* 인증서 생성시 --config-dir 옵션을 사용해서 설정 디렉토리를 변경한 경우, 이후 certbot-auto 관련 명령시 --config-dir 옵션 추가 필요
$ certbot-auto renew --config-dir /설정한/디렉토리



참고: https://letsencrypt.readthedocs.io/en/latest/using.html#lock-files

uCloud NAS 연결

- Ubuntu 12.04 기준


사전 확인

  • 과정 중 root 계정 필요
  • 마운트하려는 서버에서 lshw -C network 실행시 eth1 항목이 확인되지 않는다면 uCloud 콘솔에서 CIP 연결 필요함


eth1 interface 추가

$ su
$ vi /etc/network/interfaces
- 아래 내용 추가
auto eth1
iface eth1 inet dhcp

  • 적용
$ service networking restart
$ ifconfig
- eth1 인식 확인


Mount

  • 관련 패키지 설치
$ apt-get update
$ apt-get install nfs-common

  • NAS 볼륨 확인
$ showmount -e 10.xx.xx.xx

  • 대상 디렉토리 생성 후 mount
$ mkdir /대상디렉토리
$ mount -t nfs 10.xx.xx.xx:/볼륨명 /대상디렉토리
$ df -h
- 마운트 확인

  • reboot시에도 마운트 되도록 설정
$ vi /etc/fstab
- 아래 내용 추가
10.xx.xx.xx:/볼륨명       /대상디렉토리    nfs     ru      0       0

  • /etc/fstab 설정 오류 확인
$ mount -a
- 오류가 있을 경우에만 해당 사항 출력




참고: https://ucloudbiz.olleh.com/portal/portal.portalinfo.html

2017년 12월 5일 화요일

Hshare Demon Install (CentOS 6.9)

====================
Hshare Install
CentOS 6.9
====================

su
yum update -y

## build-essential
yum groupinstall 'Development Tools'


------------
# OpenSSL ECC
------------
## openssl elliptic curve cryptography
cd /usr/local/src/
wget https://www.openssl.org/source/openssl-1.0.2m.tar.gz
tar -zxf openssl-1.0.2m.tar.gz
cd openssl-1.0.2m
./config --prefix=/usr --openssldir=/usr/local/openssl shared
make
make test
make install

## check
openssl version
- (OpenSSL 1.0.2m)
openssl ecparam -list_curves
- (include secp256k1)


------------
# Dependencies
------------
## ld -lz
yum install zlib-devel -y
## Berkeley DB
// yum install db4-devel -y (include zlib)
## Boost
yum install boost-devel -y

## qrencode, miniupnpc
rpm -ivh ftp://195.220.108.108/linux/dag/redhat/el6/en/x86_64/dag/RPMS/rpmforge-release-0.5.3-1.el6.rf.x86_64.rpm
yum install qrencode-devel -y
yum install miniupnpc-devel -y


------------
# Build
------------
cd /usr/local/src/
git clone https://github.com/HcashOrg/Hshare.git hshare
cd hshare/src/

## nano makefile.unix 수정
nano makefile.unix
   기존: -l boost_thread$(BOOST_LIB_SUFFIX) \
   수정: -l boost_thread-mt$(BOOST_LIB_SUFFIX) \
make -f makefile.unix




# Public Node
addnode=52.193.215.1
addnode=119.254.102.218
addnode=139.198.188.182
addnode=124.42.118.99
addnode=121.201.24.167
addnode=209.9.107.116
addnode=13.56.173.122
addnode=54.79.47.132
addnode=13.54.61.175
addnode=34.203.15.31
addnode=52.59.144.109
addnode=35.177.31.30
addnode=52.220.111.66
addnode=13.114.115.237
addnode=13.126.121.197
addnode=35.182.200.22
addnode=54.233.180.109
addnode=52.64.238.215




2017년 3월 20일 월요일

[CodeIgniter] URL에서 index.php 제거



1. httpd.conf

1) rewrite_module 활성화
#LoadModule rewrite_module modules/mod_rewrite.so
라인 주석 해제

2) .htaccess 사용을 위해 AllowOverride 옵션을 All로 변경
#AllowOverride None
AllowOverride All

- 수정 후 Apache 재시작


2. 루트 폴더에 .htaccess 파일 생성
<IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /
      RewriteCond $1 !^(index\.php|images|robots\.txt) # 처리를 제외할 파일이나 디렉토리를 추가
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>


3. CI config.php 수정

- index_page 수정
//$config['index_page'] = 'index.php';
$config['index_page'] = '';



2017년 2월 28일 화요일

[Tomcat] catalina.out 날짜별 생성

Tomcat catalina.out daily logrotate



1. logrotate 설정 디렉토리로 이동
$ cd /etc/logrotate.d/

2. 설정 파일 생성
$ nano tomcat
/var/local/tomcat/logs/catalina.out {
     copytruncate
     daily
     rotate 30
     missingok
     notifempty
     dateext
}

3. (선택) 현재 파일 강제 갱신
$ logrotate -f /etc/logrotate.d/tomcat



설정 파일 참고 :
http://linuxcommand.org/man_pages/logrotate8.html


2017년 2월 16일 목요일

[Spring Security] AJAX 요청시 403 Invalid CSRF Token 발생하는 경우


--------------------
메타 태그에 값 추가
--------------------
<meta name="_csrf" content="${_csrf.token}"/>
<meta name="_csrf_header" content="${_csrf.headerName}"/>



--------------------
스크립트
--------------------
var token = $("meta[name='_csrf']").attr("content");
var header = $("meta[name='_csrf_header']").attr("content");

$.ajax({
        ...
        beforeSend: function(xhr) {
            xhr.setRequestHeader(header, token);
        },
        ...




참고:
http://docs.spring.io/spring-security/site/docs/3.2.0.CI-SNAPSHOT/reference/html/csrf.html#csrf-include-csrf-token-ajax

[Mybatis] 한글 입력시 물음표(?)로 입력될 경우

Mybatis 한글깨짐


jdbc.url=jdbc:mysql://localhost:3306/디비명?useUnicode=true&characterEncoding=utf8


2017년 1월 4일 수요일

Java에서 Command Line 명령어 실행

Java에서 wkhtmltoimage를 실행시키기 위해 외부 프로그램 실행 샘플 코드를 찾았다.



해당 코드를 활용해서 명령을 실행하고 정상 실행 여부도 확인할 수 있었다.

2017년 1월 3일 화요일

[wkhtmltopdf, wkhtmltoimage] html을 pdf나 이미지로 변환

wkhtmltopdf, wkhtmltoimage, html to pdf, html to image
  • html 페이지를 이미지화 하는 모듈을 여러가지 찾던 중 css가 브라우저에 가장 가깝게 출력되는 것으로 확인되어 선택했다.

  1. 설치


  2. 활용
    • 기본 명령어는 wkhtmltopdf http://google.com google.pdf 형태로 간단하게 사용할 수 있다.
    • 추가 옵션은 wkhtmltoimage -H 명령어로 전체 옵션을 확인 할 수 있다.


    1) 실제 적용시 활용했던 주요 옵션
    • -q 기본 출력되는 진행 메시지를 출력하지 않도록 한다. 개발 완료 후 적용했다.
    • -width 이미지의 가로 너비를 설정한다.