Fork me on GitHub
QuZheng


  • 首页

  • 分类

  • 关于

  • 归档

  • 标签

  • 搜索

搭建 PySpider 爬虫服务

发表于 2017-11-06 | 分类于 Linux | 阅读次数

PySpider 简介

PySpider 是一个国人编写的强大的网络爬虫系统并带有强大的 WebUI。 采用 Python 语言编写,分布式架构,支持多种数据库后端,强大的 WebUI 支持脚本编辑器,任务监视器,项目管理器以及结果查看器。本教程将一步一步指引您搭建属于自己的 PySpider 爬虫服务。

阅读全文 »

搭建 LNMP 环境

发表于 2017-10-27 | 阅读次数

LNMP是建立web应用的平台,是Linux、NGINX,MySQL(有时也指MariaDB,数据库软件) 和PHP(有时也是指Perl或Python) 的简称。

搭建 Nginx 静态服务器

安装 Nginx

使用 yum 安装 Nginx

1
yum -y install nginx

修改 /etc/nginx/conf.d/default.conf ,去除对 IPv6 地址的监听,可以参考下面的示例代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
server {
listen 80 default_server;
# listen [::]:80 default_server;
server_name _;
root /usr/share/nginx/html;
# Load configuration files for the default server block.
include /etc/nginx/default.d/*.conf;
location /{
}
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
}

修改完成后,启动 Nginx

1
nginx

此时,可以访问 http://\ 来确认是否安装成功

将 nginx 设置为开机自动启动

1
chkconfig nginx

安装 MySQL 数据库服务

使用 yum 安装 MySQL :

1
yum -y install mysql-server

安装完成后,启动 MySQL 服务

1
service mysqld start

设置 MySQL 管理员密码

1
/usr/bin/mysqladmin -u root password 'QuZheng'

将 MySQL 设置开机自动启动

1
chkconfig mysql on

安装 PHP

使用 yum 安装 PHP:

1
yum -y install php php-fpm php-mysql

安装之后,启动 php-fpm 进程:

1
service php-fpm start

启动之后,可以使用下面的命令查看 PHP-FPM 进程监听那个端口

1
netstat -nplt | grep php-fpm

将 PHP-FPM 设置开机自动启动

1
chkconfig php-fpm on

配置 Nginx 并运行 PHP 程序

配置 Nginx

在 /etc/nginx/conf.d 目录中新建一个名为 php.conf 的文件,并配置 Nginx 端口 ,配置示例如下:

1
2
3
4
5
6
7
8
9
10
11
server {
listen 8000;
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
location ~ .php$ {
root /usr/share/php;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}

修改配置完成后,重启 nginx 服务

1
service nginx restart

这时候,我们就可以在/usr/share/php 目录下新建一个 info.php 文件来检查 php 是否安装成功了,文件内容参考如下:

1
<?php phpinfo(); ?>

搭建 LAMP 服务

发表于 2017-10-27 | 阅读次数

搭建 MYSQL 数据库

使用 yum 安装 MySQL :

1
yum install mysql-server -y

安装完成后启动 MySQL 服务 :

1
service mysqld restart

将 MySQL 加入开机自动启动

1
chkconfig mysqld on

设置 MySQL 账户 root 密码:

1
usr/bin/mysqladmin -u root password 'QuZheng'

安装 APACHE 服务器

使用 yum 安装 Apache

1
yum -y install httpd

启动 Apache 服务

1
service httpd start

将 Apache 加入开机自动启动

1
chkconfig httpd on

安装 PHP

安装 PHP 和 PHP-MYSQL 支持工具:

使用 yum 安装 PHP:

1
yum install php php-mysql -y

检查安装是否成功

检测 PHP 是否安装成功

我们在 /var/www/html 目录下创建一个 info.php 文件来检查 php 是否安装成功 ,示例代码参考如下

1
touch /var/www/html/info.php
1
<?php phpinfo(); ?>

重启 Apache 服务 :

1
service httpd restart

此时,访问 http://1270.0.0.1/info.php 可浏览到我们刚刚创建的 info.php 页面了

搭建 ShowDoc 文档工具

发表于 2017-10-26 | 阅读次数

程序员都很希望别人能写文档,而自己却不愿意写文档。文档的编写和管理影响了团队沟通协作的效率,ShowDoc 是一个非常适合 IT 团队的在线文档分享工具,为提升团队之间的沟通协作效率而生。本实验在 centos 系统上搭建基于 Nginx + PHP 的 ShowDoc 文档工具。

准备 Nginx + PHP 环境

安装 Nginx

使用 yum 安装 Nginx

1
yum install nginx

修改 /etc/nginx/nginx.conf 文件的内容如下

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
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;
include /usr/share/nginx/modules/*.conf;
events {
worker_connections 1024;
}
http {
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
include /etc/nginx/mime.types;
default_type application/octet-stream;
include /etc/nginx/conf.d/*.conf;
server {
listen 80;
server_name 127.0.0.1;
root /var/www/html;
index index.php index.html
error_page 404 /404.html;
location = /40x.html {
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
}
location ~ .php$ {
root /var/www/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /.ht {
deny all;
}
}
}

启动 Nginx 并设置为开机启动:

1
2
service nginx start
chkconfig nginx on

安装 PHP

使用 yum 安装 php-fpm:

1
yum -y install php php-gd php-fpm php-mcrypt php-mbstring php-mysql php-pdo

启动 php-fpm 并设置开机启动:

1
2
service php-fpm start
chkconfig php-fpm on

创建项目

下载安装 Composer

Composer 是 PHP 的一个依赖管理工具,推荐使用 Composer 创建 ShowDoc 项目。

执行如下命令安装 Composer:

1
2
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

设置 Compooser 使用国内镜像

1
composer config -g repo.packagist composer https://packagist.phpcomposer.com

使用 Compooser 创建项目

执行命令创建项目:

1
cd /var/www/html/ && composer create-project showdoc/showdoc

设置 showdoc 目录写权限

执行命令赋予 showdoc 下部分目录的写权限

1
2
3
4
5
6
7
8
chmod a+w showdoc/install
chmod a+w showdoc/Sqlite
chmod a+w showdoc/Sqlite/showdoc.db.php
chmod a+w showdoc/Public/Uploads/
chmod a+w showdoc/Application/Runtime
chmod a+w showdoc/server/Application/Runtime
chmod a+w showdoc/Application/Common/Conf/config.php
chmod a+w showdoc/Application/Home/Conf/config.php

创建完毕,您现在可以通过浏览器访问 http://< IP地址>/showdoc/install/ ,进行语言的选择以后即可通过 http://< IP地址>/showdoc 查看站点效果。

搭建 Thinkjs 开发环境

发表于 2017-10-26 | 阅读次数

安装 Node.js

ThinkJS 是一款 Node.js 的MVC 框架,所以安装 ThinkJS 之前需要安装 Node.js 环境。

安装 Node.js 6.x0

ThinkJS 支持 Node.js 的 0.12 以上版本,本教程以 Node.js 6.x 为例,其他版本安装过程相似

1
2
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejs

安装 ThinkJS

npm 安装 ThinkJS

执行如下命令安装 ThinkJS

1
sudo npm install thinkjs@2 -g --verbose

创建项目

执行如下命令创建项目:

1
thinkjs new project_path;
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
create : project_path
create : project_path/package.json
create : project_path/.babelrc
create : project_path/.thinkjsrc
create : project_path/nginx.conf
create : project_path/pm2.json
create : project_path/.gitignore
create : project_path/README.md
create : project_path/www
create : project_path/www/development.js
create : project_path/www/production.js
create : project_path/www/testing.js
create : project_path/www/README.md
create : project_path/www/static
create : project_path/www/static/js
create : project_path/www/static/css
create : project_path/www/static/img
create : project_path/src
create : project_path/src/common/bootstrap
create : project_path/src/common/bootstrap/middleware.js
create : project_path/src/common/bootstrap/global.js
create : project_path/src/common/config
create : project_path/src/common/config/config.js
create : project_path/src/common/config/view.js
create : project_path/src/common/config/db.js
create : project_path/src/common/config/hook.js
create : project_path/src/common/config/session.js
create : project_path/src/common/config/error.js
create : project_path/src/common/config/env
create : project_path/src/common/config/env/development.js
create : project_path/src/common/config/env/testing.js
create : project_path/src/common/config/env/production.js
create : project_path/src/common/config/locale
create : project_path/src/common/config/locale/en.js
create : project_path/src/common/controller
create : project_path/src/common/controller/error.js
create : project_path/view/common
create : project_path/view/common/error_400.html
create : project_path/view/common/error_403.html
create : project_path/view/common/error_404.html
create : project_path/view/common/error_500.html
create : project_path/view/common/error_503.html
create : project_path/src/home/config
create : project_path/src/home/config/config.js
create : project_path/src/home/controller
create : project_path/src/home/controller/base.js
create : project_path/src/home/controller/index.js
create : project_path/src/home/logic
create : project_path/src/home/logic/index.js
create : project_path/src/home/model
create : project_path/src/home/model/index.js
create : project_path/view/home
create : project_path/view/home/index_index.html
enter path:
$ cd project_path
install dependencies:
$ npm install
run the app:
$ npm start

安装项目依赖

执行如下命令安装依赖:

1
2
cd project_path
npm install --verbose

启动项目

执行如下命令启动项目

1
npm start

启动成功将看到提示如截图所示:

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
[2017-10-26 14:27:34] [Babel] Compile file common/bootstrap/global.js 512ms
[2017-10-26 14:27:34] [Babel] Compile file common/bootstrap/middleware.js 21ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/config.js 33ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/db.js 49ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/env/development.js 6ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/env/production.js 17ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/env/testing.js 5ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/error.js 18ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/hook.js 8ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/locale/en.js 11ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/session.js 20ms
[2017-10-26 14:27:34] [Babel] Compile file common/config/view.js 26ms
[2017-10-26 14:27:35] [Babel] Compile file common/controller/error.js 167ms
[2017-10-26 14:27:35] [Babel] Compile file home/config/config.js 7ms
[2017-10-26 14:27:35] [Babel] Compile file home/controller/base.js 18ms
[2017-10-26 14:27:35] [Babel] Compile file home/controller/index.js 21ms
[2017-10-26 14:27:35] [Babel] Compile file home/logic/index.js 34ms
[2017-10-26 14:27:35] [Babel] Compile file home/model/index.js 27ms
[2017-10-26 14:27:35] [THINK] Server running at http://127.0.0.1:8360/
[2017-10-26 14:27:35] [THINK] ThinkJS Version: 2.2.24
[2017-10-26 14:27:35] [THINK] Cluster Status: closed
[2017-10-26 14:27:35] [THINK] WebSocket Status: closed
[2017-10-26 14:27:35] [THINK] File Auto Compile: true
[2017-10-26 14:27:35] [THINK] File Auto Reload: true
[2017-10-26 14:27:35] [THINK] App Enviroment: development
[2017-10-26 14:27:36] [HTTP] HEAD / 200 60ms

搭建邮件服务器

发表于 2017-10-26 | 分类于 Linux | 阅读次数

Postfix 是一个标准的 MTA [Mail Transfer Agent] 服务器 ,它负责通过 SMTP 协议管理发送到本机的邮件以及由本机发向外界的邮件;Dovecot 是一个优秀的 IMAP/POP 服务器用以接收外界发送到本机的邮件。

域名解析

添加两条域名解析

A 记录

记录类型:A

主机记录:@

记录值:IP 地址

MX 记录

记录类型:MX

主机记录:@

记录值:yourdomain.com(替换为自己域名)

生效检查

域名设置解析后需要过一段时间才会生效,通过

1
ping ping yourdomain.com

命令检查域名是否生效

检查 MX 记录

替换下面命令中的 yourdomain.com 为您自己的注册的域名:

1
nslookup -q=mx yourdomain.com

如果 nslookup 命令返回的信息中含有你设置的域名的记录值,说明解析成功。

实验之前

配置一个功能完善的邮件服务器并不是一项容易的工作,本实验知识搭建一个简单的邮件服务器,一些更为强大的功能还需要你去探索。

Postfix、Dovecot 简介

Postfix

Postfix 是一个标准的 MTA「Mail Transfer Agent」服务器,它负责通过 SMTP 协议管理发送到本机的邮件以及由本机发向外界的邮件。

Dovecot

Dovecot 是一个优秀的 IMAP/POP 服务器用以接收外界发送到本机的邮件。

Postfix、Dovecot 安装

在 CentOS 7 上,我们可以直接使用 yum 进行下载安装:

1
yum -y install postfix dovecot

Postfix

配置 Postfix

有关配置参数的具体含义,请参考 Postfix 配置文档

配置

在终端中输入一下命令修改 Postfix 相关配置:

注意:记得将 yourdomain.com 替换为你自己的域名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
postconf -e 'myhostname = server.yourdomain.com'
postconf -e 'mydestination = localhost, localhost.localdomain'
postconf -e 'myorigin = $mydomain'
postconf -e 'mynetworks = 127.0.0.0/8'
postconf -e 'inet_interfaces = all'
postconf -e 'inet_protocols = all'
postconf -e 'mydestination = $myhostname, localhost.$mydomain, localhost, $mydomain'
postconf -e 'home_mailbox = Maildir/'
postconf -e 'smtpd_sasl_type = dovecot'
postconf -e 'smtpd_sasl_path = private/auth'
postconf -e 'smtpd_sasl_auth_enable = yes'
postconf -e 'broken_sasl_auth_clients = yes'
postconf -e 'smtpd_sasl_authenticated_header = yes'
postconf -e 'smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination'
postconf -e 'smtpd_use_tls = yes'
postconf -e 'smtpd_tls_cert_file = /etc/pki/dovecot/certs/dovecot.pem'
postconf -e 'smtpd_tls_key_file = /etc/pki/dovecot/private/dovecot.pem'

配置中 Postfix 使用 sasl 和 tls 来完成身份认证和传输信息加密。

试验中使用了 Dovecot 默认的 ssl 证书和私钥,如果你需要修改为自己的,请替换最后两行配置的路径。

配置 smtps

部分邮件客户端依赖于使用 465 端口提供加密连接,所以我们修改配置,允许 postfix 使用 465 端口发送邮件。

打开 /etc/postfix/master.cf 文件,将如下两行前的 # 去除:

1
2
smtps inet n - n - - smtpd
-o smtpd_tls_wrappermode=yes

(注意:-o 前要保留空格)

启动

使用以下命令,将 Postfix 设为自动启动并首次启动该服务:

1
2
systemctl enable postfix.service
systemctl start postfix.service

搭建 Node.js 环境

发表于 2017-10-25 | 分类于 Linux | 阅读次数

yum 简介

Node.js 是运行在服务端的 JavaScript, 是基于 Chrome JavaScript V8 引擎建立的平台。

yum 安装 Node.js 环境

安装相关的依赖包

1
yum -y install openssl

安装 Node.js

1
yum -y install nodejs
阅读全文 »

搭建 SVN 服务器

发表于 2017-10-25 | 分类于 Linux | 阅读次数

SVN 简介

SVN 是 Subversion 的简称,是一个开放源代码的版本控制系统,相较于 RCS、CVS,它采用了分支管理系统,它的设计目标就是取代CVS。本实验带您一步步搭建属于自己的 SVN 服务器

安装 SVN 服务器

安装 Subversion

Subversion 是一个版本控制系统个 ,相对于的 RCS、CVS ,采用了分支管理系统,他的设计目标就是取代 CVS

1
yum install -y subversion

创建 SVN 版本库

创建项目版本库

1
2
mkdir -p /data/svn/myproject
svnadmin create /data/svn/myproject
阅读全文 »

搭建个人 Leanote 云笔记本

发表于 2017-10-25 | 分类于 Linux , leanote | 阅读次数

Leanote 简介

Leanote 是目前为止发现的最有 bigger 的云笔记,具备 markdown 输入,代码高亮,多人协作,笔记历史记录,笔记内导航,直接发布为博客等等能力。本实验将带您一步步搭建属于自己的云笔记本,您将可以通过云笔记记录生活工作的点滴。

下载启动 MongoDB

leanote 依赖 MongoDB 作为数据存储 ,下面开始安装 MongoDB:

下载 MongoDB

进入 /home 目录,并下载 MongoDB:

1
cd /home

下载源码

1
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.0.1.tgz

解压缩源码包

1
tar -xzvf mongodb-linux-x86_64-3.0.1.tgz
阅读全文 »

玩转 Jupyter Notebook

发表于 2017-10-24 | 分类于 Linux | 阅读次数

安装 Juptyer Notebook

Jupyter Notebook 简介

jupter Notebook 是一个开源的 Web 应用程序,可以用来创建和共享包含动态代码、方程式、可视化及解释性文本的文档。

其应用包括:数据整理与转换、数值模拟、统计建模、机器学习等等。

更多信息请见 官网

阅读全文 »
1234
QuZheng

QuZheng

38 日志
6 分类
30 标签
RSS
© 2019 QuZheng
由 Hexo 强力驱动
主题 - NexT.Mist
本站访客数 人次 本站总访问量 次