検証用 Ubuntu22.04.1LTS 作成手順メモ (2022/08/30 版)
以前に 自分用・検証用 Ubuntu22.04LTS Beta 作成手順メモ(2022/03/24 版) というメモを書きました。 現時点では Ubuntu 22.04.1LTS までリリースされていますので、改めて検証用 Ubuntu の作成手順をメモにしておきます。 ほぼ過去メモと同じ内容ですが、インストールするソフトウェアのバージョンなどを微修正しています。
Ubuntu の ISO イメージ¶
Ubuntu の ISO イメージは IIJ が公開しているページ からダウンロードします。 今回は ubuntu-22.04.1-live-server-amd64.iso を利用しました。
仮想マシンのスペック¶
今回、作成する仮想マシンのスペックは以下としました。 デフォルトでは LVM が利用されますが、ストレージを 10GB 以上にすると / にマウントされるのが (最大サイズでは無く) 10GB しか割り当てられません。 今回は / に最大サイズを割り当てたい為、インストール中に調整します。
| 項目 | 値 |
|---|---|
| vCPU | 2 |
| Memory | 4GB |
| Storage | 20GB |
インストールイメージは以下を利用しました。 releases.ubuntu.com からダウンロードしようとするとエラーになった為、後者の IIJ からダウンロードしました。
- https://releases.ubuntu.com/22.04/ubuntu-22.04.1-live-server-amd64.iso
- http://ftp.iij.ad.jp/pub/linux/ubuntu/releases/22.04.1/ubuntu-22.04.1-live-server-amd64.iso
インストール¶
Step.1 Willkommen! Bienvenue! Welcome! Добро пожаловать! Welkom¶
言語を選択します。 English を選択して次へ進みます。
Willkommen! Bienvenue! Welcome! Добро пожаловать! Welkom! [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Use UP, DOWN and ENTER keys to select your language.
[ Asturianu ▸ ]▴
[ Bahasa Indonesia ▸ ]█
[ Català ▸ ]
[ Deutsch ▸ ]
[ English ▸ ]
[ English (UK) ▸ ]
[ Español ▸ ]
[ Français ▸ ]
[ Galego ▸ ]
[ Hrvatski ▸ ]
[ Latviski ▸ ]
[ Lietuviškai ▸ ]
[ Magyar ▸ ]
[ Nederlands ▸ ]
[ Norsk bokmål ▸ ]
[ Occitan (aprèp 1500) ▸ ]▾
[ Back ]
Step.2 Keyboard configuration¶
キーボードの設定を行います。 Layout と Variant は両方 English (US) を選択して次に進みます。
Keyboard configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Please select the layout of the keyboard directly attached to the system, if
any.
Layout: [ English (US) ▾ ]
Variant: [ English (US) ▾ ]
[ Done ]
[ Back ]
Step.3 Choose type of install¶
インストール種別を選択します。 Ubuntu Server を選択して次へ進みます。
Choose type of install [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Choose the base for the installation.
(X) Ubuntu Server
The default install contains a curated set of packages that provide a
comfortable experience for operating your server.
( ) Ubuntu Server (minimized)
This version has been customized to have a small runtime footprint in
environments where humans are not expected to log in.
[ Done ]
Step.4 Network connections¶
ネットワーク設定を行います。 環境に合わせて設定したら次へ進みます。
Network connections [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Configure at least one interface this server can use to talk to other
machines, and which preferably provides sufficient access for updates.
NAME TYPE NOTES
[ ens160 eth - ▸ ]
DHCPv4 10.0.0.100/24
00:50:56:12:34:56 / VMware / VMXNET3 Ethernet Controller
[ Create bond ▸ ]
[ Done ]
[ Back ]
Step.5 Configure proxy¶
Proxy の設定を行います。 Proxy は利用しない想定なので空欄のまま、次へ進みます。
Configure proxy [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
If this system requires a proxy to connect to the internet, enter its
details here.
Proxy address:
If you need to use a HTTP proxy to access the outside world,
enter the proxy information here. Otherwise, leave this
blank.
The proxy information should be given in the standard form
of "http://[[user][:pass]@]host[:port]/".
[ Done ]
[ Back ]
Step.6 Configure Ubuntu archive mirror¶
ミラーの URL を指定します。 http://jp.archive.ubuntu.com/ubuntu のままで次へ進みます。
Configure Ubuntu archive mirror [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
If you use an alternative mirror for Ubuntu, enter its details here.
Mirror address: http://jp.archive.ubuntu.com/ubuntu
You may provide an archive mirror that will be used instead
of the default.
[ Done ]
[ Back ]
Step.7 Guided storage configuration¶
デフォルトでは LVM が利用されるのですが、10GB を超える領域はパーティションに割り当てられません (未使用になります)。 その為、Custom storage layout を選択して次へ進みたいのですが、ゼロから設定するのは面倒なので一度、Use an entire disk のままで次に進み、すぐに Back します。
Guided storage configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Configure a guided storage layout, or create a custom one:
(X) Use an entire disk
[ /dev/sda local disk 20.000G ▾ ]
[X] Set up this disk as an LVM group
[ ] Encrypt the LVM group with LUKS
Passphrase:
Confirm passphrase:
( ) Custom storage layout
[ Done ]
[ Back ]
画面が戻ったら、次は Custom storage layout にチェックを入れ、次へ進みます。
Guided storage configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Configure a guided storage layout, or create a custom one:
( ) Use an entire disk
[ /dev/sda local disk 20.000G ▾ ]
[X] Set up this disk as an LVM group
[ ] Encrypt the LVM group with LUKS
Passphrase:
Confirm passphrase:
(X) Custom storage layout
[ Done ]
[ Back ]
Step.8 Storage configuration¶
以下のように表示されました。 LVM の Volume Group (ubuntu-vg には 18.5GB 程度の割当があるのに / には 10GB しか割り当てられていないことが分かります。
Storage configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
FILE SYSTEM SUMMARY ▴
█
MOUNT POINT SIZE TYPE DEVICE TYPE █
[ / 10.000G new ext4 new LVM logical volume ▸ ] █
[ /boot 1.500G new ext4 new partition of local disk ▸ ] █
█
█
AVAILABLE DEVICES █
█
DEVICE TYPE SIZE
[ ubuntu-vg (new) LVM volume group 18.496G ▸ ]
free space 8.496G ▸
[ Create software RAID (md) ▸ ]
[ Create volume group (LVM) ▸ ]
▾
[ Done ]
[ Reset ]
[ Back ]
ubuntu-lv から Edit を選択します。
Storage configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
[ Create software RAID (md) ▸ ] ▴
[ Create volume group (LVM) ▸ ]
USED DEVICES
DEVICE TYPE SIZE
[ ubuntu-vg (new) LVM volume group 1┌────────────┐
ubuntu-lv new, to be formatted as ext4, mounted at / 1│◂ (close) │
│ Edit ▸│
[ /dev/sda local disk 2│ Delete ▸│
partition 1 new, BIOS grub spacer └────────────┘
partition 2 new, to be formatted as ext4, mounted at 1.500G ▸
/boot
partition 3 new, PV of LVM volume group ubuntu-vg 18.497G ▸ █
▾
[ Done ]
[ Reset ]
[ Back ]
以下のように表示されます。
Storage configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
┌───────────── Editing logical volume ubuntu-lv of ubuntu-vg ────────────┐
│ │
│ Name: ubuntu-lv │
│ │
│ │
│ Size (max 18.496G): 10.000G │
│ │
│ │
│ Format: [ ext4 ▾ ] │
│ │
│ │
│ Mount: [ / ▾ ] │
│ │
│ │
│ [ Save ] │
│ [ Cancel ] │
│ │
└────────────────────────────────────────────────────────────────────────┘
サイズを最大である 18.496G まで拡張したら Save を選択します。
Storage configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
┌───────────── Editing logical volume ubuntu-lv of ubuntu-vg ────────────┐
│ │
│ Name: ubuntu-lv │
│ │
│ │
│ Size (max 18.496G): 18.496G │
│ │
│ │
│ Format: [ ext4 ▾ ] │
│ │
│ │
│ Mount: [ / ▾ ] │
│ │
│ │
│ [ Save ] │
│ [ Cancel ] │
│ │
└────────────────────────────────────────────────────────────────────────┘
これで / に 18.496GB 割り当てられました。 Done を選択します。
Storage configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
FILE SYSTEM SUMMARY ▴
█
MOUNT POINT SIZE TYPE DEVICE TYPE █
[ / 18.496G new ext4 new LVM logical volume ▸ ] █
[ /boot 1.500G new ext4 new partition of local disk ▸ ] █
█
█
AVAILABLE DEVICES █
█
No available devices
[ Create software RAID (md) ▸ ]
[ Create volume group (LVM) ▸ ]
USED DEVICES ▾
[ Done ]
[ Reset ]
[ Back ]
「続行して良いか?」を確認されますので Continue を選択して次へ進みます。
Storage configuration [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
[ Create software RAID (md) ▸ ] ▴
[ Create volume group (LVM) ▸ ]
┌────────────────────── Confirm destructive action ──────────────────────┐
│ │
│ Selecting Continue below will begin the installation process and │
│ result in the loss of data on the disks selected to be formatted. │
│ │
│ You will not be able to return to this or a previous screen once the │
│ installation has started. │
│ │
│ Are you sure you want to continue? │
│ │
│ [ No ] │
│ [ Continue ] │
│ │
└────────────────────────────────────────────────────────────────────────┘
[ Reset ]
[ Back ]
Step.9 Profile setup¶
追加するユーザのプロファイル情報を入力します。 スキップ出来ず、しかも全項目入力必須なようです。
Profile setup [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Enter the username and password you will use to log in to the system. You
can configure SSH access on the next screen but a password is still needed
for sudo.
Your name:
Your server's name:
The name it uses when it talks to other computers.
Pick a username:
Choose a password:
Confirm your password:
[ Done ]
今回は以下のように入力しました。 入力が完了したら Done を選択して続行します。
Profile setup [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
Enter the username and password you will use to log in to the system. You
can configure SSH access on the next screen but a password is still needed
for sudo.
Your name: user
Your server's name: localhost
The name it uses when it talks to other computers.
Pick a username: user
Choose a password: ********
Confirm your password: ********
[ Done ]
Step.10 SSH Setup¶
「OpenSSH サーバをインストールするか?」確認されます。 インストールしないと SSH ログイン出来なくなってしまう為、Install OpenSSH server にチェックを入れて次へ進みます。
SSH Setup [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
You can choose to install the OpenSSH server package to enable secure remote
access to your server.
[ ] Install OpenSSH server
Import SSH identity: [ No ▾ ]
You can import your SSH keys from GitHub or Launchpad.
Import Username:
[X] Allow password authentication over SSH
[ Done ]
[ Back ]
Step.11 Featured Server Snaps¶
インストールするソフトウェアを選択します。 必要なものは・必要になった時点でインストールするのでここでは何も選択せず、次へ進みます。
Featured Server Snaps [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
These are popular snaps in server environments. Select or deselect with
SPACE, press ENTER to see more details of the package, publisher and
versions available.
[ ] microk8s Kubernetes for workstations and appliances ▸▴
[ ] nextcloud Nextcloud Server - A safe home for all your data ▸█
[ ] wekan The open-source kanban ▸█
[ ] kata-containers Build lightweight VMs that seamlessly plug into t ▸█
[ ] docker Docker container runtime ▸█
[ ] canonical-livepatch Canonical Livepatch Client ▸█
[ ] rocketchat-server Rocket.Chat server ▸█
[ ] mosquitto Eclipse Mosquitto MQTT broker ▸
[ ] etcd Resilient key-value store by CoreOS ▸
[ ] powershell PowerShell for every system! ▸
[ ] stress-ng tool to load and stress a computer ▸
[ ] sabnzbd SABnzbd ▸
[ ] wormhole get things from one computer to another, safely ▸▾
[ Done ]
[ Back ]
Step.12 Installing system¶
インストールが開始されます。 インストールが完了するまで暫く待機します。
Installing system [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
┌──────────────────────────────────────────────────────────────────────────┐
│ running 'curtin curthooks' ▴│
│ curtin command curthooks │
│ configuring apt configuring apt │
│ installing missing packages │
│ configuring iscsi service │
│ configuring raid (mdadm) service │
│ installing kernel │
│ setting up swap │
│ apply networking config │
│ writing etc/fstab │
│ configuring multipath │
│ updating packages on target system │
│ configuring pollinate user-agent on target │
│ updating initramfs configuration │
│ configuring target system bootloader - █│
│ installing grub to target devices - ▾│
└──────────────────────────────────────────────────────────────────────────┘
[ View full log ]
インストールが完了後、ネットワークに接続されている場合はアップデートが開始されます。 なぜか毎回、このアップデートが完了しない (時間がかかる?) 為、Cancel update and reboot を選択して再起動します。
Install complete! [ Help ]
▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
┌──────────────────────────────────────────────────────────────────────────┐
│ configuring pollinate user-agent on target ▴│
│ updating initramfs configuration │
│ configuring target system bootloader │
│ installing grub to target devices │
│ finalizing installation │
│ running 'curtin hook' │
│ curtin command hook │
│ executing late commands │
│final system configuration │
│ configuring cloud-init │
│ calculating extra packages to install │
│ installing openssh-server │
│ curtin command system-install │
│ downloading and installing security updates █│
│ curtin command in-target | ▾│
└──────────────────────────────────────────────────────────────────────────┘
[ View full log ]
[ Cancel update and reboot ]
標準ユーザで SSH ログインする¶
追加パッケージをインストールしなくても open-vm-tools がインストールされる為、vSphere 上から作成した仮想マシンの IP アドレスが分かるはずです。 この IP アドレスに対して、インストール中に作成したユーザで SSH ログインします。
$ ssh user@10.0.0.100
Warning: Permanently added '10.0.0.100' (ECDSA) to the list of known hosts.
user@10.0.0.100's password:
Welcome to Ubuntu Jammy Jellyfish (development branch) (GNU/Linux 5.15.0-25-generic x86_64)
(snip)
user@localhost:~$
以降の作業を実施する為に root ユーザになっておきます。
sshd の設定変更 (自動切断の防止 / root ログインの許可)¶
sshd で自動切断されるのを防ぐ為、ClientAliveInterval や ClientAliveCountMax を設定します。 これらの値は以下の意味を持ちます。
| 項目 | 意味 | デフォルト値 |
|---|---|---|
| ClientAliveInterval | 指定した秒数ごとに応答確認を行う間隔 (※ 0 の場合は何もしない) | 0 |
| ClientAliveCountMax | 応答確認を行う回数 | 3 |
これらの値をチューニングしつつ、root ユーザでの SSH ログインを許可しておきます。 設定が完了したら sshd を再起動しておきます。
sed -i -e "s/#ClientAliveInterval 0/ClientAliveInterval 60/g" /etc/ssh/sshd_config && \
sed -i -e "s/#ClientAliveCountMax 3/ClientAliveCountMax 5/g" /etc/ssh/sshd_config && \
sed -i -e "s/#PermitRootLogin prohibit-password/PermitRootLogin yes/g" /etc/ssh/sshd_config && \
systemctl restart sshd.service
sshd の設定確認には sshd -T を実行します。
root のパスワードを設定する¶
root ユーザのパスワードを変更しておきます。 パスワードは自身の環境に合わせて任意で設定します。
パスワード変更後は root ユーザを指定し、パスワード認証による SSH ログインが出来ることを確認しておきます。 以降の作業は (標準ユーザはログアウトし) root ユーザで継続します。
root ユーザの公開鍵を登録する¶
root ユーザへ鍵を使って SSH ログイン出来るよう、公開鍵を登録しておきます。 鍵の登録が終わったら、実際に鍵を使って (パスワードを入力せずに) SSH ログイン出来ることを確認します。
標準ユーザを削除する¶
一般的にはセキュリティの観点から推奨されませんが、「標準ユーザは不要」「検証環境なので全て root で作業する」と割り切れるのであれば、インストール中に作成した標準ユーザを削除します。
AppArmor を無効化する¶
AppArmor は RedHat 系で言うところの SELinux に近いセキュリティ機構です。 デフォルトでは有効化されている為、無効化しておきます。
システム全体のアップデート¶
システム全体のアップデートを実行します。 カーネルの更新などがある場合を考慮し、アップデート後は OS を再起動します。
SSH 接続時の警告時を表示しない¶
別のホストへ SSH 接続する際、警告が表示されないように設定しておきます。 また Unable to negotiate with 192.168.1.1 port 22: no matching key exchange method found. Their offer: diffie-hellman-group1-sha1 等のエラーを回避する為に、必要な鍵交換アルゴリズムを追加しておきます。
cat << EOF > /etc/ssh/ssh_config.d/99_lab.conf
Ciphers aes128-cbc,aes256-ctr
HostkeyAlgorithms +ssh-rsa
KexAlgorithms +diffie-hellman-group1-sha1
StrictHostKeyChecking no
UserKnownHostsFile=/dev/null
EOF
タイムゾーンを Asia/Tokyo に設定する¶
タイムゾーンを Asia/Tokyo に設定しておきます。 設定が完了したら date や timedatectl status でタイムゾーンが Asia/Tokyo へ変更されたことを確認しておきます。
NTP の時刻同期先サーバを設定する¶
NTP サーバは time.cloudflare.com のご紹介 で言及されている CloudFlare の NTP サーバを設定します。
cat << EOF >> /etc/systemd/timesyncd.conf
NTP=162.159.200.123 162.159.200.1
EOF
systemctl restart systemd-timesyncd.service
NTP サーバとの時刻同期状態は timedatectl timesync-status で確認出来ます。
プロンプト表示をカスタマイズする¶
RedHat / Ubuntu でシェルのプロンプト表示をカスタマイズする というメモを書きましたが、root ユーザのプロンプト表示と今後、新規作成されるユーザ用の設定を実施しておきます。
cat << 'EOF' >> ~/.bashrc
# Modify the prompt.
if [ `id -u` = 0 ]; then
PS1="[\[\033[1;31m\]\u@\h\[\033[00m\] \W]\\$ "
else
PS1="[\[\033[1;36m\]\u@\h\[\033[00m\] \W]\\$ "
fi
EOF
cat << 'EOF' >> /etc/skel/.bashrc
# Modify the prompt.
if [ `id -u` = 0 ]; then
PS1="[\[\033[1;31m\]\u@\h\[\033[00m\] \W]\\$ "
else
PS1="[\[\033[1;36m\]\u@\h\[\033[00m\] \W]\\$ "
fi
EOF
Welcome メッセージを表示しない¶
Ubuntu 21.04 で Welcome メッセージを表示しない というメモを書きましたが、Ubuntu へ SSH ログインした際に表示される Welcome メッセージを表示されないように設定しておきます。
コンソールの有効化¶
コンソールを有効化します。 /etc/default/grub を以下のように変更します。
変更前 (コメント除外版)¶
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT=""
GRUB_CMDLINE_LINUX=""
変更後¶
GRUB_DEFAULT=0
GRUB_TIMEOUT_STYLE=hidden
GRUB_TIMEOUT=0
GRUB_DISTRIBUTOR=`lsb_release -i -s 2> /dev/null || echo Debian`
GRUB_CMDLINE_LINUX_DEFAULT="console=ttyS0,115200n8"
GRUB_CMDLINE_LINUX=""
変更が完了したら update-grub を実行して GRUB を更新しておきます。
アドレス変更用スクリプトを配置する¶
IP アドレスとゲートウェイ設定を変更するスクリプトを /usr/local/bin/chaddr へ配置します。
cat << EOF > /usr/local/bin/chaddr
#!/usr/bin/env python3
import argparse
import subprocess
import textwrap
parser = argparse.ArgumentParser()
parser.add_argument('-a', '--address', required=True)
parser.add_argument('-g', '--gateway', required=True)
args = parser.parse_args()
hostname = args.address.replace('.', '-')
subprocess.call('hostnamectl set-hostname ' + hostname, shell=True)
netplan = textwrap.dedent('''
network:
ethernets:
ens160:
dhcp4: false
dhcp6: false
addresses: [{arg1}/24]
gateway4: {arg2}
nameservers:
addresses: [1.1.1.1, 1.0.0.1]
version: 2
''').format(arg1=args.address, arg2=args.gateway).strip()
with open('/etc/netplan/99_config.yaml', 'w') as f:
f.write(netplan)
hosts = textwrap.dedent('''
127.0.0.1 localhost {arg1}
127.0.1.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet {arg1}
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
''').format(arg1=hostname).strip()
with open('/etc/hosts', 'w') as f:
f.write(hosts)
EOF
chmod 755 /usr/local/bin/chaddr
パッケージのインストール¶
パッケージをインストールしておきます。
基本的なパッケージ¶
基本的なパッケージをインストールしておきます。
pip と venv¶
Ubuntu 22.04.1LST には現時点で python が無く、python3 として Python 3.10.6 がインストールされていました。
# python --version
Command 'python' not found, did you mean:
command 'python3' from deb python3
command 'python' from deb python-is-python3
# python3 --version
Python 3.10.6
しかし、pip と venv が無い為、インストールしておきます。
direnv¶
Python の venv 環境を direnv で自動的に有効/無効化する というメモを書きましたが、Python で venv を利用しているのであれば direnv が便利です。
curl -L https://github.com/direnv/direnv/releases/download/v2.32.1/direnv.linux-amd64 -o /usr/local/bin/direnv && \
chmod 755 /usr/local/bin/direnv
~/.bashrc にフックして direnv を起動する設定を追加しておきます。
uncmnt¶
コメントを除外することが出来るツールです。 GitHub の sig9org/uncmnt からインストールしておきます。
curl -L https://github.com/sig9org/uncmnt/releases/download/v0.0.2/uncmnt_v0.0.2_linux_amd64 -o /usr/local/bin/uncmnt && \
chmod 755 /usr/local/bin/uncmnt
docker¶
docker インストール後は「停止している」ものの「自動起動する」設定になっていました。 念の為、「起動」「自動起動」両方の設定を実施しておきます。
apt update && \
apt -y install apt-transport-https ca-certificates curl software-properties-common && \
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - && \
add-apt-repository -y "deb [arch=amd64] https://download.docker.com/linux/ubuntu jammy stable" && \
apt update && \
apt -y install docker-ce && \
systemctl start docker.service && \
systemctl enable docker.service
docker compose¶
mkdir -p /usr/local/lib/docker/cli-plugins/ && \
curl -SL https://github.com/docker/compose/releases/download/v2.4.1/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose && \
chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
docker purge¶
全コンテナを停止・削除する docker サブコマンド「docker purge」 というメモを書きました。 docker コンテナを一度に停止することが出来るので GitHub の sig9org/docker-purge からインストールしておきます。
mkdir -p /usr/local/lib/docker/cli-plugins/ && \
curl -SL \
https://github.com/sig9org/docker-purge/releases/download/v0.0.1/docker-purge_v0.0.1_linux_amd64 \
-o /usr/local/lib/docker/cli-plugins/docker-purge && \
chmod +x /usr/local/lib/docker/cli-plugins/docker-purge
キャッシュ / コマンド実行履歴を削除して仮想マシンを停止する¶
apt のキャッシュとコマンド実行履歴を削除しておきます。 ここまで完了したら仮想マシンを電源オフします。
VM から DVD メディアを取り出しておく¶
テンプレート化する前に仮想マシンの光学ドライブからインストールに利用した DVD メディアを取り出しておきます。
テンプレート化する¶
ここまで用意が出来たら仮想マシンをテンプレート化します。 以降、検証用の仮想マシンを作成したい場合はこのテンプレートから複製します。