manywaypark's Blog
개발, 검색, 함수

'jetty'에 해당되는 글 1건

  1. 2008.06.27 [TIP] jetty 설정 (for multiple war(solr) instance on jetty)
jetty에 동일한 war를 context path를 달리해서 여러 instance를 띄우는 방법에 관해 간략히 설명한다.
비교적 복잡한 solr를 예로 들겠다.

jetty 설치
jetty는 debian package를 다운로드 받아서 깔면 별 문제없이 잘 실행된다.
(ftp://ftp.mortbay.org/pub/)
현재 안정 버전중 최신인 jetty-6.1.11를 받았다.

동일 war 여러 instance 설정
동일한 war를 다른 context path 및 설정으로 실행시키고 싶었다.
solr로 예를 들자면, 몇개의 설정이 다른 solr가 떠서 url에 따라 다른 분야의 검색에 관한 서비스(인덱싱, 검색 질의 등)를 제공하는 것이다.
solr wiki에 관련 설명이 나오는데 좀 모호한 부분이 있어서 한번 정리해 보았다.
  1. 중복 deploy 방지 (disable WebAppDeployer): /etc/jetty6/contexts 쪽의 설정만 사용하게 하기위해서 /etc/jetty6/jetty.xml에서 다음 부분을 삭제하거나, 주석처리한다.
        <Call name="addLifeCycle">
          <Arg>
            <New class="org.mortbay.jetty.deployer.WebAppDeployer">
              <Set name="contexts"><Ref id="Contexts"/></Set>
              <Set name="webAppDir"><SystemProperty name="jetty.home" default="."/>/webapps</Set>
          <Set name="parentLoaderPriority">false</Set>
          <Set name="extract">true</Set>
          <Set name="allowDuplicates">false</Set>
              <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
            </New>
          </Arg>
        </Call>
    jetty.home/webapps에 있는 war를 자동으로 deploy하게 하는 부분인데, contexts에 있는 설정에서 webapps를 참조하게 할 것이므로 비활성화 시키는 것이다 (다른 디렉토리를 사용하면 이 과정이 아마 필요없을듯하다).

  2. 설정 파일 생성 (동일한 war를 사용하는 다른 instance도 contextPath를 달리해서 생성가능하다.)
    /etc/jetty6/contexts/people.xml :
    <?xml version="1.0"  encoding="ISO-8859-1"?>
    <!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd">
    <Configure class="org.mortbay.jetty.webapp.WebAppContext">
      <!-- Required -->
      <Set name="contextPath">/people</Set>
      <Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/apache-solr-1.3-dev.war</Set>

      <Set name="defaultsDescriptor"><SystemProperty name="jetty.home" default="."/>/etc/webdefault.xml</Set>
      <Set name="overrideDescriptor"><SystemProperty name="jetty.home" default="."/>/contexts/override.d/override-people.xml</Set>

      <!-- Active JNDI so we can specify "solr/home" -->
      <Array id="plusConfig" type="java.lang.String">
          <Item>org.mortbay.jetty.webapp.WebInfConfiguration</Item>
          <Item>org.mortbay.jetty.plus.webapp.EnvConfiguration</Item>
          <Item>org.mortbay.jetty.plus.webapp.Configuration</Item>
          <Item>org.mortbay.jetty.webapp.JettyWebXmlConfiguration</Item>
          <!-- <Item>org.mortbay.jetty.webapp.TagLibConfiguration</Item> -->
      </Array>
      <Set name="ConfigurationClasses"><Ref id="plusConfig"/></Set>

      <!-- Adding <New class="org.mortbay.jetty.plus.naming.EnvEntry"> -->
      <!-- here sets a GLOBAL jndi value. Arg!                         -->
      <!-- So we specify "solr/home" in the overrideDescriptor instead -->
    </Configure>

    /etc/jetty6/contexts/override.d/override-people.xml :
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app
       xmlns="http://java.sun.com/xml/ns/javaee"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
       version="2.5">

    <!-- This web.xml format file is applied to the people webapp
         AFTER it has been configured by the default descriptor
         and the WEB-INF/web.xml descriptor -->

      <env-entry>
        <env-entry-name>solr/home</env-entry-name>
        <env-entry-value>./people</env-entry-value>
        <env-entry-type>java.lang.String</env-entry-type>
      </env-entry>

      <!-- NOTE: If Solr looked at something like this:                -->
      <!-- NOTE:   getServletContext().getInitParameter("solr.home");  -->
      <!-- NOTE: we could do the following w/o mucking with JNDI       -->
      <!--
      <context-param>
        <param-name>solr.home</param-name>
        <param-value>fixme-some-path</param-value>
      </context-param>
      -->
     
    </web-app>

  3. 위의 두 파일은 인물 검색용 이라고 가정하자. 위의 파일에서 파일명과 파일 내용에 나오는 people을 book으로 바꾸어서 저장하면, 이제 http://localhost:8080/pepple/admin, http://localhost:8080/book/admin 두개의 독립된 solr를 하나의 servlet engine - jetty -에서 실행시키고 있는 것이다.

  4. 두 context path에서 실행은 되는데 아마도 에러가 날것이다.
    solr 관련 설정이 없어서 인데, "solr/home"으로 지정한 디렉토리에, solr의 example에 있는 solr 디렉토리 내의 파일들을 다 복사해주면 된다.
    즉 위의 설명대로 파일 및 디렉토리를 구성했다면,
    # JETTY_HOME은 보통 /usr/share/jetty6 이다.
    $ cp -R /path/to/solr/example/solr/* $JETTY_HOME/people/
    $ cp -R /path/to/solr/example/solr/* $JETTY_HOME/book/

  5. 그래도 에러날 것이다.
    이제 정말 마지막 설정하나,
    $JETTY_HOME/(people|book)/conf/solrconfig.xml 에서
    <dataDir>${solr.data.dir:./solr/data}</dataDir>로 되어 있는 부분을
    <dataDir>${solr.data.dir:./people/data}</dataDir>
    <dataDir>${solr.data.dir:./book/data}</dataDir>
    으로 각각 고친다.

  6. 이젠 에러 안날 것이다.
happy hackin'

ps. 요즘 들어 jetty를 많이 사용한다. 가볍고 편리하다. 특히나 jetty-maven-plugin은 말 그대로 zero-configuration!!
1 
분류 전체보기 (306)
잡담 (20)
함수형 언어 (65)
emacs (16)
java (18)
tips & tricks (154)
사랑 (1)
가사 (0)
독서 (4)
mobile (6)
비함수형 언어 (2)

공지사항

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

04-20 15:07