これは、なにをしたくて書いたもの?
Infinispan Serverの設定まわりを見ていて、いくつかポイントとなるファイルを目にしていたのでメモしておこうかなと。
対象はInfinispan 14.0.3.Finalとし、GitHub上のソースコードの位置で示していきます。
起動スクリプト
起動スクリプトは、こちらにあります。
https://github.com/infinispan/infinispan/tree/14.0.3.Final/server/runtime/src/main/server/bin
Infinispan Serverのbin
ディレクトリ内に入るファイルですね。
Infninispan Serverを起動する時はserver.sh
を使いますが、
変数やオプションの内容を追う時は以下も見ることになると思います。
読んでいると、JAVA_OPTS
が使えたりするようなこともわかります。
設定ファイル
デフォルトの設定ファイルは、こちらにあります。
Infinispan Serverのserver/conf
ディレクトリにあるファイルですね。
たとえば、infinispan.xml
。
設定ファイルはこれだけではなくて、全体のデフォルト設定もあります。
このinfinispan-defaults.xml
が読み込まれた後に、
infinispan.xml
のような個別の設定が読み込まれるようになっています。
この時、いくつか以下のような${変数名}
のような記述がありますが、これはシステムプロパティで指定することができます。
<global-state> <persistent-location path="${infinispan.server.data.path}"/> <shared-persistent-location path="${infinispan.server.data.path}"/> <overlay-configuration-storage/> </global-state>
設定ファイルのパース時に解決される、という感じですね。
デフォルト値は、以下あたりを見るとだいたいわかるのですが。
infinispan.server.home.path
は、server.sh
に混じったりしています。
server.conf
は、ここで読まれています。
ちなみに、Infinispan Serverはこちらのドキュメントを見るのがまずは筋だと思うのですが
infinispan.server.data.path
やinfinispan.server.lib.path
といったシステムプロパティでの上書きなどは書かれておらず、それはこちらに
記述があったりします。
Infinispan Serverにシステムプロパティを渡す時は、環境変数JAVA_OPTS
に指定するか、server.sh
のあとにコマンドライン引数として
追加しても認識してくれます。
-D
で始まっている引数については、common.sh
がJavaVMへの引数としてハンドリングしてくれます。
Infinispan Serverのmainクラス
Infinispan Serverの起動時に指定されるmainクラスは、Bootstrap
クラスです。
Bootstrap
クラスがServer
クラスのインスタンスを生成するので、この2つを見ると設定情報の解決はだいたいわかるのではないかと思います。
デフォルト値はだいたいServer
クラスに書かれていますしね。
また、server.sh
で起動時に指定可能なオプションのうち、システムプロパティでの指定に置き換えられそうなものに読めるものは、
Bootstrap
クラス内で読み替えているようです。
caches.xml
Infinispan Serverで動的にCache
を作成するとserver/data
ディレクトリ内にcaches.xml
というファイルが作成されます。
こちらについてはInfinispan Server固有の話ではなく、infinispan-core
で決まっている挙動のようです。
設定ファイル、オプション等の列挙
最後に、デフォルトの設定ファイルの中身やinfinispan.xml
の中身、server.sh
のオプションを記載しておきましょう。
$
の記述に着目するとどのあたりがシステムプロパティで上書きできそうかわかりますし、対応するserver.sh
のオプションがないかどうかも
見ておくとよいでしょう。
<?xml version="1.0" encoding="UTF-8"?> <!-- N.B. This is *not* meant to be a usable cache configuration --> <!-- This file supplies the internal configuration defaults per cache mode --> <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:14.0 https://infinispan.org/schemas/infinispan-config-14.0.xsd" xmlns="urn:infinispan:config:14.0"> <cache-container shutdown-hook="DONT_REGISTER"> <global-state> <persistent-location path="${infinispan.server.data.path}"/> <shared-persistent-location path="${infinispan.server.data.path}"/> <overlay-configuration-storage/> </global-state> <local-cache-configuration name="org.infinispan.LOCAL" statistics="true"> <locking acquire-timeout="15000" striping="false" concurrency-level="1000"/> </local-cache-configuration> <replicated-cache-configuration name="org.infinispan.REPL_SYNC" remote-timeout="17500" configuration="org.infinispan.LOCAL"> <state-transfer timeout="60000"/> </replicated-cache-configuration> <replicated-cache-configuration name="org.infinispan.REPL_ASYNC" mode="ASYNC" configuration="org.infinispan.LOCAL"> <state-transfer timeout="60000"/> </replicated-cache-configuration> <distributed-cache-configuration name="org.infinispan.DIST_SYNC" remote-timeout="17500" configuration="org.infinispan.LOCAL"> <state-transfer timeout="60000"/> </distributed-cache-configuration> <distributed-cache-configuration name="example.PROTOBUF_DIST" remote-timeout="17500" configuration="org.infinispan.LOCAL"> <!-- Template for a queryable cache. Warning: may be removed in future versions --> <encoding media-type="application/x-protostream"/> <state-transfer timeout="60000"/> </distributed-cache-configuration> <distributed-cache-configuration name="org.infinispan.DIST_ASYNC" mode="ASYNC" configuration="org.infinispan.LOCAL"> <state-transfer timeout="60000"/> </distributed-cache-configuration> <invalidation-cache-configuration name="org.infinispan.INVALIDATION_SYNC" remote-timeout="17500" configuration="org.infinispan.LOCAL"/> <invalidation-cache-configuration name="org.infinispan.INVALIDATION_ASYNC" mode="ASYNC" configuration="org.infinispan.LOCAL"/> <scattered-cache-configuration name="org.infinispan.SCATTERED_SYNC" remote-timeout="17500" configuration="org.infinispan.LOCAL"/> </cache-container> </infinispan>
<infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:infinispan:config:14.0 https://infinispan.org/schemas/infinispan-config-14.0.xsd urn:infinispan:server:14.0 https://infinispan.org/schemas/infinispan-server-14.0.xsd" xmlns="urn:infinispan:config:14.0" xmlns:server="urn:infinispan:server:14.0"> <cache-container name="default" statistics="true"> <transport cluster="${infinispan.cluster.name:cluster}" stack="${infinispan.cluster.stack:tcp}" node-name="${infinispan.node.name:}"/> <security> <authorization/> </security> </cache-container> <server xmlns="urn:infinispan:server:14.0"> <interfaces> <interface name="public"> <inet-address value="${infinispan.bind.address:127.0.0.1}"/> </interface> </interfaces> <socket-bindings default-interface="public" port-offset="${infinispan.socket.binding.port-offset:0}"> <socket-binding name="default" port="${infinispan.bind.port:11222}"/> <socket-binding name="memcached" port="11221"/> </socket-bindings> <security> <credential-stores> <credential-store name="credentials" path="credentials.pfx"> <clear-text-credential clear-text="secret"/> </credential-store> </credential-stores> <security-realms> <security-realm name="default"> <!-- Uncomment to enable TLS on the realm --> <!-- server-identities> <ssl> <keystore path="application.keystore" password="password" alias="server" generate-self-signed-certificate-host="localhost"/> </ssl> </server-identities--> <properties-realm groups-attribute="Roles"> <user-properties path="users.properties"/> <group-properties path="groups.properties"/> </properties-realm> </security-realm> </security-realms> </security> <endpoints socket-binding="default" security-realm="default" /> </server> </infinispan>
$ bin/server.sh --help Infinispan Server 14.0.3.Final (Flying Saucer) Copyright (C) Red Hat Inc. and/or its affiliates and other contributors License Apache License, v. 2.0. http://www.apache.org/licenses/LICENSE-2.0 Usage: -b, --bind-address=<address> Binds the server endpoint to a specific address. -c, --server-config=<config> Specifies a server configuration file. Defaults to `infinispan.xml`. Can be repeated, in which case the configurations are layered. -l, --logging-config=<config> Specifies a logging configuration file. Defaults to `log4j2.xml`. -g, --cluster-name=<name> Sets the name of the cluster. Default set by configuration expression -h, --help Displays usage information and exits. -j, --cluster-stack=<name> Specifies the JGroups stack for clustering. Default set by configuration expression -k, --cluster-address=<name> Specifies the JGroups bind address for clustering. -n, --node-name=<name> Sets the name of this node. Must be unique across the cluster. -o, --port-offset=<offset> Adds a numeric offset to all ports. -p, --bind-port=<port> Binds the server to a specific port. Defaults to `11222`. -s, --server-root=<path> Specifies the root path for the server. Defaults to `server`. -v, --version Displays version information and exits. -D<name>=<value> Sets a system property to the specified value. -P, --properties=<file> Sets system properties from the specified file.