【Linux 运维系列】Ubuntu 运维总结
【1】Ubuntu 更新源
- 各版本源地址查询
- 阿里源配置简记
Ubuntu 18
deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
# deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
Ubuntu 20
deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
- 源更新步骤总结
备份原始源配置文件
sudo cp /etc/apt/sources.list /etc/apt/sources.list_back
更新 /etc/apt/sources.list 内容
更新源 apt update
【2】Ubuntu 重置 root 密码
sudo passwd
【3】Ubuntu 终端分屏与配置默认终端
- 安装 Terminator 以及美化
sudo apt install terminator
在 ~/.config/terminator 路径下创建文件 config,terminator 的配置参数如下
[global_config]
suppress_multiple_term_dialog = True
title_font = Sans 11
title_use_system_font = False
[keybindings]
[layouts]
[[default]]
[[[child1]]]
parent = window0
type = Terminal
[[[window0]]]
parent = ""
type = Window
[plugins]
[profiles]
[[default]]
background_color = "#002b36"
background_darkness = 0.91
background_type = transparent
copy_on_selection = True
cursor_color = "#e0f0f1"
font = Ubuntu Mono 12
foreground_color = "#e0f0f1"
use_system_font = False
- 设置默认终端
sudo update-alternatives --config x-terminal-emulator
【4】文件压缩与解压
将 test 路径下的文件分包压缩,每个压缩包大小为 1G
tar -zcvf - test | split -b 1024M -d -a 2 - test.tar.gz
将分解的压缩包合并
cat test.tar.gz* > test.tar.gz
【5】VMware 设置共享目录
安装 open-vm-tools
sudo apt install open-vm-tools
创建目录并挂载
mkdir /mnt/hgfs
vmhgfs-fuse .host:/ /mnt/hgfs
sudo vmhgfs-fuse .host:/ /mnt -o nonempty -o allow_other
【6】VMware 磁盘扩容
- 编辑虚拟机设置->硬盘->磁盘实用工具->扩展
- 弹出的对话框中设置磁盘扩展大小
- 下载安装工具 Gparted,sudo apt install gparted
- 打开 Gparted 扩展磁盘空间
- 对于 /dev/mapper/ubuntu--vg-* 的文件系统扩容
lvextend -L 20G /dev/mapper/ubuntu–vg-ubuntu–lv //增大或减小至20G
lvextend -L +20G /dev/mapper/ubuntu–vg-ubuntu–lv //增加20G
lvreduce -L -20G /dev/mapper/ubuntu–vg-ubuntu–lv //减小20G
lvresize -l +100%FREE /dev/mapper/ubuntu–vg-ubuntu–lv //按百分比扩容
resize2fs /dev/mapper/ubuntu–vg-ubuntu–lv //执行调整
【7】安装配置SSH
- 安装并启动 ssh 服务端
sudo apt install openssh-server
sudo /etc/init.d/ssh restart
- 修改配置信息
配置文件
/etc/ssh/sshd_config
Port 22 #默认即可,如果有端口占用可以自己修改
PasswordAuthentication yes #允许用户名密码方式登录
PermitRootLogin yes #允许 root 用户登录
- 常见错误与解决方案
- sshd: no hostkeys available -- exiting
在 /etc/ssh 路径下执行 ssh-keygen -A 即可解决
【8】时间校准
CentOS:
yum -y install ntp ntpdate
Ubuntu:
apt install ntp ntpdate
ntpdate cn.pool.ntp.org
hwclock --systohc
参考与致谢
本博客为博主学习笔记,同时参考了网上众博主的博文以及相关专业书籍,在此表示感谢,本文若存在不足之处,请批评指正。