WSL2でSystemdを使用する方法
対象プロダクト:Windows 11
カテゴリー:仮想化技術
Note自動では有効化されないため、以下の手順で手動で有効にする必要があります。
WSL のバージョンは PowerShell(ターミナル)から以下のコマンドで確認できます。
wsl --version
例)
>wsl --version WSL バージョン: 1.2.5.0 カーネル バージョン: 5.15.90.1 WSLg バージョン: 1.0.51 MSRDC バージョン: 1.2.3770 Direct3D バージョン: 1.608.2-61064218 DXCore バージョン: 10.0.25131.1002-220531-1700.rs-onecore-base2-hyp Windows バージョン: 10.0.22621.1992
もし、0.67.6 未満なら WSL をアップデートしましょう。
wsl --update
バージョンが 0.67.6 以上なら、Ubuntu にログインして、/etc/wsl.conf を開きます。
$ sudo vi /etc/wsl.conf
そして以下を追記します。
[boot] systemd=true
最後に WSL を再起動ます。
wsl --shutdown
WSL の Ubuntu にログインして Systemd で Apache2 を自動起動に設定し、自動起動されることを確認してください。
$ sudo systemctl enable apache2
例)
$ sudo systemctl status apache2 ● apache2.service - The Apache HTTP Server Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2023-07-27 08:28:35 JST; 1min 54s ago Docs: https://httpd.apache.org/docs/2.4/ Process: 154 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS) Main PID: 253 (apache2) Tasks: 6 (limit: 4694) Memory: 28.9M CGroup: /system.slice/apache2.service ├─253 /usr/sbin/apache2 -k start ├─301 /usr/sbin/apache2 -k start ├─303 /usr/sbin/apache2 -k start ├─304 /usr/sbin/apache2 -k start ├─305 /usr/sbin/apache2 -k start └─306 /usr/sbin/apache2 -k start 7月 27 08:28:34 h670-win-p systemd[1]: Starting The Apache HTTP Server... 7月 27 08:28:35 h670-win-p systemd[1]: Started The Apache HTTP Server.
以上、WSL2でSystemdを使用する方法でした。
公開日時:2023年07月27日 08:08:09
最終更新日時:2023年07月27日 11:27:00