美文网首页
【故障集合】架构阶段web服务错误集合

【故障集合】架构阶段web服务错误集合

作者: 李导996 | 来源:发表于2019-06-05 09:37 被阅读0次

    运维学习交流群-点我加群:598972270

    错误整体记录

    Nginx

    1. Connection refused
    2. Address already in use
    3. 启动 或重启nginx 的报错
    4. Linux或windows 使用域名
    5. 404 Not found
    6. 403 Forbidden
    7. Cannot assign requested address
    8. 304 Not modified
    9. conflicting server name
    10. 401 Authorization Required
    11. 500 Internal Server Error
    12. no route to host
    13. Unit is masked.

    MySQL错误

    ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)

    一.Nginx错误提示:

    1.Connection refused

    连接拒绝

    root@web01 /etc/nginx]# curl www.oldboy.com
    curl: (7) Failed connect to www.oldboy.com:80; Connection refused
    

    服务 是否运行

    2Address already in use

    nginx正在运行中

    [root@web01 ~]# nginx
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
    nginx: [emerg] still could not bind()
    

    nginx 可以运行nginx服务

    3. 启动 或重启nginx 的报错

    查看详细nginx错误提示 检查语法 nginx -t

    systemctl  
    [root@web-204 html]# systemctl start nginx
    Job for nginx.service failed because the control process exited with error code. See "systemctl status nginx.service" and "journalctl -xe" for details.
    
    [root@web-204 html]# nginx -t
    nginx: [emerg] unexpected "}" in /etc/nginx/nginx.conf:49
    nginx: configuration file /etc/nginx/nginx.conf test failed
    

    4. }不成对 导致故障

    5.Linux或windows 使用域名

    hosts(linux或windows) 没有解析

    [root@web01 /etc/nginx]# curl blog.oldboy.com
    <a href="https://www.afternic.com/forsale/blog.oldboy.com?utm_source=TDFS_DASLNC&amp;utm_medium=DASLNC&amp;utm_campaign=TDFS_DASLNC&amp;traffic_type=TDFS_DASLNC&amp;traffic_id=daslnc&amp;">Found</a>.
    

    6.nginx: [emerg] directive "server_name" is not terminated by ";" in

    server_name 这一行 没有以 ";" 结尾
    terminated 结束

    [root@wed01 ~]# nginx -t
    nginx: [emerg] directive "server_name" is not terminated by ";" in /etc/nginx/nginx.conf:43
    nginx: configuration file /etc/nginx/nginx.conf test failed
    
    
     31    # include /etc/nginx/conf.d/*.conf;
     32     server   {
     33         listen       80;
     34         server_name  www.oldboy.com;
     35         location / {
     36         root   /usr/share/nginx/html/www;
     37         index  index.html index.htm;
     38         }
     39     }
     40     server   {
     41         listen       80;
     42         server_name  blog.oldboy.com
     43         location / {
     44         root   /usr/share/nginx/html/blog;
     45         index  index.html index.htm;
     46         }
     47     }
     48 
     49 }
    

    7.404 not found

    [root@web01 ~]# cat /user/share/nginx/html/{www,blog}/index.html
    www oldboy.com
    blog oldboy.com
    [root@web01 ~]# vim /etc/hosts
    [root@web01 ~]# curl blog.oldboy.com
    <html>
    <head><title>404 Not Found</title></head>
    <body>
    <center><h1>404 Not Found</h1></center>
    <hr><center>nginx/1.16.0</center>
    </body>
    </html>
    

    8.403 Forbidden

    原因1:没有权限
    原因2:站点目录中首页文件不存在

    模拟权限不足的403
    [root@web01 ~]# cd /usr/share/nginx/html/www/
    [root@web01 /usr/share/nginx/html/www]# ll
    total 4
    -rw-r--r-- 1 root root 15 Jun  5 08:39 index.html
    [root@web01 /usr/share/nginx/html/www]# chmod 000 index.html 
    [root@web01 /usr/share/nginx/html/www]# ll
    total 4
    ---------- 1 root root 15 Jun  5 08:39 index.html
    [root@web01 /usr/share/nginx/html/www]# curl www.oldboy.com 
    <html>
    <head><title>403 Forbidden</title></head>
    <body>
    <center><h1>403 Forbidden</h1></center>
    <hr><center>nginx/1.16.0</center>
    </body>
    </html>
    [root@web01 /usr/share/nginx/html/www]# chmod 644 index.html 
    [root@web01 /usr/share/nginx/html/www]# ll
    total 4
    -rw-r--r-- 1 root root 15 Jun  5 08:39 index.html
    
    模拟首页文件不存在的403

    首页文件不存在 默认找首页文件 403

    [root@web01 /usr/share/nginx/html/www]# ll
    total 0
    [root@web01 /usr/share/nginx/html/www]# curl www.oldboy.com 
    <html>
    <head><title>403 Forbidden</title></head>
    <body>
    <center><h1>403 Forbidden</h1></center>
    <hr><center>nginx/1.16.0</center>
    </body>
    </html>
    

    9.Cannot assign requested address

    无法分配指定的ip地址
    本地没有10.0.0.9ip

    [root@web01 /etc/nginx]# nginx -t 
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: [emerg] bind() to 10.0.0.9:80 failed (99: Cannot assign requested address)
    nginx: configuration file /etc/nginx/nginx.conf test failed
    

    解决方法1:添加1个ip地址

    ip addr add  10.0.0.9/24 dev eth0  label eth0:1
    

    10. 304 Not Modified 用户读取浏览器缓存

    11. conflicting server name

    域名冲突: 有两个几个 虚拟主机的域名相同了

    [root 12:27:17 @web01 conf.d]# nginx -t
    nginx: [warn] conflicting server name "www.oldboy.com" on 0.0.0.0:80, ignored
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
    [root 12:16:28 @web01 ~]# cat /etc/nginx/nginx.conf 
    
    user  nginx;
    worker_processes  1;
    
    error_log  /var/log/nginx/error.log warn;
    pid        /var/run/nginx.pid;
    
    
    events {
        worker_connections  1024;
    }
    
    
    http {
        include       /etc/nginx/mime.types;
        default_type  application/octet-stream;
    
        log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                          '$status $body_bytes_sent "$http_referer" '
                          '"$http_user_agent" "$http_x_forwarded_for"';
    
    
        sendfile        on;
        #tcp_nopush     on;
    
        keepalive_timeout  65;
    
        #gzip  on;
        include /etc/nginx/conf.d/*.conf;
    
    }
    
    
     [root 12:27:22 @web01 conf.d]# vim 01-www.conf 
    
    server {
          listen    80;
          server_name     www.oldboy.com;
          #charset koi8-r;
          access_log  /var/log/nginx/access_www.log  main;
    
          location / {
              root   /usr/share/nginx/html/www;
              index  index.html index.htm;
                    }
         }
    [root 12:29:17 @web01 conf.d]# vim 02-blog.conf 
    
    server {
          listen    80;
          server_name       blog.oldboy.com;
    
          #charset koi8-r;
          access_log  /var/log/nginx/access_blog.log  main;
    
          location / {
              root   /usr/share/nginx/html/blog;
              index  index.html index.htm;
                    }
            }
    
    [root 12:30:38 @web01 conf.d]# cat 03-status.conf 
    server {
            listen  80;
            server_name  status.oldboy.com;
            stub_status on;
            access_log off;
    
    
    } 
     
    [root 12:35:02 @web01 conf.d]# cat default.conf
    server {
        listen       80;
        server_name  www.oldboy.com;
        location / {
            root   /usr/share/nginx/html;
            index  index.html index.htm;
        }
    }
    

    12. 401 Authorization Required

    需要授权的意思,一般是认证失败(用户名和密码)

    13. 500 Internal Server Error

    原因1:
    设置了权限认证auth_basic_user_file 密码文件权限不对导致的

    14. invalid variable name

    [root@web01 /etc/nginx/conf.d]# nginx -t 
    nginx: [emerg] invalid variable name in /etc/nginx/conf.d/01-www.conf:18
    nginx: configuration file /etc/nginx/nginx.conf test failed
    
    server {
        listen       80;
        server_name  www.oldboy.com;
        root   html/www;
        location / {
           return 200  "location / \n";
        }
        location = / {
            return 200 "location = \n";
        }
    
        location /documents/ {
            return 200 "location /documents/ \n";
        }
        location ^~ /images/ {
            return 200 "location ^~ /images/ \n";
    
        }
        location ~* \.(gif|jpg|jpeg)$ {
            return 200 "location ~* \.(gif|jpg|jpeg)$ \n";
        }
        access_log off;
    }
    

    15. no route to host

    无法到达主机

    1.失联
    2.防火墙 selinux

    16. Unit is masked.

    单元被屏蔽
    检查nginx的systemctl配置文件
    systemctl cat nginx 可以发现
    原因,/usr/lib/systemd/system/nginx.serivce 文件被清空 和nginx命令被清空
    解决 从 其他机器复制过来即可。

    [root@lb02 /etc/nginx]# systemctl start nginx
    Failed to start nginx.service: Unit is masked.
    

    17. 编译安装nginx故障 /configure: error: SSL modules require the OpenSSL library.

    configure的时候报错 ,ssl模块 需要安装openssl 库
    解决yum install openssl-devel #development

    /configure: error: SSL modules require the OpenSSL library.
    You can either do not enable the modules, or install the OpenSSL library
    into the system, or build the OpenSSL library statically from the source
    with nginx by using --with-openssl=<path> option.
    

    18. 编译安装 配置的错误

    xxxx and xxxx are same file
    ./configure --prefix=解压的目录
    解决: --prefix指定其他目录

    image.png image.png

    MySQL 故障

    ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)

    错误: 使用wordpress用户在localhost(本地登录)权限拒绝 (密码是正确的)
    解决: MySQL添加用户分为远程登录权限和本地登录权限
    这里添加的用户是172.16.1.% 远程登录权限
    需要登录的时候加上-h ,本地登录需要授权wordpress@localhost

    MariaDB [(none)]> grant all on wordpress.*   to 'wordpress'@'172.16.1.%'  identified  by '123456';
    Query OK, 0 rows affected (0.00 sec)
    
    MariaDB [(none)]> select user,host from  mysql.user ;
    +-----------+------------+
    | user      | host       |
    +-----------+------------+
    | root      | 127.0.0.1  |
    | wordpress | 172.16.1.% |
    | root      | ::1        |
    |           | localhost  |
    | root      | localhost  |
    |           | web01      |
    | root      | web01      |
    +-----------+------------+
    7 rows in set (0.01 sec)
    
    MariaDB [(none)]> Bye
    [root@web01 ~]# mysql -uwordpress -p123456 
    ERROR 1045 (28000): Access denied for user 'wordpress'@'localhost' (using password: YES)
    

    相关文章

      网友评论

          本文标题:【故障集合】架构阶段web服务错误集合

          本文链接:https://www.haomeiwen.com/subject/vscjxctx.html