パペットボルトを使用したノードアプリケーションの配備
9360 ワード
アプリケーション展開は、複数のマシンまたはシステムに触れることもできるマルチステッププロセスです.このブログ記事では、人形のボルトを使用してノードアプリケーションを展開する方法を見ていきます.アプリケーションは、ノードアプリケーションとMongoDBデータベースで構成されるscotch.ioによって作成されたシンプルなTODOアプリケーションです.アプリケーションとデータベースを別々のサーバーに配備し、どのようにパペットボルトで処理できるかを示します.
自動化の別の部分に使用される3つの(3)ボルトプランを作成します.高いレベルでは、我々のデータベースの仮想マシンにMongoDBデータベースをインストールし、アプリケーションの仮想マシンにノードのアプリケーションをインストールします.
計画概要
ToDoAppは:ToDoAppの計画は、実際にアプリケーション展開のオーケストレーションを処理するoverarching計画されます.
DB : DBプランはMongoDBデータベースをデータベースサーバ仮想マシンにインストールします.
アプリケーション:アプリケーションプランは、ノード、NPM、Gitと他の前提条件をアプリケーションサーバーの仮想マシンにインストールします.
配備計画は、次のPuppet Forgeモジュールを使用してアプリケーションスタックを展開します.
ボルトプロジェクトの初期化
Ensure that the latest version of Puppet Bolt is installed before getting started.
人形のボルトは、実行中のボルト操作のためのポイントを起動としてプロジェクトディレクトリを利用します.パペットボルトプロジェクト名NodeProjectのディレクトリを作成します.
mkdir nodeproject
作業ディレクトリをNodeProjectディレクトリに変更cd nodeproject
ボルトプロジェクトをホストするディレクトリがあるので、プロジェクトを初期化する必要があります.bolt project init --modules puppet-mongodb,puppet-nodejs,camptocamp-systemd,puppetlabs-vcsrepo,puppet-firewalld
コマンドは、成功した場合に以下のような出力を生成する必要があります.Installing project modules
→ Resolving module dependencies, this may take a moment
→ Writing Puppetfile at
/system/path/nodeproject/Puppetfile
→ Syncing modules from
/system/path/nodeproject/Puppetfile to
/system/path/nodeproject/modules
→ Generating type references
Successfully synced modules from /system/path/nodeproject/Puppetfile to /system/path/nodeproject/modules
Successfully created Bolt project at /system/path/nodeproject
ボルトYAMLプラン
ボルトの計画を利用するために、計画という名前のディレクトリを作成する必要があります.
mkdir plans
計画ディレクトリを作成したので、計画の一部として何を達成したいのかを計画します.我々は、アプリケーションとDBの計画を呼び出すToDoAppの計画を作成する予定です.サブまたはネストされた計画の名前は、アプリとDBは、ボルトプロジェクトの名前と計画(BortRadioプロジェクト:BortRange計画)の名前で私たちの計画で参照されます.計画は、アプリケーションとデータベースに使用される仮想マシンのIPアドレスまたはFQDNを指定する2つのパラメータ(APP、DB)を受け入れます.
--------
parameters:
app:
type: TargetSpec
db:
type: TargetSpec
steps:
- plan: nodeproject::db
description: "Deploy todo node application mongodb database"
parameters:
db_targets: $db
- plan: nodeproject::app
description: "Deploy todo node application"
parameters:
app_targets: $app
db_targets: $db
ここで我々はToDoAppの計画を持っているので、我々はMongoDBデータベースをインストールするにはDBプランを作成する必要があります.DBという計画ディレクトリに別のプランを作成します.山口大ステップ
--------
parameters:
db_targets:
type: TargetSpec
steps:
- name: installmongo
targets: $db_targets
resources:
- class: mongodb::globals
parameters:
version: 4.2.0
manage_package_repo: true
server_package_name: mongodb-org-server
bind_ip: [0.0.0.0]
- class: mongodb::server
parameters:
port: 27017
- name: configurefirewall
targets: $db_targets
resources:
- class: firewalld
- firewalld_zone: 'public'
parameters:
ensure: present
purge_ports: true
- firewalld_port: 'node db'
parameters:
ensure: present
port: 27017
protocol: tcp
最後に、ノードアプリケーションを配備するアプリケーションプランを作成する準備が整いました.ノードアプリケーションの配備には、実際にアプリケーションを実行するための手順が必要です.プランは、アプリケーション仮想マシンとデータベース仮想マシンのIPアドレスまたはDNS名をパラメータとして受け入れます.--------
parameters:
app_targets:
type: TargetSpec
db_targets:
type: String
steps:
- name: installprerequisites
description: "install app prerequisite software"
targets: $app_targets
resources:
- package: git
parameters:
ensure: present
- name: configurefirewall
targets: $app_targets
resources:
- class: firewalld
- firewalld_zone: 'public'
parameters:
ensure: present
purge_ports: true
- firewalld_port: 'node app'
parameters:
ensure: present
port: 8080
protocol: 'tcp'
- name: installtodoapp
targets: $app_targets
resources:
- vcsrepo: '/opt/node-todo'
parameters:
ensure: present
provider: git
source: '[https://github.com/scotch-io/node-todo.git'](https://github.com/scotch-io/node-todo.git')
trust_server_cert: true
- class: nodejs
- nodejs::npm: 'app'
parameters:
ensure: present
target: /opt/node-todo
use_package_json: true
- file: '/opt/node-todo/config/database.js'
parameters:
ensure: present
content: >
module.exports = {
remoteUrl : "mongodb://$db_targets:27017/uwO3mypu",
localUrl: "mongodb://$db_targets:27017/meanstacktutorials"
};
- file: '/etc/systemd/system/todo-app.service'
parameters:
ensure: present
content: >
[Unit]
Description=Todo node application
Documentation=[https://github.com/scotch-io/node-todo](https://github.com/scotch-io/node-todo)
After=network.target
[Service]
Type=simple
WorkingDirectory=/opt/node-todo
ExecStart=/usr/bin/npm start
Restart=on-failure
[Install]
WantedBy=multi-user.target
notify: Class[systemd::systemctl::daemon_reload]
- class: systemd::systemctl::daemon_reload
- service: 'todo-app'
parameters:
ensure: running
subscribe: File[/etc/systemd/system/todo-app.service]
我々が計画を作成したので、我々はそれが以下のコマンドを実行することによってボルトによって認識されるのを確実にすることができます.bolt plan show
計画が適切に登録するなら、出力は以下のエントリーを含むべきです.NodeProject::db
aggregate::count
aggregate::nodes
aggregate::targets
canary
facts
facts::external
facts::info
nodeproject::app
nodeproject::db
nodeproject::todoapp
puppet_agent::run
puppetdb_fact
reboot
secure_env_vars
terraform::apply
terraform::destroy
secure_env_vars
terraform::apply
terraform::destroy
計画を登録すると、我々は現在、ボルトプラン実行NodeProject ::ToDoAppコマンドを実行することによって、ToDoApp計画を実行する準備が整いました.計画.bolt plan run nodeproject::todoapp app=10.0.0.41 db=10.0.0.42
プランが正常に実行された場合は、以下のような出力を生成する必要があります.Starting: plan nodeproject::todoapp
Starting: plan nodeproject::db
Starting: install puppet and gather facts on 10.0.0.42
Finished: install puppet and gather facts with 0 failures in 74.59 sec
Starting: apply catalog on 10.0.0.42
Finished: apply catalog with 0 failures in 35.91 sec
Starting: install puppet and gather facts on 10.0.0.42
Finished: install puppet and gather facts with 0 failures in 8.03 sec
Starting: apply catalog on 10.0.0.42
Finished: apply catalog with 0 failures in 19.44 sec
Finished: plan nodeproject::db in 2 min, 18 sec
Starting: plan nodeproject::app
Starting: install puppet and gather facts on 10.0.0.41
Finished: install puppet and gather facts with 0 failures in 74.78 sec
Starting: apply catalog on 10.0.0.41
Finished: apply catalog with 0 failures in 25.49 sec
Starting: install puppet and gather facts on 10.0.0.41
Finished: install puppet and gather facts with 0 failures in 7.59 sec
Starting: apply catalog on 10.0.0.41
Finished: apply catalog with 0 failures in 18.23 sec
Starting: install puppet and gather facts on 10.0.0.41
Finished: install puppet and gather facts with 0 failures in 8.9 sec
Starting: apply catalog on 10.0.0.41
Finished: apply catalog with 0 failures in 65.48 sec
Finished: plan nodeproject::app in 3 min, 21 sec
Finished: plan nodeproject::todoapp in 5 min, 40 sec
Plan completed successfully with no result
いったんコマンドが正常に完了すると、すべてのWebブラウザでのボルトターゲットのIPアドレスまたはFQDNを入力して開くことによって動作することを確認することができます.サイトは次のメッセージを表示します.パットボルトを用いたノードアプリケーションの開発に成功した.自動化は、ロード・バランサとの相互作用などのより精巧に作られることができる.そして、データベース・プレップ操作を実行する.
Reference
この問題について(パペットボルトを使用したノードアプリケーションの配備), 我々は、より多くの情報をここで見つけました https://dev.to/puppet/deploy-a-node-application-using-puppet-bolt-2nghテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol