常见问题

日常遇到的各种问题,持续更新
内容 隐藏

一、centos中常见问题

1、centos有些命令默认状态下不支持自动补全

解决方案:

安装yum install -y bash-completion


退出当前bash再次连接即可

二、Ubuntu中常见问题

1、系统Tab键不能自动补全问题解决

1、利用vi编辑器打开/etc/bash.bashrc文件(需要root权限)

sudo vi /etc/bash.bashrc 

接下来会提示输入密码

2、找到文件中的下列代码

#enable bash completion in interactive shells  
#if ! shopt -oq posix; then  
#      if [-f  /usr/share/bash-completion/bash_completion ]; then  
#          . /usr/share/bash-completion/bash_completion  
#      elif [ -f /etc/bash_completion]; then  
#           . /etc/bash_completion  
#      fi  
#fi  

将注释符号#去掉,即改成

#enable bash completion in interactive shells  
if ! shopt -oq posix; then  
     if [-f  /usr/share/bash-completion/bash_completion ]; then  
          . /usr/share/bash-completion/bash_completion  
      elif [ -f /etc/bash_completion]; then  
           . /etc/bash_completion  
      fi  
fi  

3、最后 source一下 /etc/bash.bashrc即可, 即

sudo source /etc/bash.bashrc

2、Ubuntu不支持root用户的远程连接

解决方案

修改配置文件即可

3、Ubuntu中工具安装

#ping工具
apt install iputils-ping

#ifconfig工具
apt install net-tools

#apache
apt install apache2

4、启动network 报错 mtu 1500 qdisc noop state DOWN group default qlen 1000

解决方案

ifup ens33              #直接启动ens网卡

#如果还是报错可以关闭网络服务再启动网络服务
systemctl stop NetworkManager
systemctl disable NetworkManager
service network restart

三、docker

1、centos7中安装docker-compose

docker-compose的三种安装方式

1、按官网的方式去安装

访问官网docker.com,Resources–>Docs

进入Docs页面,点Product manuals

在https://docs.docker.com/install/页面,如下图,左边选Docker Compose–>install Compose,右边选择Linux(说明一下,Max、Windows系统中Docker安装后,Docker Compose自带的,不需要另外安装的),然后安装文档的的说明,执行四步操作就可以了

# 下载docker compose
sudo curl -L "https://github.com/docker/compose/releases/download/1.25.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
# 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 将文件copy到 /usr/bin/目录下
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
# 查看版本
docker-compose --version

2、通过pip进行安装(不知道是因为网络问题还是怎么回事一直无法正常安装)

安装pip

yum -y install epel-release
yum -y install python-pip

查看版本

pip --version

更新pip

pip install --upgrade pip

安装docker-compose

pip install docker-compose 

查看docker compose的版本

docker-compose version

3、离线安装(推荐)

访问https://github.com/docker/compose/releases,下载 docker-compose-Linux-x86_64,我是复制链接地址,直接通过wget下载到设备上,将docker-compose-Linux-x86_64重命名为docker-compose

输入以下命令 添加可执行权限和查看docker compose版本

# 添加可执行权限
sudo chmod +x /usr/local/bin/docker-compose
# 查看docker-compose版本
docker-compose -v

2、运行harbor的安装脚本时候出现报错(使用http登录仓库)

[root@CT8test2 ~]# /apps/harbor/install.sh 

[Step 0]: checking if docker is installed ...

Note: docker version: 19.03.13

[Step 1]: checking docker-compose is installed ...

Note: docker-compose version: 1.29.2

[Step 2]: loading Harbor images ...
848714650cf1: Loading layer  34.63MB/34.63MB
2382b575d2e0: Loading layer  13.31MB/13.31MB
3b24ba2c50e2: Loading layer  35.84MB/35.84MB
cd6f2eb13f6c: Loading layer  5.632kB/5.632kB
77577baa8e5e: Loading layer  40.45kB/40.45kB
4c1282147082: Loading layer   2.56kB/2.56kB
Loaded image: goharbor/harbor-core:v1.10.9
ff66018f3752: Loading layer  13.31MB/13.31MB
bd819ee0d9d8: Loading layer  43.21MB/43.21MB
Loaded image: goharbor/harbor-jobservice:v1.10.9
bc7c629822d5: Loading layer  9.544MB/9.544MB
1e33f2f90ed2: Loading layer  5.925MB/5.925MB
a29a07373684: Loading layer  13.33MB/13.33MB
e1e63c8f6fbc: Loading layer  26.35MB/26.35MB
c77bf1efece8: Loading layer  22.02kB/22.02kB
09c547c26ae4: Loading layer  13.33MB/13.33MB
Loaded image: goharbor/notary-signer-photon:v1.10.9
b7a078e939f8: Loading layer  11.39MB/11.39MB
Loaded image: goharbor/nginx-photon:v1.10.9
39c0801254c9: Loading layer  9.549MB/9.549MB
9c9aa114f62d: Loading layer  62.66MB/62.66MB
93bb79cfcd45: Loading layer  3.072kB/3.072kB
52fb853e4c87: Loading layer  3.584kB/3.584kB
d92c6f70a2e6: Loading layer  63.48MB/63.48MB
Loaded image: goharbor/chartmuseum-photon:v1.10.9
4fe4beb070b9: Loading layer  9.549MB/9.549MB
232af25ffa00: Loading layer  3.584kB/3.584kB
5034afde132e: Loading layer  3.072kB/3.072kB
84120e9e89de: Loading layer  18.95MB/18.95MB
8f634476878a: Loading layer  19.78MB/19.78MB
Loaded image: goharbor/registry-photon:v1.10.9
b084a9435648: Loading layer  123.1MB/123.1MB
a769c3f0be26: Loading layer  11.97MB/11.97MB
a6f476ec2935: Loading layer  3.072kB/3.072kB
411e8461edcc: Loading layer  49.15kB/49.15kB
a4c951021525: Loading layer  3.584kB/3.584kB
65e94c8413bc: Loading layer  12.84MB/12.84MB
Loaded image: goharbor/clair-photon:v1.10.9
76700f34bf92: Loading layer  9.549MB/9.549MB
2c2726cfb50a: Loading layer  12.09MB/12.09MB
f15099ab29e8: Loading layer  12.09MB/12.09MB
Loaded image: goharbor/clair-adapter-photon:v1.10.9
d22e5ed67d0e: Loading layer  117.3MB/117.3MB
9bc3aaf25287: Loading layer  47.17MB/47.17MB
8a7880274afb: Loading layer   2.56kB/2.56kB
44fcaa7c17f3: Loading layer  1.536kB/1.536kB
68de6791cf7e: Loading layer  155.6kB/155.6kB
569dcbc72a6e: Loading layer  1.774MB/1.774MB
Loaded image: goharbor/prepare:v1.10.9
79995f2d2c5a: Loading layer  11.39MB/11.39MB
97810f22cb99: Loading layer  7.697MB/7.697MB
fc2b6791a854: Loading layer  223.2kB/223.2kB
ad337ed42ae3: Loading layer  195.1kB/195.1kB
2a3dc5c0dd4a: Loading layer  15.36kB/15.36kB
69bfd464b641: Loading layer  3.584kB/3.584kB
Loaded image: goharbor/harbor-portal:v1.10.9
d137d5aeb054: Loading layer  65.04MB/65.04MB
6a659b16847b: Loading layer  88.61MB/88.61MB
def989273255: Loading layer  5.632kB/5.632kB
e897d64b7a52: Loading layer   2.56kB/2.56kB
d61248803b3f: Loading layer   2.56kB/2.56kB
522bce2f7bac: Loading layer   2.56kB/2.56kB
84b8b3c43aa5: Loading layer   2.56kB/2.56kB
5b35ac8ae923: Loading layer  10.75kB/10.75kB
Loaded image: goharbor/harbor-db:v1.10.9
2767471e9faa: Loading layer  14.86MB/14.86MB
0725b7ce0496: Loading layer  26.35MB/26.35MB
bd3765e8e382: Loading layer  22.02kB/22.02kB
31377417e4c2: Loading layer  14.86MB/14.86MB
Loaded image: goharbor/notary-server-photon:v1.10.9
6a686644b30a: Loading layer  75.89MB/75.89MB
bb72f2a3ddb3: Loading layer  3.584kB/3.584kB
5c5699b75230: Loading layer  3.072kB/3.072kB
f6e15a9addd3: Loading layer   2.56kB/2.56kB
c6e75af7e4b9: Loading layer  3.072kB/3.072kB
f49699c969a3: Loading layer  3.584kB/3.584kB
e9aac49f4dca: Loading layer  12.29kB/12.29kB
653fc517d995: Loading layer  3.584kB/3.584kB
Loaded image: goharbor/harbor-log:v1.10.9
0fc56dd74fda: Loading layer  9.549MB/9.549MB
ca345e7af1cf: Loading layer  3.584kB/3.584kB
aeeabc09d279: Loading layer  18.95MB/18.95MB
53c28843ec3a: Loading layer  3.072kB/3.072kB
6f7b7b9f2e7d: Loading layer  7.739MB/7.739MB
f84dce0892ed: Loading layer  27.51MB/27.51MB
Loaded image: goharbor/harbor-registryctl:v1.10.9
f4946383e5bf: Loading layer  113.6MB/113.6MB
0f65e5f4e46b: Loading layer  3.072kB/3.072kB
cf1b4503230c: Loading layer   59.9kB/59.9kB
474f05d0e3dc: Loading layer  61.95kB/61.95kB
Loaded image: goharbor/redis-photon:v1.10.9


[Step 3]: preparing environment ...

[Step 4]: preparing harbor configs ...
prepare base dir is set to /apps/harbor
/usr/src/app/utils/configs.py:100: YAMLLoadWarning: calling yaml.load() without Loader=... is deprecated, as the default Loader is unsafe. Please read https://msg.pyyaml.org/load for full details.
  configs = yaml.load(f)
ERROR:root:Error: The protocol is https but attribute ssl_cert is not set

ERROR:root:Error: The protocol is https but attribute ssl_cert is not set

解决方案:将配置文件中的如下行注释掉

[root@CT8test2 ~]# vim /apps/harbor/harbor.yml
# https related config
#https:
  # https port for harbor, default is 443
  # port: 443
  # The path of cert and key files for nginx
  #certificate: /your/certificate/path
  #private_key: /your/private/key/path

3、注释掉https内容后运行了sh脚本进行http登录,无法正常登录解决方案

运行完成sh脚本后,直接访问

但是如果执行如下命令会出现报错

解决方案

#因为是使用http登录,所以需要进行关于http的设置
#在服务文件中添加选项--insecure-registry=10.0.0.7(10.0.0.7为harbor.yml中hostname字段的内容)
[root@CT7test1 ~]# vim /usr/lib/systemd/system/docker.service 
[Service]
ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock --insecure-registry=10.0.0.7

#重新加载配置文件,重启服务
[root@CT7test1 ~]# systemctl daemon-reload 
[root@CT7test1 ~]# systemctl restart docker

#再次运行docker-compose up命令
[root@CT7test1 ~]# docker-compose -f /apps/harbor/docker-compose.yml up

成功!!

总结:
在centos7中和Ubuntu18.04中直接修改docker.service文件
在centos8中需要创建/etc/docker/daemon.json文件,添加内容
#修改/etc/docker/daemon.json文件,添加以下内容
{
"insecure-registries" : ["myregistrydomain.com:5000", "0.0.0.0"]
}

#重启docker服务
systemctl restart docker

#重启服务docker-compose服务
/usr/bin/docker-compose -f /apps/harbor/docker-compose.yml down
/usr/bin/docker-compose -f /apps/harbor/docker-compose.yml up

4、停止docker-compose出现报错(ERROR: network harbor_harbor has active endpoints

解决方案

docker network inspect {network}
docker network disconnect -f {network} {endpoint-name}
[root@CT7test1 ~]#  docker network inspect harbor_harbor
[
    {
        "Name": "harbor_harbor",
        "Id": "464d40157858688a0e4543bba2ea29952491f4693eab144072278e2fe4a5e270",
        "Created": "2019-04-19T11:05:01.951836694+08:00",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.18.0.0/16",
                    "Gateway": "172.18.0.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Containers": {
            "d858f36b5ff1e879b919403cdb7f852b93b7b36c8186b20275514c306db18f18": {
                "Name": "harbor-core",
                "EndpointID": "3665ba49f53e552af6b751b643c8a816914407b8955e7fe40342d956c217d926",
                "MacAddress": "02:42:ac:12:00:03",
                "IPv4Address": "172.18.0.3/16",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

[root@CT7test1 ~]#  docker network disconnect -f harbor_harbor harbor-core 
[root@CT7test1 ~]#  docker-compose down
Removing network harbor_harbor


5、配置了/etc/docker/daemon.json然后进行服务重启出现报错

出现原因

第一种:

在docker.service文件中已经配置了相关内容,又在/etc/docker/daemon.json中配置导致冲突

第二种:

在不同的系统上有些只支持在docker.service文件中配置,有的只支持在daemon.json中配置

6、docker中已经创建的容器的端口修改

一开始容器my_wordpress_wordpress_1宿主机对外端口为8000想要修改为80端口

root@ubuntu1804:/date/my_wordpress# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                  NAMES
eaa6bcba2a18        wordpress:latest    "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        0.0.0.0:8000->80/tcp   my_wordpress_wordpress_1
50d6ada99951        mysql:5.7           "docker-entrypoint.s…"   2 minutes ago       Up 2 minutes        3306/tcp, 33060/tcp    my_wordpress_db_1


解决方案

暂停docker服务
root@ubuntu1804:/date/my_wordpress# systemctl stop docker.service 
#修改端口信息
root@ubuntu1804:/date/my_wordpress# cat /var/lib/docker/containers/eaa6bcba2a18b5e487e2739facfa44855fa83161b40c358e125412927916b8ef/hostconfig.json     #查看/var/lib/docker/containers/$CONTAINER ID/hostconfig.json  将其中的"HostPort":"8000"给为80即可
{"Binds":["my_wordpress_wordpress_data:/var/www/html:rw"],"ContainerIDFile":"","LogConfig":{"Type":"json-file","Config":{}},"NetworkMode":"my_wordpress_default","PortBindings":{"80/tcp":[{"HostIp":"","HostPort":"8000"}]},"RestartPolicy":{"Name":"always","MaximumRetryCount":0},"AutoRemove":false,"VolumeDriver":"","VolumesFrom":[],"CapAdd":null,"CapDrop":null,"Capabilities":null,"Dns":null,"DnsOptions":null,"DnsSearch":null,"ExtraHosts":null,"GroupAdd":null,"IpcMode":"private","Cgroup":"","Links":[],"OomScoreAdj":0,"PidMode":"","Privileged":false,"PublishAllPorts":false,"ReadonlyRootfs":false,"SecurityOpt":null,"UTSMode":"","UsernsMode":"","ShmSize":67108864,"Runtime":"runc","ConsoleSize":[0,0],"Isolation":"","CpuShares":0,"Memory":0,"NanoCpus":0,"CgroupParent":"","BlkioWeight":0,"BlkioWeightDevice":null,"BlkioDeviceReadBps":null,"BlkioDeviceWriteBps":null,"BlkioDeviceReadIOps":null,"BlkioDeviceWriteIOps":null,"CpuPeriod":0,"CpuQuota":0,"CpuRealtimePeriod":0,"CpuRealtimeRuntime":0,"CpusetCpus":"","CpusetMems":"","Devices":null,"DeviceCgroupRules":null,"DeviceRequests":null,"KernelMemory":0,"KernelMemoryTCP":0,"MemoryReservation":0,"MemorySwap":0,"MemorySwappiness":null,"OomKillDisable":false,"PidsLimit":null,"Ulimits":null,"CpuCount":0,"CpuPercent":0,"IOMaximumIOps":0,"IOMaximumBandwidth":0,"MaskedPaths":["/proc/asound","/proc/acpi","/proc/kcore","/proc/keys","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware"],"ReadonlyPaths":["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]}

root@ubuntu1804:/date/my_wordpress# vim /var/lib/docker/containers/eaa6bcba2a18b5e487e2739facfa44855fa83161b40c358e125412927916b8ef/hostconfig.json 

重启docker服务
root@ubuntu1804:/date/my_wordpress# systemctl start docker.service 
root@ubuntu1804:/date/my_wordpress# docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                 NAMES
eaa6bcba2a18        wordpress:latest    "docker-entrypoint.s…"   10 minutes ago      Up 3 seconds        0.0.0.0:80->80/tcp    my_wordpress_wordpress_1
50d6ada99951        mysql:5.7           "docker-entrypoint.s…"   11 minutes ago      Up 4 seconds        3306/tcp, 33060/tcp   my_wordpress_db_1

7、centos8中安装docker出现以下报错

  - package runc-1.0.0-72.rc92.module_el8.5.0+1006+8d0e68a2.x86_64 is filtered out by modular filtering
(try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)
Failed to enable unit: Unit file docker.service does not exist.

解决方案

[root@localhost ~]#yum erase podman buildah
[root@localhost ~]#yum install docker-ce

8、docker中将节点添加到swarm中出现以下报错

[root@wrk2 ~]# docker swarm join --token SWMTKN-1-61pp4aop86mhytesq1ajcj6cokcbxd5ov4w6or2gyqn10ln1n8-9f3tpw1ag0qdq71wpjli19ua8 192.168.239.10:2377
Error response from daemon: rpc error: code = Unavailable desc = all SubConns are in TransientFailure, latest connection error: connection error: desc = "transport: Error while dialing dial tcp 192.168.239.10:2377: connect: no route to host"

解决方案

关闭防火墙即可

9、拉取镜像报错

[root@mgr1 ~]# docker pull ubuntu
Using default tag: latest
Error response from daemon: Get https://registry-1.docker.io/v2/: x509: certificate has expired or is not yet valid

可能原因

镜像名填写错误

这个通过search选项查找一下想要的镜像指定正确的镜像名即可

本地系统时间错误导致报错证书过期

#同步一下时钟系统就好了
[root@mgr1 ~]# yum install -y ntpdate
[root@mgr1 ~]# ntpdate cn.pool.ntp.org 
[root@mgr1 ~]# date

四、k8s

1、ha备设备服务正常启动但是无法进行监听

解决方案

修改内核参数

在内核配置文件中将上述参数改为1,然后重新加载内核文件,重启服务,查看监听端口。已经成功监听6443端口

2、kubeadm下无法使用tab键补全命令

解决方案

root@k8s-master1:~# mkdir /data/scripts -p
root@k8s-master1:~# kubeadm completion bash > /data/scripts/kubeadm_completion.sh       #通过命令生成一个脚本
root@k8s-master1:~# source /data/scripts/kubeadm_completion.sh  #执行此脚本查看是否可以补全 

#如果要使其在下次启动后依旧生效
root@k8s-master1:~# chmod +x /data/scripts/kubeadm_completion.sh    #修改文件权限,使其具有可执行权限
root@k8s-master1:~# vim /etc/profile
source /data/scripts/kubeadm_completion.sh  #将执行脚本的命令加入一个开机执行的文件中使其开机自动运行

注意:如果是在普通用户sudo到root用户然后开机执行的脚本只会在普通用户生效,再次切换到root用户root用户并没有执行脚本,所以需要直接用root用户登录然后设置

3、k8sflannel无法正常启动


解决方案

将kubeadm的初始化配置文件中的podsubnet地址改为10.244.0.0/16,使得与flannel.ymal配置文件中的地址保持一致即可。我原先是修改flannel.ymal配置文件使其与我的初始化文件一致一直我发正常启用。后来将初始化文件中的改为与flannel一致即成功启动

4、无法正常获取运行pod



解决方案

确定输入的命令是正确的,没有sleeping 这个命令。。。。。

同时也有可能是之前kubeadm reset之后没有重启服务器,有之前的进程残留

5、运行的pod都是run状态,进入容器后pod与pod之间无法通信

解决方案

可以在容器中看一下ip route,看看路由信息与flannel中pod地址段的信息是否一致,如果不一致修改flannel中的pod地址段

五、MySQL

1、Centos8上二进制安装mysql5.7.33启动服务都是正常的,但是进入数据库的时候出现报错

[root@localhost /usr/local]#mysql -uroot -p'6.-ioLc/>T2h'
mysql: error while loading shared libraries: libncurses.so.5: cannot open shared object file: No such file or directory

解决方案

[root@localhost /usr/local]#yum install libncurses*

六、Nginx

1、nginx访问url报错

报错日志如下

[root@Centos7 ~]# tail -f /var/log/nginx/error.log 
2021/11/24 23:05:26 [error] 1521#1521: *12 directory index of "/date/nginx/pc/" is forbidden, client: 10.0.0.254, server: www.pc.com, request: "GET / HTTP/1.1", host: "10.0.0.10"
2021/11/24 23:05:27 [error] 1521#1521: *12 directory index of "/date/nginx/pc/" is forbidden, client: 10.0.0.254, server: www.pc.com, request: "GET / HTTP/1.1", host: "10.0.0.10"
2021/11/24 23:05:41 [error] 1521#1521: *14 directory index of "/date/nginx/pc/" is forbidden, client: 10.0.0.254, server: www.pc.com, request: "GET / HTTP/1.1", host: "10.0.0.10"
2021/11/24 23:05:41 [error] 1521#1521: *14 open() "/date/nginx/pc/favicon.ico" failed (2: No such file or directory), client: 10.0.0.254, server: www.pc.com, request: "GET /favicon.ico HTTP/1.1", host: "10.0.0.10", referrer: "http://10.0.0.10/"
2021/11/24 23:15:09 [error] 1521#1521: *15 directory index of "/date/nginx/pc/" is forbidden, client: 10.0.0.254, server: www.pc.com, request: "GET / HTTP/1.1", host: "10.0.0.10"
2021/11/24 23:16:42 [notice] 1613#1613: signal process started
2021/11/24 23:17:03 [error] 1614#1614: *19 directory index of "/date/nginx/pc/" is forbidden, client: 10.0.0.254, server: www.pc.com, request: "GET / HTTP/1.1", host: "10.0.0.10"
2021/11/24 23:17:23 [error] 1614#1614: *21 directory index of "/date/nginx/pc/" is forbidden, client: 10.0.0.254, server: www.pc.com, request: "GET / HTTP/1.1", host: "www.pc.com"
2021/11/24 23:17:23 [error] 1614#1614: *21 open() "/date/nginx/pc/favicon.ico" failed (2: No such file or directory), client: 10.0.0.254, server: www.pc.com, request: "GET /favicon.ico HTTP/1.1", host: "www.pc.com", referrer: "http://www.pc.com/"
2021/11/24 23:20:30 [error] 1614#1614: *22 directory index of "/date/nginx/pc/" is forbidden, client: 10.0.0.10, server: www.pc.com, request: "GET / HTTP/1.1", host: "10.0.0.10"
2021/11/24 23:26:16 [error] 1614#1614: *23 open() "/date/nginx/pc/index.html" failed (2: No such file or directory), client: 10.0.0.254, server: www.pc.com, request: "GET /index.html HTTP/1.1", host: "www.pc.com"

解决思路

(2: No such file or directory) 日志中信息显示为没有文件,那么就去查看一下自己创建的web页面的名称是否正确我就是名称不对应该是index.html,我命名为index.htm

2、nginx检查配置文件时报错

[root@localhost ~]#nginx -t
nginx: [emerg] unknown directive "echo" in /apps/nginx/conf/conf.d/echo.conf:7
nginx: configuration file /apps/nginx/conf/nginx.conf test failed

分析原因

这是因为安装nginx时候缺少了模块,无法识别echo

解决方案

下载echo模块,编译安装添加调用模版
#下载echo安装包
[root@localhost /usr/local/src]#pwd
/usr/local/src
[root@localhost /usr/local/src]#yum install git -y

[root@localhost /usr/local/src]#git clone https://github.com/openresty/echo-nginx-module.git        #换种方式从GitHub上下载echo安装包
Cloning into 'echo-nginx-module'...
remote: Enumerating objects: 3035, done.
remote: Counting objects: 100% (17/17), done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 3035 (delta 6), reused 5 (delta 2), pack-reused 3018
Receiving objects: 100% (3035/3035), 1.16 MiB | 1.84 MiB/s, done.
Resolving deltas: 100% (1630/1630), done.

[root@localhost /usr/local/src]#ls
echo-nginx-module  nginx-1.20.2

#再次编译nginx添加参数
[root@localhost /usr/local/src/nginx-1.20.2]#pwd
/usr/local/src/nginx-1.20.2

[root@localhost /usr/local/src/nginx-1.20.2]#./configure \
--prefix=/apps/nginx 
--user=nginx 
--group=nginx 
--with-http_ssl_module 
--with-http_v2_module 
--with-http_realip_module 
--with-http_stub_status_module 
--with-http_gzip_static_module 
--with-pcre --with-stream 
--with-stream_ssl_module 
--with-stream_realip_module 
--add-module=/usr/local/src/echo-nginx-module/      ##指定模块源代码路径注意最后的一个斜杠很关键,如果不加这个斜杠make的时候会出现报错

[root@localhost /usr/local/src/nginx-1.20.2]#make && make install

#再次验证nginx配置文件
[root@localhost /apps/nginx/conf/conf.d]#nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful

3、nginx编译安装报错(解决问题4时候出现的新问题)

[root@localhost /usr/local/src/nginx-1.20.2]#make && make install
.
.
.
/usr/bin/ld: final link failed: Nonrepresentable section on output
make[1]: *** [objs/Makefile:305: objs/nginx] Error 1
make[1]: Leaving directory '/usr/local/src/nginx-1.20.2'
make: *** [Makefile:10: build] Error 2

出现原因

#没有指定子目录,只指定到了父目录
[root@localhost /usr/local/src/nginx-1.20.2]#./configure \
--prefix=/apps/nginx 
--user=nginx 
--group=nginx 
--with-http_ssl_module 
--with-http_v2_module 
--with-http_realip_module 
--with-http_stub_status_module 
--with-http_gzip_static_module 
--with-pcre --with-stream 
--with-stream_ssl_module 
--with-stream_realip_module 
--add-module=/usr/local/src/echo-nginx-module

解决方案

#正确的重新编译安装在make一下就可以了
[root@localhost /usr/local/src/nginx-1.20.2]#./configure \
--prefix=/apps/nginx 
--user=nginx 
--group=nginx 
--with-http_ssl_module 
--with-http_v2_module 
--with-http_realip_module 
--with-http_stub_status_module 
--with-http_gzip_static_module 
--with-pcre --with-stream 
--with-stream_ssl_module 
--with-stream_realip_module 
--add-module=/usr/local/src/echo-nginx-module/      ##指定模块源代码路径注意最后的一个斜杠很关键,如果不加这个斜杠make的时候会出现报错

七、通用

1、https访问时,客户端获取了证书,提示证书无效(x509: certificate has expired or is not yet valid)

出现原因:

客户端与服务器的时区不同

解决方案:

yum install -y ntpdate
ntpdate ntp3.aliyun.com

2、自定义ip与域名的对应

windows上

修改C:\Windows\System32\drivers\etc\hosts

Linux上

修改/etc/hosts

3、写的脚本没有问题但是无法被正常执行

解决思路

#是否具有可执行权限,比如这个添加开机启动项的文件,如果不添加可执行权限无法正常运行
[root@localhost ~]#cat /etc/rc.d/rc.local | grep -v '#'
for i in {3306..3308};do /mysql/$i/bin/mysqld start;d

[root@localhost ~]#chmod +x /etc/rc.d/rc.local      #添加可执行权限很重要


#属主属组是否可以运行此文件,比如说mysql多实例中如果不将实例的目录的属主属组修改为mysql,则后续的启动脚本无法正常执行