はてなブログからwordpressへぶっこぬきで移行した話

現在はてなブログで運用しているけど、画像付きでのエクスポートができない、とかいう話を聞いた。

ローカルに静的コンテンツとして取り込もう

とりあえず、本文と画像をダウンロードすればいいだろう、と、まずは簡単に下記でコンテンツ取得をかけた。

wget --mirror \
    --page-requisites \
    --quiet --show-progress \
    --no-parent \
    --convert-links \
    --adjust-extension \
    --execute robots=off \
    https://retoge-mag.hatenablog.com/

適当なWebサーバに配置して見てみると、HTMLのみで、そしてサイト内リンクもhttpsからフルで指定されているタイプだったので、URL書き換えを雑に実施。

他にもHTML書き換えが必要だろう、ということでダウンロードしてきたやつではなく、閲覧用のHTMLを別に用意することにして、下記の様に実行した。

cp -r retoge-mag.hatenablog.com viewpage

for file in `find ./viewpage -name \*.html -print`
do
 sed -i -e "s/retoge-mag.hatenablog.com/retoge-mag.websa.jp\/old\/viewpage/g" $file
done

これでまずはHTMLのみがコピーされた状態だが、リンクをいくつかクリックしてみると404 not foundとなるものがある。

日付ごとのまとめはダウンロードされていないが、これについては無視することとした。

個別記事のリンクで、末尾が数字で終わっているものがいくつかあり、それで404が発生していた。それらのコンテンツは数字.htmlという形でダウンロードされていたので .htaccess に下記の設定を行った。

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond     %{REQUEST_FILENAME} !-f
RewriteRule     ^(.*)$ $1.html [L]

</IfModule>

次に画像のダウンロードを行った。

HTMLからhttp か httpsで始まるリンクっぽいものを集めてみると画像は st-hatena.com というドメイン名の所に置いてあるようだった。

なので、下記スクリプトを実行して、該当するURLを全てダウンロードしてきた。

for file in `find ./viewpage -name \*.html -print`
do
 grep -oE 'http(s?)://[0-9a-zA-Z?=#+_&:;/.%\-]+' $file >> urllists.txt
done
sort urllists.txt | uniq > urllists2.txt
grep st-hatena.com urllists2.txt > urllists3.txt
wget --mirror     --page-requisites     --quiet --show-progress     --no-parent     --convert-links     --adjust-extension -i urllists3.txt

なお、最初は「grep -oE ‘http(s?)://[0-9a-zA-Z?=#+_&:/.%-]+’ $file >> urllists.txt」だったのだが、縮小処理をかけた画像のURLに;が含まれていたので、追加している。

画像はローカルにダウンロードできたものの、HTMLの方は書き換わっていないため、以下で書き換えを実施した。

for file in `find ./viewpage -name \*.html -print`
do
 sed -i -e "s/b.st-hatena.com/retoge-mag.websa.jp\/old\/b.st-hatena.com/g" $file
 sed -i -e "s/cdn-ak.f.st-hatena.com/retoge-mag.websa.jp\/old\/cdn-ak.f.st-hatena.com/g" $file
 sed -i -e "s/cdn.blog.st-hatena.com/retoge-mag.websa.jp\/old\/cdn.blog.st-hatena.com/g" $file
 sed -i -e "s/cdn.pool.st-hatena.com/retoge-mag.websa.jp\/old\/cdn.pool.st-hatena.com/g" $file
 sed -i -e "s/cdn.profile-image.st-hatena.com/retoge-mag.websa.jp\/old\/cdn.profile-image.st-hatena.com/g" $file
 sed -i -e "s/cdn.user.blog.st-hatena.com/retoge-mag.websa.jp\/old\/cdn.user.blog.st-hatena.com/g" $file
 sed -i -e "s/usercss.blog.st-hatena.com/retoge-mag.websa.jp\/old\/usercss.blog.st-hatena.com/g" $file
done

これで、見栄えは悪いものの画像ファイル含めてローカルにコンテンツ自体はコピーされた。

WordPressに取り込もう

あまりにも見栄えが悪いので、やっぱりWordpressに取り込むべきか、とインポート用XMLファイルを作ることにする。

WordPressのサイトを調べたのだがインポート用XMLファイルの仕様がよくわからなかった。

まず、Wordpressで適当に記事とカテゴリを作成して、それをエクスポートしたXMLを作成した。

結構いらない要素が多い感じがしたので最小限の記述はなにか探したところ「Simple WordPress Import Structure XML Example」を発見。

<?xml version="1.0" encoding="UTF-8" ?>

<rss version="2.0"
	xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:wp="http://wordpress.org/export/1.2/"
>

<channel>
	<wp:wxr_version>1.2</wp:wxr_version>
	<wp:author></wp:author>

	<item>
		<title>Test 1</title>
		<description></description>
		<content:encoded><![CDATA[Test Post 1]]></content:encoded>
		<excerpt:encoded><![CDATA[]]></excerpt:encoded>
		<wp:status>publish</wp:status>
		<wp:post_type>post</wp:post_type>
		<category domain="post_tag" nicename="redy"><![CDATA[redy]]></category>
		<category domain="category" nicename="teory"><![CDATA[Teory]]></category>
		<category domain="category" nicename="tree"><![CDATA[Tree]]></category>
	</item>
	<item>
		<title>Test 2</title>
		<description></description>
		<content:encoded><![CDATA[Test Post 2]]></content:encoded>
		<excerpt:encoded><![CDATA[]]></excerpt:encoded>
		<wp:status>publish</wp:status>
		<wp:post_type>post</wp:post_type>
		<category domain="category" nicename="test-category"><![CDATA[Test Category]]></category>
	</item>
</channel>
</rss>

これをベースに作成することにした。

はてなブログが出力したHTMLから下記の要素を抜き出してXMLタグを出力する test.plを作成した。

#!/bin/perl
#

use strict;
use warnings;

my $sourcefile=$ARGV[0];

if(!-f $sourcefile){
        print "file not found\n";
        exit 1;
}

my $i=0;
my @bodys;

open(FILE,$sourcefile);
while(<FILE>){
        $bodys[$i]=$_;
        $i++;
}
close(FILE);

my $maxline=$i;
my $line;

my ($st,$ed,$tmp);

my $createdate="";
my $modifydate="";
my $title="";
my $categorys="";
my $categoryssub="";
my $categorysterm="";
my $author="";
my $contents="";
my $description="";

$i=0;
while($i<$maxline){
        $line=$bodys[$i];
        if(($line =~ /<time datetime=/)&&($createdate eq "")){
                # 作成日取得
                # 下の方に他のページのdatetimeもあるので1個目だけ採用
                $st=index($line,"datetime=");
                $st=index($line,"\"",$st)+length("\"");
                $ed=index($line,"\"",$st);
                $createdate=substr($line,$st,$ed-$st);
        #}elsif(($line =~ /entry-footer-time/)&&($line =~ /class=\"updated\"/)){
        }elsif($line =~ /dateModified/){
                # 更新日取得
                $st=index($line,"dateModified");
                $st=index($line,":",$st);
                $st=index($line,"\"",$st)+length("\"");
                $ed=index($line,"\"",$st);
                $modifydate=substr($line,$st,$ed-$st);
        }elsif($line =~ /entry-title-link/){
                # タイトル取得
                $st=index($line,">")+length(">");
                $ed=index($line,"</",$st);
                $title=substr($line,$st,$ed-$st);
        }elsif($line =~ /entry-categories/){
                # カテゴリ取得
                my $flag=0;
                while($flag==0){
                        $i++;
                        $line=$bodys[$i];
                        if($line =~/<\/div>/){
                                # カテゴリ終了
                                $flag=1;
                        }elsif($line =~ /entry-category-link/){
                                $st=index($line,">")+length(">");
                                $ed=index($line,"</",$st);
                                $tmp=substr($line,$st,$ed-$st);
                                $categorys.="<category domain=\"category\" nicename=\"".$tmp."\" ><![CDATA[".$tmp."]]></category>";
                        }
                }
        }elsif($line =~ /author vcard/){
                # 作者取得
                $ed=index($line,"</");
                $st=rindex($line,">",$ed)+length(">");
                $author=substr($line,$st,$ed-$st);
        }elsif($line =~ /entry-content/){
                # 本文取得
                my $flag=0;
                while($flag==0){
                        $i++;
                        $line=$bodys[$i];
                        if($line =~/entry-footer/){
                                # 本文終了
                                $flag=1;
                        }else{
                                $contents.=$line;
                        }
                }
        }elsif($line =~ /og:description/){
                # description取得
                $st=index($line,"content=\"")+length("content=\"");
                $ed=index($line,"\"",$st);
                $description=substr($line,$st,$ed-$st);
        }


        $i++;
}
# URL変換処理
$contents =~ s/b.st-hatena.com/retoge-mag.websa.jp\/old\/b.st-hatena.com/g;
$contents =~ s/cdn-ak.f.st-hatena.com/retoge-mag.websa.jp\/old\/cdn-ak.f.st-hatena.com/g;
$contents =~ s/cdn.blog.st-hatena.com/retoge-mag.websa.jp\/old\/cdn.blog.st-hatena.com/g;
$contents =~ s/cdn.pool.st-hatena.com/retoge-mag.websa.jp\/old\/cdn.pool.st-hatena.com/g;
$contents =~ s/cdn.profile-image.st-hatena.com/retoge-mag.websa.jp\/old\/cdn.profile-image.st-hatena.com/g;
$contents =~ s/cdn.user.blog.st-hatena.com/retoge-mag.websa.jp\/old\/cdn.user.blog.st-hatena.com/g;
$contents =~ s/usercss.blog.st-hatena.com/retoge-mag.websa.jp\/old\/usercss.blog.st-hatena.com/g;

#


print "<item>\n";
print "<description>".$description."</description>\n";
print "<excerpt:encoded><![CDATA[]]></excerpt:encoded>\n";
print "<wp:status>publish</wp:status>\n";
print "<wp:post_type>post</wp:post_type>\n";
print "<wp:post_date_gmt>".$createdate."</wp:post_date_gmt>\n";
#print "<wp:post_modified_gmt>".$modifydate."</wp:post_modified_gmt>\n";
print "<wp:post_modified>".$modifydate."</wp:post_modified>\n";
print "<title><![CDATA[".$title."]]></title>\n";
print $categorys."\n";
#print "<dc:creator><![CDATA[".$author."]]></dc:creator>\n";
print "<dc:creator><![CDATA[pc88multi2]]></dc:creator>\n";
#print "<content:encoded><![CDATA[<!-- wp:paragraph -->\n".$contents."<!-- /wp:paragraph -->]]></content:encoded>\n";
print "<content:encoded><![CDATA[".$contents."]]></content:encoded>\n";
print "</item>\n";

このtest.pl は単体ファイルに対してのみ実行されるので、対象ファイル群に対して実行するために下記の別スクリプトを用意して実行した。

echo '<?xml version="1.0" encoding="UTF-8" ?>' > wordpress.xml
echo '<rss version="2.0" xmlns:excerpt="http://wordpress.org/export/1.2/excerpt/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"  xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:wp="http://wordpress.org/export/1.2/" >' >> wordpress.xml

echo '<channel><wp:wxr_version>1.2</wp:wxr_version>' >> wordpress.xml
echo '<wp:author></wp:author>' >> wordpress.xml

for file in `find retoge-mag.hatenablog.com/entry/* -name \*.html`
do echo --- $file ---
        ./test.pl $file >> wordpress.xml
done

echo '</channel>' >> wordpress.xml
echo '</rss>' >> wordpress.xml

こうして出力されたwordpress.xmlをWordpressにてインポートすることで取り込みは完了した。

なお、画像ファイルについてはXMLへどうかけばいいのかが分からなかったため、ローカルにコピーした際のURLをそのまま利用し、Wordpress管理下には置かなかった。


2021/11/30追記

この手法で取り込むとWordpress上は「クラシック」形式での状態となっていた。

各記事で「ブロックへ変換」を行ったあと

各画像でを選択し「↑」ボタンをクリックすると画像がWordpress管理下にあるwp-contentsディレクトリ内にダウンロードされ、Wordpressで管理できるようになった。

画像

Oracle Cloudで人に仮想マシンを作ってもらうための準備

Oracle CloudのFree Tierで仮想マシン作りたいけど、誰かに最初の設定をお任せしたい、という時の手順。

超絶に簡易的なもので、セキュリティ関連を考慮しない、全権限を渡してしまうタイプの手順になっていますので注意。

その1: Oracle Cloudにアカウントを作る

Oracle公式の「チュートリアル – Oracle Cloud Infrastructure を使ってみよう」を参照しながら実施します。

その2: Oracle Cloudの管理画面にログインする

2023年に管理画面のURL は https://cloud.oracle.com/ に統一されました

また、2023年後半から2段階認証が必須となり、FIDOデバイス連携もしくはモバイルアプリ(Oracle Mobile Authenticator でなくとも、 Microsoft AuthenticatorGoogle Authenticator でも大丈夫です。)を登録する必要がありますので、準備してください。

その3:ユーザー管理画面を開く

2024年3月版手順

「アイデンティティとセキュリティ」の「ドメイン」を開きます。

表示されるドメインから「Default」を選択します。(Defaultがない場合は、”コンパートメント”から(ルート)となっているものを選択します)

Defaultドメインでは「ユーザー」を選択します

開くと現在登録されているユーザー一覧が表示されます。

その4: ユーザー追加

「ユーザーの作成」をクリックして、下記の画面で「名前」としてログインする際に入力するユーザの名前を指定します。

説明はユーザを区別しやすくするためのものを入れて、最後にユーザー作成メールが届くメールアドレスを入力します。

作成すると下記のようなユーザー画面に移動します

電子メールのところが「検証保留中」となっています。

「ユーザーのパスワード作成/リセット」を選択します

ここで「パスワードの作成/リセット」をクリックすると下記の画面になります。

このパスワードは、認証する際に必要となります。ユーザ作成時に指定したメールアドレスのユーザに何らかの手段で伝えてください。

その5: ユーザー権限の追加

「ユーザーをグループに追加」を選択し、「Administrators」を選び、追加します

これでそのユーザに全ての権限を割り当てています。

なので、仮想マシンの削除も出来てしまいます。作業が終わったあとの取り扱いに注意が必要です。

その6: 届いたユーザ側の手続き

指定したメールアドレスには下記の様なメールが届いています。

URLをクリックして、もらったユーザ名とパスワードを入力してログインします。

2024年3月版手順追加

仮パスワードから本パスワードに設定したあと、2段階認証の設定を要求されます。

Oracle Mobile Authenticator でなくとも、 Microsoft AuthenticatorGoogle Authenticator でも大丈夫です。

私は Microsoft Authenticator を使用しています。その場合は、「オフライン・モードまたは別のオーセンティケータ・アプリケーションを使用」にチェックを入れて、QRコードを読み込みます。

登録完了/作業開始

ユーザ登録が完了したら必要な作業をやっていきます。

作業完了後手順

作業が終わったら、ユーザーのグループにある「administrators」の登録を削除します。

各ユーザの「グループ」にあるAdministratorの前にあるチェックボックスにチェックを入れて「削除」をクリックします。

「メンバーの削除」を選択すると下記の様にグループになにも表示されない状態となります。

この状態であればログインは出来るけど、作業はなにもできません。

そこから、さらにユーザーの削除を行う場合は「他のアクション」から「削除」を選択します。

これでログインもできなくなりました。

なお、この手順で削除されるのはOracle Cloudの管理画面だけで、別途wordpressなどの管理画面アクセスについてはそちらの設定で削除する必要がある点に注意してください。

SteamDeck疑似環境の構築方法

(2022/08/04追記:一番後ろに、SteamDeck用LinuxのSteam OSとそれを他機種でも使えるように細工したものの紹介を追加)

Steam Deckという手持ちゲーミング端末がリリースされる予定になっている。

現状は一部の開発者向けに実機の提供が行われているが、それ以外のPCでもSteam Deckで使われるManjaro Linux OSをインストールすることで検証ができるように公式の手順が公開されていた。

Developing for Steam Deck without a Dev-Kit

書いてある内容を要約すると・・・

ハードウェア構成

本体:MINISFORUM Elite Mini UM700 (日本代理店 Linksの製品紹介)の Ryzen 7 3750H 搭載モデル

AmazonのMINIFORUM直販より、日本代理店Links直販が安い場合も・・・


ディスプレイ:7インチで1280*800のカーナビ液晶を流用しているものを適当に調達

コントローラ: PS4コントローラかPS5コントローラが最適。XBOXやスイッチ用も使えなくは無いが、トラックパッドがないためフル機能が使えないことに注意。

以前売ってたSteam純正コントローラについては触れられてない・・・

OS設定について

Manjaro LinuxのKDE Plasmaエディションをインストールする。

注:実際にはGPD Pocketでインストールしてみたが、画面キャプチャが面倒だったので、以降の手順は仮想環境で行ったもので代用している。

インストーラで起動すると、下記の様に表示される

環境に合わせて「tz(タイムゾーン)」「keytable(キーボード配列)」「lang(表示言語)」を選び、「Boot with ~」を選ぶ。どっちがいいかは環境による?

しばらく待つとKDEデスクトップが表示される。

この状態でsteam導入もできなくはないのだが、起動ごとに毎回設定がやり直しになるので推奨しない。(OSアップデートがあると警告が表示されたりするが、再起動すると消えるので毎回表示される)

内蔵ディスクや、さらに別途用意したUSBメモリなどへインストールをした方が良い。

インストールはデスクトップ上の「Install Manjaro Linux」をクリックして、インストーラを進めていく。

標準では「スワップを使用しない」が設定されているが、どちらの方がいいんだろうか?(使用しないで進めた)

ゲーミング用途なら、パスワードなしの自動ログイン想定かなぁ?と

インストールを開始します。

…?

FAT32パーテーションを作成した後のLinuxパーテーション作成に失敗している?

パーテーション容量を最大サイズから少し減らしたらインストールが始まった・・・(パーテーション設定のキャプチャなし)

インストール完了

内蔵ディスクから起動しているのでデスクトップ上にInstallのアイコンが消えています。

つづいて、steamのセットアップを実施

左下の「m」メニューから「ゲーム」の「Steam (Runtime)」を選択するか

デスクトップ上で右クリックメニューにある「Show KRunnner」を選択

表示されるウィンドウに「steam」と入力して「アプリケーション Steam(Runtime)」を選択します。

そうするとデスクトップ上に「Steam (Runtime)」アイコンが追加され、Steam setupが開始されます。

セットアップではいろいろダウンロードが行われていきます。

いろいろ処理しているウィンドウが表示されなくなったらダウンロードが終わりなようで、改めてデスクトップ上の「Steam (Runtime)」をクリックすると、Steamのログイン画面が表示されます。

steamにログインすると、まあ、普通に表示されます。

最初に「Steam」の「Settings」を開きます。

「Interface」のlanguageを「日本語(Japanese)」に変更

「Steam Play」の「Enable Steam Play for all other titles」にチェックを入れて、Windowsエミュレーション機能を有効にします。

この設定でいろんなゲームがインストール可能な状態となります。

インストールを選ぶと選択したゲームの他に「Proton(Windowsエミュレーション機能)」と「Steamworks Common Redistributables」のダウンロードが始まります。

ダウンロードが終わり「プレイ」を選択します。

そうすると、「プラットフォーム互換ツールを使用して、このゲームをSteam Playで起動します」というメッセージが表示されます。

ゲームによっては起動前に Microsoft VC Redist Packageインストールなどの処理も実行されます。

やっかいな事に、こういった共有ライブラリが必須であるにも関わらず、特に設定されていないゲームの場合は、プレイボタンを押しても開始に失敗してしまいます。(そういうゲームで起動失敗した場合は何も表示されず、ただゲーム一覧のプレイボタンが再度押せるように戻っていることで察する、という感じ)

なお、仮想環境上での検証は下記の様な感じでDirectX11が上手く動かずに失敗となりました。

GPD Pocket 1で実験した所、FF3は実用的な速度で動作

A列車でいこう9は、かなり遅いものの動く

ライザのアトリエについては、タイトル画面までは出たものの、それ以後の画面は表示できず、という状態でした。


2022/08/04追記

SteamOSとその類似OS

Steam公式にある「自分だけのSteam Machineを組み立てる」はDebian 8ベースの古いSteam OSを使った説明

SteamOS 2.195 リリースノート(2019/07/18)

SteamDeck用のSteamOS 3.xはリカバリイメージとしての提供となっており「Steam Deckリカバリー手順」から入手可能

SteamOS 3.2リリースノート(2022/05/27)
SteamOS 3.3リリースノート(2022/08/03)

Steam Deckリカバリイメージは8GBのUSBメモリに書き込む形式のものとなっているが、vSphere環境上で起動してみようとしたが、うまくいかなかった。

Steam OSのバグについては https://github.com/ValveSoftware/SteamOS/issues から行える。

Steam Deckの内部構造について「Steam Deck Guide」にまとまっている。また、SteamOS相当の機能を他機種でも使えるようにしたLinuxについても紹介されている。

HoloISO

公式: https://github.com/theVakhovskeIsTaken/holoiso

Steam OS 3.xと同じArch Linuxをベースに作られているもの。

SteamDeckと同じAMD系GPUだけではなく、Intel UHD 630+ iGPUや、NVIDIA GTX 9xx GPUでも動く

Nobara Project

公式: https://gitlab.com/GloriousEggroll/nobara-images

こちらはFedora をベースにSteam OS的な機能を盛り込んだもの

ISO生成スクリプトを配布しているだけであるため、ISOファイルをつくるのは別のFedora OSが起動しているサーバで必要なパッケージをインストールした上でスクリプトを実行する必要がある。

winesapOS

公式: https://github.com/LukeShortCloud/winesapOS

USBメモリで起動して使うことを想定したもので、Intel Macでの動作もするらしい。

PlayStation4でLinuxを起動するプロジェクトと組んでPS4上でSteamゲームで遊ぶなんてこともできるらしい。→「WinesapOS 3, based on SteamOS 3 for PS4 with Mesa 22.0.3: PS4 Distro Release

USBメモリから起動する、というあたりはBatocera Linux を使っているようだ

Firewall内のCentOSからhttps://mirror.centos.org/にアクセスできなかった件

FortigateによるFirewall内にあるCentOS9サーバから「dnf check-update」を実行してみたところ、失敗した。

[root@centos9 ~]# dnf update
サブスクリプション管理リポジトリーを更新しています。
コンシューマー識別子を読み込めません

このシステムは、エンタイトルメントサーバーに登録されていません。subscription-manager で登録できます。

CentOS Stream 9 - BaseOS                        0.0  B/s |   0  B     00:03
Errors during downloading metadata for repository 'baseos':
  - Curl error (60): SSL peer certificate or SSH remote key was not OK for https://mirrors.centos.org/metalink?repo=centos-baseos-9-stream&arch=x86_64&protocol=https,http [SSL certificate problem: self-signed certificate in certificate chain]
エラー: repo 'baseos' のメタデータのダウンロードに失敗しました : Cannot prepare internal mirrorlist: Curl error (60): SSL peer certificate or SSH remote key was not OK for https://mirrors.centos.org/metalink?repo=centos-baseos-9-stream&arch=x86_64&protocol=https,http [SSL certificate problem: self-signed certificate in certificate chain]
[root@centos9 ~]#

内容的には https://mirrors.centos.org/ へのアクセスでエラーになっていたので、curlコマンドで状況を確認してみることにした。

[root@centos9 ~]# curl -vvv https://mirrors.centos.org/publiclist/
*   Trying 13.125.120.8:443...
* Connected to mirrors.centos.org (13.125.120.8) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
*  CAfile: /etc/pki/tls/certs/ca-bundle.crt
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS header, Certificate Status (22):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS header, Finished (20):
* TLSv1.2 (IN), TLS header, Unknown (23):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.2 (IN), TLS header, Unknown (23):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (OUT), TLS header, Unknown (21):
* TLSv1.3 (OUT), TLS alert, unknown CA (560):
* SSL certificate problem: self-signed certificate in certificate chain
* Closing connection 0
curl: (60) SSL certificate problem: self-signed certificate in certificate chain
More details here: https://curl.se/docs/sslcerts.html

curl failed to verify the legitimacy of the server and therefore could not
establish a secure connection to it. To learn more about this situation and
how to fix it, please visit the web page mentioned above.
[root@centos9 ~]#

同じ環境にあるCentOS7サーバやOracle Linux8サーバでも同じ結果になった。

他の環境にあるCentOS7サーバで実行してみると下記のような感じになった。

-bash-4.2$ curl -vvv https://mirrors.centos.org/publiclist/
* About to connect() to mirrors.centos.org port 443 (#0)
*   Trying 2620:52:3:1:dead:beef:cafe:fed6...
* Connected to mirrors.centos.org (2620:52:3:1:dead:beef:cafe:fed6) port 443 (#0)
* Initializing NSS with certpath: sql:/etc/pki/nssdb
*   CAfile: /etc/pki/tls/certs/ca-bundle.crt
  CApath: none
* SSL connection using TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256
* Server certificate:
*       subject: CN=mirrors.centos.org
*       start date: 10月 19 06:06:54 2021 GMT
*       expire date:  1月 17 06:06:53 2022 GMT
*       common name: mirrors.centos.org
*       issuer: CN=R3,O=Let's Encrypt,C=US
> GET /publiclist/ HTTP/1.1
> User-Agent: curl/7.29.0
> Host: mirrors.centos.org
> Accept: */*
>
< HTTP/1.1 302 Found
< Date: Fri, 12 Nov 2021 08:44:59 GMT
< Server: Apache
< X-Frame-Options: SAMEORIGIN
< X-Xss-Protection: 1; mode=block
< X-Content-Type-Options: nosniff
< Referrer-Policy: same-origin
< Location: https://admin.fedoraproject.org/mirrormanager/
< Content-Length: 299
< Content-Type: text/html; charset=iso-8859-1
<
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>302 Found</title>
</head><body>
<h1>Found</h1>
<p>The document has moved <a href="https://admin.fedoraproject.org/mirrormanager/">here</a>.</p>
<hr>
<address>Apache Server at mirrors.centos.org Port 443</address>
</body></html>
* Connection #0 to host mirrors.centos.org left intact
-bash-4.2$

Let’s Encryptの証明書使ってるな、ということで、同じ環境にあるブラウザからアクセスしてみると、Fortigateによるhttps周りの動作の問題であることが判明

解決方法は「FortiGate環境で”This Connection is Invalid. SSL certificate expired.”を食らった」にあるやつと同じでした。

ONTAP 9.xでntpやDNSの動作確認

NetApp ONTAP 9.x環境でNTPやDNSの設定をした際に、正常に動作しているかを確認する手法

(2022/08/12追記 「ONTAP 9.x環境でActive DirectoryとNISとでユーザ名マッピングを行わせた場合の確認手法」)

NTPの設定確認

NTP設定がされているかどうかを「cluster time-service ntp server show」で確認

::> cluster time-service ntp server show
                                        Is
                                        Authentication
Server                         Version  Enabled        Key ID
------------------------------ -------  -------------- ------
10.20.8.10                     auto     false          -

::>

NTPの動作確認

指定したNTPサーバと同期が取れているかは、adminモードでは確認出来ない。

advancedかdiagモードに切り替えて「cluster time-service ntp status show」を実行して確認。(注:ONTAPバージョンが9.1とかの古いものだと存在しない)

::> set adv

Warning: These advanced commands are potentially dangerous; use them only when
         directed to do so by NetApp personnel.
Do you want to continue? {y|n}: y

::*> cluster time-service ntp status show

Node: netapp_02
Server                  Reachable  Selection State                Offset (ms)
----------------------- ---------  ------------------------------ ------------
10.20.8.10                   true  Currently Selected Server            21.552

Node: netapp_02
Server                  Reachable  Selection State                Offset (ms)
----------------------- ---------  ------------------------------ ------------
10.20.8.10                   true  Currently Selected Server             21.68
2 entries were displayed.

::*>

上記の様に「Reachable:true」となっていればNTPサーバと通信が取れている。

下記の様に「Reachable:false」となっている場合は接続が取れないか、リトライ中である。

::*> cluster time-service ntp status show

Node: netapp_01
Server                  Reachable  Selection State                Offset (ms)
----------------------- ---------  ------------------------------ ------------
10.20.8.10                  false  Server Not Responding or Too              0
                                   Distant

Node: netapp_02
Server                  Reachable  Selection State                Offset (ms)
----------------------- ---------  ------------------------------ ------------
10.20.8.10                  false  Server Not Responding or Too              0
                                   Distant
2 entries were displayed.

::*>

なお、-insオプションを付けると詳細が確認出来る。

::*> cluster time-service ntp status show -ins

                                      Node: netapp_01
NTP Server Host Name, IPv4 or IPv6 Address: 10.20.8.10
                         Server IP Address: 10.20.8.10
Is Peer Reachable and Responding to Polls?: true
         Is Peer Selected as Clock Source?: true
                 State of Server Selection: sys_peer
     Description of Server Selection State: Currently Selected Server
                      Poll Interval (secs): 64
                Time from Last Poll (secs): 9
              Offset from Server Time (ms): -16.61
                 Delay Time to Server (ms): 0.395
                 Maximum Offset Error (ms): 20.946
                    Reachability of Server: 1f
                   Stratum of Server Clock: 2
                 Reference Clock at Server: 133.243.238.163
           Reported Packet and Peer Errors: -

                                      Node: netapp_02
NTP Server Host Name, IPv4 or IPv6 Address: 10.20.8.10
                         Server IP Address: 10.20.8.10
Is Peer Reachable and Responding to Polls?: true
         Is Peer Selected as Clock Source?: true
                 State of Server Selection: sys_peer
     Description of Server Selection State: Currently Selected Server
                      Poll Interval (secs): 64
                Time from Last Poll (secs): 14
              Offset from Server Time (ms): 6.623
                 Delay Time to Server (ms): 0.398
                 Maximum Offset Error (ms): 17.906
                    Reachability of Server: 1f
                   Stratum of Server Clock: 2
                 Reference Clock at Server: 133.243.238.163
           Reported Packet and Peer Errors: -
2 entries were displayed.

::*>

“Stratum of Server Clock”と”Reference Clock at Server”の値が見えてればだいたい大丈夫でしょう。(ちなみに上記の 133.243.238.163 は ntp.nict.jp / ntp.nict.go.jp を構成するIPアドレスの1つです)

diagモードにしてsystemshellが使える状態であれば「systemshell -node local -command “sudo ntpq -pn”」を実行することで各ノードごとで動作しているntpdの状態を取得することもできます。

ontap91::*> systemshell -node local -command "sudo ntpq -pn"
  (system node systemshell)
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 xxx.xx.xx.xxx   133.243.238.164  2 u   33   64    1    0.489   29.541   2.335

ontap91::*>

“Error: command failed: Error: Account currently locked. Contact the storage administrator to unlock it.”と出力される場合は「security login show -username diag」を実行してdiagユーザ「Acct Locked」状態を確認し、「security login unlock -username diag」でロック解除することで実行できるようになります。(詳細→「NetApp ONTAPから他サーバに気軽にsshできる穴がふさがれてしまった」)

DNSの設定確認

DNSに関する設定は「vserver services name-service dns show」を実行する。

ontap98::> vserver services name-service dns show
                                                    Name
Vserver         Domains                             Servers
--------------- ----------------------------------- ----------------
ontap98         adosakana.local                   172.17.44.49
share225        adosakana.local                  172.17.44.49
share228        adosakana.local                  172.17.44.49
3 entries were displayed.

ontap98::>

Active Directoryに参加している場合は、DNSの自動更新に関する設定も重要なので「vserver services name-service dns dynamic-update show」で確認する。

ontap98::> vserver services name-service dns dynamic-update show
Vserver         Is-Enabled Use-Secure Vserver FQDN             TTL
--------------- ---------- ---------- ------------------------ -------
share225        true       false      adosakana.local    24h
share228        false      false      -                        24h
2 entries were displayed.

ontap98::>

上記例では、Storage VM:share225ではDNS自動更新を有効にしている、ということになる。

/etc/hosts ファイルに相当する固定の名前解決を行っているかは「vserver services name-service dns hosts show」で確認する。

注意が必要なのは、「NetAppのクラスタ管理」と「各Storage VM」でそれぞれ別の設定になっているということ。これを勘違いしているとうまく名前解決が実施できない。

ネットワークインタフェースとルーティングの設定も関係してくるので「network interface show」と「network route show」も確認すると良い。

DNSの動作確認

DNSサーバに接続ができているかは「vserver services name-service dns check -vserver SVM名 -ins」で確認出来る。

ontap98::> vserver services name-service dns check  -vserver ontap98 -ins

           Vserver: ontap98
       Name Server: 172.17.44.49
Name Server Status: up
    Status Details: Response time (msec): 1

ontap98::>

上記はStorageVM:ontap98 に対して確認を実施した結果となり、「Name Server status:up」で「Response time(msec)」の値があるのでDNSサーバ応答があった、ということになる。

指定したホスト名が名前解決できるかはadvancedモード/diagモードが必須となる。

コマンドは「vserver services name-service getxxbyyy getaddrinfo -vserver SVM名 -hostname 解決したいホスト名」か「vserver services name-service getxxbyyy gethostbyname -vserver SVM名 -hostname 解決したいホスト名」となる。

ontap98::> set advanced

Warning: These advanced commands are potentially dangerous; use them only when directed to do so by NetApp personnel.
Do you want to continue? {y|n}: y

ontap98::*>vserver services name-service getxxbyyy getaddrinfo -vserver ontap98 -hostname adserver
Host name: adserver
Canonical Name: adserver.adosakana.local
IPv4: 172.17.44.49


ontap98::*>

IPアドレスの逆引きは 「vserver services name-service getxxbyyy getnameinfo -vserver SVM名 -ipaddress IPアドレス」 か 「vserver services name-service getxxbyyy getnameinfo -vserver SVM名 -ipaddress IPアドレス 」 となる

ontap98::*> vserver services name-service getxxbyyy gethostbyaddr -vserver ontap98 -ipaddress 172.17.44.49
IP address: 172.17.44.49
Host name: adserver.adosakana.local


ontap98::*>

Active Directory関連

SVMのCIFSが動いてるかどうか確認

netapp9101::> vserver cifs show
            Server          Status    Domain/Workgroup Authentication
Vserver     Name            Admin     Name             Style
----------- --------------- --------- ---------------- --------------
svm0        SVM0            up        ADOSAKANA              domain

netapp9101::>

Active Directoryへの接続確認

netapp9101::> vserver cifs check -vserver svm0

                              Vserver : svm0
                    Cifs NetBIOS Name : SVM0
                          Cifs Status : Running
                                 Site : Default-First-Site-Name

Node Name       DC Server Name  DC Server IP    Status   Status Details
--------------- --------------  --------------- ------   --------------
netapp9101-01   adosakana.local   172.17.44.49    up       Response time (msec): 51

netapp9101::>

クライアントからアクセスがあった後に確認できるようになる情報

クライアントから共有にアクセスがあったあとに表示されるようになる情報群

どのActive Directoryサーバに接続してるか

netapp9101::> vserver active-directory discovered-servers show

Node: netapp9101-01
Vserver: svm0

Domain Name     Type     Preference DC-Name         DC-Address      Status
--------------- -------- ---------- --------------- --------------- ---------
adosakana.local   MS-LDAP  adequate   adserver      172.17.44.49    OK
adosakana.local   MS-DC    adequate   adserver      172.17.44.49    OK
2 entries were displayed.

netapp9101::>
netapp9101::> vserver active-directory discovered-servers show

Node: netapp9101-01
Vserver: svm0

Domain Name     Type     Preference DC-Name         DC-Address      Status
--------------- -------- ---------- --------------- --------------- ---------
adosakana.local   KERBEROS favored    adserver      172.17.44.49    undetermined
adosakana.local   MS-LDAP  favored    adserver      172.17.44.49    undetermined
adosakana.local   MS-DC    favored    adserver      172.17.44.49    OK
3 entries were displayed.

netapp9101::>

接続しにきたクライアントをどのLIFで受けたのか

netapp9101::> vserver cifs connection show

Node:    netapp9101-01
Vserver: svm0
Connection Session                               Workstation
ID         IDs                   Workstation IP  Port        LIF IP
---------- --------------------- --------------- ----------- ---------------
936674349  3075958545494048785   172.17.44.170   61391       172.17.44.56

netapp9101::>