5

現在、Tika を使用して、AWS Elastic Beanstalk (Ruby 2.2 を実行する 64 ビット Amazon Linux 2016.03 v2.1.2) で実行されている Rails アプリにアップロードされたファイルからテキストを抽出しています。スキャンした画像もインデックス化したいので、Tesseract をインストールする必要があります。

このようにソースからインストールすることで動作させることができましたが、新しいインスタンスへのデプロイに 10 分かかりました。これを行うより速い方法はありますか?

.ebextensions/02-tesseract.config

packages:
  yum:
    autoconf: []
    automake: []
    libtool: []
    libpng-devel: []
    libtiff-devel: []
    zlib-devel: []

container_commands:
  01-command:
    command: mkdir -p install
    cwd: /home/ec2-user
  02-command:
    command: cp .ebextensions/scripts/install_tesseract.sh /home/ec2-user/install/
  03-command:
    command: bash install/install_tesseract.sh
    cwd: /home/ec2-user

.ebextensions/scripts/install_tesseract.sh

#!/usr/bin/env bash

cd_to_install () {
  cd /home/ec2-user/install
}

cd_to () {
  cd /home/ec2-user/install/$1
}

if ! [ -x "$(command -v tesseract)" ]; then
  # Add `usr/local/bin` to PATH
  echo 'pathmunge /usr/local/bin' > /etc/profile.d/usr_local.sh
  chmod +x /etc/profile.d/usr_local.sh

  # Install leptonica
  cd_to_install
  wget http://www.leptonica.org/source/leptonica-1.73.tar.gz
  tar -zxvf leptonica-1.73.tar.gz
  cd_to leptonica-1.73
  ./configure
  make
  make install
  rm -rf /home/ec2-user/install/leptonica-1.73.tar.gz
  rm -rf /home/ec2-user/install/leptonica-1.73

  # Install tesseract ~ the jewel of Odin's treasure room
  cd_to_install
  wget https://github.com/tesseract-ocr/tesseract/archive/3.04.01.tar.gz
  tar -zxvf 3.04.01.tar.gz
  cd_to tesseract-3.04.01
  ./autogen.sh
  ./configure
  make
  make install
  ldconfig
  rm -rf /home/ec2-user/install/3.04.01.tar.gz
  rm -rf /home/ec2-user/install/tesseract-3.04.01

  # Install tessdata
  cd_to_install
  wget https://github.com/tesseract-ocr/tessdata/archive/3.04.00.tar.gz
  tar -zxvf 3.04.00.tar.gz
  cp /home/ec2-user/install/tessdata-3.04.00/eng.* /usr/local/share/tessdata/
  rm -rf /home/ec2-user/install/3.04.00.tar.gz
  rm -rf /home/ec2-user/install/tessdata-3.04.00
fi
4

1 に答える 1

13

簡潔な答え

.ebextensions/02-tesseract.config

commands:
  01-libwebp:
    command: "yum --enablerepo=epel --disablerepo=amzn-main -y install libwebp"
  02-tesseract:
    command: "yum --enablerepo=epel -y install tesseract"

長い答え

私は Ubuntu 以外のパッケージ マネージャーや ebextensions に詳しくないので、いろいろ調べたところ、Amazon Linux の安定版EPEL リポジトリにインストールできるプリコンパイル済みバイナリがあることがわかりました。

最初の障害は、EPEL リポジトリの使用方法を理解することでした。最も簡単な方法は、コマンドでenablerepoオプションを使用することです。yum

これで次のようになります。

yum --enablerepo=epel install tesseract

次に、この依存関係エラーを解決する必要がありました。

[root@ip-10-0-1-193 ec2-user]# yum install --enablerepo=epel tesseract
Loaded plugins: priorities, update-motd, upgrade-helper
951 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package tesseract.x86_64 0:3.04.00-3.el6 will be installed
--> Processing Dependency: liblept.so.4()(64bit) for package: tesseract-3.04.00-3.el6.x86_64
--> Running transaction check
---> Package leptonica.x86_64 0:1.72-2.el6 will be installed
--> Processing Dependency: libwebp.so.5()(64bit) for package: leptonica-1.72-2.el6.x86_64
--> Finished Dependency Resolution
Error: Package: leptonica-1.72-2.el6.x86_64 (epel)
           Requires: libwebp.so.5()(64bit)
 You could try using --skip-broken to work around the problem
 You could try running: rpm -Va --nofiles --nodigest

ここで解決策を見つけました

amzn-main リポジトリのパッケージが epel リポジトリのパッケージを上書きしているように見えるため、epel リポジトリを追加するだけでは解決しません。amzn-main リポジトリの libwebp パッケージが除外されている場合、動作するはずです

Tesseract のインストールには、リポジトリにいくつかの依存関係がありamzn-mainます。libwebpこれが、最初にインストールする理由です--disablerepo=amzn-main

yum --enablerepo=epel --disablerepo=amzn-main install libwebp
yum --enablerepo=epel install tesseract

最後に、オプションを使用して Elastic Beanstalk に yum パッケージをインストールする方法を次に示します。

.ebextensions/02-tesseract.config

commands:
  01-libwebp:
    command: "yum --enablerepo=epel --disablerepo=amzn-main -y install libwebp"
  02-tesseract:
    command: "yum --enablerepo=epel -y install tesseract"

幸いなことに、これは、Elastic Beanstalk に Tesseract をインストールする最も簡単な方法でもあります!

于 2016-06-28T02:07:18.700 に答える