【Folio LSP】单服务器部署教程(核心版)
开场白
在这篇文章中,我们将介绍Folio教程中Single Server Deployment的内容。
源文链接:https://github.com/folio-org/folio-install/tree/master/runbooks/single-server#folio-deployment-single-server
关于这个教程中的Docker(https://qiita.com/ayungn/items/b15979d26e0a8e354ef2),关于这个教程中的数据库(https://qiita.com/ayungn/items/2ef718846424ca581282)。
问答
-
- 元ネタの中にmainbar/sidebarとありますが、mainbar/sidebarとは何ですか?
sidebarを実行すると「最新スナップショット」をもとにしたビルドができます。mainbarは四半期に一度のリリースをもとにビルドします。
plartform-core/platform-completeとは何ですか?
platform-coreは基本機能、platform-comleteは全機能をビルドします。バックエンドモジュールの数でいうとplatform-coreは25、platform-completeは55です。この記事では、platform-coreのビルドについて説明します。
关键文件
-
- PstgreSQL 10
- RAM 12GB以上(バックエンドモジュールごとに、平均160MBのDocker Imageを使います。DB I/Oがある場合もあります。環境構築時にもっとメモリが必要になる場合もあります。)
准备之前
请确保先安装 git。
请确保先安装 VirtualBox。
请确保先安装 Vagrant。
在Linux主机上进行构建
在适当的目录下,克隆包含用于此教程的脚本等的代码库。
git clone https://github.com/folio-org/folio-install
cd folio-install
git checkout q2-2020
cd runbooks/single-server
在cd runbooks/single-server中,正在切换到含有Vagrantfile的目录。

这个Vagrantfile将创建一个以下配置的VirtualBox虚拟机。
– Ubuntu Xenial操作系统(12GB RAM,2个CPU)
– 端口转发:将客户端端口9130转发到主机端口9130,并将客户端端口80转发到主机端口3000
– 从这里开始,如果看到/vagrant,则认为是指这个路径(folio-install/runbooks/single-server)。
使用Vagrant启动虚拟机并登录到虚拟机上。
vagrant box update
vagrant up
vagrant ssh
※vagrant的初始密码是vagrant
执行到这一步就会是这种感觉


安装并配置所需的软件包
运行环境要求:Java 8、nginx(引擎X)、PostgreSQL 10、Docker。
①更新apt cache
sudo apt-get update
安装Java 8和nginx,并将Java 8设置为系统默认选项。
sudo apt-get -y install openjdk-8-jdk nginx
sudo update-java-alternatives --jre-headless --jre --set java-1.8.0-openjdk-amd64
导入PostgreSQL的密钥,添加PostgreSQL apt仓库,并安装PostgreSQL。
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo add-apt-repository "deb http://apt.postgresql.org/pub/repos/apt/ xenial-pgdg main"
sudo apt-get update
sudo apt-get -y install postgresql-10 postgresql-client-10 postgresql-contrib-10 libpq-dev
④配置 PostgreSQL 以便可以从 Docker 进行连接。
-
- /etc/postgresql/10/main/postgresql.confの「Connection Settings」にlisten_addresses = ‘*’を追記
-
- /etc/postgresql/10/main/pg_hba.confにhost all all 0.0.0.0/0 md5を追記
- PostgreSQLをsudo systemctl restart postgresqlでリスタート
sudo vim /etc/postgresql/10/main/postgresql.conf
sudo vim /etc/postgresql/10/main/pg_hba.conf
sudo systemctl restart postgresql
⑤导入Docker的密钥,添加Docker的apot仓库,并安装Docker引擎。
sudo apt-get -y install apt-transport-https ca-certificates gnupg-agent software-properties-common
wget --quiet -O - https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository "deb https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get -y install docker-ce docker-ce-cli containerd.io
Docker引擎的配置
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo cp /vagrant/scripts/docker-opts.conf /etc/systemd/system/docker.service.d
sudo systemctl daemon-reload
sudo systemctl restart docker
⑦安装Docker Compose
sudo curl -L \
"https://github.com/docker/compose/releases/download/1.26.2/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
git(版本控制工具)、curl(命令行工具用于发送网络请求的库)、NodeJS(JavaScript运行环境)、npm(NodeJS包管理器)、Yarn(新一代JavaScript依赖管理工具)、libjson-perl(Perl语言的JSON解析库)、libwww-perl(Perl语言的网络请求库)、libuuid-tiny-perl(Perl语言的UUID生成库)。
从Ubuntu的APT软件仓库安装
sudo apt-get -y install git curl nodejs npm libjson-perl libwww-perl libuuid-tiny-perl
从npm上安装n。
请注意,n是一个用于管理node的命令。
sudo npm install n -g
导入Yarn的密钥,添加Yarn apt仓库,并安装Yarn。
wget --quiet -O - https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
sudo add-apt-repository "deb https://dl.yarnpkg.com/debian/ stable main"
sudo apt-get update
sudo apt-get -y install yarn
安装Apache Kafka和Apache ZooKeeper
※上述内容需要在mod-subpub中进行处理。
sudo mkdir /opt/kafka-zk
sudo cp /vagrant/scripts/docker-compose-kafka-zk.yml /opt/kafka-zk/docker-compose.yml
cd /opt/kafka-zk
sudo docker-compose up -d
cd -
创建数据库和角色
以超级用户身份登录到PostgreSQL
$ sudo su -c psql postgres postgres
创建Okapi、租户的DB和角色。
CREATE ROLE okapi WITH PASSWORD 'okapi25' LOGIN CREATEDB;
CREATE DATABASE okapi WITH OWNER okapi;
CREATE ROLE folio WITH PASSWORD 'folio123' LOGIN SUPERUSER;
CREATE DATABASE folio WITH OWNER folio;
退出psql。
Okapi的安装和配置
wget --quiet -O - https://repository.folio.org/packages/debian/folio-apt-archive-key.asc | sudo apt-key add -
sudo add-apt-repository "deb https://repository.folio.org/packages/ubuntu xenial/"
sudo apt-get update
sudo apt-get -y install okapi=3.1.2-1
sudo apt-mark hold okapi
编辑 /etc/folio/okapi/okapi.conf 文件下述内容
-
- role=”dev”
-
- port_end=”9230″
-
- host=”10.0.2.15″
-
- storage=”postgres”
- okapiurl=”http://10.0.2.15:9130″
修正后的okapi.conf将如下所示。
#
# FOLIO Okapi configuration
#
# Okapi requires exactly one command to be given depending on how
# it is utilized.
#
# 'cluster' - for running in clustered mode/production
# 'dev' - for running in development, single-node mode
# 'deployment' - for okapi deployment only. Clustered mode
# 'proxy' - for proxy + discovery. Clustered mode
#
#
role="dev"
# 'cluster' config options
#
# -hazelcast-config-cp file -- Read config from class path
# -hazelcast-config-file file -- Read config from local file
# -hazelcast-config-url url -- Read config from URL
#
#cluster_config="-hazelcast-config-file /etc/folio/okapi/hazelcast.xml"
# Specify the network interface Vertx cluster should bind to.
# By default, it will bind to all network interfaces. This may have
# unintended consequences.
#cluster_interface="eth0"
# Specify which port the cluster should bind to for cluster
# communication. (Note: This different from '5701' which is used for
# cluster discovery). If not set, a random port will be used.
#cluster_port="9001"
# Enable the sending of various metrics to a Carbon back end.
# Boolean '0' or '1'. Set to '1' to enable and set Carbon/Graphite
# host and port.
enable_metrics=0
carbon_host="localhost"
carbon_port="2003"
# Default okapi port
port="9130"
# Define port range for modules. Default range: 9131-9141.
port_start="9131"
port_end="9230"
# Hostname to be used in the URLs returned by the deployment service.
# Defaults to 'localhost'
host="10.0.2.15"
# Set '-Dnodename'. Required for deployment persistence when
# running Okapi in cluster mode. Defaults to `/bin/hostname`
#nodename=
# Define the storage back end - 'postgres' or 'inmemory'
# ('postgres' only valid when 'role' is set to 'cluster' or 'dev')
# (valid only when 'role' is set to 'dev' or 'cluster')
# If set to 'postgres', make sure the okapi database has been
# created and okapi user has been configured in the postgres
# instance and then run:
# /usr/share/folio/okapi/bin/okapi.sh --initdb
# to initialize the okapi database for restarting okapi.
storage="postgres"
# Set Postgres parameters. Ignored unless 'storage="postgres"'
postgres_host="localhost" # default 'localhost'
postgres_port="5432" # default postgres port
postgres_username="okapi" # default
postgres_password="okapi25" # default
postgres_database="okapi" # default
# Define Docker URL if we are deploying modules via Docker.
dockerurl="http://localhost:4243"
# Tell Okapi its own official URL. This gets passed to the
# modules as X-Okapi-Url header, and the modules can use this
# to make further requests to Okapi. Defaults to 'http://localhost:9130'
# or whatever port specified. There should be no trailing slash, but if
# there happens to be one, Okapi will remove it.
okapiurl="http://10.0.2.15:9130"
# Okapi Logging options
#
# Define logging level. Defaults to 'INFO'; other valid values are 'DEBUG',
# 'TRACE', 'WARN', and 'ERROR'
loglevel="INFO"
# Specify external log4j2 configuration file. Otherwise logging defaults
# to STDOUT. If defined, 'loglevel' is ignored.
log4j_config="/etc/folio/okapi/log4j2.properties"
Okapi的重新启动
sudo systemctl daemon-reload
sudo systemctl restart okapi
从中央注册表中提取模块描述符
curl -w '\n' -D - -X POST -H "Content-type: application/json" \
-d @/vagrant/scripts/okapi-pull.json \
http://localhost:9130/_/proxy/pull/modules
以上所述的与以下具有相同的意思。
curl -w '\n' -D - -X POST -H "Content-type: application/json" -d '{"urls":["http://folio-registry.aws.indexdata.com"]}' http://localhost:9130/_/proxy/pull/modules
创建 Folio 租户
将租户初始化信息发布到Okapi上
curl -w '\n' -D - -X POST -H "Content-type: application/json" \
-d @/vagrant/scripts/tenant.json \
http://localhost:9130/_/proxy/tenants
这句话的意思与以下相同。
curl -w '\n' -D - -X POST -H "Content-type: application/json" -d '{"id" : "diku","name" : "Datalogisk Institut","description" : "Danish Library Technology Institute"}' http://localhost:9130/_/proxy/tenants
激活Okapi内部模块以供租户使用。
curl -w '\n' -D - -X POST -H "Content-type: application/json" -d '{"id":"okapi"}' http://localhost:9130/_/proxy/tenants/diku/modules
构建FolioStropes平台的最新版本
在指定的节点版本 n 中,可以进行更新。
我们将更新到 lts 版本。
sudo n lts
git clone https://github.com/folio-org/platform-core
cd platform-core
git checkout q2-2020
yarn install
NODE_ENV=production yarn build output
cd ..
配置网络服务器并提供 Stripes webpack 服务。
配置Nginx服务器。
sudo cp folio-install/runbooks/single-server/scripts/nginx-stripes.conf /etc/nginx/sites-available/stripes
sudo ln -s /etc/nginx/sites-available/stripes /etc/nginx/sites-enabled/stripes
sudo rm /etc/nginx/sites-enabled/default
sudo systemctl restart nginx
部署相关的Folio后端部署并激活给租户
将部署的模块所使用的数据源信息发布到Okapi上。
curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"DB_HOST\",\"value\":\"10.0.2.15\"}" http://localhost:9130/_/env
curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"DB_PORT\",\"value\":\"5432\"}" http://localhost:9130/_/env
curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"DB_DATABASE\",\"value\":\"folio\"}" http://localhost:9130/_/env
curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"DB_USERNAME\",\"value\":\"folio\"}" http://localhost:9130/_/env
curl -w '\n' -D - -X POST -H "Content-Type: application/json" -d "{\"name\":\"DB_PASSWORD\",\"value\":\"folio123\"}" http://localhost:9130/_/env
提交后端模块列表以进行启用。设置租户参数,加载示例数据和参考数据。
curl -w '\n' -D - -X POST -H "Content-type: application/json" \
-d @platform-core/okapi-install.json \
http://localhost:9130/_/proxy/tenants/diku/install?deploy=true\&preRelease=false\&tenantParameters=loadSample%3Dtrue%2CloadReference%3Dtrue
请注意,由于需要从Docker Hub获取Docker image,因此这将需要一些时间。
查看进度→在/var/log/folio/okapi/okapi.log查看Okapi日志 或者 使用sudo docker ps | grep -v “^CONTAINER” | wc -l命令。
发布并启用 Stripes 模块列表
curl -w '\n' -D - -X POST -H "Content-type: application/json" \
-d @platform-core/stripes-install.json \
http://localhost:9130/_/proxy/tenants/diku/install?preRelease=false
创建Folio的超级用户,并加载权限。
perl folio-install/runbooks/single-server/scripts/bootstrap-superuser.pl --tenant diku --user diku_admin --password admin --okapi http://localhost:9130
若顯示為「完成!」則表示OK。
加载样本数据
加载MODS记录
curl -w '\n' -D - -X POST -H "Content-type: application/json" -H "Accept: application/json" -H "X-Okapi-Tenant: diku" -d '{"username":"diku_admin","password":"admin"}' http://localhost:9130/authn/login

将返还的 token 值放入下述的 中。
for i in /vagrant/sample-data/mod-inventory/*.xml; do curl -w '\n' -D - -X POST -H "Content-type: multipart/form-data" -H "X-Okapi-Tenant: diku" -H "X-Okapi-Token: <okapi token>" -F upload=@${i} http://localhost:9130/inventory/ingest/mods; done

使用diku_admin/admin进行登录
