1 | #设置键值 ex表示妙 nx:键不存在时创建 |
1 | 127.0.0.1:6379[2]> hset people age 18 |
1 | 127.0.0.1:6379[2]> lpush frined 1 2 3 4 5 |
1 | #集合追加元素 |
1 | #增加集合元素 |
1 | server { |
1 | http{ |
1 | #gzip on; |
#compose 版本 有 1,2,3 三个版本1
version: "3"
##服务器信息1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114services:
#web服务器
web:
image: dockercloud/hello-world #镜像信息 本地有用本地,没有的话从远程获取
#容器名称
container_name: hello-world
#主机名称
hostname: hello-world.com
#本机端口映射到容器端口,YAML将会解析xx:yy这种数字格式为60进制,建议采用字符串格式
ports:
-"8080:8080"
-"127.0.0.1:9000:8080"
#向hosts文件中添加域名解析记录
extra_hosts:
-"www.test.com:162.185.32.65"
#挂载一个目录或已存在的数据卷容器,格式: [HOST:CONTAINER] or [HOST:CONTAINER:ro](只读)
volumes:
-./web/data_dir:/demo/data_dir
-./web/logs:/demo/logs
#不使用宿主目录而使用自定义驱动
volume_driver:yourdriver
#从另外服务或容器挂载数据卷
volumes_from:
-server_name
-container_name
#定义接入点,会覆盖dockerfile文件中的entrypoint
entrypoint:./
restart:
#服务器连接
links:
-database:database
#容器启动后执行的命令,例:composer install or ['composer','install']
command:composer install
#控制服务容器启动顺序,在web服务器启动前先启动databse服务及redis
depends_on:
-database
-redis
#基于其他模板进行扩展
extends:
-file:common.yaml
-service:common
#连接到docker-compose.yaml外部容器
external_links:
-project_db_1:mysql
#为容器添加Docker元数据(metadata)信息
lables:
decription:"web app service"
#日志驱动类型,有json-file|syslog|none三种类型
log_driver:
"josn-file"
#日志驱动参数
log_opt:
address:""
#增加指定容器内核能力
cap_add:
-ALL
#去掉指定容器内核能力
cap_drop:
-NET_ADMIN
#配置DNS服务器
dns:
-8.8.8.8
-4.4.4.4
#从文件中获取环境变量,优先级低于environment设置的环境变量
env_file:
-./env
#redis服务容器
redis:
image: redis
links:
-web
networks:
-back-tier
#数据库服务容器
database:
image: beginor/postgis:9.3
container_name: postgis
hostname: postgis
ports:
-5432:5432
volumes:
-./database/data:/var/lib/postgresql/data
environment:
POSTGRES_PASSWORD: 1q2w3e4R
restart:
networks:
front-tier:
driver: bridge
back-tier:
driver: bridge
#移除老版本1
sudo apt-get remove docker docker-engine docker.io containerd runc
#安装1
sudo apt-get install docker-ce docker-ce-cli containerd.io
#安装指定版本
#查看可用的版本1
apt-cache madison docker-ce
#安装1
sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io
#验证安装1
sudo docker run hello-world
#查看docker信息1
docker info
#避免使用sudo 加入docker用户组1
sudo usermod -aG docker $USER
#启动服务1
sudo service docker start
#停止服务1
sudo service docker stop
#列出image文件1
docker image ls
#删除image文件1
docker image rm [imagename]
#拉取远程image到本地1
docker image pull library/hello-world 或者 docker image pull hello-world
注:library是官方默认组
#运行image1
docker container run hello-world
注:此命令实际等同于 docker image pull hello-world + docker container run
#启动容器1
docker container start [containerID]
注:与run的区别是:start每次执行的是同一个containerID 而run每次都是新contarinerID
#停止1
docker container stop [containerID]
#查看容器里shell输出1
docker container logs
#进入到正在运行的容器中1
docker container exec -it [containerID] /bin/bash
#copy 文件到本地1
docker container cp [containerID]:/var/www/html
#强制停止容器进程1
docker container kill [containerID]
#列出正在运行的容器1
docker container ls
#删除本地容器文件1
docker container rm [containerID]
##编写dockerfile 文件,例子1
2
3
4
5
6
7
8
9
10
11
12#该文件继承官方(docker官方)mysql image,版本号是5.7
FROM mysql:5.7
#运行授权用户组命令
RUN chown -R mysql:root /var/lib/mysql/
#copy本机文件到image /etc/mysql...目录
COPY my.cnf /etc/mysql/conf.d/my.cnf
#分配权限为配置文件
RUN chmod 0444 /etc/mysql/conf.d/my.cnf
#
CMD ["mysqld"]
#外部访问端口
EXPOSE 3306
#使用dockerfile 创建image文件1
docker image build -t image-demo . or docker image build -t image-demo:0.0.1 ./demo
注:./demo/ 为创建的目录地址,:0.0.1为版本号,默认为latest
#查看刚才创建的image1
docker image ls
#使用刚才建立的image 生成对应容器1
docker container [--rm] run -p 9000:3306 -it image-demo /bin/bash
注:-p 9000 本机访问端口 -it:将本地shell映射到image shell,/bin/bash 运行的命令使用bash shell
–rm 运行停止后自动清除本地容器文件
##发布image
#注册账号在[hub.docker.com]hub.docker.com
#登陆1
docker login
#为本地image标注用户名和标签1
docker image tag image-demo:0.0.1 demo-username/image-demo:0.0.1
#发布1
docker image push demo-username/image-demo:0.0.1
##使用docker-compose
#安装1
sudo curl -L "https://github.com/docker/compose/releases/download/1.26.0/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
#赋权限1
sudo chmod +x /usr/local/bin/docker-compose
#增加软连接1
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
#测试安装1
docker-compose --version
#启动1
docker-compose up
#停止1
docker-compose stop
#容器停止后移除容器文件1
docker-compose rm
1 | mkdir /test |
修改完执行以下操作1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23/usr/bin/php74/bin/phpize
./configure --with-php-config=/usr/bin/php74/bin/php-config
make
make test
make install
编辑php.ini
查看php配置文件 /usr/bin/php74/bin/php -i |grep php.ini
增加扩展: extension=my_test.so
查看扩展
/usr/bin/php74/bin/php -m
测试新加函数
/usr/bin/php74/bin/php -r "my_test();"
1 | DB::select("select a.title,a.name from |
1 | /** |
1 | #! /bin/bash |
1 | select |
1 | select |
1 | select |
1 | select |
1.步骤1
在配置文件增加三行
1 | ### 将mysql二进制日志取名为mysql-bin |
重启mysql
1 | service mysqld restart |
配置从服务器,与上面一样,不过 server-id要换成 200,这个值你随便设置 在1-2^23之间
2.步骤2
1 | #### 先登陆mysql |
3.步骤3
1 | #### 配置完从服务器之前不要对主服务器进行任何操作,因为每次操作数据库时这两值会发生改变 |
4.步骤4
配置从服务器
1 | #### 先看下从服务器状态 |
参数解释:
master_host
:设置要连接的主服务器的ip地址 master_user
:设置要连接的主服务器的用户名 matser_password
:设置要连接的主服务器的密码mysql_log_file
:设置要连接的主服务器的bin日志的日志名称,即第3步得到的信息mysql_log_pos
:设置要连接的主服务器的bin日志的记录位置,即第3步得到的信息,(这里注意,最后一项不需要加引号。否则配置失败5.查看是否成功1
2show master status;
#### 成功会提示 Slave_IO_Running: yes | Slave_sql_Running yes
1.基于SQL语句的复制(statement-based replication,SBR) binlog_format=statement
2.基于行的复制(row-based replication,RBR) binlog_format=row
3.混合模式复制(mixed-based replication,MBR) binlog_format=mixed
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
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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.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 参数CURLOPT_USERAGENT为Google Bot,伪装成google bot去抓取
代码部分:1
curl_setopt($ch, CURLOPT_USERAGENT, "Google Bot");
作用:伪装成谷歌机器去抓取页面信息
]]>Distributor ID | Desc | Third Realease |
---|---|---|
Debian | CDebian GNU/Linux 9.4 (stretch) | 9.4 |
Command | showinfo | other |
---|---|---|
uname -r | 4.9.0-6-amd64 | none |
cat /proc/version | Linux version 4.9.0-6-amd64 | (gcc 6.3.0 20170516(Debian 6.3.0-18+deb9u1) |
CGI全称是“公共网关接口”(Common Gateway Interface),HTTP服务器与你的或其它机器上的程序进行“交谈”的一种工具,
其程序须运行在网络服务器上。CGI可以用任何一种语言编写,只要这种语言具有标准输入、输出和环境变量。如php,
perl,tcl等
PS:是一种协议
FastCGI像是一个常驻(long-live)型的CGI,它可以一直执行着,只要激活后,不会每次都要花费时间去fork一次(这是CGI
最为人诟病的fork-and-execute 模式)。它还支持分布式的运算, 即 FastCGI 程序可以在网站服务器以外的主机上执行并
且接受来自其它网站服务器来的请求。FastCGI是语言无关的、可伸缩架构的CGI开放扩展,其主要行为是将CGI解释器进程
保持在内存中并因此获得较高的性能。众所周知,CGI解释器的反复加载是CGI性能低下的主要原因,如果CGI解释器保持在
内存中并接受FastCGI进程管理器调度,则可以提供良好的性能、伸缩性、Fail- Over特性等等。
PS:同样是一种协议
PHP-CGI是PHP自带的FastCGI管理器。
PS:PHP解释器
PHP-FPM是一个PHP FastCGI管理器,是一个补丁,用于将fastCGI整合进php包中,php5.3.3后已经集成到php中,之前的版
本属于第三方包
PS:php-fpm是fastcgi进程的管理器,用来管理fastcgi进程的,它实现了Fastcgi的程序,被PHP官方收了
Spawn-FCGI是一个通用的FastCGI管理服务器,它是lighttpd中的一部份,很多人都用Lighttpd的Spawn-FCGI进行FastCGI模
式下的管理工作
PS:一个通用的FastCGI管理服务器
CGI:每当客户请求CGI的时候,WEB服务器就请求操作系统生成一个新的CGI解释器进程(如php-cgi.exe,CGI的一个进程则处
理完一个请求后退出,下一个请求来时再创建新进程。当然,这样在访问量很少没有并发的情况也行。可是当访问量增大并
发存在,这种方式就不 适合了。于是就有了fastcgi。
fastCGI:FastCGI像是一个常驻(long-live)型的CGI,它可以一直执行着,只要激活后,不会每次都要花费时间去fork一次
(这是CGI最为人诟病的fork-and-execute 模式)。
1、Web Server启动时载入FastCGI进程管理器(IIS ISAPI或Apache Module)
2、FastCGI进程管理器自身初始化,启动多个CGI解释器进程(可见多个php-cgi)并等待来自Web Server的连接。
3、当客户端请求到达Web Server时,FastCGI进程管理器选择并连接到一个CGI解释器。Web server将CGI环境变量和标
准输入发送到FastCGI子进程php-cgi。
4、FastCGI子进程完成处理后将标准输出和错误信息从同一连接返回WebServer。当FastCGI子进程关闭连接时,请求便
告处理完成。FastCGI子进程接着等待并处理来自FastCGI进程管理器(运行在Web Server中)的下一个连接。 在CGI模式中,
php-cgi在此便退出了。
在上述情况中,你可以想象CGI通常有多慢。每一个Web请求PHP都必须重新解析php.ini、重新载入全部扩展并重初始化
全部数据结构。使用FastCGI,所有这些都只在进程启动时发生一次。一个额外的好处是,持续数据库连接可以工作。
因为是多进程,所以比CGI多线程消耗更多的服务器内存,PHP-CGI解释器每进程消耗7至25兆内存,将这个数字乘以50或
100就是很大的内存数。Nginx 0.8.46+PHP 5.2.14(FastCGI)服务器在3万并发连接下,开启的10个Nginx进程消耗150M内存
(15M10=150M),开启的64个php-cgi进程消耗1280M内存(20M64=1280M),加上系统自身消耗的内存,总共消耗不到2GB
内存。如果服务器内存较小,完全可以只开启25个php-cgi进程,这样php-cgi消耗的总内存数才500M。
1、php-cgi变更php.ini配置后需重启php-cgi才能让新的php-ini生效,不可以平滑重启
2、直接杀死php-cgi进程,php就不能运行了。(PHP-FPM和Spawn-FCGI就没有这个问题,守护进程会平滑从新生成新的子进程。)
首先,CGI是干嘛的?CGI是为了保证web server传递过来的数据是标准格式的,方便CGI程序的编写者。
web server(比如说nginx)只是内容的分发者。比如,如果请求index.html,那么webserver会去文件系统中找到这个文件
,发送给浏览器,这里分发的是静态数据。好了,如果现在请求的是/index.php,根据配置文件,nginx知道这个不是静态
文件,需要去找PHP解析器来处理,那么他会把这个请求简单处理后交给PHP解析器。Nginx会传哪些数据给PHP解析器呢?
url要有吧,查询字符串也得有吧,POST数据也要有,HTTP header不能少吧,好的,CGI就是规定要传哪些数据、以什么
样的格式传递给后方处理这个请求的协议。仔细想想,你在PHP代码中使用的用户从哪里来的。
当web server收到/index.php这个请求后,会启动对应的CGI程序,这里就是PHP的解析器。接下来PHP解析器会解
析php.ini文件,初始化执行环境,然后处理请求,再以规定CGI规定的格式返回处理后的结果,退出进程。web server
再把结果返回给浏览器。好了,CGI是个协议,跟进程什么的没关系。那fastcgi又是什么呢?Fastcgi是用来提高CGI程序
性能的。提高性能,那么CGI程序的性能问题在哪呢?”PHP解析器会解析php.ini文件,初始化执行环境”,就是这里了。
标准的CGI对每个请求都会执行这些步骤(不闲累啊!启动进程很累的说!),所以处理每个时间的时间会比较长。这明
显不合理嘛!那么Fastcgi是怎么做的呢?首先,Fastcgi会先启一个master,解析配置文件,初始化执行环境,然后再启
动多个worker。当请求过来时,master会传递给一个worker,然后立即可以接受下一个请求。这样就避免了重复的劳动,
效率自然是高。而且当worker不够用时,master可以根据配置预先启动几个worker等着;当然空闲worker太多时,也会
停掉一些,这样就提高了性能,也节约了资源。这就是fastcgi的对进程的管理。
那PHP-FPM又是什么呢?是一个实现了Fastcgi的程序,被PHP官方收了。
大家都知道,PHP的解释器是php-cgi。php-cgi只是个CGI程序,他自己本身只能解析请求,返回结果,不会进程管理
所以就出现了一些能够调度php-cgi进程的程序,比如说由lighthttpd分离出来的spawn-fcgi。好了PHP-FPM也是这么
个东东,在长时间的发展后,逐渐得到了大家的认可(要知道,前几年大家可是抱怨PHP-FPM稳定性太差的),也越来越流行。
参考地址:
https://www.cnblogs.com/wanghetao/p/3934350.html
https://www.lvtao.net/tool/885.html
究竟该如何选择PHP版本,什么是线程安全,什么又是非线程安全
线程安全:线程安全就是多线程访问时,采用了加锁机制,当一个线程访问该类的某个数据时,进行保护,其他线程不能进行访问直到该线程读取完,其他线程才可使用。不会出现数据不一致或者数据污染
非线程安全(即线程不安全):线程不安全就是不提供数据访问保护,有可能出现多个线程先后更改数据造成所得到的数据是脏数据。
我选择哪个版本?
IIS
如果你使用的是PHP的FastCGI IIS,你应该使用非线程安全(NTS)版本的PHP。
Apache
请使用Apache Lounge提供的Apache构建。 他们提供了针对x86和x64的Apache的VC9,VC11和VC14版本。 我们使用他们的二进制文件构建Apache SAPI。
如果你使用PHP作为apache.org(不推荐)的Apache模块,你需要使用旧的Visual Studio 6编译的VC6版本的PHP。 不要使用apache.org二进制文件的VC9 +版本的PHP。
使用Apache,您必须使用Thread Safe(TS)版本的PHP。
解释如下:
从2000年10月20日发布的第一个Windows版的PHP3.0.17开始的都是线程安全的版本,这是由于与Linux/Unix系统是采用多进程的工作方式不同的是Windows系统是采用多线程的工作方式。如果在IIS下以CGI方式运行PHP会非常慢,这是由于CGI模式是建立在多进程的基础之上的,而非多线程。一般我们会把PHP配置成以ISAPI的方式来运行,ISAPI是多线程的方式,这样就快多了。但存在一个问题,很多常用的PHP扩展是以Linux/Unix的多进程思想来开发的,这些扩展在ISAPI的方式运行时就会出错搞垮IIS。因此在IIS下CGI模式才是PHP运行的最安全方式,但CGI模式对于每个HTTP请求都需要重新加载和卸载整个PHP环境,其消耗是巨大的。
为了兼顾IIS下PHP的效率和安全,微软给出了FastCGI的解决方案。FastCGI可以让PHP的进程重复利用而不是每一个新的请求就重开一个进程。同时FastCGI也可以允许几个进程同时执行。这样既解决了CGI进程模式消耗太大的问题,又利用上了CGI进程模式不存在线程安全问题的优势。
因此,如果是使用ISAPI的方式来运行PHP就必须用Thread Safe(线程安全)的版本;而用FastCGI模式运行PHP的话就没有必要用线程安全检查了,用None Thread Safe(NTS,非线程安全)的版本能够更好的提高效率。
]]>1 | warning: LF will be replaced by CRLF in tags/sublime/index.html. |
回车(CR, ASCII 13, \r) 换行(LF, ASCII 10, \n)。
这两个ACSII字符不会在屏幕有任何输出,但在Windows中广泛使用【CRLF】来标识一行的结束。而在Linux/UNIX系统中只有换行符。
也就是说在windows中的换行符为 CRLF, 而在linux下的换行符为:LF
因为git是基于unix的,默认为LF,而现在使用的是windows,所以会提示 LF呗替换为CRLF
删除刚刚生成的.git文件,代码1
2$ rm -rf .git
$ git config --gobal core.autocrlf false
英文:1
npm WARN deprecated swig@1.4.2:This package is no longer maintained
翻译:npm WARN弃用swig@1.4.2:这个包不再维护
使用国内安装源,这里使用淘宝的,命令如下:1
npm install -g cnpm --registry=https://registry.npm.taobao.org
使用国内的安装源后命令变为cnpm,如下:
1 | $ npm install hexo-cli -g |
1 | $ cnpm install hexo-cli -g |
如果我不想使用国内的镜像怎么办呢,那也很简单,命令如下1
$ cnpm onfig edit
找到bash registry=https://registry.npm.taobao.org
将其注释即可