在 WSL2 Ubuntu 20.04 中配置数据库和大数据组件

WSL2 Ubuntu 20.04 并不是很稳定,又或者由于其它的原因需要重置子系统,已经安装配置好的应用又要重新安装配置,已经踩过的坑又要重新踩一遍。所以有了这篇作为总结和备忘,以后再重新配置直接抄作业就行,不用再重新 debug 已经被 debug 多次的问题。不过新系统每个应用都要重新配置毕竟不是长久之道,早点升级机器配置安装 CDH 之类的集成环境才是正解(现在的机器内存就这么几个 G 你还要装 CDH 它能装吗? 装不了,没这个能力知道吧 ╮(╯_╰)╭)。

WSL2 Ubuntu 重置

Windows - 设置 - 应用 - 应用和功能 - 应用列表 - Ubuntu on Windows - 高级设置 - 重置

WSL2 Ubuntu 移动到 D 盘

下载 LxRunOffline
查看子系统列表 LxRunOffline l:

1
Ubuntu

Ubuntu 从默认位置移动到 D:\Virtual Machines\WSL\Ubuntu

1
LxRunOffline m -n Ubuntu -d "D:\Virtual Machines\WSL\Ubuntu"

查看子系统安装位置验证是否迁移成功:

1
LxRunOffline di -n Ubuntu

设置默认 WSL2 子系统发行版

1
wsl --setdefault Ubuntu

apt 换源、更新、手动安装 ca-certificates

1
2
3
4
5
sudo vim /etc/apt/sources.list
sudo apt update && sudo apt upgrade
cd /tmp
wget http://ports.ubuntu.com/pool/main/c/ca-certificates/ca-certificates_20210119~20.04.2_all.deb
sudo dpkg -i ./ca-certificates_20210119~20.04.2_all.deb

SSH

1
2
ssh-keygen
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

/run/nologin 导致的 SSH 启动失败问题

sudo vim /etc/pam.d/sshd 注释掉 account required pam_nologin.so

配置 systemd

安装 daemonize : sudo apt install daemonize

安装 systemd:ubuntu-wsl2-systemd-script

解决 nsenter: cannot open /proc/10867/ns/time: No such file or directory 报错

nsenter: cannot open /proc/320/ns/time: No such file or directory

测试是否安装成功:systemctl

子系统内屏蔽 Windows 环境变量

新建 /etc/wsl.conf 文件并添加以下内容:

1
2
[interop]
appendWindowsPath = false

上述操作后无法执行 code . 来打开主系统的 VS Code, 所以需要把主系统 VS Code 的安装路径添加到子系统环境变量中:

1
2
## VS Code
PATH=$PATH:'/mnt/c/Program Files/Microsoft VS Code/bin'

重启子系统

Python 软连接、PIP 安装、pip 换源

1
2
3
sudo ln -s /usr/bin/python3.8 /usr/bin/python
sudo apt install python3-pip -y
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple

Conda 环境

1
2
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh
bash Miniconda3-latest-Linux-x86_64.sh

Jupyter 环境

PIP 安装 Jupyter:

1
pip install jupyterlab jupyterlab-language-pack-zh-CN jupyterlab-execute-time

Jupyter 环境变量:export PATH=$PATH:~/.local/bin
Jupyter 笔记本设置:

1
2
3
4
{"codeCellConfig":
{"autoClosingBrackets": false,},
"recordTiming": true
}

Java 环境

安装 Java 8 :sudo apt-get install openjdk-8-jdk
Java 环境变量:

1
2
3
4
5
## JAVA
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64
export JRE_HOME=${JAVA_HOME}/jre
export CLASSPATH=.:${JAVA_HOME}/lib:${JRE_HOME}/lib
export PATH=${JAVA_HOME}/bin:$PATH

MySQL

在 WSL2 Ubuntu 20.04 上安装 MySQL 并配置账户

SQL Server

在 Windows 中配置端口 1433 入站规则:打开 Windows 防火墙的端口以进行 TCP 访问

在 WSL2 Ubuntu 20.04 上安装 SQL Server 并用 Sqoop 将数据导入 HDFS

Hadoop

在 WSL2 Ubuntu 20.04 上安装 Hadoop 并写一个 WordCount

Spark

Apache Spark - Installation

1
2
3
4
5
6
## SPARK
export SPARK_HOME=/home/herman/apps/spark-3.2.1
export PATH=$PATH:$SPARK_HOME/bin
export PYSPARK_DRIVER_PYTHON=jupyter
export PYSPARK_PYTHON=python
export PYSPARK_DRIVER_PYTHON_OPTS='lab --no-browser'

Hive

在 WSL2 Ubuntu 20.04 上安装 Hive

Presto

在 WSL2 Ubuntu 20.04 上安装 Presto