さくら VPS のローカルネットワークに接続するインターフェイスを Ubuntu 20.04 で設定する

さくら VPS には同一リージョンの複数サーバーを仮想スイッチングハブに接続することでプライベートネットワークを構築することができます。今回は Ubuntu 20.04 をセットアップした時の設定のメモです。 いつもは OS アップグレードしていたので気づかなかったですが、最近の Ubuntu はネットワークインターフェース設定が netplan というユーティリティに標準は置き換わっています。そのため、その設定の紹介になります。 ローカルネットワークの構築設定 さくら VPS のコントロールパネルで、スイッチを追加して、各サーバーのネットワーク接続画面でそれぞれ追加したスイッチに接続させます。(なお、現状はサーバーはシャットダウンしておかないとこの適用できません。) インターフェースを確認 $ ip addr show でネットワークインターフェースを確認します。 2: ens3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 52:54:12:00:XX:XX brd ff:ff:ff:ff:ff:ff inet 153.120.xx.xxx/23 brd 153.120.xx.255 scope global ens3 valid_lft forever preferred_lft forever inet6 2401:2500:102:2b03:xxx:xxx:xx:xxx/64 scope global valid_lft forever preferred_lft forever inet6 fe80::5054:12ff:fe00:xxxx/64 scope link valid_lft forever preferred_lft forever 3: ens4: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 52:54:12:00:XX:XX brd ff:ff:ff:ff:ff:ff 4: ens5: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN group default qlen 1000 link/ether 52:54:12:00:XX:XX brd ff:ff:ff:ff:ff:ff 今回は ens で始まる物理インターフェイスの2番目の ens4 をスイッチに接続したものとしてセットアップします。 ...

2020年11月14日 · Toshimitsu Takahashi

さくら VPS の Ubuntu 18.04 で LUKS によるディスク暗号化をするには

さくら VPS は、AWS LightSail のようにディスクの暗号化をサービス側でしているという情報がありませんでした。昨今のハードディスク廃棄問題も気になるところで、あまり漏れたくない情報を保存したいのでディスクをまるごと(/boot は除く)暗号化してみます。 Ubuntu 18.04 のインストール コントロールパネルから カスタムOSインストール Ubuntu 18.04 を行います。 途中の「Partition disks」で Guided - use entire disk and set up encrypted lvm を選択します。そしてパスフレーズを設定します。 OS セットアップ後 VPSのコントロールパネルで緑の起動ボタンをクリックして、さらにコンソールボタンメニューのシリアルコンソールも即座に開いておきます。 シリアルコンソール画面がパスフレーズ入力で止まるので、ここで先ほどのパスフレーズを入力して起動させます。 暗号化状態の確認 # cryptsetup status /dev/mapper/vda5_crypt /dev/mapper/vda5_crypt is active and is in use. type: LUKS1 cipher: aes-xts-plain64 keysize: 512 bits key location: dm-crypt device: /dev/vda5 sector size: 512 offset: 4096 sectors size: 208207872 sectors mode: read/write flags: discards 起動時のアンロック設定 現状は起動時にパスフレーズを入力するしかありません。ここにさらに別途鍵ファイルをbootパーティション内に追加して自動起動するようにします。 ここからは Debian/Ubuntuで暗号化 LVM を使いつつ自動起動する - @znz blog の受け売りが大半です。大変参考になりました。ありがとうございます。 ...

2020年2月2日 · Toshimitsu Takahashi

Ubuntu で RAM ディスクを設定して docker をオンメモリで動かすには

自分は Windows PC ホスト内で VirtualBox で Ubuntu 系 Linux Mint を起動しているのですが、docker のコンテナやボリュームデータをまるごとオンメモリで高速に動作させたいと思い、RAMディスクを設定して載せるようにしました。RAM ディスクだと OS をシャットダウンすると消えてしまいますが、Docker の場合、古いコンテナのデータがどんどん溜まっていくために掃除できて開発上好都合でもあります。 RAMディスクの設定 まずパス /ramdisk をマウントポイントとして RAM ディスクを設定することにします。 マウントポイントの作成 ディレクトリを作成して、スティッキービットを付けて誰でも書き込み可能にします。 $ sudo mkdir /ramdisk $ sudo chmod 1777 /ramdisk /etc/fstab の設定 /etc/fstab に下記を追記します。 tmpfs /ramdisk tmpfs defaults 0 0 一旦、OSを再起動します。(fstab に設定しなくても一時的には mount コマンドで対応することも可能) Docker のコンテナとボリュームを置き場を設定 以下の設定中は Docker を停止しておきます。 /ramdisk にディレクトリを作る $ sudo mkdir -p /ramdisk/docker/containers $ sudo mkdir -p /ramdisk/docker/volumes シンボリックを張る /var/lib/docker の containers, volumes が /ramdisk/docker を見るようにします。 $ sudo -i # cd /var/lib/docker # mv containers containers.old # mv volumes volumes.old # ln -s /ramdisk/docker/containers # ln -s /ramdisk/docker/volumes 動作確認 Docker を起動して、適当なコンテナを走らせて、 /ramdisk/docker 内にファイルが作られることを確認します。 ...

2019年9月5日 · Toshimitsu Takahashi

Ubuntu の Nginx に対して Let's Encrypt の certbot を設定するには

昔は SSL 証明書は購入することが必要でしたが、最近は Let’s Encrypt が普及したことで無料で https 対応できるようになりました。 ただこの証明書は有効期間が短いため、適切に設定しておかないとすぐに期限切れになってしまいます。 これは、 certbot を使って Ubuntu の Nginx の指定ドメインに対してセットアップするときの忘備録です。 certbot のリポジトリ追加とインストール $ sudo add-apt-repository ppa:certbot/certbot $ sudo apt-get update $ sudo apt-get install python-certbot-nginx 指定したドメインに certbot を設定する $ sudo certbot --nginx -d yourdomain.com 実行すると、下記のとおり出力されます。 途中訊かれるのは http のリクエストを https にリダイレクトするかどうかです。 Saving debug log to /var/log/letsencrypt/letsencrypt.log Plugins selected: Authenticator nginx, Installer nginx Obtaining a new certificate Performing the following challenges: http-01 challenge for yourdomain.com Waiting for verification... Cleaning up challenges Deploying Certificate to VirtualHost /etc/nginx/sites-enabled/yourdomain.com Please choose whether or not to redirect HTTP traffic to HTTPS, removing HTTP access. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1: No redirect - Make no further changes to the webserver configuration. 2: Redirect - Make all requests redirect to secure HTTPS access. Choose this for new sites, or if you're confident your site works on HTTPS. You can undo this change by editing your web server's configuration. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Select the appropriate number [1-2] then [enter] (press 'c' to cancel): 2 Redirecting all traffic on port 80 to ssl in /etc/nginx/sites-enabled/yourdomain.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Congratulations! You have successfully enabled https://yourdomain.com You should test your configuration at: https://www.ssllabs.com/ssltest/analyze.html?d=yourdomain.com - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - IMPORTANT NOTES: - Congratulations! Your certificate and chain have been saved at: /etc/letsencrypt/live/yourdomain.com/fullchain.pem Your key file has been saved at: /etc/letsencrypt/live/yourdomain.com/privkey.pem Your cert will expire on 2019-07-07. To obtain a new or tweaked version of this certificate in the future, simply run certbot again with the "certonly" option. To non-interactively renew *all* of your certificates, run "certbot renew" - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le 外部からの SSL 設定の確認 上記の You should test your configuration at: にある通り、 ブラウザで https://www.ssllabs.com/ssltest/analyze.html?d=_yourdomain.com_ を開いて適切かどうか確認しましょう。 ...

2019年4月8日 · Toshimitsu Takahashi

Ubuntu で Unicorn で動かす Redmine を 2.6 にアップデートしたときのメモ

RMagickに必要なパッケージインストール RMagick系のパッケージが要るといわれたので入れておく。 # apt-get install graphicsmagick-libmagick-dev-compat libmagickcore-dev libmagickwand-dev 新しい Redmine の展開 新しい Redmine のパッケージをダウンロードして展開する。 前の場所から以下のファイルをコピーする。 Gemfile.local config.ru config/unicorn.rb config/configuration.yml config/database.yml 以下のディレクトリ内のファイルを移動する。 plugins files public/themes お約束の手順 $ bundle install --path vendor/bundler $ rake generate_secret_token $ RAILS_ENV=production rake db:migrate $ rake db:migrate:upgrade_plugin_migrations RAILS_ENV=production $ rake db:migrate_plugins RAILS_ENV=production $ rake tmp:cache:clear $ rake tmp:sessions:clear 起動 $ bundle exec unicorn_rails -D -E production -c $APP_ROOT/config/unicorn.rb

2014年10月28日 · Toshimitsu Takahashi

Apache SSL だったものを Nginx をフロントにおいてリバースプロキシ化したときの設定

さくらの VPS (Ubuntu) で Apache に 80 (http), 443 (https) で Listen させていました。バーチャルホストでいくつかのドメインをこれで処理していましたが、フロントに Nginx を置いて必要な処理だけ Apache にすることにしました。 そこで SSL を Nginx で動かすにあたって、リバースプロキシ下でも Redmine など https 設定で動くように設定したときのメモです。 SSL証明書、秘密鍵の設定 Apache の /etc/apache2/ssl.crt/server.crt と ca-bundle.crt を Nginx の /etc/nginx/ssl/cert.pem に移す $ cd /etc/apache2/ssl.crt # cat server.crt ca-bundle.crt > /etc/nginx/ssl/cert.pem ※CA証明書を別にできないのでサーバ証明書に追記する。 Apache の /etc/apache2/ssl.key/server.key を Nginx の /etc/nginx/ssl/server.key にコピー $ cp /etc/apache2/ssl.key/server.key /etc/nginx/ssl/cert.key Nginx の設定 Apache は 8080 (http) ポートで動かす。Nginx の 443 (https) をそこにリバースプロキシする。 # HTTPS server # server { listen 443; server_name www.example.com; access_log off; ssl on; ssl_certificate ssl/cert.pem; ssl\_certificate\_key ssl/cert.key; ssl\_session\_timeout 5m; ssl_protocols SSLv2 SSLv3 TLSv1; ssl_ciphers HIGH:!aNULL:!MD5; ssl\_prefer\_server_ciphers on; location / { proxy_redirect off; proxy\_set\_header Host $host; proxy\_set\_header X-Real-IP $remote_addr; proxy\_set\_header X-Forwarded-Proto https; proxy\_set\_header X-Forwarded-Host $host; proxy\_set\_header X-Forwarded-Server $host; proxy\_set\_header X-Forwarded-For $proxy\_add\_x\_forwarded\_for; proxy_pass http://127.0.0.1:8080/; } } proxy_set_header でいくつかのヘッダを Apache に渡すことで https 設定の Redmine などが動くようになる。

2011年12月31日 · Toshimitsu Takahashi

Node.js と npm を Ubuntu にセットアップ

Ubuntu を 11.04 に上げたが、apt-get で入る node.js が 0.2.x だったので、ソースからコンパイルしてインストールすることにした。 当初 github からチェックアウトして 0.5.x で試していたが、最終的に express が未対応だったので、安定板をダウンロードして入れることにした。 さらに node.js のパッケージ管理ツール npm もインストールする。 node.js インストール node.js をインストール。 必要パッケージの準備 コンパイル、ビルド、依存ライブラリのインストール $ sudo apt-get update $ sudo apt-get install gcc $ sudo apt-get install libssl-dev $ sudo apt-get install build-essential opensslをコンパイル時に参照できるようにパッケージを設定 $ sudo pkg-config openssl –cflags –libs -lssl -lcrypto 最近のバージョンでは $ sudo apt-get install libcurl4-openssl-dev を行うとよいようだ(2012/3/30 追記)。 ダウンロードからビルド・インストール http://nodejs.org/#download から安定板の 0.4.12 を落としてビルドインストール。 $ wget http://nodejs.org/dist/node-v0.4.12.tar.gz $ tar zxvf node-v0.4.12.tar.gz $ cd node-v0.4.12 $ ./configure $ make $ sudo make install ...

2011年9月23日 · Toshimitsu Takahashi