wiki:epics/Archiver Appliance インストールメモ

Version 1 (modified by shuei, 6 years ago) (diff)

--

はじめに

このドキュメントはJ-PARC加速器向けにArchiver Appliance (AA)をインストールして立ち上げた際の作業メモなので、適宜読み替えて頂きたい。

  • AAのインストールガイドを良く読んでおくこと。
    • Quickstartの方法では、AAを停止するとどのPVをアーカイブしていたのという設定情報が失われてしまう。
  • AAのインストールガイドを良く読んでおくこと。
    • Quickstartの方法では、AAを停止するとどのPVをアーカイブしていたのという設定情報が失われてしまう。
  • jkjarchiver-ap.mr.jkcontにインストールする
    • OS : SL 6.8 / x86_64
    • epicsアカウントで作業する
    • 作業ディレクトリ: /home/epics/archappl
    • AAのインストール先: /opt/archappl
    • AAのデータ保存先: /localdata/archappl
    • 各種設定ファイル・起動スクリプトは(できるだけ)mercurialでバージョン管理している
  • インストールの際に、X Window System上での作業が必要
  • AAインストール後の運用についてはArchiver Appliance 運用メモを参照のこと

ダウンロード

AAに必要なソフトウェアをあらかじめダウンロードしておく。ここでは/home/epics/archappl/downloadにダウンロードする。

Archiver Appliance

インストールするのはバイナリの配布物だが、ソースコードに管理用のスクリプトの例が含まれているので一緒にダウンロードしておく。

  • バイナリ
    % wget https://github.com/slacmshankar/epicsarchiverap/releases/download/v0.0.1_SNAPSHOT_20-Sept-2016/archappl_v0.0.1_SNAPSHOT_20-September-2016T13-50-17.tar.gz
    
  • ソースコード
    % git clone https://github.com/slacmshankar/epicsarchiverap epicsarchiverap.git
    

Apache Tomcat

AAを走らせるにはApache Tomcat 7.0.61以降が必要。Apache Tomcat配布元から8.5.16をダウンロードした。

MySQL

AAがアーカイブするレコードの情報を記録するのに、MySQL 5.1以降が必要。 SL6の配布物からMySQL 5.1.73をrpmでインストールした。

# yum install mysql mysql-server mysql-devel
  • 今回はAAを実行するマシンでMySQLサーバも走らせる
  • MySQLのテーブルはNFSサーバ上に置く
  • MySQLサーバはAAとは独立したマシンにした方がよかったかもしれない

MySQL クライアント jar

mysql-connector-javaをMySQL本家からダウンロードする。 SL6標準のrpmパッケージは依存するライブラリを多数インストールするのでやめておく。

JDK 1.8

制御計算機にはすでにインストールしてあるので省略。

zenity

制御計算機にはSL標準のrpmパッケージがインストールしてあるので省略。

tar ballの展開

% mkdir -p ~/archappl/workspace
% cd ~/archappl/workspace
% tar xf ../download/archappl_v0.0.1_SNAPSHOT_20-September-2016T13-50-17.tar.gz
% tar xf ../download/mysql-connector-java-5.1.40.tar.gz

MySQLのセットアップ

uid, gid

mysql:mysqlが27:27になっている(mysqlをインストールする際に作られる?)のを、既存のマシンにあわせて38099:38099にする。 mysqlが使うディレクトリのownerも変えておく:

# chown 38099:38099 /var/lib/mysql
# chown 38099:38099 /var/run/mysql

dbを置くディレクトリ

dbは/svrdbに置く。NFSサーバがexportしているディレクトリを/svrdbにマウントする。

jkjds01.ccr.jkcont:/svrdb    /svrdb    nfs  bg,intr,soft,timeo=10,retrans=15,nfsvers=3 0 0

/svrdbを掘ってマウントし、パーミッションを設定する。mysqlの起動スクリプトがroot権限でこのディレクトリに書き込もうとするので、NFSサーバも設定しておく。

# mkdir /svrdb
# mount /svrdb
# mkdir /svrdb/mysql5.1/jkjarchiver-ap
# chown 38099:38099 /svrdb/mysql5.1/jkjarchiver-ap

/etc/my.cnf

MySQLの設定ファイルをリポジトリからコピーして使う。

[mysqld]
#datadir=/var/lib/mysql
#socket=/var/lib/mysql/mysql.sock
#user=mysql
# Disabling symbolic-links is recommended to prevent assorted security risks
#symbolic-links=0

#datadir=/localdata/mysql
#socket=/localdata/mysql/mysql.sock
datadir=/svrdb/mysql5.1/jkjarchiver-ap/
socket=/var/lib/mysql/mysql.sock
user=mysql
symbolic-links=0
character-set-server = utf8
innodb_flush_log_at_trx_commit = 1

[mysqld_safe]
log-error=/var/log/mysqld.log
pid-file=/var/run/mysqld/mysqld.pid

logrotate

/etc/logrotate.d/mysqld に手順が書いてある。後回し。

mysqlサーバ自動起動の設定

# cd /etc/rd.c/ini.d
# /sbin/chkconfig  --level 3 mysqld on
# /sbin/chkconfig  --level 4 mysqld on
# /sbin/chkconfig  --level 5 mysqld on

MySQLサーバの起動

dbが存在しない場合は、MySQLサーバの初回起動時に、スクリプトがdbを作ってくれる。

# /etc/rc.d/init.d/mysqld start
MySQL データベースを初期化中:  Installing MySQL system tables...

Filling help tables...
OK

To start mysqld at boot time you have to copy
support-files/mysql.server to the right place for your system

PLEASE REMEMBER TO SET A PASSWORD FOR THE MySQL root USER !
To do so, start the server, then issue the following commands:

/usr/bin/mysqladmin -u root password 'new-password'
/usr/bin/mysqladmin -u root -h jkjarchiver-ap.mr.jkcont password 'new-password'

Alternatively you can run:
/usr/bin/mysql_secure_installation

which will also give you the option of removing the test
databases and anonymous user created by default.  This is
strongly recommended for production servers.

See the manual for more instructions.

You can start the MySQL daemon with:
cd /usr ; /usr/bin/mysqld_safe &

You can test the MySQL daemon with mysql-test-run.pl
cd /usr/mysql-test ; perl mysql-test-run.pl

Please report any problems with the /usr/bin/mysqlbug script!

                                                           [  OK  ]
mysqld を起動中:                                           [  OK  ]

/usr/bin/mysql_secure_installation

MySQLの初期設定を行う。質問をよく読む。Yes/Noの質問には全てYで答える。

# /usr/bin/mysql_secure_installation




NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
 ... Success!

Cleaning up...



All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

schemaの作成

DB(archappl), ユーザー(archappl)とパスワード(archappl)を作る。

% mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 14
Server version: 5.1.73 Source distribution

Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE DATABASE IF NOT EXISTS archappl;
Query OK, 1 row affected (0.00 sec)

mysql> GRANT ALL PRIVILEGES ON archappl.* TO 'archappl'@'localhost' IDENTIFIED BY 'archappl';
Query OK, 0 rows affected (0.00 sec)

テーブルの作成

AA用のテーブルはAAのインストールスクリプト(後述)が作ってくれる。

Archiver Applianceのインストール

インストールスクリプトを走せると、

  1. MySQLのテーブル
  2. Tomcatのデプロイ
  3. アプライアンスの設定ファイルの作成
  4. 起動スクリプトの作成

をやってくれる

インストール先のディレクトリ

AAをインストールするディレクトリ(/opt/archappl)をあらかじめ掘っておく

# mkdir -p /opt/archappl

ポリシーファイル

ポリシーファイルは AAにレコードを登録する際に用いられるファイルで、

  • LTS/MTS/STSの設定
  • レコードをサンプルする方法(monitor/scan)とサンプリング時間
  • 値と一緒に保存するHIGH/HIGH/LOW/LOLO等のフィールド

等をPythonのdictionaryとして記述する。

インストールスクリプトを走らせる前に、ポリシーファイルを用意しておく。雛形が

epicsarchiverap.git/src/sitespecific/tests/classpathfiles/policies.py

に用意されている。

  • インストールスクリプトがポリシーファイルの所在を尋ねてくる。存在しないファイルを指定すると、スクリプトの実行に失敗する
  • 中身は後で書き換えるので、ここでは気にしない
  • AAのクラスタを組む場合は、各ノードに同じファイルのコピーを置くか、共有ディレクトリに置いておく

制御計算機用のポリシーファイルは

/jk/dev/operation_app/jkControl/ArchiverAppliance/deploy/policies.py

に置いてある

LTS/MTS/STS

  • STS ... PARTITION_HOUR
  • MTS ... PARTITION_DAY&hold=5&gather=1
  • LTS ... PARTITION_MONTH

sampling method/sampling period

  • 基本的にはMONITORにする
  • 25Hzで更新されるLIのPVはSCAN 1.0secにする

metaFields

HIHI等のメタフィールドは保存しない。pvPolicyDict\["archiveFields"\]は空のarrayにしておく。

インストールスクリプト

予めインストール先のディレクトリを作っておく。epicsアカウントで書き込めるようにownerを変更しておく:

# mkdir -p /opt/archappl
# chown epics.epics /opt/archappl

AAを展開したディレクトリにあるインストールスクリプトをepicsアカウントで走らせる。 スクリプトを走らせると、ダイアログが開いて

  • DEPLOY_DIR (tomcatを展開するディレクトリ) → /opt/archappl
  • apache-tomcat-x.y.z.tar.gz の所在
  • mysql-connector-java-x.y.z-bin.jar の所在
  • mysqlサーバに接続するためのmysqlコマンドに渡す引き数 → ここでは--user=archappl --password=archappl --database=archappl
  • ポリシーファイル(policies.py)の所在

を尋ねてくる。

% cd ~archappl/workspace
% install_scripts/single_machine_install.sh
This script runs thru a typical install scenario for a single machine
You can use this to create a standard multi-instance (one Tomcat for ear WAR) tomcat deployment in a multi machine cluster by setting the ARCHAPPL_APPLIANCES and the ARCHAPPL_MYIDENTITY
For installations in a cluster, please do create a valid appliances.xml and export ARCHAPPL_APPLIANCES and ARCHAPPL_MYIDENTITY
...
...
Setting TOMCAT_HOME to the mgmt webapp in /opt/archappl/mgmt
Setting TOMCAT_HOME to /opt/archappl/apache-tomcat-8.5.16
Calling deploy release with /opt/archappl/deployRelease.sh /home/epics/archappl/workspace
Deploying a new release from /home/epics/archappl/workspace onto /opt/archappl
/opt/archappl/mgmt/webapps ~/archappl/workspace
~/archappl/workspace
/opt/archappl/engine/webapps ~/archappl/workspace
~/archappl/workspace
/opt/archappl/etl/webapps ~/archappl/workspace
~/archappl/workspace
/opt/archappl/retrieval/webapps ~/archappl/workspace
~/archappl/workspace
Done deploying a new release from /home/epics/archappl/workspace onto /opt/archappl
Do you have a site specific policies.py file?
Where's your site specific policies.py file?
Setting ARCHAPPL_POLICIES to /home/epics/archappl/policies.py
Done with the installation. Please use /opt/archappl/sampleStartup.sh to start and stop the appliance and /opt/archappl/deployRelease.sh to deploy a new release.

アプライアンスの設定

appliances.xmlでノードのidentityと各webappが使うURLを設定する

  • デフォルトでは/opt/archappl/appliances.xmlが使われる
    • 起動スクリプトの環境変数でファイル名を指定する
  • AAのクラスタを組む場合は、各ノードに同じファイルのコピーを置くか、共有ディレクトリに置いておく
<appliances>
   <appliance>
     <identity>appliance0</identity>
     <cluster_inetport>jkjarchiver-ap.mr.jkcont:16670</cluster_inetport>
     <mgmt_url>http://jkjarchiver-ap.mr.jkcont:17665/mgmt/bpl</mgmt_url>
     <engine_url>http://jkjarchiver-ap.mr.jkcont:17666/engine/bpl</engine_url>
     <etl_url>http://jkjarchiver-ap.mr.jkcont:17667/etl/bpl</etl_url>
     <retrieval_url>http://localhost:17668/retrieval/bpl</retrieval_url>
     <data_retrieval_url>http://jkjarchiver-ap.mr.jkcont:17668/retrieval</data_retrieval_url>
   </appliance>
 </appliances>

プロパティファイル

archappl.propertiesでAAの動作を設定する。

  • デフォルトでは各web appのWEB-INF/classes/archappl.propertiesが使われる
    • 例えば: /opt/archappl/engine/webapps/engine/WEB-INF/classes/archappl.properties
    • 起動スクリプトの環境変数でファイル名を指定する

アーカイブエンジンのバッファがあふれるので、プロパティファイルでマージンを大きめにとることにする:

...
# Increase buffer capacity adjustment in order to avoid buffer overflow in J-PARC MR.
org.epics.archiverappliance.config.PVTypeInfo.sampleBufferCapacityAdjustment = 5.0
...

サンプリング間隔の補正は無効にしておく:

...
# J-PARC MR
org.epics.archiverappliance.engine.epics.scanJitterFactor=1.00
...

pbファイルのディレクトリの区切りに使う文字を指定する。とりあえずデフォルトのままにしたが、アンダースコア("_")も含めておいた方がよかったかもしれない。

org.epics.archiverappliance.config.ConvertPVNameToKey.siteNameSpaceSeparators = [\\:\\-]

TOMCATの設定

${TOMCAT_HOME}/conf/server.xml

  • mgmt webappが使うポートを、8080(tomcatのデフォルト)からappliances.xmlで指定したポート番号に合わせて17665にする。
    ...
        <!-- A "Connector" represents an endpoint by which requests are received
             and responses are returned. Documentation at :
             Java HTTP Connector: /docs/config/http.html (blocking & non-blocking)
             Java AJP  Connector: /docs/config/ajp.html
             APR (HTTP/AJP) Connector: /docs/apr.html
             Define a non-SSL HTTP/1.1 Connector on port 8080
        -->
        <Connector port="17665" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" />
    
    ...
    
  • apache httpdとAJPを使った連携をしない場合は、AJP Connectorの設定をコメントアウトしておく:
    ...
        <!--<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />-->
    ...
    
  • SHUTDOWNコマンドの使うポートは8005のままにしておく。

${TOMCAT_HOME}/lib/log4j.properties

# Set root logger level and its only appender to A1.
log4j.rootLogger=ERROR, A1
log4j.logger.config.org.epics.archiverappliance=INFO
log4j.logger.org.apache.http=ERROR


# A1 is set to be a DailyRollingFileAppender
log4j.appender.A1=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A1.File=arch.log
log4j.appender.A1.DatePattern='.'yyyy-MM-dd


# A1 uses PatternLayout.
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n

${TOMCAT_HOME}/conf/context.xml にMySQLの設定を追加する

  • 'jdbc/archappl'の設定を追加する:
    ...
    <Context>
    
        <!-- Default set of monitored resources -->
        <WatchedResource>WEB-INF/web.xml</WatchedResource>
    
        <!-- Uncomment this to disable session persistence across Tomcat restarts -->
        <!--
        <Manager pathname="" />
        -->
    
        <!-- Uncomment this to enable Comet connection tacking (provides events
             on session expiration as well as webapp lifecycle) -->
        <!--
        <Valve className="org.apache.catalina.valves.CometConnectionManagerValve" />
        -->
    
        <Resource   name="jdbc/archappl"
                    auth="Container"
                    type="javax.sql.DataSource"
                    factory="org.apache.tomcat.jdbc.pool.DataSourceFactory"
                    username="archappl"
                    password="archappl"
                    testWhileIdle="true"
                    testOnBorrow="true"
                    testOnReturn="false"
                    validationQuery="SELECT 1"
                    validationInterval="30000"
                    timeBetweenEvictionRunsMillis="30000"
                    maxActive="10"
                    minIdle="2"
                    maxWait="10000"
                    initialSize="2"
                    removeAbandonedTimeout="60"
                    removeAbandoned="true"
                    logAbandoned="true"
                    minEvictableIdleTimeMillis="30000"
                    jmxEnabled="true"
                    driverClassName="com.mysql.jdbc.Driver"
                    url="jdbc:mysql://localhost:3306/archappl"
                    />
    </Context>
    

起動スクリプトの修正

インストールスクリプトがAAの起動スクリプトsampleStartup.shを生成するので、環境に合わせて書き換える。

アプライアンスの設定

export ARCHAPPL_APPLIANCES=/jk/dev/operation_app/jkControl/ArchiverAppliance/deploy/appliances.xml
export ARCHAPPL_MYIDENTITY="appliance0"

EPICSの設定

EPICS用の環境変数を設定するshスクリプトをsourceする:

source /jk/dev/operation_app/jkControl/ArchiverAppliance/deploy/setEPICSEnv.sh
export EPICS_CA_ADDR_LIST=...
#export EPICS_CA_AUTO_ADDR_LIST=false
#export EPICS_CA_SERVER_PORT=5064
#export EPICS_CA_REPEATER_PORT=5065

export EPICS_TS_MIN_WEST=-540
#export EPICS_CA_MAX_ARRAY_BYTES=6000000
export EPICS_CA_MAX_ARRAY_BYTES=65536

ポリシーファイル

ポリシーファイルは環境変数で指定する。インストールスクリプトを実行した際に指定したファイルを指しているので、運転用のポリシーファイルを指すように書き換える:

export ARCHAPPL_POLICIES=/jk/dev/operation_app/jkControl/ArchiverAppliance/deploy/policies.py

プロパティファイル

インストールスクリプトが作るAAの起動スクリプトには何も書かれていないが、プロパティファイルも起動スクリプトから環境変数で指定する:

export ARCHAPPL_PROPERTIES_FILENAME=/jk/dev/operation_app/jkControl/ArchiverAppliance/deploy/archappl.properties

ストレージの設定

export ARCHAPPL_SHORT_TERM_FOLDER=/localdata/archappl/sts/ArchiverStore
export ARCHAPPL_MEDIUM_TERM_FOLDER=/localdata/archappl/mts/ArchiverStore
export ARCHAPPL_LONG_TERM_FOLDER=/localdata/archappl/lts/ArchiverStore

データ保存先の作成

起動スクリプトでの設定に合うように、データを保存するディレクトリを作る。epicsアカウントで書き込めるようにownerを変更しておく:

# mkdir -p /localdata/archappl/lts
# mkdir -p /localdata/archappl/mts
# mkdir -p /localdata/archappl/sts
# chown epics.epics /localdata/archappl
# chown epics.epics /localdata/archappl/lts
# chown epics.epics /localdata/archappl/mts
# chown epics.epics /localdata/archappl/sts

Apache httpdとの連携

AAの各web appにポート80番でアクセスできるようにするため、jkjarchiver-apにリバースプロキシを立ち上げる。ここではAJPを使わずに、naiiveなhttpプロキシにする:

# yum install httpd24-httpd-tools httpd24-httpd
  • /opt/rh/httpd24/root/etc/httpd/conf/httpd.confには触らないようにする
  • ドキュメントのディレクトリにあるファイルをconf.dにコピーして適宜書き換える
    # cd /opt/rh/httpd24/root/etc/httpd/conf.d
    # cp /opt/rh/httpd24/root/usr/share/doc/httpd24-httpd-2.4.18/httpd-default.conf 00-default.conf
    # cp /opt/rh/httpd24/root/usr/share/doc/httpd24-httpd-2.4.18/httpd-mpm.conf 00-mpm.conf
    

基本的な設定

  • conf.d/00-default.cont
    Timeout 600
    
  • conf.d/00-mpm.conf
    <IfModule mpm_prefork_module>
    ...
       MaxConnecitonPerChild 2000
    </ifModule>
    

リバースプロキシの設定

  • conf.d/proxy.conf
    ProxyRequests Off
    
    ProxyPass        /mgmt http://localhost:17665/mgmt
    ProxyPassReverse /mgmt http://localhost:17665/mgmt
    
    ProxyPass        /retrieval http://localhost:17668/retrieval
    ProxyPassReverse /retrieval http://localhost:17668/retrieval
    
    <Proxy *>
       Order deny,allow
       Allow from all
    </Proxy>
    

httpd24の自動起動の設定

chkconfig --add httpd24-httpd
chkconfig --level 3 httpd24-httpd on
chkconfig --level 4 httpd24-httpd on
chkconfig --level 5 httpd24-httpd on

AAの起動と確認

  • 自動起動/自動停止させる

/etc/rc.d/init.dに起動スクリプトを用意し、マシンの起動時/停止時にepicsアカウントでAAが自動的に起動/停止するようにする。

インストールスクリプトが作った起動スクリプトをrcスクリプトに書き換えたものが

/jk/dev/operation_app/jkControl/ArchiverAppliance/deploy/sampleStartup.sh

に置いてある。/etc/rc.d/init.dにコピーし、chkconfigを使って適切にsymlinkを張る:

cp /jk/dev/operation_app/jkControl/ArchiverAppliance/deploy/sampleStartup.sh /etc/rc.d/init.d/archappl
/sbin/chkconfig --add archappl
chkconfig --level 3 archappl on
chkconfig --level 4 archappl on
chkconfig --level 5 archappl on
  • 手動で起動する
    # /etc/rc.d/init.d/archappl start
    
  • webブラウザで管理用web appにアクセスする
    http://jkjarchiver-ap.mr.jkcont:17665/mgmt
    
  • http://jkjarchiver-ap.mr.jkcont:17665/mgmt/ui/index.html にforwardされる
  • 各web appが起動する前にアクセスすると503が返ってきて"数分待て"と表示されるが、数分では起動しない。気長に待て
  • 各web appが起動する前にアクセスすると503が返ってきて"数分待て"と表示されるが、数分では起動しない。気長に待て
  • Archiver Appliance 運用メモに続く

参考