Linux常见问题

虚拟机ping不通主机

Linux查看网卡

Linux删除网卡

ping出现的错误中发现,是docker0这个网卡引起的错误,直接删掉这个网卡

删除网卡
1
sudo ifconfig 网卡名 down

02解决成功

给远程主机传输文件出错

远程主机是我的CentOS 7虚拟机,因为一些问题,我重装了虚拟机,重装虚拟机后的IP地址不变,但是我用powershell给虚拟机传输文件就出错了,查阅了一下相关信息,是本机存储了192.168.232.130这个IP地址的公钥,导致连接失败,知道了问题就好解决了,直接删掉这个公钥的缓存就好

1
2
3
4
5
6
7
8
9
10
11
12
13
14
PS V:\Download\IDM> scp nginx-1.22.0.tar.gz lilbai@192.168.232.130:/home/lilbai/Downloads
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:AQwRNHiaj9xZRd9uf94RSJfPsz9B6Gxcb+ob4D201OU.
Please contact your system administrator.
Add correct host key in C:\\Users\\lilbai518/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in C:\\Users\\lilbai518/.ssh/known_hosts:5
ECDSA host key for 192.168.232.130 has changed and you have requested strict checking.
Host key verificat

删除远程机公钥

清除ssh秘钥,解决旧的远程记录存在导致新的不生效

1
2
3
4
ssh-keygen -R 192.168.232.130 # 这个IP地址就是你想要清除的IP地址的公钥
# Host 192.168.232.130 found: line 5
C:\Users\lilbai518/.ssh/known_hosts updated.
Original contents retained as C:\Users\lilbai518/.ssh/known_hosts.old

重新上传文件

1
2
3
4
5
6
7
PS V:\Download\IDM> scp nginx-1.22.0.tar.gz lilbai@192.168.232.130:/home/lilbai/Downloads
The authenticity of host '192.168.232.130 (192.168.232.130)' can't be established.
ECDSA key fingerprint is SHA256:AQwRNHiaj9xZRd9uf94RSJfPsz9B6Gxcb+ob4D201OU.
Are you sure you want to continue connecting (yes/no/[fingerprint])?
Warning: Permanently added '192.168.232.130' (ECDSA) to the list of known hosts.
lilbai@192.168.232.130's password:
nginx-1.22.0.tar.gz

上传成功!

nginx配置没有反应

可能是你配置的文件不对

我的nginx安装目录(配置无效)

我的nginx安装目录是/opt/nginx-1.22.0,我就觉得配置文件也应该在/opt/nginx-1.22.0/conf/nginx.conf,然而我修改后一直在重启nginx,停止,重启服务器,但还是解决不了问题。

01配置无效的nginx.conf文件

配置文件真实路径(配置有效)

/usr/local/nginx/conf/nginx.conf,无意间看到/usr/local/nginx/下怎么还有个conf文件夹,就打开看看,发现怎么还有个nginx.conf文件,然后重新配置一下,重启,生效。

02真实配置文件

总结

nginx在编译安装的时候,配置文件和其他文件都是在/usr/local/nginx下,所以要配置nginx的时候,应该vim /usr/local/nginx/nginx.conf

日志资源文件配置等都是在/usr/local/nginx

wget下载失败

发现问题

1
2
3
4
5
6
7
8
9
[root@localhost opt]# wget https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.67/bin/
--2022-09-27 02:32:35-- https://dlcdn.apache.org/tomcat/tomcat-9/v9.0.67/bin/ap
Resolving dlcdn.apache.org (dlcdn.apache.org)... 151.101.2.132, 2a04:4e42::644
Connecting to dlcdn.apache.org (dlcdn.apache.org)|151.101.2.132|:443... connecte
ERROR: cannot verify dlcdn.apache.org's certificate, issued by ‘/C=US/O=Let's En
Issued certificate has expired.
To connect to dlcdn.apache.org insecurely, use `--no-check-certificate'.
[root@localhost opt]# ping www.baidu.comn
ping: www.baidu.comn: Name or service not known

解决问题

wget命令下载不安全的https 域名下的内容时会提示以上内容

解决办法:安装一下A证书即可解决问题

1
yum install -y ca-certificates

删除端口失败:Could not delete non-existent rule

报错内容

想删除8888端口,但是发现删除失败

1
2
3
root@ecs-205380:/home/lilbai# ufw delete allow 8888
Could not delete non-existent rule
Could not delete non-existent rule (v6)

分析问题

这里可以看到8888端口是属于tcp连接,那么我直接删除8888端口似乎有点不合适,那改为删除8888/tcp会怎么样呢?

1
2
3
4
5
6
root@ecs-205380:/home/lilbai# ufw status
Status: active

To Action From
-- ------ ----
8888/tcp (v6) ALLOW Anywhere (v6)

解决问题

在端口后面加个/tcp即可,删除成功

1
2
3
root@ecs-205380:/home/lilbai# ufw delete allow 8888/tcp
Rule deleted
Rule deleted (v6)

启动Jenkins.war包报错:AWT is not properly configured on this server.

刚想跑一下war包,就出错了

报错内容

报错内容
1
AWT is not properly configured on this server. Perhaps you need to run your container with “-Djava.awt.headless=true”? See also: https://jenkins.io/redirect/troubleshooting/java.awt.headless

01运行出错

解决办法 1

博主的系统是CentOS 7 Minimal版

1
2
3
yum install dejavu-sans-fonts
yum install fontconfig
yum install xorg-x11-server-Xvfb

安装完后重新启动Jenkins.war

1
java -jar jenkins.war

02运行成功

解决办法 2

在startup.sh文件增加一句:export CATALINA_OPTS="-Djava.awt.headless=true"

1
export CATALINA_OPTS="-Djava.awt.headless=true"

然后重启tomcat即可

CentOS 7升级vim9出错

报错内容

21安装完找不到vim

解决方法

思路:CentOS 7在/usr/bin/vim没有找到vim的执行文件,说明vim没有安装在这里,找到vim的安装路径,将vim的执行文件创建一个软链接到/usr/bin/vim就可以了

查找vim安装路径

1
which vim

使用which命令,找到vim安装到/usr/local/bin/vim

21vim安装路径已改变

创建软链接

1
2
ln -s /usr/local/bin/vim /usr/bin/vim
vim

打开成功!

23创建软链接

缺少依赖导致报错

No package ‘libxml-2.0’ found

1
2
3
4
5
checking whether to build with LIBXML support... yes
checking for libxml-2.0 >= 2.9.0... no
configure: error: Package requirements (libxml-2.0 >= 2.9.0) were not met:

No package 'libxml-2.0' found

解决方法

1
apt install libxml2

No package ‘krb5-gssapi’ found

1
2
3
4
5
checking for krb5-gssapi krb5... no
configure: error: Package requirements (krb5-gssapi krb5) were not met:

No package 'krb5-gssapi' found
No package 'krb5' found

解决方法

1
apt-get -y install gcc libkrb5-dev

No package ‘sqlite3’ found

1
2
3
4
checking for sqlite3 >= 3.7.7... no
configure: error: Package requirements (sqlite3 >= 3.7.7) were not met:

No package 'sqlite3' found

解决方法

1
apt-get install libsqlite3-dev

configure: error: Please reinstall the BZip2 distribution

bzip2Ubuntu中的名字叫libbz2-dev,所以我们在安装bzip2的时候应该安装libbz2-dev

解决方法

1
apt-get install libbz2-dev

No package ‘oniguruma’ found

1
2
3
4
checking for oniguruma... no
configure: error: Package requirements (oniguruma) were not met:

No package 'oniguruma' found

解决方法

1
apt-get install libonig-dev

No package ‘libxslt’ found

1
apt-get install libxslt-dev

创建软链接出错

起因:在安装acme.sh时,acme.sh没有自动给我创建环境变量,也没有给我生成软链接,那我就需要自己新建一个软链接,快速访问。

出错原因是自己手抖了,将ln打成ls了,之后再次添加软链接,就显示已存在。

1
2
3
4
root@-ubuntu:~/.acme.sh# ls -s /root/.acme.sh/acme.sh /usr/bin/acme.sh 
216 /root/.acme.sh/acme.sh 0 /usr/bin/acme.sh
root@-ubuntu:~/.acme.sh# ln -s /root/.acme.sh/acme.sh /usr/bin/acme.sh
ln: failed to create symbolic link '/usr/bin/acme.sh': File exists

报错内容说我的软链接已存在。

解决方法

软链接就类似window的软件快捷方式。在编程中类似指针,只是充当一个路标指向,占用存储不大。

  • -s:添加两文件之间的链接
  • -f:强制执行两文件的链接,如果有,则覆盖,没有则新建一个软链接

我们直接重新强制执行软链接创建即可。

1
ln -sf /root/.acme.sh/acme.sh /usr/bin/acme.sh 

SSH登录Ubuntu出现Access Denied错误

原因

ssh没有开放root用户SSH登录权限,需要手动开启。

解决方法

添加权限

/etc/ssh/sshd_config文件中,添加PermitRootLogin yes即可,如果存在PermitRootLogin no,则将no改为yes,没有则新增。

1
PermitRootLogin yes

重启SSH

1
/etc/init.d/ssh restart

重新SSH登录

1
ssh root@192.168.27

启动iptables出错

1
Unit iptables.service could not be found.

原因是没安装iptables,安装一下就可以了。

安装

1
yum install -y iptables-services

启动

设置开机自启

1
systemctl enable iptables

启动服务

1
systemctl start iptables

查看防火墙状态

1
service iptables status

apt install update失败

错误分析

造成apt install update失败的原因很多,我这里是因为/dev/mapper/ubuntu--vg-ubuntu--lv空间占满了,导致无法写入新的文件。

01-内存空间不足-20230312-464

在安装软件或者更新包时会出现的错误:

1
2
3
4
Err:6 http://archive.canonical.com/ubuntu xenial InRelease
Error writing to file - write (28: No space left on device) [IP: 91.189.91.15 80]

W: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/xenial/InRelease Error writing to file - write (28: No space left on device) [IP: 111.170.130.228 80] ...

解决方法

/dev/mapper/ubuntu--vg-ubuntu--lv增加存储空间就可以了

增加空间

1
lvextend -L +10G /dev/mapper/ubuntu--vg-ubuntu--lv

02-增加存储空间-20230312-736

刷新存储空间

1
resize2fs /dev/mapper/ubuntu--vg-ubuntu--lv

重新查看空间情况

1
df -h

03-刷新存储空间-20230312-586

更换源

1
vim /etc/apt/sources.list

我这里更新网易的源,将以下的文件写入到sources.list

1
2
3
4
5
6
7
8
9
10
11
# 网易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-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ jammy-backports main restricted universe multiverse

配置nginx日志format出错

错误内容

1
2
nginx: [emerg] unknown log format "main" in /usr/local/nginx/conf/conf/conf.default:6
nginx: configuration file /usr/local/nginx/conf/nginx.conf test failed

其中conf.default文件内容为如下:

1
2
3
4
5
6
7
server {
listen 80;
server_name nginx.test www.nginx.test;
root /usr/local/nginx/html;
index test15.html;
access_log /usr/local/nginx/a.com.access.log main;
}

错误前

这是我主配置nginx.conf文件。

01-主配置项出错-20230330-776

修改错误后

主要的错误是log_format 日志配置放在了include /usr/local/nginx/conf/conf/conf.default;前面。

因为我在conf.default文件里面设置了main格式的日志,导致识别不到该格式就报错。

可能是配置的读取顺序是从上往下读取的,类似局部变量,上面的获取不到下面的变量值。

02--修改后-120230330-698