aiastia / note

笔记
17 stars 5 forks source link

UBUNTU 常用命令 #44

Open aiastia opened 4 years ago

aiastia commented 4 years ago

sudo apt-get update

sudo apt-get upgrade -y

aiastia commented 4 years ago

uname -r

echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf

sysctl -p

aiastia commented 4 years ago

service sshd restart

aiastia commented 4 years ago

adduser 用户名

aiastia commented 4 years ago

升级前备份当前系统镜像 确认外网可用,同时配置好任意一个国内源(这里用的是网易源) 获取5.0.0内核版本 sudo apt list | grep linux-generic* 能够获取到5.0.0版本之后直接安装 sudo apt-get install linux-generic-hwe-18.04-edge 安装完成再重启一下设备新内核即可生效

———————————————— 版权声明:本文为CSDN博主「Z_Stand」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。 原文链接:https://blog.csdn.net/Z_Stand/article/details/100109552

aiastia commented 4 years ago

.tar.gz 和 .tgz

tar -zxvf FileName.tar.gz # 解压 tar -zcvf FileName.tar.gz DirName # 将DirName和其下所有文件(夹)压缩 tar -C DesDirName -zxvf FileName.tar.gz # 解压到目标路径 ————————————————

aiastia commented 3 years ago

sudo apt-get dist-upgrade

aiastia commented 3 years ago

rm -rf /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

aiastia commented 3 years ago

sudo apt-get update sudo apt-get upgrade sudo apt-get dist-upgrade sudo reboot

aiastia commented 3 years ago

sudo rm /var/lib/dpkg/lock-frontend

sudo rm /var/cache/apt/archives/lock

sudo rm /var/lib/dpkg/lock

aiastia commented 3 years ago

wget -O /etc/apt/sources.list https://raw.githubusercontent.com/aiastia/note/master/sources.list

wget -O /etc/apt/sources.list https://raw.githubusercontent.com/aiastia/note/master/aws-sources.list

wget -O /etc/apt/sources.list https://raw.githubusercontent.com/aiastia/note/master/orc-sources.list

aiastia commented 3 years ago

apt-get的卸载相关的命令有remove/purge/autoremove/clean/autoclean等。具体来说:

apt-get purge / apt-get --purge remove 

删除已安装包(不保留配置文件)。 如软件包a,依赖软件包b,则执行该命令会删除a,而且不保留配置文件

apt-get autoremove 

删除为了满足依赖而安装的,但现在不再需要的软件包(包括已安装包),保留配置文件。

apt-get remove 

删除已安装的软件包(保留配置文件),不会删除依赖软件包,且保留配置文件。

apt-get autoclean 

APT的底层包是dpkg, 而dpkg 安装Package时, 会将 *.deb 放在 /var/cache/apt/archives/中,apt-get autoclean 只会删除 /var/cache/apt/archives/ 已经过期的deb。

apt-get clean 

使用 apt-get clean 会将 /var/cache/apt/archives/ 的 所有 deb 删掉,可以理解为 rm /var/cache/apt/archives/*.deb。

那么如何彻底卸载软件呢? 具体来说可以运行如下命令:

删除软件及其配置文件

apt-get --purge remove <package>

删除没用的依赖包

apt-get autoremove <package>

此时dpkg的列表中有“rc”状态的软件包,可以执行如下命令做最后清理:

dpkg -l |grep ^rc|awk '{print $2}' |sudo xargs dpkg -P

当然如果要删除暂存的软件安装包,也可以再使用clean命令。

aiastia commented 3 years ago

network_mode: "host"

aiastia commented 3 years ago
  1. root 用户下执行 iptables 命令将 80 端口请求转发到 8080
    iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080

    注意:网上朋友的命令 dport 前面都是一个 -,通常都会报错。另外如果防火墙重新启动,该命令就会失效。

可以使用下面的命令把该规则保存到 iptables 里面 :

  1. 将此规则保存到 iptables 第一步的设置并没有保存到 iptables,如果防火墙重启,该命令失效,还得重新执行。所以我们需要将此设置保存到 iptables
    service iptables save
aiastia commented 3 years ago

临时端口开启(http 、被墙检测)

python -m SimpleHTTPServer 8000
python3 -m http.server 8000

http://port.ping.pe/

aiastia commented 3 years ago

https://docs.azure.cn/zh-cn/articles/azure-operations-guide/virtual-machines/linux/aog-virtual-machines-linux-ubuntu-howto-upgrade-kernel

image

aiastia commented 3 years ago

如果先安装了docker再安装bbr导致无法启动docker怎么办?

rm -rf /var/lib/docker/aufs
aiastia commented 3 years ago

sudo apt-get install iperf3 iperf3 -s

搭完了服务端,最后就是用客户端来测速了,其实区别就是输的指令不同,客户端最简单的测速指令就是输入:

iperf3 -c 192.168.2.165

aiastia commented 2 years ago

wget https://raw.githubusercontent.com/aiastia/key/master/us.pub

mkdir -p ~/.ssh

mv ~/us.pub ~/.ssh/authorized_keys

aiastia commented 2 years ago

修改为北京时间

sudo cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

aiastia commented 2 years ago

甲骨文开放所有端口 iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -F

Ubuntu镜像默认设置了Iptable规则,关闭它 apt-get purge netfilter-persistent reboot

aiastia commented 2 years ago

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 40976EAF437D05B5

sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32

aiastia commented 1 year ago

sudo apt install neofetch -y

neofetch

9977EC4F-0865-4124-A510-4B8AD3253338

aiastia commented 1 year ago

Ubuntu 安装 微信 可以试试下载安装 优麒麟 版 微信:

http://archive.ubuntukylin.com/software/pool/partner/weixin_2.1.4_amd64.deb

(Ubuntu 能双击 deb 包安装软件) 注意无法用聊天记录备份和小程序功能。

如果需要全功能可以试试 Windows 版微信

--

ubuntu 安装 windows 版 微信 QQ

最新版 微信 windows 安装程序应该可以用 wine 直接安装使用。 即先 安装 wine sudo dpkg --add-architecture i386 sudo add-apt-repository universe sudo apt install -y wine cabextract exe-thumbnailer

然后浏览器打开微信官网 https://windows.weixin.qq.com/ 下载 windows 版微信安装程序, 双击用 wine 执行安装。

如果直接安装的 wine 微信发现有问题,可以试试用下边的 winetricks-zh 安装。

打开终端(比如桌面右键点终端) 逐行复制粘贴下边的命令到终端执行,注意询问密码输入密码时不会回显

sudo dpkg --add-architecture i386 sudo add-apt-repository universe sudo apt install -y wine cabextract exe-thumbnailer

sudo -E wget -O /usr/local/bin/winetricks-zh https://github.com/hillwoodroc/winetricks-zh/raw/dev/winetricks-zh

sudo -E wget -O /usr/local/bin/winetricks-zh https://raw.fastgit.org/hillwoodroc/winetricks-zh/dev/winetricks-zh # 改用国内地址

sudo chmod +x /usr/local/bin/winetricks-zh

安装 微信

winetricks-zh wechat

安装 QQ

winetricks-zh qq

然后双击 微信 windows 安装包用 wine 执行覆盖安装。 在安装微信后,可以自行 wine 运行 企业微信安装文件。

如果需要让他安装在独立容器,就改为: env WINEPREFIX=~/.wine-qq winetricks-zh wechat

env WINEPREFIX=~/.wine-qq winetricks-zh qq

另外,因为 gnome 砍掉了系统托盘图标,所以 gnome 用户需要 安装 top icon plus 扩展,才能让微信、qq 出现在系统托盘

aiastia commented 1 year ago

1.4 扩容分区

现在就可以将空闲的磁盘容量合并到分区里了,这里利用界面和操作都更加友好的 cfdisk 来进行操作。 按上下键选中要扩容的分区,再按左右键选择 Resize 操作,回车。cfdisk 应该会自动填写此分区与未分配空间的总容量,也可以自己输入扩容后的大小,回车即可。 再次执行 fdisk -l ,可见分区容量已变为 64G。

1.5 扩容文件系统

此时扩容并未结束,因为文件系统记录的分区容量仍为 40G,我们需要让文件系统知道分区已被扩容。

1.5 扩容文件系统

此时扩容并未结束,因为文件系统记录的分区容量仍为 40G,我们需要让文件系统知道分区已被扩容。 这里需要用到 resize2fs,以我的磁盘 sda2 为例,执行以下命令:

resize2fs -p /dev/sda2

aiastia commented 1 year ago

对于Ubuntu系统,以下方法可以让系统优先使用IPv4地址。

sudo vi /etc/gai.conf 将上述打开文件以下内容取消注释(同时将最后的数字由10改成100):

precedence ::ffff:0:0/96 100

aiastia commented 1 year ago

要临时禁用 IPv6,您只需在「终端」中执行以下 3 条命令: sudo sysctl -w net.ipv6.conf.all.disable_ipv6=1 sudo sysctl -w net.ipv6.conf.default.disable_ipv6=1 sudo sysctl -w net.ipv6.conf.lo.disable_ipv6=1

aiastia commented 1 year ago

如果要在 Ubuntu 系统中永久禁用 IPv6,我们可以通过本文编辑器来修改 /etc/sysctl.conf 文件:

1使用 VIM 或 Nano 等文件编辑器打开 /etc/sysctl.conf 配置文件

2将以下 3 行内容添加到 /etc/sysctl.conf 配置文件当中:

net.ipv6.conf.all.disable_ipv6=1 net.ipv6.conf.default.disable_ipv6=1 net.ipv6.conf.lo.disable_ipv6=1

aiastia commented 1 year ago

关闭Ubuntu 22 重启提醒 案列


sed -i "/#\$nrconf{restart} = 'i';/s/.*/\$nrconf{restart} = 'a';/" /etc/needrestart/needrestart.conf````