初始化Linux系统

multipass 安装虚拟机命令

1
2
3
multipass launch --mem=2G --disk=20G --cpus=2 --name=master jammy
multipass launch --mem=2G --disk=20G --cpus=2 --name=work-1 jammy
multipass launch --mem=2G --disk=20G --cpus=2 --name=work-2 jammy

初始化虚拟机中的Linux系统

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
cat << EOF | sudo tee /etc/apt/sources.list >/dev/null && sudo apt update && sudo apt -y upgrade 
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
EOF

############# network #############
sudo apt install -y \
net-tools bridge-utils iputils-ping iproute2 \
netcat telnet traceroute

############# zsh #############
sudo apt install -y zsh
sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-syntax-highlighting
git clone https://github.com/zsh-users/zsh-autosuggestions ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-autosuggestions
sed -i '2s/# //g' ~/.zshrc
sed -i 's/ZSH_THEME=.*/ZSH_THEME=ys/g' ~/.zshrc
sed -i 's/plugins=(git)/plugins=(git zsh-syntax-highlighting zsh-autosuggestions)/' ~/.zshrc

############# docker #############
echo "See https://docs.docker.com/engine/install/ubuntu if any problem"
#curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo tee /etc/apt/trusted.gpg.d/kubernetes-aliyun.gpg >/dev/null
sudo apt-get install -y ca-certificates curl gnupg lsb-release
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
containerd config default | sudo tee /etc/containerd/config.toml > /dev/null
sudo sed -i 's/SystemdCgroup = false/SystemdCgroup = true/g' /etc/containerd/config.toml
sudo systemctl restart containerd
sudo usermod -aG docker $USER
cat <<EOF | sudo tee /etc/docker/daemon.json >/dev/null
{
"registry-mirrors": [
"https://registry.docker-cn.com",
"https://reg-mirror.qiniu.com"
]
}
EOF
sudo systemctl restart docker

# Docker 开启 TCP 访问
sudo sed -i '/^ExecStart=/s#$# -H tcp://0.0.0.0:2375#' /lib/systemd/system/docker.service
sudo systemctl daemon-reload && sudo systemctl restart docker

############# kube #############
curl -s https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg | sudo tee /etc/apt/trusted.gpg.d/kubernetes-aliyun.gpg >/dev/null
cat <<EOF | sudo tee /etc/apt/sources.list.d/kubernetes.list >/dev/null
deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-xenial main
EOF
sudo apt update
sudo apt install -y kubelet kubeadm kubectl kubernetes-cni
############# kube join #############
sudo kubeadm join 192.168.64.3:6443 --token y3oi0w.cykyv4tdfusizfmw --discovery-token-ca-cert-hash sha256:7d8e37e91f682d6474ae10e889d1aefac908d1d5ad24775f28b4b653381c965e
作者

遇寻

发布于

2023-06-12

更新于

2023-06-12

许可协议

评论