常见问题及命令¶
查看系统是32位还是64位¶
uname -m
Could not get lock /var/lib/apt/lists/lock - open (11: Resource temporarily unavailable)¶
出现此问题的原因是因为可能是有另外一个程序正在运行,导致资源被锁不可用。而导致资源被锁的原因,可能是上次安装时没正常完成,而导致出现此状况。 解决办法:
sudo rm /var/cache/apt/archives/lock
sudo rm /var/lib/dpkg/lock
dhcp重新获取IP¶
dhclient -r # 清空当前ip
dhclient # 重新获取ip
apt update
时报错The following signatures couldn't be verified because the public key is not available: NO_PUBKEY XXXXXX
¶
原因是没有将公钥导入到Ubuntu服务器 使用如下命令导入,修改KEY为报错信息中对应的KEY
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys XXXXXXXX
Ubuntu系统日志文件kern.log
,syslog
过大¶
配置crontab定时任务定时清空
*/3 * * * * echo " " > /var/log/kern.log
*/3 * * * * echo " " > /var/log/syslog
查看系统历史重启时间¶
root@shunyu-System-Product-Name:~# last reboot
reboot system boot 5.0.0-23-generic Fri May 27 16:55 still running
reboot system boot 5.0.0-23-generic Fri May 27 16:28 still running
reboot system boot 5.0.0-23-generic Fri May 27 16:01 - 16:26 (00:25)
reboot system boot 5.0.0-23-generic Fri May 27 15:45 - 15:57 (00:11)
reboot system boot 5.0.0-23-generic Fri May 27 14:28 - 15:57 (01:28)
reboot system boot 5.0.0-23-generic Thu May 26 22:54 - 15:57 (17:02)
reboot system boot 5.0.0-23-generic Thu May 26 15:16 - 15:57 (1+00:41)
reboot system boot 5.0.0-23-generic Mon May 23 19:08 - 15:14 (2+20:05)
reboot system boot 5.0.0-23-generic Mon May 23 17:42 - 15:14 (2+21:31)
reboot system boot 5.0.0-23-generic Mon May 23 16:30 - 15:14 (2+22:43)
reboot system boot 5.0.0-23-generic Mon May 23 16:16 - 16:29 (00:13)
reboot system boot 5.0.0-23-generic Mon May 23 14:37 - 16:29 (01:52)
reboot system boot 5.0.0-23-generic Sat May 21 15:44 - 16:29 (2+00:45)
reboot system boot 5.0.0-23-generic Fri May 20 20:49 - 16:29 (2+19:40)
reboot system boot 5.0.0-23-generic Thu May 19 09:48 - 20:45 (1+10:57)
reboot system boot 5.0.0-23-generic Wed May 11 15:56 - 20:45 (9+04:49)
reboot system boot 5.0.0-23-generic Wed May 11 15:55 - 15:56 (00:00)
reboot system boot 5.0.0-23-generic Mon May 9 16:56 - 15:56 (1+22:59)
reboot system boot 5.0.0-23-generic Mon May 9 09:52 - 14:01 (04:08)
查看实时网络流量¶
nethogs enp4s0
NetHogs version 0.8.5-2
PID USER PROGRAM DEV SENT RECEIVED
? root 192.168.111.111:58434-192.168.111.10:8000 33.522 1499.913 KB/sec
? root 192.168.111.111:37578-192.168.111.18:8000 31.008 1388.624 KB/sec
? root 192.168.111.111:56650-192.168.111.17:8000 30.248 1355.811 KB/sec
? root 192.168.111.111:36370-192.168.111.37:8000 16.674 729.673 KB/sec
? root 192.168.111.111:35344-192.168.111.39:8000 15.449 680.105 KB/sec
? root 192.168.111.111:53772-192.168.111.62:8000 13.322 578.897 KB/sec
? root 192.168.111.111:52822-192.168.111.27:8000 12.820 556.761 KB/sec
? root unknown TCP 0.000 0.000 KB/sec
查看实时硬盘读写¶
iotop
Ubuntu系统设置Swappiness值¶
Swappiness决定使用交换内存的倾向,值越大,系统越倾向于使用交换分区。范围为0-100,默认值为60,表示当物理内存低于60%时开始使用交换分区。 但是交换分区相比于物理内存通常性能较差,所以应该尽量避免使用交换分区,因此Swappiness值应该尽量小,如10
cat /proc/sys/vm/swappiness
60
#临时修改
sysctl vm.swappiness=10
#永久修改
echo "vm.swappiness=10" >> /etc/sysctl.conf
#生效
sysctl -p
cat /proc/sys/vm/swappiness
10
Ubuntu更改用户名¶
首先切换到root用户,把以下文件中的所有现有用户名都改成新用户名,然后重启
/etc/passwd
/etc/shadow
/etc/group
/etc/gshadow
Ubuntu修改交换分区大小¶
# 停止交换分区
swapoff /swapfile
# 删除交换分区
rm /swapfile
# 创建新的交换分区 1M*2048=2G 按需修改
dd if=/dev/zero of=/swapfile bs=1M count=2048
# 设置权限
chmod 600 /swapfile
# 设置交换分区
mkswap -f /swapfile
# 启动交换分区
swapon /swapfile
# 查看交换分区
swapon -s
查看已经使用的空间和便利删除¶
apt install ncdu