Vagrant で CentOS7.8 ゲストを使えるようにする
やりたいこと
手元のVagrant環境で、CentOS7.8の環境を用意する。だけ。
操作メモ
vagrant initとup
> vagrant init bento/centos-7.8 > vagrant up ・・・中略・・・ Vagrant was unable to mount VirtualBox shared folders. This is usually because the filesystem "vboxsf" is not available. This filesystem is made available via the VirtualBox Guest Additions and kernel module. Please verify that these guest additions are properly installed in the guest. This is not a bug in Vagrant and is usually caused by a faulty Vagrant box. For context, the command attempted was: mount -t vboxsf -o uid=1000,gid=1000 vagrant /vagrant The error output from the command was: /sbin/mount.vboxsf: mounting failed with the error: No such device
VirtualBoxの共有フォルダをマウントできなかった。vboxsfが利用できないせいらしい。 Guest Additionsがゲストで適切にインストールされているか確認せよ、とのこと。
vbguestを確認
>vagrant vbguest --status Got different reports about installed GuestAdditions version: Virtualbox on your host claims: VBoxService inside the vm claims: 6.1.16 Going on, assuming VBoxService is correct... [default] GuestAdditions seems to be installed (6.1.16) correctly, but not running.
ホスト上のVirtualBox は、何もない? VM内のVBoxService は、6.1.16 ホストにGuest Additionsを入れないといけないのかな?
Guest Additionsをインストールしてみる
> vagrant plugin install vagrant-vbguest Installing the 'vagrant-vbguest' plugin. This can take a few minutes... Installed the plugin 'vagrant-vbguest (0.29.0)'!
インストールできた。
upとssh接続
> vagrant up Bringing machine 'default' up with 'virtualbox' provider... ==> default: Checking if box 'bento/centos-7.8' version '202010.22.0' is up to date... > vagrant ssh Last login: Mon Feb 8 13:52:12 2021 from 10.0.2.2 This system is built by the Bento project by Chef Software More information can be found at https://github.com/chef/bento
できた、のかな?
ブレードサーバでメザニンカードをメザニンスロット1からメザニンスロット2に差し替える
やりたいこと
ブレードサーバ(BL460c Gen10)のメザニンカード(ネットワークアダプター)をメザニンスロット1からメザニンスロット2に入れ替える。
メザニンコネクターガイドピンの位置
ガイドピンは、メザニンカードの位置を決めるのに使うメザニンアセンブリ上のピン(棒)。下の図で数値が示しているのがピン。
説明にある通り、メザニンスロット1に挿す場合は2番と4番を使う。メザニンスロット2に挿す場合は、1番と3番を使う。
取り付け手順
手順は、Googleでユーザーガイドを探してきて読みます。
メザニンカードオプション⇒メザニンカードオプションを取り付ける
- サーバーの電源を切る
- サーバーブレードを取り外す
- サーバーブレードを平らで水平な面に置く
- アクセスパネルを取り外す
- メザニンアセンブリを取り外す
現状:2番と4番のピンを使っているので、メザニンスロット1用
取り外してみた
- 適切なガイドピンを使用して、メザニンカードをメザニンアセンブリの上に合わせる
- メザニンカードをメザニンアセンブリに取り付ける
メザニンスロット2に挿すために、1番と3番のピンを使う。
- メザニンアセンブリをシステムボード上のガイドピンに合わせて、メザニンアセンブリをシステムボードに取り付ける
- アクセスパネルを取り付ける
- サーバーブレードを取り付ける
- サーバーブレードの電源を入れる
Hyper-Vで仮想ハードディスクを容量固定から容量可変に変更する
概要
Hyper-V上の仮想マシンで、容量固定から容量可変に変更する。変更にはPowerShellを使用する。
- 環境は、Hyper-V Server 2012R2
PowerShellのコマンド
容量固定から容量可変への変換
- 容量固定で作成したTESTVM001.vhdxを、容量可変の仮想ハードディスクTESTVM001_dynamic.vhdxに変換する。
- VHDTypeにはDynamicを指定する。なお、逆(可変⇒固定)の場合は、Fixedを使う。
PS> Convert-VHD -Path "\\CSVPATH\TestDir\TESTVM001\Virtual Hard Disks\TESTVM001.vhdx" -DestinationPath "\\CSVPATH\TestDir\TESTVM001\Virtual Hard Disks\TESTVM001_dynamic.vhdx" -VHDType Dynamic
仮想マシンへのアタッチ
PS> Set-VMHardDiskDrive -VMName TESTVM001 -ControllerType IDE -Path "\\CSVPATH\TestDir\TESTVM001\Virtual Hard Disks\TESTVM001_dynamic.vhdx"
参考にしたサイト
4.7GB+ のISOファイルをDVDに焼く
Windows Server 2019 の評価版を使ってみようと思ってダウンロードしたら、5.17GBで、DVD-Rには焼けなさそうです。
以下で実施しました
- DVD-R DL(2層DVD)を用意します。イオンで買ってきました。5枚で1280円くらい。
- 書き込みソフトには、Active@ISO Burner を選びました。ダウンロードして、インストールしておきます。 freesoft-100.com
- DVD-R DL メディアをDVDドライブに挿入します。
- Active@ISO Burnerを起動します
- ISOファイルを選択、あとはデフォルトで、「BURN」をクリックします
- 完了(約22分)
以上。 これでインストールできるだろうか・・・。
wmi_exporterでCluster Shared Volumeのディスクサイズを監視する
概要
Hyper-Vクラスタ環境のCluster Shared VolumeをPrometheusで監視する。
- PrometheusでCluster Shared Volumeのmetricsを取得して監視する
- wmi_exporterのtextfile collectorを使用する
- Cluster Shared Volumeのボリューム情報はpowershellを使って取得する
- powershellスクリプトは、タスクスケジューラで1日1回実行する
ちなみに、wmi_exporterではローカルディスクのメトリクスを取得できるが、Cluster Shared Volumeのメトリクスは取得できない。
参考
以下を参考にしました。 github.com
要約すると、workaround として、スケジュールされたタスクと組み合わせてtextfile collectorを使って実現できる。
また、以下の投稿のpowershellスクリプトを参考にしました。
@jrcresawn you could try my own version, which I wrote a few days ago.
https://gist.github.com/basroovers/91c99d919cb0769b3d257692ed4ef99e
I'm running it via Task Scheduler but I rather have it started from wmi_exporter itself, the way Telegraf does it.
textfile collectorについて
textfile collectorについては、こちら github.com
- 他の処理によって書かれたファイルから、メトリクスを作成する
- デフォルトで有効なので、簡単に使える。
- デフォルトでは、C:\Program Files\wmi_exporter\textfile_inputs\ フォルダ配下の.promファイルのみが読み取られる。
- ファイルの場所は、--collector.textfile.directory オプションで指定可能
- このtextfile_inputs フォルダは、wmi_exporterのインストール時に作成されている
- .promファイルは、空の行で終わる必要がある。
環境
- 仮想化ホスト Windows Server 2012 R2
- wmi_exporter 0.10.2
Powershellスクリプトの作成
要件
- Cluster Shared Volumeのディスク容量情報をファイルに出力する
- 使用率等を計算したいので、ボリュームのサイズと、空き容量をそれぞれ出力する
csv-to-prom.ps1
※powershellの構文は、環境によって異なる。
# variables $csv_size_promLocation = "C:\Program Files\wmi_exporter\textfile_inputs\csv_size.prom" $csv_free_promLocation = "C:\Program Files\wmi_exporter\textfile_inputs\csv_free.prom" Import-Module FailoverCluster $clustername = Get-Cluster $objs = @() $CurrentFree = @{} $csvs = Get-ClusterSharedVolume foreach ( $csv in $csvs ) { $csvinfos = $csv | select -Property Name -ExpandProperty SharedVolumeInfo foreach ( $csvinfo in $csvinfos ) { $obj = New-Object PSObject -Property @{ Name = $csv.Name Path = $csvinfo.FriendlyVolumeName Size = $csvinfo.Partition.Size FreeSpace = $csvinfo.Partition.FreeSpace UsedSpace = $csvinfo.Partition.UsedSpace PercentFree = $csvinfo.Partition.PercentFree } $objs += $obj } } Set-Content -Path $csv_size_promLocation -Encoding Ascii -Value "" Add-Content -Path $csv_size_promLocation -Encoding Ascii -Value "# HELP win_csv_disksize Clustered Shared Volume disk size. `n" Add-Content -Path $csv_size_promLocation -Encoding Ascii -Value "# TYPE win_csv_disksize gauge `n" Set-Content -Path $csv_free_promLocation -Encoding Ascii -Value "" Add-Content -Path $csv_free_promLocation -Encoding Ascii -Value "# HELP win_csv_freespace Clustered Shared Volume disk size. `n" Add-Content -Path $csv_free_promLocation -Encoding Ascii -Value "# TYPE win_csv_freespace gauge `n" foreach ( $k in $objs) { Add-Content -Path $csv_size_promLocation -Encoding Ascii -Value "win_csv_disksize{name=""$($k.Name)""} $($k.Size)`n" Add-Content -Path $csv_free_promLocation -Encoding Ascii -Value "win_csv_freespace{name=""$($k.Name)""} $($k.FreeSpace)`n" }
出力結果
csv_size.prom
# HELP win_csv_disksize Clustered Shared Volume disk size. # TYPE win_csv_disksize gauge win_csv_disksize{name="volume1"} 2997416357888 win_csv_disksize{name="volume2"} 2997416357888 win_csv_disksize{name="volume3"} 2997416357888
csv_free.prom
# HELP win_csv_freespace Clustered Shared Volume free space. # TYPE win_csv_freespace gauge win_csv_freespace{name="volume1"} 807385362432 win_csv_freespace{name="volume2"} 1439418380288 win_csv_freespace{name="volume3"} 3793255264256
wmi_exporterでの確認
C:\Program Files\wmi_exporter\textfile_inputs\フォルダに、.promファイルが生成されると、wmi_exporterのメトリクスが表示される。
win_csv_freespaceの場合
Element | Value |
---|---|
win_csv_freespace{instance="Server01:9182", job="windows", name="volume1"} | 807385362432 |
win_csv_freespace{instance="Server01:9182", job="windows", name="volume2"} | 1439418380288 |
win_csv_freespace{instance="Server01:9182", job="windows", name="volume3"} | 3793255264256 |
タスクスケジューラの登録
- タスクスケジューラを起動
- タスクスケジューラライブラリに、新規フォルダーを作成(OS標準のものと分けるために)
- タスクの作成
- [全般]タブ
- 名前: csv-to-prom.ps1の実行
- 説明:任意
- 「ユーザーがログオンしているかどうかにかかわらず実行する」を選択
- 「最上位の特権で実行する」をチェック
- [トリガー]タブ
- 毎日、開始の日時と時刻(任意)
- [操作]タブ
- プログラム/スクリプト: C:\Windows\System32\WindowsPowershell\v1.0\powershell.exe
- 引数の追加: -c "C:\Scripts\csv-to-prom.ps1"
- 実行するアカウントを入力
Grafanaでの表示
最終的に、以下のようなグラフを生成した。設定方法は、省略。
Volume Name | Size | Used | Avail | Usage |
---|---|---|---|---|
volume1 | 3.00TB | 2.19TB | 807.63GB | 7.2% |
volume2 | 3.00TB | 1.56TB | 1.44TB | 52.0% |
volume3 | 3.00TB | 2.40TB | 593.30GB | 80.2% |
このグラフは、以下のダッシュボード・テンプレートのグラフ「Disk Space Used Base(EXT4/XFS)」を参考に作成した。
以上
grok_exporterとExample
概要
grok_exporterを使ってみる
- 対象のバージョンは、grok_exporter-1.0.0.RC3 (現時点の最新)
- exampleで確認
grok_exporterとは?
- 任意の非構造化ログデータから、Prometheusのメトリクスをエクスポートする
- 非構造化ログデータをパースするのにGrokを使う
インストール
$ cd /opt/prometheus $ sudo wget https://github.com/fstab/grok_exporter/releases/download/v1.0.0.RC3/grok_exporter-1.0.0.RC3.linux-amd64.zip $ sudo unzip grok_exporter-1.0.0.RC3.linux-amd64.zip $ sudo ln -s grok_exporter-1.0.0.RC3.linux-amd64 grok_exporter
フォルダの中身
grok_exporter //本体 example/ //grok_exporterを理解するためのサンプル pattens/ //grokのパターンファイル置き場
example
このサンプルでは、サンプルログ example/exim-rejected-RCPT-examles.log をconfig.yml に従ってパースし、Prometheusのメトリクスにする。
設定ファイル
global: config_version: 3 input: type: file path: ./example/exim-rejected-RCPT-examples.log readall: true imports: - type: grok_patterns dir: ./patterns grok_patterns: - 'EXIM_MESSAGE [a-zA-Z]*' metrics: - type: counter name: exim_rejected_rcpt_total help: Total number of rejected recipients, partioned by error message match: '%{EXIM_DATE} %{EXIM_REMOTE_HOST} F=<%{EMAILADDRESS}> rejected RCPT <%{EMAILADDRESS}>: %{EXIM_MESSAGE:message}' labels: error_message: '{{.message}}' logfile: '{{base .logfile}} server: protocol: http port: 9144
パラメータについてのさらっとした説明(恐らく)
- input: -> readall: trueはファイルの先頭から読み込む(検証、デバッグならこっち)、falseは新しい行から読む(運用ならこっち)
- imports: 定義済みのgrok_patternsを使う場合。入れておけばいい。
- grok_patterns: ここにカスタムのGROKパターン(正規表現)を直書きできる。patterns/ 配下にファイルを作ってそこに書いてもいい。
- metrics: 読み込んだログ行を変数(メトリクス)に入れるところ
- name: 変数名(メトリクス名)
- match: ここが取りたいログの正規表現を作るところ。%{PATTERN: message} のようにすると、以降のlabelsで .message で呼び出せる
- labels: メトリクス内のラベル
- logfile: '{{base. logfile}} logifleは、GROKパターンに依存しないラベル変数でファイルのフルパスを表す。base はGoテンプレート関数でフルパスのうちファイル名を取り出すもの。いずれもマニュアルに書かれている。
match: について
match: '%{EXIM_DATE} %{EXIM_REMOTE_HOST} F=<%{EMAILADDRESS}> rejected RCPT <%{EMAILADDRESS}>: %{EXIM_MESSAGE:message}'
- EXIM_DATE、EXIM_REMOTE_HOSTは、patterns/exim に定義されている
- EMAILADDRESSは、patterns/grok_patterns に定義されている
- EXIM_MESSAGEは、config.ymlのgrok_patterns に定義したもの
実行する
./grok_exporter -config example/config.yml
実行結果を確認する
http://localhost:9144/metrics にアクセスすると、以下のように表示される
exim_rejected_rcpt_total {error_message="Sender verify failed"} 2000 exim_rejected_rcpt_total {error_message="Unrouteable address"} 32 exim_rejected_rcpt_total {error_message="relay not permitted"} 165
Prometheusをサービス化する
概要
今後使っていくにあたって、Prometheusをサービス化する。 まだ、とりあえずの試運転。
雑誌やネットの記事を参考に、以下のようにする。
Promtheus本体
設計
場所 | パス |
---|---|
prometheusのインストール場所 | /opt/prometheus/current -> /opt/prometheus/prometheus-2.16.0.linux-amd64(シンボリックリンク) |
設定ファイルの場所 | /etc/prometheus/prometheus.yml |
DBの保存場所 | /var/db/prometheus |
prometheus.service
$ sudo vi /usr/lib/systemd/system/prometheus.service [Unit] Description=Prometheus Server Documentation=https://prometheus.io/docs/introduction/overview/ After=network-online.target [Service] ExecStart=/opt/prometheus/current/prometheus --config.file=/etc/prometheus/prometheus.yml --storage.tsdb.path=/var/db/prometheus ExecStop=/bin/kill -TERM ${MAINPID} ExecReload=/bin/kill -HUP ${MAINPID} [Install] WantedBy=multi-user.target $ sudo systemctl daemon-reload $ sudo systemctl enable prometheus $ sudo systemctl start prometheus
Node_Exporter
設計
場所 | パス |
---|---|
node_exporterのインストール場所 | /opt/prometheus/node_exporter-> /opt/prometheus/node_exporter-0.18.1.linux-amd64(シンボリックリンク) |
node_exporter.service
$ sudo vi /usr/lib/systemd/system/node_exporter.service [Unit] Description=Node Exporter [Service] ExecStart=/opt/prometheus/node_exporter/node_exporter [Install] WantedBy=multi-user.target $ sudo systemctl daemon-reload $ sudo systemctl enable node_exporter $ sudo systemctl start node_exporter
参考
node_exporterのexampleに、systemdのサンプルファイルがありました。 https://github.com/prometheus/node_exporter/tree/master/examples/systemd