AWS Elastic Beanstalk中安装tesseract5.3.4版本
问题
需要在eb(Elastic Beanstalk)的amazon linux 2023中安装tesseract软件。但是,因为amazon linux 2023官方软件库里面没有包含tesseract软件,需要通过开源的Fedora软件源来解决这个问题。
思路
配置Fedora 40软件源(amazon linux 2023的官方文档是说最高兼容Fedora 36,但是这次2025年11月,测试一下Fedora 40软件源中的tesseract5.3.4版本也可以用),然后,使用dnf安装tesseract和中文,英文语言包。
.ebextensions目录结构
├── .ebextensions
│ ├── 01launch-template.config
│ ├── 02tesseract.config
│ ├── 03timezone.config
│ └── 04environment-variables.config
01launch-template.config
设置应用程序的环境变量。
option_settings:aws:elasticbeanstalk:application:environment:TESSDATA_PREFIX: /usr/share/tesseract/tessdataaws:autoscaling:launchconfiguration:DisableIMDSv1: trueLaunchTemplateTagPropagationEnabled: true
02tesseract.config
这是安装tesseract库。
files:"/etc/yum.repos.d/fedora.repo":mode: "000644"owner: rootgroup: rootcontent: |[fedora]name=Fedora 40 - $basearch#baseurl=http://download.example/pub/fedora/linux/releases/40/Everything/$basearch/os/metalink=https://mirrors.fedoraproject.org/metalink?repo=fedora-40&arch=$basearchenabled=1metadata_expire=7drepo_gpgcheck=0type=rpmgpgcheck=1gpgkey=https://src.fedoraproject.org/rpms/fedora-repos/raw/f40/f/RPM-GPG-KEY-fedora-40-primaryskip_if_unavailable=Falsecontainer_commands:install_tesseract:command: |sudo dnf install tesseract -ysudo dnf install tesseract-langpack-eng -ysudo dnf install tesseract-langpack-chi_sim -ysudo dnf install tesseract-langpack-chi_sim_vert -yignoreErrors: true
03timezone.config
这是设置时区。
commands:set_timezone:command: |sudo timedatectl set-timezone Asia/ShanghaiignoreErrors: true
04environment-variables.config
设置环境变量
files:"/etc/profile.d/environment_variables.sh":mode: "000755"owner: rootgroup: rootcontent: |#!/bin/bashexport TZ="Asia/Shanghai"export TESSDATA_PREFIX="/usr/share/tesseract/tessdata"container_commands:environment_variables:command: |source /etc/profileignoreErrors: true
总结
这就是eb安装tesseract库和设置时区的过程。执行是按照文件名执行顺序。如果在java中使用Tess4J库通过jni方式调用tesseract,需要注意Tess4J库版本号与tesseract库版本号对应。
参考
- 在 Elastic Beanstalk 环境的实例上配置 IMDS
- 在 Amazon Linux 2 及更高版本上运行的 ECS 的实例部署工作流
- Fedora Public Active Mirrors
- Tess4J
- tess4j
- tesseract fedoraproject
- Fedora Linux
- Tess4J API Documentation
- Tesseract wiki
- 环境变量和其他软件设置
