mysql主从复制实现

原理

  • mysql要做到主从复制,其实依靠的是二进制日志,即:假设主服务器叫A,从服务器叫B;主从复制就是B跟着A学,A做什么,B就做什么。那么B怎么同步A的动作呢?现在A有一个日志功能,把自己所做的增删改查的动作全都记录在日志中,B只需要拿到这份日志,照着日志上面的动作施加到自己身上就可以了。这样就实现了主从复制。

实现步骤

1.步骤1

  • 打开主服务器(master)mysql配置文件 例:/etc/my.ini
  • 在配置文件增加三行

    1
    2
    3
    4
    5
    6
    ### 将mysql二进制日志取名为mysql-bin
    log-bin=mysql-bin
    ### 二进制日志的格式,有三种:statement/row/mixed,具体分别不多做解释,这里使用mixed
    binlog_format=mixed
    ### 为服务器设置一个独一无二的id便于区分
    server-id=100
  • 重启mysql

    1
    service mysqld restart
  • 配置从服务器,与上面一样,不过 server-id要换成 200,这个值你随便设置 在1-2^23之间

2.步骤2

  • 为从服务器设置一个可以同步复制主服务器日志的权限
  • 命令
    1
    2
    3
    4
    #### 先登陆mysql
    mysql -u root -p ******
    #### 分配权限 replication slave:分配复制权限 *.*:操作哪个数据库 slave:用户名 %:哪个主机 pass:密码
    GRANT replication slave ON *.* TO 'slave'@'%' IDENTIFIED BY 'pass';

3.步骤3

  • 查看主服务器BIN日志的信息
    1
    2
    3
    #### 配置完从服务器之前不要对主服务器进行任何操作,因为每次操作数据库时这两值会发生改变
    show master status;
    #### 记住`File` 与 Position的值,下面第四步mysql_log_file,与mysql_log_pos要使用.

4.步骤4

  • 配置从服务器

    1
    2
    3
    4
    5
    6
    #### 先看下从服务器状态
    show slave status;
    #### 如果存在则执行:
    stop slave;
    #### 设置
    change master to master_host="192.168.1.100",master_user="uname",matser_password="pass",mysql_log_file="mysql-bin-0600",mysql_log_pos=876;
  • 参数解释:

  • master_host :设置要连接的主服务器的ip地址
  • master_user :设置要连接的主服务器的用户名
  • matser_password :设置要连接的主服务器的密码
  • mysql_log_file :设置要连接的主服务器的bin日志的日志名称,即第3步得到的信息
  • mysql_log_pos :设置要连接的主服务器的bin日志的记录位置,即第3步得到的信息,(这里注意,最后一项不需要加引号。否则配置失败

5.查看是否成功

1
2
show master status;
#### 成功会提示 Slave_IO_Running: yes | Slave_sql_Running yes

mysql日志的三种模式

1.基于SQL语句的复制(statement-based replication,SBR) binlog_format=statement

  • 每一条会修改数据的sql都会记录在binlog中。

2.基于行的复制(row-based replication,RBR) binlog_format=row

  • 它不记录sql语句上下文相关信息,仅保存哪条记录被修改

3.混合模式复制(mixed-based replication,MBR) binlog_format=mixed

  • 一般的语句修改使用statment格式保存binlog,如一些函数,statement无法完成主从复制的操作,则采用row格式保存binlog,MySQL会根据执行的每一条具体的sql语句来区分对待记录的日志形式,也就是在Statement和Row之间选择一种

4.binlog相关命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#### 查看使用的模式
show variables like 'binlog_format'
#### 查看是否开启binlog
show variables like 'log_bin'
#### 获取binlog文件列表
show binary logs
#### 查看当前正在写入的binlog文件
show master status
#### 查看master上的binlog
show master logs
#### 只查看第一个binlog文件的内容
show binlog events
#### 查看指定binlog文件的内容
show binlog events in 'mysql-bin.000002'
####日志被刷新时,新生成一个日志文件
flush logs

http状态码一览

http状态吗及解释,英文版

1xx

code reason description spec
1xx Informational “indicates an interim response for communicating connection status or request progress prior to completing the requested action and sending a final response.” ~ sure RFC7231#6.2,
RFC2616#10.1
100 Continue “indicates that the initial part of a request has been received and has not yet been rejected by the server.” RFC7231#6.2.1,
RFC2616#10.1.1
101 Switching Protocols “indicates that the server understands and is willing to comply with the client’s request, via the Upgrade header field, for a change in the application protocol being used on this connection.” RFC7231#6.2.2,
RFC2616#10.1.2

2xx

code reason description spec
2xx Successful “indicates that the client’s request was successfully received, understood, and accepted.” ~ cool RFC7231#6.3,
RFC2616#10.2
200 OK “indicates that the request has succeeded.” RFC7231#6.3.1,
RFC2616#10.2.1
201 Created “indicates that the request has been fulfilled and has resulted in one or more new resources being created.” RFC7231#6.3.2,
RFC2616#10.2.2
202 Accepted “indicates that the request has been accepted for processing, but the processing has not been completed.” RFC7231#6.3.3,
RFC2616#10.2.3
203 Non-Authoritative Information “indicates that the request was successful but the enclosed payload has been modified from that of the origin server’s 200 (OK) response by a transforming proxy.” RFC7231#6.3.4,
RFC2616#10.2.4
204 No Content “indicates that the server has successfully fulfilled the request and that there is no additional content to send in the response payload body.” RFC7231#6.3.5,
RFC2616#10.2.5
205 Reset Content “indicates that the server has fulfilled the request and desires that the user agent reset the “document view”, which caused the request to be sent, to its original state as received from the origin server.” RFC7231#6.3.6,
RFC2616#10.2.6
206 Partial Content “indicates that the server is successfully fulfilling a range request for the target resource by transferring one or more parts of the selected representation that correspond to the satisfiable ranges found in the requests’s Range header field.” RFC7233#4.1,
RFC2616#10.2.7

3xx

code reason description spec
3xx Redirection “indicates that further action needs to be taken by the user agent in order to fulfill the request.” ~ ask that dude over there RFC7231#6.4,
RFC2616#10.3
300 Multiple Choices “indicates that the target resource has more than one representation, each with its own more specific identifier, and information about the alternatives is being provided so that the user (or user agent) can select a preferred representation by redirecting its request to one or more of those identifiers.” RFC7231#6.4.1,
RFC2616#10.3.1
301 Moved Permanently “indicates that the target resource has been assigned a new permanent URI and any future references to this resource ought to use one of the enclosed URIs.” RFC7231#6.4.2,
RFC2616#10.3.2
302 Found “indicates that the target resource resides temporarily under a different URI.” RFC7231#6.4.3,
RFC2616#10.3.3
303 See Other “indicates that the server is redirecting the user agent to a different resource, as indicated by a URI in the Location header field, that is intended to provide an indirect response to the original request.” RFC7231#6.4.4,
RFC2616#10.3.4
304 Not Modified “indicates that a conditional GET request has been received and would have resulted in a 200 (OK) response if it were not for the fact that the condition has evaluated to false.” RFC7232#4.1,
RFC2616#10.3.5
305 Use Proxy deprecated RFC7231#6.4.5,
RFC2616#10.3.6
306 unused RFC7231#6.4.6,
RFC2616#10.3.7
307 Temporary Redirect “indicates that the target resource resides temporarily under a different URI and the user agent MUST NOT change the request method if it performs an automatic redirection to that URI.” RFC7231#6.4.7,
RFC2616#10.3.8

4xx

code reason description spec
4xx Client Error “indicates that the client seems to have erred.” ~ you fucked up RFC7231#6.5,
RFC2616#10.4
400 Bad Request “indicates that the server cannot or will not process the request because the received syntax is invalid, nonsensical, or exceeds some limitation on what the server is willing to process.” RFC7231#6.5.1,
RFC2616#10.4.1
401 Unauthorized “indicates that the request has not been applied because it lacks valid authentication credentials for the target resource.” RFC7235#6.3.1,
RFC2616#10.4.2
402 Payment Required reserved RFC7231#6.5.2,
RFC2616#10.4.3
403 Forbidden “indicates that the server understood the request but refuses to authorize it.” RFC7231#6.5.3,
RFC2616#10.4.4
404 Not Found “indicates that the origin server did not find a current representation for the target resource or is not willing to disclose that one exists.” RFC7231#6.5.4,
RFC2616#10.4.5
405 Method Not Allowed “indicates that the method specified in the request-line is known by the origin server but not supported by the target resource.” RFC7231#6.5.5,
RFC2616#10.4.6
406 Not Acceptable “indicates that the target resource does not have a current representation that would be acceptable to the user agent, according to the proactive negotiation header fields received in the request, and the server is unwilling to supply a default representation.” RFC7231#6.5.6,
RFC2616#10.4.7
407 Proxy Authentication Required “is similar to 401 (Unauthorized), but indicates that the client needs to authenticate itself in order to use a proxy.” RFC7235#3.2,
RFC2616#10.4.8
408 Request Timeout “indicates that the server did not receive a complete request message within the time that it was prepared to wait.” RFC7231#6.5.7,
RFC2616#10.4.9
409 Conflict “indicates that the request could not be completed due to a conflict with the current state of the resource.” RFC7231#6.5.8,
RFC2616#10.4.10
410 Gone “indicates that access to the target resource is no longer available at the origin server and that this condition is likely to be permanent.” RFC7231#6.5.9,
RFC2616#10.4.11
411 Length Required “indicates that the server refuses to accept the request without a defined Content-Length.” RFC7231#6.5.10,
RFC2616#10.4.12
412 Precondition Failed “indicates that one or more preconditions given in the request header fields evaluated to false when tested on the server.” RFC7232#4.2,
RFC2616#10.4.13
413 Payload Too Large “indicates that the server is refusing to process a request because the request payload is larger than the server is willing or able to process.” RFC7231#6.5.11,
RFC2616#10.4.14
414 URI Too Long “indicates that the server is refusing to service the request because the request-target is longer than the server is willing to interpret.” RFC7231#6.5.12,
RFC2616#10.4.15
415 Unsupported Media Type “indicates that the origin server is refusing to service the request because the payload is in a format not supported by the target resource for this method.” RFC7231#6.5.13,
RFC2616#10.4.16
416 Range Not Satisfiable “indicates that none of the ranges in the request’s Range header field overlap the current extent of the selected resource or that the set of ranges requested has been rejected due to invalid ranges or an excessive request of small or overlapping ranges.” RFC7233#4.4,
RFC2616#10.4.17
417 Expectation Failed “indicates that the expectation given in the request’s Expect header field could not be met by at least one of the inbound servers.” RFC7231#6.5.14,
RFC2616#10.4.18
418 I’m a teapot “Any attempt to brew coffee with a teapot should result in the error code 418 I’m a teapot.” RFC2324#2.3.2
426 Upgrade Required “indicates that the server refuses to perform the request using the current protocol but might be willing to do so after the client upgrades to a different protocol.” RFC7231#6.5.15

5xx

code reason description spec
5xx Server Error “indicates that the server is aware that it has erred or is incapable of performing the requested method.” ~ we fucked up RFC7231#6.6,
RFC2616#10.5
500 Internal Server Error “indicates that the server encountered an unexpected condition that prevented it from fulfilling the request.” RFC7231#6.6.1,
RFC2616#10.5.2
501 Not Implemented “indicates that the server does not support the functionality required to fulfill the request.” RFC7231#6.6.2,
RFC2616#10.5.3
502 Bad Gateway “indicates that the server, while acting as a gateway or proxy, received an invalid response from an inbound server it accessed while attempting to fulfill the request.” RFC7231#6.6.3,
RFC2616#10.5.4
503 Service Unavailable “indicates that the server is currently unable to handle the request due to a temporary overload or scheduled maintenance, which will likely be alleviated after some delay.” RFC7231#6.6.4,
RFC2616#10.5.5
504 Gateway Time-out “indicates that the server, while acting as a gateway or proxy, did not receive a timely response from an upstream server it needed to access in order to complete the request.” RFC7231#6.6.5,
RFC2616#10.5.6
505 HTTP Version Not Supported “indicates that the server does not support, or refuses to support, the protocol version that was used in the request message.” RFC7231#6.6.6,
RFC2616#10.5.6

Extensions

code reason description spec
102 Processing “is an interim response used to inform the client that the server has accepted the complete request, but has not yet completed it.” RFC5218#10.1
207 Multi-Status “provides status for multiple independent operations.” RFC5218#10.2
226 IM Used “The server has fulfilled a GET request for the resource, and the response is a representation of the result of one or more instance-manipulations applied to the current instance.” RFC3229#10.4.1
308 Permanent Redirect “The target resource has been assigned a new permanent URI and any future references to this resource outght to use one of the enclosed URIs. […] This status code is similar to 301 Moved Permanently (Section 7.3.2 of rfc7231), except that it does not allow rewriting the request method from POST to GET.” RFC7538
422 Unprocessable Entity “means the server understands the content type of the request entity (hence a 415(Unsupported Media Type) status code is inappropriate), and the syntax of the request entity is correct (thus a 400 (Bad Request) status code is inappropriate) but was unable to process the contained instructions.” RFC5218#10.3
423 Locked “means the source or destination resource of a method is locked.” RFC5218#10.4
424 Failed Dependency “means that the method could not be performed on the resource because the requested action depended on another action and that action failed.” RFC5218#10.5
428 Precondition Required “indicates that the origin server requires the request to be conditional.” RFC6585#3
429 Too Many Requests “indicates that the user has sent too many requests in a given amount of time (“rate limiting”).” RFC6585#4
431 Request Header Fields Too Large “indicates that the server is unwilling to process the request because its header fields are too large.” RFC6585#5
451 Unavailable For Legal Reasons “This status code indicates that the server is denying access to the resource in response to a legal demand.” draft-ietf-httpbis-legally-restricted-status
506 Variant Also Negotiates “indicates that the server has an internal configuration error: the chosen variant resource is configured to engage in transparent content negotiation itself, and is therefore not a proper end point in the negotiation process.” RFC2295#8.1
507 Insufficient Storage “means the method could not be performed on the resource because the server is unable to store the representation needed to successfully complete the request.” RFC5218#10.6
511 Network Authentication Required “indicates that the client needs to authenticate to gain network access.” RFC6585#6
7xx Developer Error err 7xx-rfc

http状态码一览

http状态吗及解释,中文版

1xx

code reason description spec
1xx 信息响应 “indicates an interim response for communicating connection status or request progress prior to completing the requested action and sending a final response.” ~ sure RFC7231#6.2,
RFC2616#10.1
100 Continue “信息型状态响应码表示目前为止一切正常, 客户端应该继续请求, 如果已完成请求则忽略.” RFC7231#6.2.1,
RFC2616#10.1.1
101 Switching Protocols “该代码是响应客户端的 Upgrade 标头发送的,并且指示服务器也正在切换的协议。.” RFC7231#6.2.2,
RFC2616#10.1.2

2xx

code reason description spec
2xx 成功响应 “indicates that the client’s request was successfully received, understood, and accepted.” ~ cool RFC7231#6.3,
RFC2616#10.2
200 OK “请求成功.” RFC7231#6.3.1,
RFC2616#10.2.1
201 Created “该请求已成功,并因此创建了一个新的资源。这通常是在PUT请求之后发送的响应。.” RFC7231#6.3.2,
RFC2616#10.2.2
202 Accepted “请求已经接收到,但还未响应,没有结果。意味着不会有一个异步的响应去表明当前请求的结果,预期另外的进程和服务去处理请求,或者批处理.” RFC7231#6.3.3,
RFC2616#10.2.3
203 Non-Authoritative Information N服务器已成功处理了请求,但返回的实体头部元信息不是在原始服务器上有效的确定集合,而是来自本地或者第三方的拷贝。当前的信息可能是原始版本的子集或者超集。例如,包含资源的元数据可能导致原始服务器知道元信息的超集。使用此状态码不是必须的,而且只有在响应不使用此状态码便会返回200 OK的情况下才是合适的.” RFC7231#6.3.4,
RFC2616#10.2.4
204 No Content “服务器成功处理了请求,但不需要返回任何实体内容,并且希望返回更新了的元信息。响应可能通过实体头部的形式,返回新的或更新后的元信息。如果存在这些头部信息,则应当与所请求的变量相呼应。如果客户端是浏览器的话,那么用户浏览器应保留发送了该请求的页面,而不产生任何文档视图上的变化,即使按照规范新的或更新后的元信息应当被应用到用户浏览器活动视图中的文档。由于204响应被禁止包含任何消息体,因此它始终以消息头后的第一个空行结尾.” RFC7231#6.3.5,
RFC2616#10.2.5
205 Reset Content “服务器成功处理了请求,且没有返回任何内容。但是与204响应不同,返回此状态码的响应要求请求者重置文档视图。该响应主要是被用于接受用户输入后,立即重置表单,以便用户能够轻松地开始另一次输入。与204响应一样,该响应也被禁止包含任何消息体,且以消息头后的第一个空行结束.” RFC7231#6.3.6,
RFC2616#10.2.6
206 Partial Content “服务器已经成功处理了部分 GET 请求。类似于 FlashGet 或者迅雷这类的 HTTP 下载工具都是使用此类响应实现断点续传或者将一个大文档分解为多个下载段同时下载。该请求必须包含 Range 头信息来指示客户端希望得到的内容范围,并且可能包含 If-Range 来作为请求条件.” RFC7233#4.1,
RFC2616#10.2.7

3xx

code reason description spec
3xx 重定向 “indicates that further action needs to be taken by the user agent in order to fulfill the request.” ~ ask that dude over there RFC7231#6.4,
RFC2616#10.3
300 Multiple Choices “被请求的资源有一系列可供选择的回馈信息,每个都有自己特定的地址和浏览器驱动的商议信息。用户或浏览器能够自行选择一个首选的地址进行重定向。” RFC7231#6.4.1,
RFC2616#10.3.1
301 Moved Permanently “被请求的资源已永久移动到新位置,并且将来任何对此资源的引用都应该使用本响应返回的若干个 URI 之一。如果可能,拥有链接编辑功能的客户端应当自动把请求的地址修改为从服务器反馈回来的地址。除非额外指定,否则这个响应也是可缓存的。” RFC7231#6.4.2,
RFC2616#10.3.2
302 Found “请求的资源现在临时从不同的 URI 响应请求。由于这样的重定向是临时的,客户端应当继续向原有地址发送以后的请求。只有在Cache-Control或Expires中进行了指定的情况下,这个响应才是可缓存的。” RFC7231#6.4.3,
RFC2616#10.3.3
303 See Other “对应当前请求的响应可以在另一个 URI 上被找到,而且客户端应当采用 GET 的方式访问那个资源。这个方法的存在主要是为了允许由脚本激活的POST请求输出重定向到一个新的资源。” RFC7231#6.4.4,
RFC2616#10.3.4
304 Not Modified “如果客户端发送了一个带条件的 GET 请求且该请求已被允许,而文档的内容(自上次访问以来或者根据请求的条件)并没有改变,则服务器应当返回这个状态码。304 响应禁止包含消息体,因此始终以消息头后的第一个空行结尾。” RFC7232#4.1,
RFC2616#10.3.5
305 Use Proxy 被请求的资源必须通过指定的代理才能被访问。Location 域中将给出指定的代理所在的 URI 信息,接收者需要重复发送一个单独的请求,通过这个代理才能访问相应资源。只有原始服务器才能建立305响应。 RFC7231#6.4.5,
RFC2616#10.3.6
306 unused 在最新版的规范中,306 状态码已经不再被使用。 RFC7231#6.4.6,
RFC2616#10.3.7
307 Temporary Redirect “请求的资源现在临时从不同的URI 响应请求。由于这样的重定向是临时的,客户端应当继续向原有地址发送以后的请求。只有在Cache-Control或Expires中进行了指定的情况下,这个响应才是可缓存的。” RFC7231#6.4.7,
RFC2616#10.3.8

4xx

code reason description spec
4xx 客户端响应 “indicates that the client seems to have erred.” ~ you fucked up RFC7231#6.5,
RFC2616#10.4
400 Bad Request “1、语义有误,当前请求无法被服务器理解。除非进行修改,否则客户端不应该重复提交这个请求。2、请求参数有误。” RFC7231#6.5.1,
RFC2616#10.4.1
401 Unauthorized “当前请求需要用户验证。该响应必须包含一个适用于被请求资源的 WWW-Authenticate 信息头用以询问用户信息。客户端可以重复提交一个包含恰当的 Authorization 头信息的请求。如果当前请求已经包含了 Authorization 证书,那么401响应代表着服务器验证已经拒绝了那些证书。如果401响应包含了与前一个响应相同的身份验证询问,且浏览器已经至少尝试了一次验证,那么浏览器应当向用户展示响应中包含的实体信息,因为这个实体信息中可能包含了相关诊断信息。” RFC7235#6.3.1,
RFC2616#10.4.2
402 Payment Required 此响应码保留以便将来使用,创造此响应码的最初目的是用于数字支付系统,然而现在并未使用。 RFC7231#6.5.2,
RFC2616#10.4.3
403 Forbidden “服务器已经理解请求,但是拒绝执行它。与 401 响应不同的是,身份验证并不能提供任何帮助,而且这个请求也不应该被重复提交。如果这不是一个 HEAD 请求,而且服务器希望能够讲清楚为何请求不能被执行,那么就应该在实体内描述拒绝的原因。当然服务器也可以返回一个 404 响应,假如它不希望让客户端获得任何信息。” RFC7231#6.5.3,
RFC2616#10.4.4
404 Not Found “请求失败,请求所希望得到的资源未被在服务器上发现。没有信息能够告诉用户这个状况到底是暂时的还是永久的。假如服务器知道情况的话,应当使用410状态码来告知旧资源因为某些内部的配置机制问题,已经永久的不可用,而且没有任何可以跳转的地址。404这个状态码被广泛应用于当服务器不想揭示到底为何请求被拒绝或者没有其他适合的响应可用的情况下。” RFC7231#6.5.4,
RFC2616#10.4.5
405 Method Not Allowed “请求行中指定的请求方法不能被用于请求相应的资源。该响应必须返回一个Allow 头信息用以表示出当前资源能够接受的请求方法的列表。   鉴于 PUT,DELETE 方法会对服务器上的资源进行写操作,因而绝大部分的网页服务器都不支持或者在默认配置下不允许上述请求方法,对于此类请求均会返回405错误。” RFC7231#6.5.5,
RFC2616#10.4.6
406 Not Acceptable “请求的资源的内容特性无法满足请求头中的条件,因而无法生成响应实体。” RFC7231#6.5.6,
RFC2616#10.4.7
407 Proxy Authentication Required “与401响应类似,只不过客户端必须在代理服务器上进行身份验证。代理服务器必须返回一个 Proxy-Authenticate 用以进行身份询问。客户端可以返回一个 Proxy-Authorization 信息头用以验证。” RFC7235#3.2,
RFC2616#10.4.8
408 Request Timeout “请求超时。客户端没有在服务器预备等待的时间内完成一个请求的发送。客户端可以随时再次提交这一请求而无需进行任何更改。” RFC7231#6.5.7,
RFC2616#10.4.9
409 Conflict “由于和被请求的资源的当前状态之间存在冲突,请求无法完成。这个代码只允许用在这样的情况下才能被使用:用户被认为能够解决冲突,并且会重新提交新的请求。该响应应当包含足够的信息以便用户发现冲突的源头。” RFC7231#6.5.8,
RFC2616#10.4.10
410 Gone “被请求的资源在服务器上已经不再可用,而且没有任何已知的转发地址。这样的状况应当被认为是永久性的。如果可能,拥有链接编辑功能的客户端应当在获得用户许可后删除所有指向这个地址的引用。如果服务器不知道或者无法确定这个状况是否是永久的,那么就应该使用 404 状态码。除非额外说明,否则这个响应是可缓存的。” RFC7231#6.5.9,
RFC2616#10.4.11
411 Length Required “服务器拒绝在没有定义 Content-Length 头的情况下接受请求。在添加了表明请求消息体长度的有效 Content-Length 头之后,客户端可以再次提交该请求。” RFC7231#6.5.10,
RFC2616#10.4.12
412 Precondition Failed “服务器在验证在请求的头字段中给出先决条件时,没能满足其中的一个或多个。这个状态码允许客户端在获取资源时在请求的元信息(请求头字段数据)中设置先决条件,以此避免该请求方法被应用到其希望的内容以外的资源上。” RFC7232#4.2,
RFC2616#10.4.13
413 Payload Too Large “服务器拒绝处理当前请求,因为该请求提交的实体数据大小超过了服务器愿意或者能够处理的范围。此种情况下,服务器可以关闭连接以免客户端继续发送此请求。如果这个状况是临时的,服务器应当返回一个 Retry-After 的响应头,以告知客户端可以在多少时间以后重新尝试。” RFC7231#6.5.11,
RFC2616#10.4.14
414 URI Too Long “请求的URI 长度超过了服务器能够解释的长度,因此服务器拒绝对该请求提供服务。这比较少见,通常的情况包括:本应使用POST方法的表单提交变成了GET方法,导致查询字符串(Query String)过长。” RFC7231#6.5.12,
RFC2616#10.4.15
415 Unsupported Media Type “对于当前请求的方法和所请求的资源,请求中提交的实体并不是服务器中所支持的格式,因此请求被拒绝。” RFC7231#6.5.13,
RFC2616#10.4.16
416 Range Not Satisfiable “如果请求中包含了 Range 请求头,并且 Range 中指定的任何数据范围都与当前资源的可用范围不重合,同时请求中又没有定义 If-Range 请求头,那么服务器就应当返回416状态码。” RFC7233#4.4,
RFC2616#10.4.17
417 Expectation Failed “此响应代码意味着服务器无法满足 期望 请求标头字段指示的期望值。” RFC7231#6.5.14,
RFC2616#10.4.18
418 I’m a teapot “服务器拒绝尝试用 “茶壶冲泡咖啡”。” RFC2324#2.3.2
426 Upgrade Required “服务器拒绝使用当前协议执行请求,但可能在客户机升级到其他协议后愿意这样做。 服务器在 426 响应中发送 Upgrade 头以指示所需的协议。” RFC7231#6.5.15

5xx

code reason description spec
5xx 服务端响应 “indicates that the server is aware that it has erred or is incapable of performing the requested method.” ~ we fucked up RFC7231#6.6,
RFC2616#10.5
500 Internal Server Error “服务器遇到了不知道如何处理的情况。” RFC7231#6.6.1,
RFC2616#10.5.2
501 Not Implemented “此请求方法不被服务器支持且无法被处理。只有GET和HEAD是要求服务器支持的,它们必定不会返回此错误代码。” RFC7231#6.6.2,
RFC2616#10.5.3
502 Bad Gateway “此错误响应表明服务器作为网关需要得到一个处理这个请求的响应,但是得到一个错误的响应。” RFC7231#6.6.3,
RFC2616#10.5.4
503 Service Unavailable “服务器没有准备好处理请求。 常见原因是服务器因维护或重载而停机。 请注意,与此响应一起,应发送解释问题的用户友好页面。 这个响应应该用于临时条件和 Retry-After:如果可能的话,HTTP头应该包含恢复服务之前的估计时间。 网站管理员还必须注意与此响应一起发送的与缓存相关的标头,因为这些临时条件响应通常不应被缓存。” RFC7231#6.6.4,
RFC2616#10.5.5
504 Gateway Time-out “当服务器作为网关,不能及时得到响应时返回此错误代码。” RFC7231#6.6.5,
RFC2616#10.5.6
505 HTTP Version Not Supported “服务器不支持请求中所使用的HTTP协议版本。” RFC7231#6.6.6,
RFC2616#10.5.6

扩展码

code reason description spec
102 Processing “此代码表示服务器已收到并正在处理该请求,但没有响应可用” RFC5218#10.1
207 Multi-Status “由WebDAV(RFC 2518)扩展的状态码,代表之后的消息体将是一个XML消息,并且可能依照之前子请求数量的不同,包含一系列独立的响应代码。” RFC5218#10.2
226 IM Used “服务器已经完成了对资源的 GET 请求,并且响应是对当前实例应用的一个或多个实例操作结果的表示。” RFC3229#10.4.1
308 Permanent Redirect “T这意味着资源现在永久位于由 Location: HTTP Response 标头指定的另一个 URI。 这与 301 Moved Permanently HTTP 响应代码具有相同的语义,但用户代理不能更改所使用的 HTTP 方法:如果在第一个请求中使用 POST,则必须在第二个请求中使用 POST。” RFC7538
422 Unprocessable Entity “请求格式良好,但由于语义错误而无法遵循。” RFC5218#10.3
423 Locked “正在访问的资源被锁定。” RFC5218#10.4
424 Failed Dependency “由于先前的请求失败,所以此次请求失败。” RFC5218#10.5
428 Precondition Required “原始服务器要求该请求是有条件的。 旨在防止“丢失更新”问题,即客户端获取资源状态,修改该状态并将其返回服务器,同时第三方修改服务器上的状态,从而导致冲突。” RFC6585#3
429 Too Many Requests “用户在给定的时间内发送了太多请求(“限制请求速率”)。” RFC6585#4
431 Request Header Fields Too Large “服务器不愿意处理请求,因为它的 请求头字段太大( Request Header Fields Too Large)。 请求可以在减小请求头字段的大小后重新提交.” RFC6585#5
451 Unavailable For Legal Reasons “T用户请求非法资源,例如:由政府审查的网页。” draft-ietf-httpbis-legally-restricted-status
506 Variant Also Negotiates “服务器有一个内部配置错误:对请求的透明内容协商导致循环引用。” RFC2295#8.1
507 Insufficient Storage “服务器有内部配置错误:所选的变体资源被配置为参与透明内容协商本身,因此不是协商过程中的适当端点。” RFC5218#10.6
511 Network Authentication Required “511 状态码指示客户端需要进行身份验证才能获得网络访问权限。” RFC6585#6
7xx Developer Error err 7xx-rfc

php使用curl时报错解决方法

问题总结

问:file_get_contents 开启https支持

答:配置php.ini 开启php_openssl.dll 扩展,开启allow_url_fopen=On
代码部分:

1
2
3
4
5
$w = stream_get_wrappers();
echo 'openssl: ', extension_loaded ('openssl') ? 'yes':'no', "\n";
echo 'http wrapper: ', in_array('http', $w) ? 'yes':'no', "\n";
echo 'https wrapper: ', in_array('https', $w) ? 'yes':'no', "\n";
echo 'wrappers: ', var_export($w);

作用:用于检测配置项是否存在https;

问:curl 抓取网站信息时,出现此错误:This site requires JavaScript and Cookies to be enabled.

答:修改curl 参数CURLOPT_USERAGENT为Google Bot,伪装成google bot去抓取
代码部分:

1
curl_setopt($ch, CURLOPT_USERAGENT, "Google Bot");

作用:伪装成谷歌机器去抓取页面信息

hexo deploy failed

question


INFO Deploying: git

INFO Clearing .deploy folder…

FATAL Something’s wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html

FATAL EACCES: permission denied, open ‘/home/yang/hexo/db.json’

Error: EACCES: permission denied, open ‘/home/yang/hexo/db.json’

* answer:

1. sudo ssh-keygen -t rsa -b 4096 -C “xxx@xxx.com

2. copy /var/root/.ssh/id_rsa/id_rsa_pub -> github/settings/SSH and GPG keys/new ssh key

3. hexo deploy

* answer2:

1. su root

3. hexo deploy

你是本站第位访客 本站访客数人次
Fork me on GitHub