13 KiB
Flight Manual for working on Virtual Machines
スタッフまたは開発チームのメンバーとして Azure、Digital Oceanなどの クラウドサービスプロバイダーへのアクセスが許可されている可能性があります。
仮想マシン (VM) で作業するために使用できる便利なコマンドをいくつか紹介します。 例えばメンテナンスの更新や ハウスキーピングなどです
Get a list of the VMs
[!注:] 既にVMへのSSHアクセスがある場合があります。 クラウドポータルへのアクセスが許可されていない限り、 VMをリストすることはできません。
Azure
Azure CLI をインストール az
: https://docs.microsoft.com/en-us/cli/azure/install-azure-cli
(One-time) Install on macOS with
homebrew
:
brew install azure-cli
(One-time) Login:
az login
Get the list of VM names and P addresses:
az vm list-ip-addresses --output table
Digital Ocean
Digital Ocean CLI をインストールする doctl
: https://github.com/digitalocean/doctl#installing-doctl
(One-time) Install on macOS with
homebrew
:
brew install doctl
(One-time) Login:
認証とコンテキストの切り替え: https://github.com/digitalocean/doctl#authenticating-with-digitalocai
doctl auth init
Get the list of VM names and IP addresses:
doctl compute droplet list --format "ID,Name,PublicIPv4"
Spin a VM (or VM Scale Set)
Todo: Add instructions for spinning VM(s)
Keep VMs updated
You should keep the VMs up to date by performing updates and upgrades. これにより により、仮想マシンが最新のセキュリティ修正でパッチを適用されるようになります。
[!WARNING] Before you run these commands:
- VMが完全にプロビジョニングされており、 インストール後のステップが実行されていないことを確認してください。
- アプリケーションをすでに提供している VM 上のパッケージを更新している場合は、 アプリが停止/保存されていることを確認してください。 パッケージの更新により、 ネットワーク帯域幅、メモリ、CPU使用率のスパイクが発生し、 実行中のアプリケーションで停止します。
Update package information
sudo apt update
Upgrade installed packages
sudo apt upgrade -y
Cleanup unused packages
sudo apt autoremove -y
Work on Web Servers (Proxy)
Web サーバーのロードバランシング(Azure Load Balancer)インスタンスを実行しています。 これらのサーバーは、すべてのトラフィック を、独自の インフラストラクチャ上で実行されるさまざまなアプリケーションから freeCodeCamp.org にリバースプロキシする NGINX を実行しています。
NGINX 設定は このリポジトリ で利用できます。
First Install
Provisioning VMs with the Code
1. (Optional) Install NGINX and configure from repository.
The basic setup should be ready OOTB, via the cloud-init configuration. SSH と は特定のインスタンスに対して必要に応じて変更を加えます。
cloud-init 設定を以前に使用していない場合は、NGINX とエラーページの手動設定に 以下を使用します。
sudo su
cd /var/www/html
git clone https://github.com/freeCodeCamp/error-pages
cd /etc/
rm -rf nginx
git clone https://github.com/freeCodeCamp/nginx-config nginx
cd /etc/nginx
2. Install Cloudflare origin certificates and upstream application config.
安全なストレージからCloudflareのオリジン証明書を取得し、 必要な場所にインストールしてください。
OR
Move over existing certificates:
# Local
scp -r username@source-server-public-ip:/etc/nginx/ssl ./
scp -pr ./ssl username@target-server-public-ip:/tmp/
# Remote
rm -rf ./ssl
mv /tmp/ssl ./
Update Upstream Configurations:
vi configs/upstreams.conf
Add/update the source/origin application IP addresses.
3. Setup networking and firewalls.
Configure Azure firewalls and ufw
as needed for ingress origin addresses.
4. Add the VM to the load balancer backend pool.
Configure and add rules to load balancer if needed. バランサバックエンドプールをロードするために、 VMを追加する必要があるかもしれません。
インスタンスの更新 (メンテナンス)
- Check status for NGINX service using the below command:
sudo systemctl status nginx
- Logging and monitoring for the servers are available at:
https://amplify.nginx.com
Updating Instances (Maintenance)
NGINX インスタンスへの設定変更は GitHub 上でメンテナンスされています。 これらは以下のように各インスタンスに デプロイされる必要があります。
- SSH into the instance and enter sudo
sudo su
- Get the latest config code.
cd /etc/nginx
git fetch --all --prune
git reset --hard origin/master
- を でテストし、リロードします。
nginx -t
nginx -s reload
Work on API Instances
- Install build tools for node binaries (
node-gyp
) etc.
sudo apt install build-essential
First Install
Provisioning VMs with the Code
-
Install Node LTS.
-
Update
npm
and install PM2 and setup logrotate and startup on bootnpm i -g npm npm i -g pm2 pm2 install pm2-logrotate pm2 startup
-
Clone freeCodeCamp, setup env and keys.
git clone https://github.com/freeCodeCamp/freeCodeCamp.git cd freeCodeCamp git checkout production-current # or any other branch to be deployed
-
Create the
.env
from the secure credentials storage. -
Create the
google-credentials.json
from the secure credentials storage. -
Install dependencies
npm ci
-
Build the server
npm run ensure-env && npm run build:server
-
Start Instances
cd api-server pm2 start production-start.js -i max --max-memory-restart 600M --name org
インスタンスの更新 (メンテナンス)
## ロギングとモニタリング
```console
pm2 ログ
pm2 monit
Updating Instances (Maintenance)
Code changes need to be deployed to the API instances from time to time. は、ローリングアップデートまたはマニュアルアップデートとすることができます。 依存関係を変更したり、環境変数を追加したりする場合は、後者が重要です。
[!DANGER] 自動パイプラインは 分間で依存関係の更新を処理していません。 We need to do a manual update before any deployment pipeline runs.
1. Manual Updates - Used for updating dependencies, env variables.
- Stop all instances
pm2 stop all
- Install dependencies
npm ci
- Build the server
npm run ensure-env && npm run build:server
- Start Instances
pm2 start all --update-env && pm2 logs
2. Rolling updates - Used for logical changes to code.
pm2 reload all --update-env && pm2 logs
[!NOTE] We are handling rolling updates to code, logic, via pipelines. はこれらのコマンドを実行する必要はありません。 These are here for documentation.
Work on Client Instances
- Install build tools for node binaries (
node-gyp
) etc.
sudo apt install build-essential
First Install
Provisioning VMs with the Code
-
Install Node LTS.
-
Update
npm
and install PM2 and setup logrotate and startup on bootnpm i -g npm npm i -g pm2 npm install -g serve pm2 install pm2-logrotate pm2 startup
-
Clone client config, setup env and keys.
git clone https://github.com/freeCodeCamp/client-config.git client cd client
git clone https://github.com/freeCodeCamp/client-config.git client cd client
Web クライアントのプレースホルダー インスタンスを開始します。 これらは 個の Azure ピプラインのアーティファクトで更新されます。
Todo: This setup needs to move to S3 or Azure Blob storage
echo "serve -c ../../serve.json www -p 50505" >> client-start-primary.sh chmod +x client-start-primary.sh pm2 delete client-primary pm2 start ./client-start-primary.sh --name client-primary echo "serve -c ../../serve.json www -p 52525" >> client-start-secondary.sh chmod +x client-start-secondary.sh pm2 delete client-secondary pm2 start ./client-start-secondary.sh --name client-secondary
## インスタンスの更新 (メンテナンス)
```console
## ロギングとモニタリング
```console
pm2 ログ
pm2 monit
Updating Instances (Maintenance)
Code changes need to be deployed to the API instances from time to time. は、ローリングアップデートまたはマニュアルアップデートとすることができます。 依存関係を変更したり、環境変数を追加したりする場合は、後者が重要です。
[!DANGER] 自動パイプラインは 分間で依存関係の更新を処理していません。 We need to do a manual update before any deployment pipeline runs.
1. Manual Updates - Used for updating dependencies, env variables.
-
Stop all instances
pm2 stop all
-
Install or update dependencies
-
Start Instances
pm2 start all --update-env && pm2 logs
2. Rolling updates - Used for logical changes to code.
pm2 reload all --update-env && pm2 logs
[!NOTE] We are handling rolling updates to code, logic, via pipelines. はこれらのコマンドを実行する必要はありません。 These are here for documentation.