解决方案:
1 | export LC_ALL="en_US.UTF-8" |
ModuleNotFoundError: No module named 'twisted.persisted'
1 | 1.pip uninstall twisted |
生活心情
1 | export LC_ALL="en_US.UTF-8" |
ModuleNotFoundError: No module named 'twisted.persisted'
1 | 1.pip uninstall twisted |
并发是指同时处理的request的数量。其有全局限制和局部(每个网站)的限制。
Scrapy默认的全局并发限制对同时爬取大量网站的情况并不适用,因此您需要增加这个值。 增加多少取决于您的爬虫能占用多少CPU。 一般开始可以设置为 100 。不过最好的方式是做一些测试,获得Scrapy进程占取CPU与并发数的关系。 为了优化性能,您应该选择一个能使CPU占用率在80%-90%的并发数
在setting.py
文件中写上CONCURRENT_REQUESTS = 100
,scrapy中默认的并发数是32
当进行通用爬取时,一般您所注意的仅仅是爬取的速率以及遇到的错误。 Scrapy使用 INFO log级别来报告这些信息。为了减少CPU使用率(及记录log存储的要求), 在生产环境中进行通用爬取时您不应该使用 DEBUG log级别。 不过在开发的时候使用 DEBUG 应该还能接受。
setting.py
文件中设置LOG_LEVEL = 'INFO'
除非您 真的 需要,否则请禁止cookies。在进行通用爬取时cookies并不需要, (搜索引擎则忽略cookies)。禁止cookies能减少CPU使用率及Scrapy爬虫在内存中记录的踪迹,提高性能。
COOKIES_ENABLED = False
对失败的HTTP请求进行重试会减慢爬取的效率,尤其是当站点响应很慢(甚至失败)时, 访问这样的站点会造成超时并重试多次。这是不必要的,同时也占用了爬虫爬取其他站点的能力。
RETRY_ENABLED = False
如果您对一个非常慢的连接进行爬取(一般对通用爬虫来说并不重要), 减小下载超时能让卡住的连接能被快速的放弃并解放处理其他站点的能力。
DOWNLOAD_TIMEOUT = 15
,其中15是设置的下载超时时间
除非您对跟进重定向感兴趣,否则请考虑关闭重定向。 当进行通用爬取时,一般的做法是保存重定向的地址,并在之后的爬取进行解析。 这保证了每批爬取的request数目在一定的数量, 否则重定向循环可能会导致爬虫在某个站点耗费过多资源。
REDIRECT_ENABLED = False
1 | from scrapy import log |
1 | 200:请求成功 处理方式:获得响应的内容,进行处理 |
1 | import random |
DOWMLOAD_DELY=3
,设置延迟下载可以避免被发现
scrapy shell url
查看网页,不过这种方式可能对于要请求头的网页不行,对于一般的网页还是可以的scrapy view shell
用来查看动态加载的网页,如果查看的网页用了动态加载,那么用这个命令行打开的网页就是不完整的,肯定缺少了什么
1 | from scrapy.shell import inspect_response |
初学者最头疼的事情就是没有处理好异常,当爬虫爬到一半的时候突然因为错误而中断了,但是这时又不能从中断的地方开始继续爬,顿时感觉心里日了狗,但是这里有一个方法可以暂时的存储你爬的状态,当爬虫中断的时候继续打开后依然可以从中断的地方爬,不过虽说持久化可以有效的处理,但是要注意的是当使用cookie临时的模拟登录状态的时候要注意cookie的有效期
只需要在setting.py中JOB_DIR=file_name
其中填的是你的文件目录,注意这里的目录不允许共享,只能存储单独的一个spdire的运行状态,如果你不想在从中断的地方开始运行,只需要将这个文件夹删除即可
当然还有其他的放法:scrapy crawl somespider -s JOBDIR=crawls/somespider-1
,这个是在终端启动爬虫的时候调用的,可以通过ctr+c
中断,恢复还是输入上面的命令
ROBOTSTXT_OBEY = False
ROBOTSTXT_OBEY = False
1 | DEFAULT_REQUEST_HEADERS={{ |
源代码包放在 /usr/local/src 目录下,安装路径在 /usr/local下
下载 Nginx 源码包,我选择的是 1.10.3 稳定版
1 | # cd /usr/local/src |
解压源码包
1 | $ cd /usr/local/src |
配置安装路径
1 | $ cd /usr/local/src/nginx-1.10.3/ |
此时编译报错:没有 C 编译器 ./configure: error: C compiler cc is not found
1 | sudo apt-get install build-essential |
再次配置安装路径,报错:缺少 PCRE 库 ./configure: error: the HTTP rewrite module requires the PCRE library.
下载 pcre 库源码并解压
1 | $ cd /usr/local/src/ |
再次配置安装路径
1 | $ cd /usr/local/src/nginx-1.10.3/ |
报错:缺少 zlib 库 ./configure: error: the HTTP gzip module requires the zlib library.
如上方法,下载 zlib 源码并解压
1 | $ cd /usr/local/src/ |
再次配置安装路径
1 | $ cd /usr/local/src/nginx-1.10.3/ |
此时成功了 o( ̄▽ ̄)
别忘了最后一步
1 | make && make install |
启动 nginx
1 | $ /user/local/nginx/sbin/nginx |
可能会出现的问题
1 | The program 'nginx' can be found in the following packages: |
* 解决方案:
1
2
3
4
apt-get install nginx-core
apt-get install nginx-extras
apt-get install nginx-full
apt-get install nginx-light
查看网页
在chrome查看80端口,出现该页面,说明我已经成功安装nginx了o( ̄▽ ̄)
1 | $ cd /usr/local/src/ |
1 | $ cd /usr/local/src/ |
1 | $ cd /usr/local/src/php-7.1.4 |
configure: error: xml2-config not found. Please check your libxml2 installation.
1 | # 安装libxml2和libxml2-dev |
configure: error: Cannot find OpenSSL’s
1 | # 安装openssl和libssl-dev Ubuntu上没有openssl-develb包 |
configure: error: Cannot find OpenSSL’s libraries
1 | $ apt-get install pkg-config libssl-dev openssl |
configure: error: png.h not found.
1 | $ apt-get install libjpeg-dev libpng-dev |
继续配置安装路径,这一次终于成功了😄
编译PHP
1 | $ cd /usr/local/src/php-7.1.4 |
1 | $ cd /usr/local/php |
1 | # 位置 /etc/nginx/nginx.conf |
配置文件里这些都给你写了,其实只要把注释去掉即可。
然后优雅的重启下 Nginx
和 php-fpm
1 | # 目录 /usr/local/nginx |
ERROR: [pool www] cannot get gid for group ‘nobody’1
2
- 解决:
$ cd /usr/local/php/etc/php-fpm.d/
$ vim www.conf
group
后边的 nobody
改为 www-data
group=www-data1
2
3
4
5
6
7
8
9
10
然后再启动`php-fpm`。
ok~

### 编译MySQL
* 新增mysql用户组和用户
groupadd mysql
useradd -g mysql mysql1
2
- 下载源码
$ wget http://dev.mysql.com/get/Downloads/MySQL-5.7/mysql-5.7.10.tar.gz1
2
- 安装说明文档
shell> groupadd mysql
shell> useradd -r -g mysql -s /bin/false mysql
shell> tar zxvf mysql-VERSION.tar.gz
shell> cd mysql-VERSION
shell> mkdir bld
shell> cd bld
shell> cmake ..
shell> make
shell> make install
shell> cd /usr/local/mysql
shell> chown -R mysql .
shell> chgrp -R mysql .
shell> bin/mysql_install_db –user=mysql # Before MySQL 5.7.6
shell> bin/mysqld –initialize –user=mysql # MySQL 5.7.6 and up
shell> bin/mysql_ssl_rsa_setup # MySQL 5.7.6 and up
shell> chown -R root .
shell> chown -R mysql data
shell> bin/mysqld_safe –user=mysql &
shell> cp support-files/mysql.server /etc/init.d/mysql.server1
2
- 报错`The program 'cmake' is currently not installed. `
$ apt install cmake1
2
cmake -DCMAKE_INSTALL_PREFIX=/usr/local/mysql -DMYSQL_DATADIR=/usr/local/mysql/data -DDEFAULT_CHARSET=utf8mb4 -DDEFAULT_COLLATION=utf8_general_ci -DMYSQL_TCP_PORT=3306 -DMYSQL_USER=mysql -DWITH_MYISAM_STORAGE_ENGINE=1 -DWITH_INNOBASE_STORAGE_ENGINE=1 -DWITH_ARCHIVE_STORAGE_ENGINE=1 -DWITH_BLACKHOLE_STORAGE_ENGINE=1 -DWITH_MEMORY_STORAGE_ENGINE=1 -DDOWNLOAD_BOOST=1 -DWITH_BOOST=/usr/local/boost1
2
3
4
5
### 安装 nginx-rtmp-module
- 下载 nginx-rtmp-module
git clone https://github.com/sergey-dryabzhinsky/nginx-rtmp-module.git1
2
- 安装 Nginx 依赖关系
sudo apt-get install build-essential libpcre3 libpcre3-dev libssl-dev1
2
- 安装
./configure –prefix=/usr/local/nginx –with-pcre=/usr/local/src/pcre-8.40 –with-zlib=/usr/local/src/zlib-1.2.11 –with-http_ssl_module –add-module=/usr/local/src/nginx-rtmp-module
make -j 1
sudo make install1
2
3
4
5
6
7
8
9
10
11
> `--add-module=/usr/local/src/nginx-rtmp-module` 写成你 Git 下来的那个路径
- 配置 `Nginx` 文件
`nginx`中的应用程序意味着`rtmp`端点。
基本`uri`语法:`rtmp://nginx_host[:nginx_port]/app_name/stream_name`
我们将使用流作为流名称,因此我们的端点将是:`rtmp://localhost/show/stream`,以后可以作为`http://localhost:8080/hls/stream.m3u8`。
- `rtmp module config`
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application show {
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/; #是播放的流文件以及视频分段文件的地址,你可以更改任意位置
hls_fragment 3; #3秒片段
hls_playlist_length 60; #60秒播放列表。
# disable consuming the stream from nginx as rtmp
deny play all;
}
}
}1
2
* `http server config`
server {
listen 8080;
location /hls {
# Disable cache
add_header Cache-Control no-cache;
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
}
}1
2
* `nginx.conf` 配置文件模板
worker_processes auto;
events {
worker_connections 1024;
}
rtmp {
server {
listen 1935; # Listen on standard RTMP port
chunk_size 4000;
application show {
live on;
# Turn on HLS
hls on;
hls_path /mnt/hls/;
hls_fragment 3;
hls_playlist_length 60;
# disable consuming the stream from nginx as rtmp
deny play all;
}
}
}
http {
sendfile off;
tcp_nopush on;
aio on;
directio 512;
default_type application/octet-stream;
server {
listen 8080;
location / {
# Disable cache
add_header 'Cache-Control' 'no-cache';
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /mnt/;
}
}
}1
2
- 重启 `Nginx`
$ /usr/local/nginx/sbin/nginx -t #测试配置文件是否成功
$ /usr/local/nginx/sbin/nginx -t && nginx -s reload #启动并重新加载配置文件`
1 |
|
目前,CentOS 仅发行版本中的内核支持 Docker。
Docker 运行在 CentOS 7 上,要求系统为64位、系统内核版本为 3.10 以上。
Docker 运行在 CentOS-6.5 或更高的版本的 CentOS 上,要求系统为64位、系统内核版本为 2.6.32-431 或者更高版本。
###2、使用 yum 安装(CentOS 7下)
Docker 要求 CentOS 系统的内核版本高于 3.10 ,查看本页面的前提条件来验证你的CentOS 版本是否支持 Docker 。
1 | #查看你当前的内核版本 |
1、使用 sudo 或 root 权限登录 Centos。
2、确保 yum 包更新到最新。
1 | #确保 yum 包更新到最新 |
到此,docker 在 CentOS 系统的安装完成。
1 | 替换brew.git: |
1 | 重置brew.git: |
1 | [!--news.url--]:网站地址(参数设置的站点地址) |
1 | [!--pagetitle--]:页面标题 |
1 | [!--pagetitle--]:页面标题 |
1 | 实时显示点击数(不统计) <script src=[!--news.url--]e/public/ViewClick/?classid=[!--classid--]&id=[!--id--]></script> |
先生成公钥和私钥,在 Mac OSX
终端(或 iTerm 2
等)中进入 ~/.ssh
目录,输入:
1 | $ ssh-keygen -t rsa |
会询问一些问题,直接全部回车,即可在 ~/.ssh
目录中生成 id_rsa
(私钥) 和 id_rsa.pub
(公钥)文件。我们需要将公钥上传到 testhost
服务器的 ~/.ssh
目录下面,因为第二种方式中我们已经配置了 testhost
服务器,scp
也能识别这个服务器,所以,可以使用如下命令将文件传输到 testhost
服务器中:
1 | $ scp ~/.ssh/id_rsa.pub testhost:~/.ssh/ |
接下来,用第二种方式登录到 testhost
服务器中,在 ~/.ssh
目录中使用以下命令将 id_rsa.pub
更名为 authorized_keys
:
1 | foo@testhost: $ mv id_rsa.pub authorized_keys |
最后确保下文件权限正常:
1 | foo@testhost: $ chmod 700 ~/.ssh/ |
现在,我们可以在 Mac OSX
的终端中使用 ssh testhost
登录到 testhost
服务器了,无需输入密码,更无需记忆服务器参数。
如果无法连接,请在服务器的 /etc/ssh/sshd_config
文件中查看 PubkeyAuthentication
的值是否为 yes
,如果不是,请修改为 yes
,并使用以下命令重启 ssh 服务:
1 | foo@testhost: $ /etc/init.d/ssh restart #6.0 |
如果需要禁止密码登录,同样可以编辑 /etc/ssh/sshd_config
文件中 PasswordAuthentication
的值为 no
并重启 ssh 服务。
1 | apt-get update && apt-get install -y vim zsh git |
克隆Github
上的 Repository
,如下:
1 | git clone git@github.com:FBing/design-patterns.git |
使用git branch
命令,如下:
1 | $ git branch |
*标识的是你当前所在的分支。
命令如下:
1 | git branch -r |
命令如下:
1 | git branch -a |
命令如下:
1 | git branch [branch name] |
命令如下:
1 | git checkout [branch name] |
创建分支的同时切换到该分支上,命令如下:
1 | git checkout -b [branch name] |
git checkout -b [branch name]
的效果相当于以下两步操作:
1 | git branch [branch name] |
命令如下:
1 | git push origin [branch name] |
命令如下:
1 | git branch -d [branch name] |
命令如下:
1 | git push origin :[branch name] |