- 投稿日:2021-01-01T17:00:52+09:00
とりあえずMacでVueの環境を整えてみた
スタンドアロン版のVue.js devtoolsをmacに入れていくメモ。
なおNode.JSのインストールまでは
MacにNode.jsをインストール
を参考にさせていただいています。必要なこと
1.Homebrewのインストール(済)
2.nodebrewのインストール
3.Node.jsのインストール
4.Vue.js devtoolsのインストールHomebrew
HomebrewはMacでのソフトウェアや拡張機能の管理を行うパッケージマネージャです。便利です。
Homebrewのインストールについては
Homebrewのインストール
を参照してます。環境
開始段階の環境として
・mac OS Catalina 10.15.7
・Homebrew 2.7.1
はインストール済みです。nodebrewのインストール
・インストール
ターミナルを開いてnodebrewをインストールしていきます。
ターミナル コマンドbrew install nodebrew・確認
インストールできたか確認してみます。
ターミナル コマンドnodebrew -vターミナル 結果nodebrew 1.0.1 Usage: nodebrew help Show this message nodebrew install <version> Download and install <version> (from binary) nodebrew compile <version> Download and install <version> (from source) nodebrew install-binary <version> Alias of `install` (For backward compatibility) nodebrew uninstall <version> Uninstall <version> nodebrew use <version> Use <version> nodebrew list List installed versions nodebrew ls Alias for `list` nodebrew ls-remote List remote versions nodebrew ls-all List remote and installed versions nodebrew alias <key> <value> Set alias nodebrew unalias <key> Remove alias nodebrew clean <version> | all Remove source file nodebrew selfupdate Update nodebrew nodebrew migrate-package <version> Install global NPM packages contained in <version> to current version nodebrew exec <version> -- <command> Execute <command> using specified <version> Example: # install nodebrew install v8.9.4 # use a specific version number nodebrew use v8.9.4こんな感じでツラツラと出てきたらOKです。
Node.jsのインストール
・インストール
今回はとりあえず最新版をインストールしようと思います。
ターミナル コマンドnodebrew install-binary latestターミナル 結果Fetching: https://nodejs.org/dist/v15.5.0/node-v15.5.0-darwin-x64.tar.gz ######################################################################## 100.0% Installed successfully・有効化
最新版をそのまま有効化していきます。
ターミナル コマンドnodebrew use latestターミナル 結果use v15.5.0今回はインストールされている最新版がv15.5.0だったので、これでOKです。
・パスを通す
ターミナルから起動できるようにパスを通します。
ターミナル コマンドecho 'export PATH=$HOME/.nodebrew/current/bin:$PATH' >> ~/.bash_profile確認のためターミナルで以下のコマンドを実行します。
ターミナル コマンドnode -vターミナル 結果v15.5.0先程有効化したv15.5.0が表示されました。
これでNode.jsのインストールは完了です。Vue.js devtoolsのインストール
・インストール
最後に本命のVue.js devtoolsをインストールしていきます。
引き続きターミナルで以下のコマンドを実行します。ターミナル コマンドnpm install -g @vue/devtoolsなんやかんや出てきます。
ターミナル 結果added 201 packages, and audited 202 packages in 21s 6 packages are looking for funding run `npm fund` for details found 0 vulnerabilities・起動
インストールできたようなので、動作確認していきます。
ターミナル コマンドvue-devtools・結果
- 投稿日:2021-01-01T00:11:52+09:00
PM2のinstancesの値の変更時の確認方法
あけましておめでとうございます。
この記事を編集していたら年を越していました。EC2のインスタンスを作成
key value インスタンスタイプ t2.micro vCPU 1 Node.js, pm2をインストール
curl -sL https://rpm.nodesource.com/setup_12.x | bash - yum install nodejs -y node -v > v12.20.0 npm -v > 6.14.8 npm install pm2 -g > 4.5.1distributions/README.md at master · nodesource/distributions · GitHub
PM2の設定
# 再帰的にディレクトリを作成する mkdir -p /var/www/test # pm2の設定ファイルを作成 touch pm2.yaml # pm2の設定ファイルを編集 vi pm2.yamlpm2.yamlapps: - script : ./app.js name : 'tes-app' instances: -1 # cpuの数-1のプロセスを起動。(clusterモードに限る) # instances: 0 # cpuの数に応じて最大のプロセスを起動。(clusterモードに限る) exec_mode: cluster # n個のインスタンスを起動し、クラスターモジュールに負荷分散を処理させます。コア数、環境もによりますが、
instances: -1
がよさそうです。(コア数8なら7プロセス起動)(脳死でMaxはNG)
またt2.micro
は1コアのはずですが、instances: 4
にするとプロセスが4つ起動しました。(どういう状態?)参考: Optimising NginX, Node.JS and networking for heavy workloads - GoSquared Blog
Expressの準備
# expressをインストール(4.17.1: 2020/12/30) npm install expressNode.js アプリケーションの簡単なプロファイリング | Node.js のコードを今回はお借りします。
app.jsconst express = require("express"); const crypto = require("crypto"); const app = express(); server = app.listen(3000, function(){ console.log("Node.js is listening to PORT:" + server.address().port); }); const users = []; app.get('/newUser', (req, res) => { let username = req.query.username || ''; const password = req.query.password || ''; username = username.replace(/[!@#$%^&*]/g, ''); if (!username || !password || users.username) { return res.sendStatus(400); } const salt = crypto.randomBytes(128).toString('base64'); const hash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512'); users[username] = { salt, hash }; res.sendStatus(200); }); app.get('/auth', (req, res) => { let username = req.query.username || ''; const password = req.query.password || ''; username = username.replace(/[!@#$%^&*]/g, ''); if (!username || !password || !users[username]) { return res.sendStatus(400); } const { salt, hash } = users[username]; const encryptHash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512'); if (crypto.timingSafeEqual(hash, encryptHash)) { res.sendStatus(200); } else { res.sendStatus(401); } });pm2を起動
pm2 start pm2.yaml [PM2][WARN] Applications test-app not running, starting... [PM2] App [test-app] launched (1 instances) ┌─────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐ │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ ├─────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤ │ 0 │ test-app │ default │ 1.0.0 │ cluster │ 24606 │ 0s │ 0 │ online │ 0% │ 30.1mb │ root │ disabled │ └─────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘設定を変更したい場合は一度レジストリを削除してから再度スタートします。(restartだと変更した設定は反映されない)
pm2 delete test-app pm2 start pm2.yaml以上。
- 投稿日:2021-01-01T00:11:52+09:00
pm2のプロファイリングを試してみる(前準備)
あけましておめでとうございます。
この記事を編集していたら年を越していました。EC2を作成
key value インスタンスタイプ t2.micro vCPU 1 Node.js, pm2をインストール
curl -sL https://rpm.nodesource.com/setup_12.x | bash - yum install nodejs -y node -v > v12.20.0 npm -v > 6.14.8 npm install pm2 -g > 4.5.1pm2の設定
# 再帰的にディレクトリを作成する mkdir -p /var/www/test # pm2の設定ファイルを作成 touch pm2.yaml # pm2の設定ファイルを編集 vi pm2.yamlpm2.yamlapps: - script : ./app.js name : 'tes-app' instances: -1 # cpuの数-1のプロセスを起動。(clusterモードに限る) # instances: 0 # cpuの数に応じて最大のプロセスを起動。(clusterモードに限る) exec_mode: cluster # n個のインスタンスを起動し、クラスターモジュールに負荷分散を処理させます。コア数、環境もによりますが、
instances: -1
がよさそうです。(コア数8なら7プロセス起動)(脳死でMaxはNG)
またt2.micro
は1コアのはずですが、instances: 4
にするとプロセスが4つ起動しました。(どういう状態?)参考: Optimising NginX, Node.JS and networking for heavy workloads - GoSquared Blog
Expressの準備
# expressをインストール(4.17.1: 2020/12/30) npm install expressNode.js アプリケーションの簡単なプロファイリング | Node.js
app.jsconst express = require("express"); const app = express(); server = app.listen(3000, function(){ console.log("Node.js is listening to PORT:" + server.address().port); }); app.get('/newUser', (req, res) => { let username = req.query.username || ''; const password = req.query.password || ''; username = username.replace(/[!@#$%^&*]/g, ''); if (!username || !password || users.username) { return res.sendStatus(400); } const salt = crypto.randomBytes(128).toString('base64'); const hash = crypto.pbkdf2Sync(password, salt, 10000, 512, 'sha512'); users[username] = { salt, hash }; res.sendStatus(200); });pm2を起動
pm2 start pm2.yaml [PM2][WARN] Applications test-app not running, starting... [PM2] App [test-app] launched (1 instances) ┌─────┬─────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐ │ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │ ├─────┼─────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤ │ 0 │ test-app │ default │ 1.0.0 │ cluster │ 24606 │ 0s │ 0 │ online │ 0% │ 30.1mb │ root │ disabled │ └─────┴─────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘設定を変更したい場合は一度レジストリを削除してから再度スタートします。(restartだと変更した設定は反映されない)
pm2 delete test-app pm2 start pm2.yaml今回はここまで。