Skip to content

Linux Ubuntu相关

Kervin edited this page Jun 7, 2023 · 13 revisions

一、系统

1.源镜像配置

OS Vesion Image LTS
Ubuntu 24.04 -
Ubuntu 23.04 lunar x
Ubuntu 22.10 kinetic x
Ubuntu 22.04 jammy
Ubuntu 21.10 impish x
Ubuntu 21.04 hirsute x
Ubuntu 20.10 groovy x
Ubuntu 20.04 focal
Ubuntu 19.10 eoan x
Ubuntu 19.04 disco x
Ubuntu 18.10 cosmic x
Ubuntu 18.04 bionic
Ubuntu 17.10 artful x
Ubuntu 17.04 zesty x
Ubuntu 16.10 yakkety x
Ubuntu 16.04 xenial
Ubuntu 15.10 wily x
Ubuntu 15.04 vivid x
Ubuntu 14.04 trusty
Ubuntu 12.04 precise
Debian - bookworm x
Debian 11 bullseye x
Debian 10 buster x
Debian 9 stretch
Debian 8 jessie
Debian 7 wheezy x
Debian 6 squeeze x
查看系统版本
lsb_release -a

输出

root@server:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.6 LTS
Release:	20.04
Codename:	focal
vim /etc/apt/sources.list

默认源:http://archive.ubuntu.com/ubuntu

v22.04

#tsinghua
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
#deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse

#aliyun
deb http://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
#deb http://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

#tencent
deb http://mirrors.cloud.tencent.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ jammy-backports main restricted universe multiverse
#deb http://mirrors.cloud.tencent.com/ubuntu/ jammy-proposed main restricted universe multiverse

# 163
deb http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
#deb http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse

v20.04

#tsinghua
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
#deb http://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

#aliyun
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
#deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

#tencent
deb http://mirrors.cloud.tencent.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.cloud.tencent.com/ubuntu/ focal-backports main restricted universe multiverse
#deb http://mirrors.cloud.tencent.com/ubuntu/ focal-proposed main restricted universe multiverse

# 163
deb http://mirrors.163.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ focal-backports main restricted universe multiverse
#deb http://mirrors.163.com/ubuntu/ focal-proposed main restricted universe multiverse

v18.04

# tsinghua
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse

# aliyun
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse

v16.04

# tsinghua
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-security main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse

# aliyun
deb http://mirrors.aliyun.com/ubuntu/ xenial main
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb http://mirrors.aliyun.com/ubuntu/ xenial universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main
deb http://mirrors.aliyun.com/ubuntu/ xenial-security universe

2.软件更新/系统全部更新

apt clean all
apt update --fix-missing
apt list --upgradable
apt dist-upgrade -y

系统清理

apt autoremove -y
apt autoclean -y

卸载软件

apt autoremove --purge -y xxx

安装软件

apt install -y  xxx
apt install -y  xxx=x.y.z
#apt install -y  mysql-client=8.0.27-26.9+1ubuntu20.04

桌面版设置

#中文版(设置->区域与语言->中文)
apt install language-pack-zh-hans language-pack-gnome-zh-hans language-pack-zh-hans-base language-pack-gnome-zh-hans-base

#分辨率设置(GRUB_GFXMODE=1920x1080)
vim /etc/default/grub

系统升级

apt dist-upgrade -y
do-release-upgrade
或
apt upgrade -y
do-release-upgrade --allow-third-party -q -d

若版本不是LTS,无法升级则修改源为低版本的LTS再升级

  • 关闭防火墙:通过crontab -e添加@reboot systemctl stop ufw > /dev/null 2>&1进行关闭(/var/spool/cron/crontabs/root)

3.通用插件

  • 常用插件
apt install -y net-tools sysstat htop glances zip gzip curl aptitude apt-transport-https ca-certificates mercurial  nfs-common dos2unix
  • JDK安装
apt install -y openjdk-8-jdk-headless openjdk-8-jdk gedit

4.兼容依赖安装

curl -sSL https://get.docker.com/ | sh
aptitude install -y docker.io

事件说明

  • aptitude也会想apt那样检测到依赖冲突,然后给出一个解决方案将会自动降级安装依赖的软件(如果是一系列软件版本过高的话),这个时候选择同意基本都可以安装成功,不过唯一美中不足的问题在于,这样安装之后的软件版本会比较低,不过好在确实可以用了。
  • aptitude在删除一个包时,会同时删除本身所依赖的包。这样,系统中不会残留无用的包,整个系统更为干净

5.彩蛋小货车

apt install sl
sl

6.Docker升级

systemctl stop docker
apt autoremove --purge -y docker-ce docker-ce-cli containerd.io

rm -rf /var/lib/docker
rm -rf /etc/docker
rm -rf /var/lib/containerd

rm -rf /var/cache/apt/archives/docker*
rm -rf /run/docker*
rm -rf /sys/class/net/docker0
rm -rf /sys/devices/virtual/net/docker0
rm -rf /sys/fs/cgroup/systemd/system.slice/docker.socket
rm -rf /sys/fs/cgroup/unified/system.slice/docker.socket
rm -rf /proc/sys/net/*/conf/docker0
rm -rf /proc/sys/net/*/neigh/docker0
rm -rf /proc/*/task/*/net/dev_snmp6/docker0
rm -rf /proc/*/net/dev_snmp6/docker0

systemctl daemon-reload
#apt purge docker.io
# find / -name docker*
# apt install -y docker.io
# apt remove docker docker-engine docker.io containerd runc
curl -fsSL https://get.docker.com/ | sh
apt update
apt install -y apt-transport-https ca-certificates curl
curl -fsSL "https://download.docker.com/linux/ubuntu/gpg" | apt-key add
#curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/trusted.gpg.d/ubuntu_docker.gpg
#echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu bionic stable" > /etc/apt/sources.list.d/docker.list
#echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu disco stable" > /etc/apt/sources.list.d/docker.list
#echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu eoan stable" > /etc/apt/sources.list.d/docker.list
echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" > /etc/apt/sources.list.d/docker.list
apt update
apt install -y --no-install-recommends docker-ce
#apt install -y --no-install-recommends containerd
#apt install -y --no-install-recommends docker-ce  docker-ce-cli containerd
#systemctl daemon-reload & systemctl restart containerd & systemctl restart docker
docker version

7.K8S升级

ufw disable
swapoff -a
apt update
apt install -y apt-transport-https ca-certificates curl
curl -fsSL "https://mirrors.aliyun.com/kubernetes/apt/doc/apt-key.gpg" | apt-key add
echo "deb https://mirrors.aliyun.com/kubernetes/apt/ kubernetes-yakkety main" > /etc/apt/sources.list.d/kubernetes.list
apt update
apt install -y kubelet kubeadm kubectl

8.Microk8s升级

snap install microk8s --classic 
microk8s.start
microk8s.stop

如启动不起来

#修改pod的sandbox
pod的sandbox 默认是 k8s.gcr.io/pause:3.1,这个镜像是无法获取的。需要将sandbox修改为国内可以获取的镜像。

修改/var/snap/microk8s/current/args/kubelet。 添加--pod-infra-container-image=s7799653/pause:3.1
修改/var/snap/microk8s/current/args/containerd-template.toml的plugins -> plugins.cri -> sandbox_image为s7799653/pause:3.1
重启服务 

9.K3S升级

curl -sfL https://get.k3s.io | sh -
#看一下执行命令

 kubectl get nodes

二、第三方软件

1.FTP安装

apt install -y vsftpd

修改配置(/etc/vsftpd.conf)

#允许匿名访问
anonymous_enable=YES
#匿名目录
anon_root=/data/logs
no_anon_password=YES

重启服务

#/etc/init.d/vsftpd restart
systemctl restart vsftpd
systemctl status vsftpd

访问服务: ftp://127.0.0.1

2.nfs共享服务

  • 安装
apt install -y nfs-kernel-server
  • 配置(/etc/exports)
#共享目录
/data	172.21.32.*(rw,sync,no_subtree_check,no_root_squash)
/data1	172.21.32.0/24(rw,sync,no_subtree_check,no_root_squash)
  • 重启服务
#/etc/init.d/nfs-kernel-server	restart
systemctl restart nfs-kernel-server
systemctl status nfs-kernel-server
  • 查看nfs服务是否开启
showmount -e
  • 查看nfs指标状态
nfsstat -m, --mounts
nfsstat -c, --client
nfsstat -s, --server

这里需要注意的是,将文件系统挂载到嵌入式linux目标版时,由于这里使用的ubuntu版本是19的,ubuntu 17.10之后的nfs默认就只支持协议3和协议4,但是uboot默认启动的是协议2,要想让nfs支持协议2,就得在/etc/default/nfs-kernel-server添加RPCNFSDOPTS="--nfs-version 2,3,4 --debug --syslog",然后重新启动nfs服务。(vim /etc/default/nfs-kernel-server 最后追加)