OpenSearch1.2.4 のインストールとセットアップ
このドキュメントでは、Bitbucket で クラスターモードで運用する際に利用できる、OpenSearch のインストール方法について記載します。OpenSearch は もっと新しいバージョンも出ていますが、Bitbucket 7.21 がサポートしているのは、OpenSearch 1.2 です。
目次
1.OpenSearch のインストール
記のページから OpenSearch の Linux - x64 - tar.gz をダウンロードします。
下記のドキュメントにインストール手順がありますが、Tar版の場合は基本的には解凍するだけです。
/opt ディレクトリに回答する場合は下記のコマンドを実行します。下記は、opensearch の tar ファイルが /root に有る場合です。
# cd /opt
# tar -zxf /root/opensearch-1.2.4-linux-arm64.tar.gz
Install and configure a remote OpenSearch server の Step.2 に有る通りファイルを修正します。
# vi /opt/opensearch-1.2.4/config/opensearch.yml
以下の3行を追加します。最後の1行は、Atlassian のドキュメントには有りませんが、シングルノードで稼働させる場合は必要です。
/opt/opensearch-1.2.4/config/opensearch.yml に追加 |
---|
action.auto_create_index: ".watches,.triggered_watches,.watcher-history-*"
network.host: 0.0.0.0
discovery.type: single-node |
オープン可能なファイル数が CentOS のデフォルトでは足りないので、OS の設定ファイルのを修正します。
vi /etc/sysctl.conf
ファイルの最後に以下を追加します。
/etc/sysctl.conf に追加 |
---|
opensearch soft nofile 65535
opensearch hard nofile 65535
opensearch soft nproc 65535
opensearch hard nproc 65535 |
プロセスが使用可能なメモリマップ領域の最大数が、CentOS のデフォルトでは不足しているので、OS の設定ファイルを修正します。
# vi /etc/sysctl.conf
ファイルの最後に以下を追加します。
/etc/sysctl.conf に追加 |
---|
vm.max_map_count = 262144 |
修正後はコマンドを実行して設定を反映します。
# sysctl -p
vm.max_map_count = 262144
外部から、OpenSearh を利用するために、以下のコマンドでポートを開放します。
# firewall-cmd --permanent --zone=public --add-port=9200/tcp
# firewall-cmd --reload
OpenSearch は root ユーザーでは実行できないので、実行ユーザーとして opensearch を作成して実行します。動作確認のために、以下のコマンドで起動します。
# adduser opensearch
# su - opensearch
$ /opt/opensearch-1.2.4/opensearch-tar-install.sh
OpenSearch Security Demo Installer
** Warning: Do not use on production or public reachable systems **
Basedir: /opt/opensearch-1.2.4
OpenSearch install type: .tar.gz on CentOS Linux release 7.9.2009 (Core)
OpenSearch config dir: /opt/opensearch-1.2.4/config
OpenSearch config file: /opt/opensearch-1.2.4/config/opensearch.yml
OpenSearch bin dir: /opt/opensearch-1.2.4/bin
OpenSearch plugins dir: /opt/opensearch-1.2.4/plugins
OpenSearch lib dir: /opt/opensearch-1.2.4/lib
Detected OpenSearch Version: x-content-1.2.4
Detected OpenSearch Security Version: 1.2.4.0
---- 中略 ------
[2022-06-21T15:13:45,574][INFO ][o.o.s.c.ConfigurationRepository] [opensearch] Node 'opensearch' initialized
最後の initialized が表示されれば、起動は成功です。動作確認のために、curl コマンドで Bitbucket サーバーから確認します。下記の様に表示されれば、インストールは成功です。
# curl -XGET https://192.168.56.126:9200 -u 'admin:admin' --insecure
{
"name" : "opensearch",
"cluster_name" : "opensearch",
"cluster_uuid" : "yrv7TC63QUeRmE_bVZuuIQ",
"version" : {
"distribution" : "opensearch",
"number" : "1.2.4",
"build_type" : "tar",
"build_hash" : "e505b10357c03ae8d26d675172402f2f2144ef0f",
"build_date" : "2022-01-14T03:38:06.881862Z",
"build_snapshot" : false,
"lucene_version" : "8.10.1",
"minimum_wire_compatibility_version" : "6.8.0",
"minimum_index_compatibility_version" : "6.0.0-beta1"
},
"tagline" : "The OpenSearch Project: https://opensearch.org/"
# curl -XGET https://192.168.56.126:9200/_cat/plugins?v -u 'admin:admin' --insecure
name component version
opensearch opensearch-alerting 1.2.4.0
opensearch opensearch-anomaly-detection 1.2.4.0
opensearch opensearch-asynchronous-search 1.2.4.0
opensearch opensearch-cross-cluster-replication 1.2.4.0
opensearch opensearch-index-management 1.2.4.0
opensearch opensearch-job-scheduler 1.2.4.0
opensearch opensearch-knn 1.2.4.0
opensearch opensearch-observability 1.2.4.0
opensearch opensearch-performance-analyzer 1.2.4.0
opensearch opensearch-reports-scheduler 1.2.4.0
opensearch opensearch-security 1.2.4.0
opensearch opensearch-sql
2.TLS の設定
https を実現するためのTLSの設定をします。以下のコマンドで OpenSSL がインストールされている事を確認します。
$ openssl version
OpenSSL 1.0.2k-fips 26 Jan 2017
インストールされていない場合は、# yum install openssl でインストールできます。
サーバーの秘密鍵を作成します。PKCS#8形式である必要が有ります。
# openssl genpkey -out server.key -algorithm RSA -pkeyopt rsa_keygen_bits:2048
TLS サーバ証明書発行要求書作成ファイルを作成します。対話形式となっていますので、質問に回答して下さい。
# openssl req -new -key server.key -out server.csr
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) [XX]:JP
State or Province Name (full name) []:Tokyo
Locality Name (eg, city) [Default City]:Chiyoda-ku
Organization Name (eg, company) [Default Company Ltd]:Ricksoft Co., Ltd
Organizational Unit Name (eg, section) []:
Common Name (eg, your name or your server's hostname) []:opensearch.ricksoft.local
Email Address []:xxxxxx.@ricksoft.jp
Please enter the following 'extra' attributes
to be sent with your certificate request
A challenge password []:
An optional company name []:
上記で作成した、server.csr を公的証明機関に依頼して証明書を発行して貰うか、自前の CA を作成して 証明書を作成します。
2.1. 自己証明書の場合
openssl のインストールされたサーバーで実施します。以下のコマンドで、認証局を作成します。
# cd /etc/pki/tls/misc/
# ./CA -newca
対話形式となりますので、質問に答えて下さい。PEM pass phrase は重要ですので記録しておいて下さい。上記で作成した、server.csr をカレント・ディレクトリに置いて、以下のコマンドを実行します。パスワードを聞かれますので、認証局を作成した時の PEM pass phrase を入力して下さい。server.crt がサーバー証明書となります。
# openssl ca -out server.crt -infiles server.csr
Using configuration from /etc/pki/tls/openssl.cnf
Enter pass phrase for /etc/pki/CA/private/cakey.pem:
Check that the request matches the signature
Signature ok
Certificate Details:
Serial Number:
85:f4:c7:03:f9:e3:e6:7b
Validity
Not Before: Jul 24 12:09:05 2022 GMT
Not After : Jul 24 12:09:05 2023 GMT
Subject:
countryName = JP
stateOrProvinceName = Tokyo
organizationName = Ricksoft Co., Ltd.
commonName = opensearch.ricksoft.local
emailAddress = higuchi.akira@ricksoft.jp
X509v3 extensions:
X509v3 Basic Constraints:
CA:FALSE
Netscape Comment:
OpenSSL Generated Certificate
X509v3 Subject Key Identifier:
AF:A3:CF:CA:53:C1:5D:65:70:AF:E9:83:77:10:7F:90:CD:0B:3B:DB
X509v3 Authority Key Identifier:
keyid:57:6E:C3:42:23:7E:DC:BC:A1:1E:0E:14:80:43:03:60:FC:6D:81:FD
Certificate is to be certified until Jul 24 12:09:05 2023 GMT (365 days)
Sign the certificate? [y/n]:y
1 out of 1 certificate requests certified, commit? [y/n]y
Write out database with 1 new entries
Data Base Updated
2.2. 証明書の配置
以下のファイルを、/opt/opensearch-1.2.4/config に保管します。ファイル名は下記と違っていても問題ありません。
ファイル | 備考 | 当ドキュメントのファイル名 |
---|---|---|
サーバー証明書 | 自己の認証局で署名したものか、公的機関により認証を受けたもの。 | server.crt |
サーバー秘密鍵 | 作成した PKCS#8形式の秘密鍵 | server.key |
CA証明書/中間証明書 | 自己の認証局で署名した場合は署名したサーバーの /etc/pki/CA/cacert.pem。公的機関により認証を受けた場合は、提供される証明書。 | cacert.pem |
上記のファイルを定義ファイルに記載します。
# vim /opt/opensearch-1.2.4/config/opensearch.yml
上表のファイル名を下記の通り記載します。
opensearch.yml を編集 |
---|
plugins.security.ssl.transport.pemcert_filepath: server.crt
plugins.security.ssl.transport.pemkey_filepath: server.key
plugins.security.ssl.transport.pemtrustedcas_filepath: cacert.pem
plugins.security.ssl.transport.enforce_hostname_verification: false
plugins.security.ssl.http.enabled: true
plugins.security.ssl.http.pemcert_filepath: server.crt
plugins.security.ssl.http.pemkey_filepath: server.key
plugins.security.ssl.http.pemtrustedcas_filepath: cacert.pem |
3.セキュリティ設定
OpenSearch にはセキュリティ機能を提供する Security Plugin が最初から導入されています。下記のドキュメントの Step3 の内容で /opt/opensearch-1.2.4/plugins/opensearch-security/securityconfig の各ファイルを修正して下さい。
セキュリティ設定はファイルを更新して OpenSearch を再起動しても反映されません。 Java のプログラムを実行する必要が有ります。Java が利用できるように環境変数を設定します。
# export JAVA_HOME=/opt/opensearch-1.2.4/jdk
# export PATH=$JAVA_HOME/bin:$PATH
bitbucket ユーザーとadmin のユーザーのパスワード は下記の手順で生成します。admin ユーザーのパスワードは変更しないと、admin OpenSearch を利用できてしまうので再作成して設定する事をお薦めします。
# cd /opt/opensearch-1.2.4/plugins/opensearch-security/tools
# chmod u+x hash.sh
./hash.sh -p <任意のパスワード>
$2y$12$5RzuN2i/UsvXbPaVEs.qt.P3g3ZjMvLyCb8FpO2DOegHVkpGteRfG
admin のパスワードが、デフォルトの'admin' のままではセキュリティ的なリスクが有るので、変更する事をお薦めします。
上記の出力を internal_users.yml のhash: にコピー&ペーストします。
# vi /opt/opensearch-1.2.4/plugins/opensearch-security/securityconfig/internal_users.yml
/opt/opensearch-1.2.4/plugins/opensearch-security/securityconfig/internal_users.yml を編集 |
---|
---
# This is the internal user database
# The hash value is a bcrypt hash and can be generated with plugin/tools/hash.sh
_meta:
type: "internalusers"
config_version: 2
# Define your internal users here
## Demo users
admin:
hash: "$2y$12$uD9d8uIpDbXmaGpZ7gbWWe.8yJtOWWKaMaCX6ANGHNCyBtLCdUr8i"
reserved: true
backend_roles:
- "admin"
description: "Demo admin user"
bitbucket:
hash: "$2y$12$pNNUqK2YxwrwVq0otPO23eCm9R83tHNNNaPA2odESmB3zv1vFbhdG"
reserved: true
backend_roles:
- "admin"
description: "Bitbucket user" |
ファイルの修正ができたら、下記の様に ./securityadmin.sh を実行して、設定内容を反映します。実行すると、下記の様に出力されます。最後の、Done with success を確認して下さい。
# cd /opt/opensearch-1.2.4/plugins/opensearch-security/tools
# chmod u+x securityadmin.sh
# ./securityadmin.sh -cd ../securityconfig/ -icl -nhnv \
-cacert ../../../config/root-ca.pem \
-cert ../../../config/kirk.pem \
-key ../../../config/kirk-key.pem
Security Admin v7
Will connect to localhost:9300 ... done
Connected as CN=kirk,OU=client,O=client,L=test,C=de
OpenSearch Version: 1.2.4
OpenSearch Security Version: 1.2.4.0
Contacting opensearch cluster 'opensearch' and wait for YELLOW clusterstate ...
Clustername: opensearch
Clusterstate: GREEN
Number of nodes: 1
Number of data nodes: 1
.opendistro_security index already exists, so we do not need to create one.
Populate config from /opt/opensearch-1.2.4/plugins/opensearch-security/securityconfig
Will update '_doc/config' with ../securityconfig/config.yml
SUCC: Configuration for 'config' created or updated
Will update '_doc/roles' with ../securityconfig/roles.yml
SUCC: Configuration for 'roles' created or updated
Will update '_doc/rolesmapping' with ../securityconfig/roles_mapping.yml
SUCC: Configuration for 'rolesmapping' created or updated
Will update '_doc/internalusers' with ../securityconfig/internal_users.yml
SUCC: Configuration for 'internalusers' created or updated
Will update '_doc/actiongroups' with ../securityconfig/action_groups.yml
SUCC: Configuration for 'actiongroups' created or updated
Will update '_doc/tenants' with ../securityconfig/tenants.yml
SUCC: Configuration for 'tenants' created or updated
Will update '_doc/nodesdn' with ../securityconfig/nodes_dn.yml
SUCC: Configuration for 'nodesdn' created or updated
Will update '_doc/whitelist' with ../securityconfig/whitelist.yml
SUCC: Configuration for 'whitelist' created or updated
Will update '_doc/audit' with ../securityconfig/audit.yml
SUCC: Configuration for 'audit' created or updated
Done with success
4.サービス化
OpenSearch がバックグラウンドでサービスとして動作するように、起動スクリプトを変更します。
# vi /opt/opensearch-1.2.4/opensearch-tar-install.sh
最後の1行に “&” を追加します。
/opt/opensearch-1.2.4/opensearch-tar-install.sh の最後に & を追加 |
---|
##Start OpenSearch
echo "Starting OpenSearch"
exec $OPENSEARCH_HOME/bin/opensearch "$@" & |
以下のコマンドでサービスファイルを作成します。
# vi /usr/lib/systemd/system/opensearch.service
内容は下記の通りとします。
/usr/lib/systemd/system/opensearch.service の編集内容 |
---|
[Unit]
Description=OpenSearch Server
After=network.target remote-fs.target
[Service]
Type=forking
User=opensearch
ExecStart=/opt/opensearch-1.2.4/opensearch-tar-install.sh
[Install]
WantedBy=multi-user.target |
ファイルを保存したら、以下のコマンドでシステムに反映させて有効化します。
# systemctl daemon-reload
# systemctl enable opensearch
以下のコマンドで OpenSearch を起動する事ができます。
# systemctl start opensearch
以下のコマンドで OpenSearch を停止する事ができます。
# systemctl stop opensearch
ご不明点は ヘルプデスク (要サポートサービス契約)までお問い合わせください。
サポートサービスの新規ご契約は お問い合わせフォーム にご連絡ください。
リックソフト株式会社 は、日本でトップレベルのAtlassian Platinum Solution Partnerです。
大規模ユーザーへの対応実績が認められたEnterpriseの認定をうけ、高度なトレーニング要件をクリアし、小規模から大規模のお客様まで対応可能な実績を示したパートナー企業です。
Copyright © Ricksoft Co., Ltd. プライバシーポリシー お問い合わせ