spring boot에 레디스 클러스트와 연동하는 코드를 작성했는데, 


http://docs.spring.io/spring-data/redis/docs/current/reference/html/#cluster 예제를 사용하면 잘 동작한다.



build.gradle 추가

compile("org.springframework.data:spring-data-redis:1.7.2.RELEASE")
compile("redis.clients:jedis:2.8.1")



applicationproperties

spring.redis.cluster.nodes=...
spring.redis.cluster.timeout=5
spring.redis.cluster.max-redirects=3



코드


import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
@ConfigurationProperties(prefix = "spring.redis.cluster")
public class ClusterConfigurationProperties {

List<String> nodes;

public List<String> getNodes() {
return nodes;
}

public void setNodes(List<String> nodes) {
this.nodes = nodes;
}
}




import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

@Service
public class RedisClusterService {

@Autowired
private RedisTemplate<String, String> redisTemplate;

@Resource(name="redisTemplate")
private ListOperations<String, String> listOps;

public void addKeyValue(String key, String value) {
listOps.leftPush(key, value);
}

public String getKey(String key) {
return listOps.rightPop(key);
} }


set, zset, list,  일반 key-value에 대한 command는 아래 커맨드를 사용하여 의미있는 커맨드를 카테고리 별로 확인/실행할 수 있다. 

redisTemplate.opsForSet() redisTemplate.opsForZSet() redisTemplate.opsForValue() redisTemplate.opsForList()
...




Posted by '김용환'
,



proxy 서버(redirection)를 쉽게 구축할 수 있다.


$ sudo yum install redir



현 서버에서 10000포트로 접근하면 8.8.8.8의 22 번 포트로 TCP 연결을 redirection해준다.


$ redir --lport=10000 --caddr=8.8.8.8 --cport=22



현 서버의  ip가 10.10.10.10인 네트워크 이더넷에서 9001 포트로 접근하면 80포트로 TCP 연결을 redirection해준다.


$ redir –laddr=10.10.10.10 –lport=9001 –caddr=10.10.10.10 –cport=80

'unix and linux' 카테고리의 다른 글

linux에서 빠른 디렉토리 copy 툴  (0) 2016.06.28
FQDN-도메인  (0) 2016.06.25
ipcalc - ip 계산기  (0) 2016.06.14
sudo echo > 에러 대신 tee 커맨드  (0) 2016.06.07
[pv] rpm으로 파이프 뷰 프로그램 설치 및 실행  (0) 2016.05.27
Posted by '김용환'
,

[nginx] http2 적용하기

nginx 2016. 6. 18. 13:16



많은 사람들이 구글이 만든 http2를 점차 적용하고 있다.


https://w3techs.com/technologies/details/ce-http2/all/all





nginx는 1.9.5부터 http2를 사용할 수 있다.

https://www.nginx.com/blog/nginx-1-9-5/



구글 크롬을 지원하려면 특정 open ssl 버전이 필요하다.

https://www.nginx.com/blog/supporting-http2-google-chrome-users/



Operating SystemOpenSSL Version
CentOS/Oracle Linux/RHEL 6.5+, 7.0+1.0.1e


센트OS 에서 1.0.1e 이상의 open ssl 버전을 사용하려면, open ssl을 1.0.1e 이상을 설치하고, nginx에서 버전을 확인하고 사용한다.

아래 예시에서는 1.0.2h을 사용했다. (필요하다면 nginx 모듈을 추가할 수 있다)


--prefix=/usr/local/nginx --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_secure_link_module --with-openssl=/usr/local/src/openssl-1.0.2h 




nginx 설정에는 아주 간단하게 listen 지시자 옆에 http2를 추가한다.


    listen               443 http2 default_server;



nginx 서버에 openssl가 제대로 적용되었는지, 확인한다.



$ ./nginx/sbin/nginx -V

nginx version: nginx/1.10.1

built by gcc 4.4.7 20120313 (Red Hat 4.4.7-17) (GCC)

built with OpenSSL 1.0.2h  3 May 2016

TLS SNI support enabled




클라이언트에서도 http2를 확인할 수 있다.(크롬 브라우져에서 http2가 지원되는지 확인할 수 있다.)


크롬 확장 프로그램 HTTP/2 and SPDY indicator 을 설치한다.


http2를 적용한 페이지를 열고, 크롬 브라우져의 플러그인에서 파란 번개 마크 확인할 수 있다. 

파란 번개 마크를 클릭하면, "HTTP/2 Enabled: true"가 화면에 출력되는지 확인할 수 있다.







Posted by '김용환'
,


2004년 궁궐디지털사진콘테스트에서 특선작을 받음.

(이제 슬슬 카메라를 들고 다니기 시작..)


http://www.palaceguide.or.kr/gb4/bbs/board.php?bo_table=gnu_notice&wr_id=44



Posted by '김용환'
,


ip 계산기라는 ipcalc 툴이 있다. 

$ sudo yum install ipcalc


mac에서도 설치 가능하다.

$ brew install ipcalc



ipcalc 확인

Usage: ipcalc [OPTION...]

  -c, --check         Validate IP address for specified address family

  -4, --ipv4          IPv4 address family (default)

  -6, --ipv6          IPv6 address family

  -b, --broadcast     Display calculated broadcast address

  -h, --hostname      Show hostname determined via DNS

  -m, --netmask       Display default netmask for IP (class A, B, or C)

  -n, --network       Display network address

  -p, --prefix        Display network prefix

  -s, --silent        Don't ever display error messages




브로드캐스트 주소 계산기

$  ipcalc -b 192.168.0.88/24

BROADCAST=192.168.0.255

$  ipcalc -b 192.168.0.88/25

BROADCAST=192.168.0.127



ip 확인하기

$ ipcalc -c 192.168.1.99

$ ipcalc -c 192.168.1.9999999999

ipcalc: bad IPv4 address: 192.168.1.9999999999


넷마스크 얻기

$ ipcalc -m 192.168.1.99

NETMASK=255.255.255.0



IP 네트워크 주소 확인하기

$ ipcalc -n 192.168.1.99/24

NETWORK=192.168.1.0

$ ipcalc -n 192.168.1.99/25

NETWORK=192.168.1.0

$ ipcalc -n 192.168.1.99/1

NETWORK=128.0.0.0





Posted by '김용환'
,


play1 framework 유틸리티는 문서로 잘 설명되어 있지 않다.

이럴 때를 위해 play help 명령어를 실행한다.


$ play help

~        _            _

~  _ __ | | __ _ _  _| |

~ | '_ \| |/ _' | || |_|

~ |  __/|_|\____|\__ (_)

~ |_|            |__/

~

~ play! 1.4.2, https://www.playframework.com

~

~ For all commands, if the application is not specified, the current directory is used

~ Use 'play help cmd' to get more help on a specific command

~

~ Core commands:

~ ~~~~~~~~~~~~~~

~ antify          Create a build.xml file for this project

~ autotest        Automatically run all application tests

~ build-module    Build and package a module

~ check           Check for a release newer than the current one

~ classpath       Display the computed classpath

~ clean           Delete temporary files (including the bytecode cache)

~ dependencies    Resolve and retrieve project dependencies

~ eclipsify       Create all Eclipse configuration files

~ evolutions      Run the evolution check

~ evolutions:applyAutomatically apply pending evolutions

~ evolutions:markAppliedMark pending evolutions as manually applied

~ evolutions:resolveResolve partially applied evolution

~ help            Display help on a specific command

~ id              Define the framework ID

~ idealize        Create all IntelliJ Idea configuration files

~ install         Install a module

~ javadoc         Generate your application Javadoc

~ list-modules    List modules available from the central modules repository

~ modules         Display the computed modules list

~ netbeansify     Create all NetBeans configuration files

~ new             Create a new application

~ new-module      Create a module

~ out             Follow logs/system.out file

~ pid             Show the PID of the running application

~ precompile      Precompile all Java sources and templates to speed up application start-up

~ restart         Restart the running application

~ run             Run the application in the current shell

~ secret          Generate a new secret key

~ start           Start the application in the background

~ status          Display the running application's status

~ stop            Stop the running application

~ test            Run the application in test mode in the current shell

~ version         Print the framework version

~ war             Export the application as a standalone WAR archive

~

~ Also refer to documentation at https://www.playframework.com/documentation



status가 궁금하다면, 다음 명령어를 사용한다.


$ play help status

~        _            _

~  _ __ | | __ _ _  _| |

~ | '_ \| |/ _' | || |_|

~ |  __/|_|\____|\__ (_)

~ |_|            |__/

~

~ play! 1.4.2, https://www.playframework.com

~

~ Name:

~ ~~~~~

~ status -- Display the running application's status

~

~ Alias:

~ ~~~~~

~ st

~

~ Synopsis:

~ ~~~~~~~~~

~ play status [app_path] [--url=http://...] [--secret=...]

~

~ Description:

~ ~~~~~~~~~~~~

~ This script tries to connect to the running application's /@status URL to request the application status.

~ The application status contains useful informations about the running application.

~

~ The status command is aimed at monitoring applications running on production servers.

~

~ Options:

~ ~~~~~~~~

~ --url:

~ The script try to connect to the application at the localhost domain. If you want to monitor an application running on

~ a remote server, specify the application URL using this option (eg. play status --url=http://myapp.com)

~

~ --secret:

~ The script uses the secret key to generate an authorization token. It assumes that the secret key available from the

~ app_path/conf/application.conf is valid. If not you can provide your own secret key using this option

~ (eg. play status --secret=bghjT7ZG7ZGCO8)

~

~ If you provide both options, you can run this command without a local application directory (app_path is not required).

~


프로젝트 디렉토리에서 다음 커맨드를 실행한다.


$ play status --url=http://127.0.0.1:9000

~        _            _

~  _ __ | | __ _ _  _| |

~ | '_ \| |/ _' | || |_|

~ |  __/|_|\____|\__ (_)

~ |_|            |__/

~

~ play! 1.4.2, https://www.playframework.com

~

~ Status from http://127.0.0.1:19000/@status,

~

Java:

~~~~~

Version: 1.8.0_40

Home: /usr/java/jdk1.8.0_40/jre

Max memory: 438304768

Free memory: 36274240

Total memory: 233832448

Available processors: 2

Play framework:

~~~~~~~~~~~~~~~

Version: 1.4.2

Path: /usr/local/play-1.4.2

ID: beta

Mode: PROD

Tmp dir: xxxxxxx


Application:

~~~~~~~~~~~~

Path: xxxxx

Name: play-server

Started at: 06/13/2016 22:23


Loaded modules:

~~~~~~~~~~~~~~

spring at xxxxx


Loaded plugins:

~~~~~~~~~~~~~~

0:play.CorePlugin [enabled]

1:play.ConfigurationChangeWatcherPlugin [disabled]

10:play.modules.router.ext.YetAnotherRouterAnnotationsPlugin [enabled]

100:play.data.parsing.TempFilePlugin [enabled]

200:play.data.validation.ValidationPlugin [enabled]

300:play.db.DBPlugin [enabled]

400:play.db.jpa.JPAPlugin [enabled]

450:play.db.Evolutions [enabled]

500:play.i18n.MessagesPlugin [enabled]

600:play.libs.WS [enabled]

700:play.jobs.JobsPlugin [enabled]

1000:play.modules.spring.SpringPlugin [enabled]

100000:play.plugins.ConfigurablePluginDisablingPlugin [enabled]

Threads:
~~~~~~~~
Thread[Reference Handler,10,system] WAITING
Thread[Finalizer,8,system] WAITING
Thread[Signal Dispatcher,9,system] RUNNABLE
Thread[RMI TCP Accept-0,5,system] RUNNABLE
Thread[RMI TCP Accept-19100,5,system] RUNNABLE
Thread[RMI TCP Accept-0,5,system] RUNNABLE
......
Thread[nifty-client-worker-2,5,main] RUNNABLE
Thread[nifty-client-worker-3,5,main] RUNNABLE

Requests execution pool:
~~~~~~~~~~~~~~~~~~~~~~~~
Pool size: 256
Active count: 0
Scheduled task count: 1936
Queue size: 0

Monitors:

~~~~~~~~

AController.list()                             ->      121 hits;    226.6 avg;    116.0 min;    707.0 max;

........


Jobs execution pool:

~~~~~~~~~~~~~~~~~~~

Pool size: 0

Active count: 0

Scheduled task count: 0

Queue size: 0




만약 play 커맨드를 알고 싶다면, 다음 소스를 살펴본다.


https://github.com/playframework/play1/tree/master/framework/pym/play/commands


만약 status에 대해서 깊이 알고 싶다면,

CorePlugin.java와  https://github.com/playframework/play1/blob/master/framework/pym/play/commands/status.py를 살펴본다.

실제 url이  url = 'http://localhost:%s/@status' % http_port 인 것을 볼 수 있다.



Posted by '김용환'
,



ivy 기반 빌드 프로젝트는 ~/.ivy 디렉토리를 사용한다. 

예를 들어, play1 framework는 ~/.ivy/cache 디렉토리에 저장된 의존 lib가 저장된다. 


예를 들어, org.apache.httpcomponents.httpcore는 아래와 같이 저장된다.

~/.ivy2/cache/org.apache.httpcomponents/httpcore


$ ls

ivy-4.2.4.xml            ivy-4.3.3.xml.original   ivy-4.4.4.xml            ivydata-4.3.3.properties jars

ivy-4.2.4.xml.original   ivy-4.4.1.xml            ivy-4.4.4.xml.original   ivydata-4.4.1.properties sources

ivy-4.3.3.xml            ivy-4.4.1.xml.original   ivydata-4.2.4.properties ivydata-4.4.4.properties



디렉토리에는 버전 별 xml 파일, xml.original 파일, jars, sources가 있다.


xml.original 파일은 pom 다음과 같다. 


$ cat ivy-4.4.4.xml.original


<?xml version="1.0" encoding="UTF-8"?>

<!--

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

   Licensed to the Apache Software Foundation (ASF) under one

   or more contributor license agreements.  See the NOTICE file

   distributed with this work for additional information

   regarding copyright ownership.  The ASF licenses this file

   to you under the Apache License, Version 2.0 (the

   "License"); you may not use this file except in compliance

   with the License.  You may obtain a copy of the License at


     http://www.apache.org/licenses/LICENSE-2.0


   Unless required by applicable law or agreed to in writing,

   software distributed under the License is distributed on an

   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

   KIND, either express or implied.  See the License for the

   specific language governing permissions and limitations

   under the License.

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


   This software consists of voluntary contributions made by many

   individuals on behalf of the Apache Software Foundation.  For more

   information on the Apache Software Foundation, please see

   <http://www.apache.org />.

 --><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <parent>

    <groupId>org.apache.httpcomponents</groupId>

    <artifactId>httpcomponents-core</artifactId>

    <version>4.4.4</version>

  </parent>

  <artifactId>httpcore</artifactId>

  <name>Apache HttpCore</name>

  <inceptionYear>2005</inceptionYear>

  <description>

   Apache HttpComponents Core (blocking I/O)

  </description>

  <url>http://hc.apache.org/httpcomponents-core-ga</url>

  <packaging>jar</packaging>

...




ivy는 ivy 기반의 xml로 변경한다.


$ cat ivy-4.4.4.xml

<?xml version="1.0" encoding="UTF-8"?>

<ivy-module version="2.0" xmlns:m="http://ant.apache.org/ivy/maven">

<info organisation="org.apache.httpcomponents"

module="httpcore"

revision="4.4.4"

status="release"

publication="20151027021814"

>

<description homepage="http://hc.apache.org/httpcomponents-core-ga">

Apache HttpComponents Core (blocking I/O)

</description>

<m:properties__api.comparison.version>4.4</m:properties__a

...


메타정보는 properties에 정의된다.


$ cat ivydata-4.4.4.properties

#ivy cached data file for org.apache.httpcomponents#httpcore;4.4.4

#Mon Jun 13 22:10:57 KST 2016

artifact\:httpcore\#pom.original\#pom\#-401045955.exists=true

artifact\:httpcore\#jar\#jar\#-2053608617.original=artifact\:httpcore\#jar\#jar\#-2053608617

artifact\:httpcore\#pom.original\#pom\#-401045955.original=artifact\:httpcore\#pom.original\#pom\#-401045955

artifact\:ivy\#ivy\#xml\#-726796163.location=https\://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.4.4/httpcore-4.4.4.pom

artifact\:httpcore\#pom.original\#pom\#-401045955.is-local=false

resolver=mavenCentral

artifact\:ivy\#ivy\#xml\#-726796163.exists=true

artifact\:httpcore\#pom.original\#pom\#-401045955.location=https\://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.4.4/httpcore-4.4.4.pom

artifact\:httpcore\#jar\#jar\#-2053608617.location=https\://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.4.4/httpcore-4.4.4.jar

artifact\:ivy\#ivy\#xml\#-726796163.is-local=false

artifact\:httpcore\#source\#jar\#-410049307.original=artifact\:httpcore\#source\#jar\#-410049307

artifact\:httpcore\#jar\#jar\#-2053608617.exists=true

artifact\:httpcore\#jar\#jar\#-2053608617.is-local=false

artifact\:ivy\#ivy\#xml\#-726796163.original=artifact\:httpcore\#pom.original\#pom\#-401045955

artifact\:httpcore\#source\#jar\#-410049307.exists=true

artifact\:httpcore\#source\#jar\#-410049307.is-local=false

artifact.resolver=mavenCentral

artifact\:httpcore\#source\#jar\#-410049307.location=https\://repo1.maven.org/maven2/org/apache/httpcomponents/httpcore/4.4.4/httpcore-4.4.4-sources.ja



만약 ivy 컴파일일 실패하면, jars에 jar가 있는지. properties,xml, xml.original 파일이 존재하는지 확인해본다.


참고

ivy 파일 이슈를 해결해도

컴파일 안되면, maven repository 이슈이다.



참고

https://theholyjava.wordpress.com/2011/01/26/using-ivy-with-pom-xml/

Posted by '김용환'
,

[nginx] 499 에러

nginx 2016. 6. 10. 20:07



nginx에서 499 에러가 발생했다. nginx를 연결하는 클라이언트에서 exception이 발생했을 것이다.

499는 nginx에서만 사용하는 cient closed request 상태 값이다. 

https://httpstatuses.com/499



문제를 해결하기 위해 nginx와 통신하는 클라이언트에서 http client timeout을 좀 길게 준다. (1초였다면 3초로)

Posted by '김용환'
,


gradle 빌드 성능을 높일 수 있다.


org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.workers.max=3
org.gradle.configureondemand=true
org.gradle.jvmargs=-Xms128m -Xmx248m


* org.gradle.daemon : 빌드 데몬 떠있도록 설정

* org.gradle.parllel : 병렬 쓰레드 동작

* org.gradle.workers.max : 병렬 쓰레드 개수 제한

* org.gradle.configureondemand : 멀티 프로젝트 모드에서 필요한 부분(on demand)만 컴파일

* org.gradle.jvmargs : 컴파일시 jvm 매개변수 전달 (메모리..)





제일 중요한 것은 gradle 버전업만 해도 성능이 좋아진다. 최근에 출시된 2.13 버전부터 많이 좋아졌다.




참고

https://docs.gradle.org/current/userguide/build_environment.html


http://gradle.org/blog/performance-is-a-feature/


Posted by '김용환'
,



어떤 이가 내게 Python의 외래어 표기법이 

파이썬이 아니라 파이선이라고 해서 대충 검색해봤다.

국립국어원의 외래어 사전에는 파이선, 파이썬이 없다.


활용 측면에서 보면..


내가 자주 구글 검색에서는 파이선 대신 파이썬을 추천한다.

그리고, 국립국어원에 파이썬이라는 단어를 사용했다.

http://www.korean.go.kr/nkview/nklife/2006_4/2006_0404.pdf

http://www.korean.go.kr/nkview/nklife/2006_4/16_4.html


네이버 국어 사전에는 파이썬이라 검색해야 python이 나온다. 

http://dic.naver.com/search.nhn?dicQuery=%ED%8C%8C%EC%9D%B4%EC%8D%AC&x=0&y=0&query=%ED%8C%8C%EC%9D%B4%EC%8D%AC&target=dic&ie=utf8&query_utf=&isOnlyViewEE=


위키피디아도 파이썬으로 표현했다.

https://ko.wikipedia.org/wiki/%ED%8C%8C%EC%9D%B4%EC%8D%AC



여기에 좀 설명이 되어 있는데.. 출처는 명확하지는 않지만, 전체적인 문맥 상 파이썬이 맞음.. 

 외래어 표기법에 따르면 Python은 영어를 기준으로 할 때 한글로 '파이선'으로 적어야 하나, 정식으로 채택된 한글 표기는 파이썬이다.[출처 필요]






Posted by '김용환'
,