投稿日:	
Ubuntu22.04 LTSのターミナルのレンダリングが異常に重いのでバージョンを落として運用するためのメモ
Node.jsの開発環境だけ入れる
環境
| 環境 | Version | 
|---|---|
| Windows 11 Pro | Build 22621.3155 | 
| Ubuntu | 20.04.6 LTS | 
| zsh | 5.8 (x86_64-ubuntu-linux-gnu) | 
| MariaDB | Ver 15.1 Distrib 10.3.38-MariaDB | 
| Docker | 20.10.17, build 100c701 | 
| Git | 2.42.0 | 
WSL2の構成
- 管理者権限のPowerShellで以下を流す
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart - OS再起動
 - Linuxカーネル更新プログラム パッケージをインストールする
 - Ubuntuを入れる
 
Ubuntu側のセットアップ
適当な開発環境をサクッと。
~/.ssh/には予め鍵を入れておき、パーミッション700で作っておく。
# systemdの有効化
cat <<EOF | sudo tee /etc/wsl.conf
[boot]
command=service docker start; service nginx start; service mysql start;
[interop]
appendWindowsPath = false
[user]
default=ここにユーザー名
EOF
sudo apt update -y
sudo apt upgrade -y
sudo apt install -y \
    zsh \
    ssh \
    net-tools \
    traceroute \
    unzip \
    mariadb-server \
    nginx \
    git \
    keychain
# chsh
sudo apt -y install unzip traceroute
chsh -s $(which zsh)
# Docker
sudo apt remove docker docker-engine docker.io containerd runc
sudo apt update
# 依存関係のインストール
sudo apt install -y \
   apt-transport-https \
   ca-certificates \
   curl \
   gnupg \
   lsb-release
# Docker公式のGPG鍵を追加
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
# リポジトリをパッケージマネージャーに登録
echo \
  "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt update
# docker本体のインストール
sudo apt install -y dockerdocker-ce docker-ce-cli containerd.io docker-compose-plugin
# sudo緩和
sudo usermod -aG docker $USER
# WSLをリブート
# dot file設定
git clone https://github.com/Lycolia/my-dotfiles.git
rm -Rf my-dotfiles/.git/
mv my-dotfiles/.* .
rm -Rf my-dotfiles/
# Node.js @ nvm
export NVM_DIR="$HOME/.nvm" && (
  git clone https://github.com/nvm-sh/nvm.git "$NVM_DIR"
  cd "$NVM_DIR"
  git checkout `git describe --abbrev=0 --tags --match "v[0-9]*" $(git rev-list --tags --max-count=1)`
) && \. "$NVM_DIR/nvm.sh"
nvm install --lts
# Keychain設定
cat <<'EOF' | tee -a ~/.zshrc
Keychain
keychain -q --nogui $HOME/.ssh/id_ed25519
source $HOME/.keychain/hostname-sh
EOF
トラブルシューティング
上記手順に書いてないことをすると起きるが、一応付記しておく
<3>WSL (639) ERROR: CreateProcessEntryCommon:345: getpwnam(USER_NAME) failed 0というエラーが出る
wsl.confの[user]セクションでdefault=USER_NAMEが存在しないユーザーを指定していると出る
Dockerやnginxのサービスが起動しない
systemdが有効になっていると起動しないので/etc/wsl.confからsystemd=trueを消す
keychainがError: Problem adding; giving upという
パーミッションを治す
chmod -R 700 .ssh
		
投稿日:	
フルスクラッチで組むやつ
確認環境
| Env | Ver | 
|---|---|
| Ubuntu | 20.04.4 LTS | 
| nginx | 1.18.0 (Ubuntu) | 
| MariaDB | 15.1 Distrib 10.3.34-MariaDB | 
| grafana-server | Version 9.2.5 (commit: 042e4d216b, branch: HEAD) | 
前提
- Windows側から
http://grafana.test/としてアクセスする - DBにはMariaDBを使用
 
hostsの編集
Windows側のhostsに以下を追記
127.0.0.1 grafana.test
各種環境のインストール
sudo apt update
sudo apt install -y nginx mariadb-server
sudo apt-get install -y apt-transport-https software-properties-common wget
sudo wget -q -O /usr/share/keyrings/grafana.key https://apt.grafana.com/gpg.key
echo "deb [signed-by=/usr/share/keyrings/grafana.key] https://apt.grafana.com stable main" | sudo tee -a /etc/apt/sources.list.d/grafana.list
sudo apt-get update
sudo apt-get install grafana
nginxの設定
cat <<'EOF' | sudo tee /etc/nginx/conf.d/granafa.conf
map $http_upgrade $connection_upgrade {
  default upgrade;
  '' close;
}
upstream grafana {
  server localhost:4000;
}
server {
  listen       80;
  server_name  grafana.test;
  access_log   /var/log/nginx/grafana.access.log;
  error_log    /var/log/nginx/grafana.error.log;
  location / {
    proxy_set_header Host $http_host;
    proxy_pass  http://grafana;
  }
  location /api/live/ {
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
    proxy_set_header Host $http_host;
    proxy_pass http://grafana;
  }
}
EOF
sudo service nginx start
MariaDBの設定
ユーザー作成
idとpwの部分は適当に変える
sudo service mysql start
sudo mysql
CREATE USER 'id'@'%' IDENTIFIED BY 'pw';
GRANT ALL PRIVILEGES ON *.* TO 'id'@'%' WITH GRANT OPTION;
quit
外部接続テスト
適当なRDBクライアントから繋げればOK
grafanaの設定
sudo nano /etc/grafana/grafana.iniで適当にいじる
# The http port  to use
http_port = 4000
# The public facing domain name used to access grafana from a browser
domain = grafana.test
sudo service grafana-server start- http://grafana.test/ へアクセス
- IDPW共に
adminが初期 
 - IDPW共に
 
DBの読み込み
- MariaDBに適当なDBとテーブルを作る
 - Grafanaにログインする
 - サイドバーから
Configuration-> Data sources - DBの情報を入れて接続
 - 後はよしなにやる