aboutsummaryrefslogtreecommitdiffhomepage
path: root/public/posts/2022-10-28/setup-server-for-this-site
diff options
context:
space:
mode:
authornsfisis <nsfisis@gmail.com>2023-03-19 00:47:11 +0900
committernsfisis <nsfisis@gmail.com>2023-03-19 00:47:11 +0900
commit88b66f82aae2d7784002b07bfc7877932da3ec94 (patch)
tree4950a8f9f740715f2c56383309edab97df37a2f5 /public/posts/2022-10-28/setup-server-for-this-site
parent0e5fff11e9a455273dad77fc26796af03ddf08d3 (diff)
downloadblog.nsfisis.dev-88b66f82aae2d7784002b07bfc7877932da3ec94.tar.gz
blog.nsfisis.dev-88b66f82aae2d7784002b07bfc7877932da3ec94.tar.zst
blog.nsfisis.dev-88b66f82aae2d7784002b07bfc7877932da3ec94.zip
fix(content): fix XML notations
Diffstat (limited to 'public/posts/2022-10-28/setup-server-for-this-site')
-rw-r--r--public/posts/2022-10-28/setup-server-for-this-site/index.html198
1 files changed, 99 insertions, 99 deletions
diff --git a/public/posts/2022-10-28/setup-server-for-this-site/index.html b/public/posts/2022-10-28/setup-server-for-this-site/index.html
index ae78d67..63990bd 100644
--- a/public/posts/2022-10-28/setup-server-for-this-site/index.html
+++ b/public/posts/2022-10-28/setup-server-for-this-site/index.html
@@ -9,7 +9,7 @@
<meta name="keywords" content="備忘録">
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
<title>【備忘録】 このサイト用の VPS をセットアップしたときのメモ | REPL: Rest-Eat-Program Loop</title>
- <link rel="stylesheet" href="/style.css?h=48694677b43b77e5c45f25e6bfdebb41">
+ <link rel="stylesheet" href="/style.css?h=36f8a090080ebb76d78b17f1d93b3ba4">
<link rel="stylesheet" href="/hl.css?h=340e65ffd5c17713efc9107c06304f7b">
</head>
<body class="single">
@@ -53,106 +53,106 @@
</li>
</ol>
</section>
- <section id="section--_はじめに">
- <h2><a href="#section--_はじめに">はじめに</a></h2>
+ <section id="section--intro">
+ <h2><a href="#section--intro">はじめに</a></h2>
<p>
- これまでこの blog は GitHub Pages でホストしていたのだが、先日 VPS に移行した。そのときにおこなったサーバのセットアップ作業を書き残しておく。99 % 自分用の備忘録。別のベンダに移したりしたくなったら見に来る。
+ これまでこの blog は GitHub Pages でホストしていたのだが、先日 VPS に移行した。 そのときにおこなったサーバのセットアップ作業を書き残しておく。 99 % 自分用の備忘録。別のベンダに移したりしたくなったら見に来る。
</p>
<p>
- 未来の自分へ: 特に自動化してないので、せいぜい苦しんでくれ。
+ 未来の自分へ: 特に自動化してないので、せいぜい苦しんでくれ。
</p>
</section>
- <section id="section--_vps">
- <h2><a href="#section--_vps">VPS</a></h2>
+ <section id="section--vps">
+ <h2><a href="#section--vps">VPS</a></h2>
<p>
- <a href="https://vps.sakura.ad.jp/">さくらの VPS</a> の 2 GB プラン。そこまで真面目に選定していないので、困ったら移動するかも。
+ <a href="https://vps.sakura.ad.jp/">さくらの VPS</a> の 2 GB プラン。 そこまで真面目に選定していないので、困ったら移動するかも。
</p>
</section>
- <section id="section--_事前準備">
- <h2><a href="#section--_事前準備">事前準備</a></h2>
- <section id="section--_サーバのホスト名を決める">
- <h3><a href="#section--_サーバのホスト名を決める">サーバのホスト名を決める</a></h3>
+ <section id="section--preparation">
+ <h2><a href="#section--preparation">事前準備</a></h2>
+ <section id="section--preparation--hostname">
+ <h3><a href="#section--preparation--hostname">サーバのホスト名を決める</a></h3>
<p>
- モチベーションが上がるという効能がある。今回は藤原定家から取って ``teika&apos;&apos; にした。たいていいつも源氏物語の帖か小倉百人一首の歌人から選んでいる。
+ モチベーションが上がるという効能がある。今回は藤原定家から取って <code>teika</code> にした。 たいていいつも源氏物語の帖か小倉百人一首の歌人から選んでいる。
</p>
</section>
- <section id="section--_ssh_の鍵生成">
- <h3><a href="#section--_ssh_の鍵生成">SSH の鍵生成</a></h3>
+ <section id="section--preparation--ssh-key">
+ <h3><a href="#section--preparation--ssh-key">SSH の鍵生成</a></h3>
<p>
- ローカルマシンで鍵を生成する。
+ ローカルマシンで鍵を生成する。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/teika.key
- $ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/github2teika.key</code></pre>
+$ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/github2teika.key</code></pre>
<p>
- <code>teika.key</code> はローカルからサーバへの接続用、<code>github2teika.key</code> は、GitHub Actions からサーバへのデプロイ用。
+ <code>teika.key</code> はローカルからサーバへの接続用、<code>github2teika.key</code> は、GitHub Actions からサーバへのデプロイ用。
</p>
</section>
- <section id="section--_ssh_の設定">
- <h3><a href="#section--_ssh_の設定">SSH の設定</a></h3>
+ <section id="section--preparation--ssh-config">
+ <h3><a href="#section--preparation--ssh-config">SSH の設定</a></h3>
<p>
- <code>.ssh/config</code> に設定しておく。
+ <code>.ssh/config</code> に設定しておく。
</p>
<pre class="highlight" language="ssh_config" linenumbering="unnumbered"><code>Host teika
- HostName **********
- User **********
- Port **********
- IdentityFile ~/.ssh/teika.key</code></pre>
+HostName **********
+User **********
+Port **********
+IdentityFile ~/.ssh/teika.key</code></pre>
</section>
</section>
- <section id="section--_基本のセットアップ">
- <h2><a href="#section--_基本のセットアップ">基本のセットアップ</a></h2>
- <section id="section--_ssh_接続">
- <h3><a href="#section--_ssh_接続">SSH 接続</a></h3>
+ <section id="section--basic-setup">
+ <h2><a href="#section--basic-setup">基本のセットアップ</a></h2>
+ <section id="section--basic-setup--login">
+ <h3><a href="#section--basic-setup--login">SSH 接続</a></h3>
<p>
- VPS 契約時に設定した管理者ユーザとパスワードを使ってログインする。
+ VPS 契約時に設定した管理者ユーザとパスワードを使ってログインする。
</p>
</section>
- <section id="section--_ユーザを作成する">
- <h3><a href="#section--_ユーザを作成する">ユーザを作成する</a></h3>
+ <section id="section--basic-setup--user">
+ <h3><a href="#section--basic-setup--user">ユーザを作成する</a></h3>
<p>
- 管理者ユーザで作業すると危ないので、メインで使うユーザを作成する。<code>sudo</code> グループに追加して <code>sudo</code> できるようにし、<code>su</code> で切り替え。
+ 管理者ユーザで作業すると危ないので、メインで使うユーザを作成する。<code>sudo</code> グループに追加して <code>sudo</code> できるようにし、<code>su</code> で切り替え。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo adduser **********
- $ sudo adduser ********** sudo
- $ su **********
- $ cd</code></pre>
+$ sudo adduser ********** sudo
+$ su **********
+$ cd</code></pre>
</section>
- <section id="section--_ホスト名を変える">
- <h3><a href="#section--_ホスト名を変える">ホスト名を変える</a></h3>
+ <section id="section--basic-setup--hostname">
+ <h3><a href="#section--basic-setup--hostname">ホスト名を変える</a></h3>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo hostname teika</code></pre>
</section>
- <section id="section--_公開鍵を置く">
- <h3><a href="#section--_公開鍵を置く">公開鍵を置く</a></h3>
+ <section id="section--basic-setup--public-key">
+ <h3><a href="#section--basic-setup--public-key">公開鍵を置く</a></h3>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ mkdir ~/.ssh
- $ chmod 700 ~/.ssh
- $ vi ~/.ssh/authorized_keys</code></pre>
+$ chmod 700 ~/.ssh
+$ vi ~/.ssh/authorized_keys</code></pre>
<p>
- <code>authorized_keys</code> には、ローカルで生成した <code>~/.ssh/teika.key.pub</code> と <code>~/.ssh/github2teika.key.pub</code> の内容をコピーする。
+ <code>authorized_keys</code> には、ローカルで生成した <code>~/.ssh/teika.key.pub</code> と <code>~/.ssh/github2teika.key.pub</code> の内容をコピーする。
</p>
</section>
- <section id="section--_ssh_の設定_2">
- <h3><a href="#section--_ssh_の設定_2">SSH の設定</a></h3>
+ <section id="section--basic-setup--ssh-config">
+ <h3><a href="#section--basic-setup--ssh-config">SSH の設定</a></h3>
<p>
- SSH の設定を変更し、少しでも安全にしておく。
+ SSH の設定を変更し、少しでも安全にしておく。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
- $ sudo vi /etc/ssh/sshd_config</code></pre>
+$ sudo vi /etc/ssh/sshd_config</code></pre>
<ul>
<li>
@@ -169,56 +169,56 @@
</ul>
<p>
- そして設定を反映。
+ そして設定を反映。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo systemctl restart sshd
$ sudo systemctl status sshd</code></pre>
</section>
- <section id="section--_ssh_で接続確認">
- <h3><a href="#section--_ssh_で接続確認">SSH で接続確認</a></h3>
+ <section id="section--basic-setup--ssh-connect">
+ <h3><a href="#section--basic-setup--ssh-connect">SSH で接続確認</a></h3>
<p>
- 今の SSH セッションは閉じずに、ターミナルを別途開いて疎通確認する。セッションを閉じてしまうと、SSH の設定に不備があった場合に締め出しをくらう。
+ 今の SSH セッションは閉じずに、ターミナルを別途開いて疎通確認する。セッションを閉じてしまうと、SSH の設定に不備があった場合に締め出しをくらう。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ ssh teika</code></pre>
</section>
- <section id="section--_ポートの遮断">
- <h3><a href="#section--_ポートの遮断">ポートの遮断</a></h3>
+ <section id="section--basic-setup--close-ports">
+ <h3><a href="#section--basic-setup--close-ports">ポートの遮断</a></h3>
<p>
- デフォルトの 22 番を閉じ、設定したポートだけ空ける。
+ デフォルトの 22 番を閉じ、設定したポートだけ空ける。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo ufw deny ssh
- $ sudo ufw allow *******
- $ sudo ufw enable
- $ sudo ufw reload
- $ sudo ufw status</code></pre>
+$ sudo ufw allow *******
+$ sudo ufw enable
+$ sudo ufw reload
+$ sudo ufw status</code></pre>
<p>
- ここでもう一度 SSH の接続確認を挟む。
+ ここでもう一度 SSH の接続確認を挟む。
</p>
</section>
- <section id="section--_github_用の_ssh_鍵">
- <h3><a href="#section--_github_用の_ssh_鍵">GitHub 用の SSH 鍵</a></h3>
+ <section id="section--basic-setup--ssh-key-for-github">
+ <h3><a href="#section--basic-setup--ssh-key-for-github">GitHub 用の SSH 鍵</a></h3>
<p>
- GitHub に置いてある private リポジトリをサーバから clone したいので、SSH 鍵を生成して置いておく。
+ GitHub に置いてある private リポジトリをサーバから clone したいので、SSH 鍵を生成して置いておく。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ ssh-keygen -t ed25519 -b 521 -f ~/.ssh/github.key
$ cat ~/.ssh/github.key.pub</code></pre>
<p>
- <a href="https://github.com/settings/ssh">GitHub の設定画面</a> から、この公開鍵を追加する。
+ <a href="https://github.com/settings/ssh">GitHub の設定画面</a> から、この公開鍵を追加する。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ vi ~/.ssh/config</code></pre>
<p>
- 設定はこう。
+ 設定はこう。
</p>
<pre class="highlight" language="ssh_config" linenumbering="unnumbered"><code>Host github.com
@@ -227,77 +227,77 @@ User git
IdentityFile ~/.ssh/github.key</code></pre>
<p>
- 最後に接続できるか確認しておく。
+ 最後に接続できるか確認しておく。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>ssh -T github.com</code></pre>
</section>
- <section id="section--_パッケージの更新">
- <h3><a href="#section--_パッケージの更新">パッケージの更新</a></h3>
+ <section id="section--basic-setup--upgrade-packages">
+ <h3><a href="#section--basic-setup--upgrade-packages">パッケージの更新</a></h3>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo apt update
- $ sudo apt upgrade
- $ sudo apt update
- $ sudo apt upgrade
- $ sudo apt autoremove</code></pre>
+$ sudo apt upgrade
+$ sudo apt update
+$ sudo apt upgrade
+$ sudo apt autoremove</code></pre>
</section>
</section>
- <section id="section--_サイトホスティング用のセットアップ">
- <h2><a href="#section--_サイトホスティング用のセットアップ">サイトホスティング用のセットアップ</a></h2>
- <section id="section--_dns_に_ip_アドレスを登録する">
- <h3><a href="#section--_dns_に_ip_アドレスを登録する">DNS に IP アドレスを登録する</a></h3>
+ <section id="section--site-hosting-setup">
+ <h2><a href="#section--site-hosting-setup">サイトホスティング用のセットアップ</a></h2>
+ <section id="section--site-hosting-setup--dns">
+ <h3><a href="#section--site-hosting-setup--dns">DNS に IP アドレスを登録する</a></h3>
<p>
- このサーバは固定の IP アドレスがあるので、<code>A</code> レコードに直接入れるだけで済んだ。
+ このサーバは固定の IP アドレスがあるので、<code>A</code> レコードに直接入れるだけで済んだ。
</p>
</section>
- <section id="section--_使うソフトウェアのインストール">
- <h3><a href="#section--_使うソフトウェアのインストール">使うソフトウェアのインストール</a></h3>
+ <section id="section--site-hosting-setup--install-softwares">
+ <h3><a href="#section--site-hosting-setup--install-softwares">使うソフトウェアのインストール</a></h3>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo apt install docker docker-compose git make</code></pre>
</section>
- <section id="section--_メインユーザが_docker_を使えるように">
- <h3><a href="#section--_メインユーザが_docker_を使えるように">メインユーザが Docker を使えるように</a></h3>
+ <section id="section--site-hosting-setup--docker">
+ <h3><a href="#section--site-hosting-setup--docker">メインユーザが Docker を使えるように</a></h3>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>sudo adduser ********** docker</code></pre>
</section>
- <section id="section--_httphttps_を通す">
- <h3><a href="#section--_httphttps_を通す">HTTP/HTTPS を通す</a></h3>
+ <section id="section--site-hosting-setup--open-http-ports">
+ <h3><a href="#section--site-hosting-setup--open-http-ports">HTTP/HTTPS を通す</a></h3>
<p>
- 80 番と 443 番を空ける。
+ 80 番と 443 番を空ける。
</p>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ sudo ufw allow 80/tcp
- $ sudo ufw allow 443/tcp
- $ sudo ufw reload
- $ sudo ufw status</code></pre>
+$ sudo ufw allow 443/tcp
+$ sudo ufw reload
+$ sudo ufw status</code></pre>
</section>
- <section id="section--_リポジトリのクローン">
- <h3><a href="#section--_リポジトリのクローン">リポジトリのクローン</a></h3>
+ <section id="section--site-hosting-setup--clone-repositories">
+ <h3><a href="#section--site-hosting-setup--clone-repositories">リポジトリのクローン</a></h3>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ cd
- $ git clone git@github.com:nsfisis/nsfisis.dev.git
- $ cd nsfisis.dev
- $ git submodule update --init</code></pre>
+$ git clone git@github.com:nsfisis/nsfisis.dev.git
+$ cd nsfisis.dev
+$ git submodule update --init</code></pre>
</section>
- <section id="section--_certbot_で証明書取得">
- <h3><a href="#section--_certbot_で証明書取得">certbot で証明書取得</a></h3>
+ <section id="section--site-hosting-setup--certbot">
+ <h3><a href="#section--site-hosting-setup--certbot">certbot で証明書取得</a></h3>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ docker-compose up -d acme-challenge
- $ make setup</code></pre>
+$ make setup</code></pre>
</section>
- <section id="section--_サーバを稼動させる">
- <h3><a href="#section--_サーバを稼動させる">サーバを稼動させる</a></h3>
+ <section id="section--site-hosting-setup--run-server">
+ <h3><a href="#section--site-hosting-setup--run-server">サーバを稼動させる</a></h3>
<pre class="highlight" language="shell-session" linenumbering="unnumbered"><code>$ make serve</code></pre>
</section>
</section>
- <section id="section--_感想">
- <h2><a href="#section--_感想">感想</a></h2>
+ <section id="section--outro">
+ <h2><a href="#section--outro">感想</a></h2>
<p>
- (業務でなく) 個人だと数年ぶりのサーバセットアップで、これだけでも割と時間を食ってしまった。とはいえ式年遷宮は楽しいので、これからも定期的にやっていきたい。コンテナデプロイにしたい気持ちもあるのだが、色々実験したい関係上、本物のサーバも欲しくはある。次の式年遷宮では、手順の一部だけでも自動化したいところ。
+ (業務でなく) 個人だと数年ぶりのサーバセットアップで、これだけでも割と時間を食ってしまった。とはいえ式年遷宮は楽しいので、これからも定期的にやっていきたい。コンテナデプロイにしたい気持ちもあるのだが、色々実験したい関係上、本物のサーバも欲しくはある。次の式年遷宮では、手順の一部だけでも自動化したいところ。
</p>
</section>
</div>