标签:enable 才有 web group int 通过 cgroup err start
服务器CentOS 7
[root@VM_0_6_centos ~]# yum install systemd
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
epel | 5.3 kB 00:00:00
extras | 2.9 kB 00:00:00
os | 3.6 kB 00:00:00
updates | 2.9 kB 00:00:00
Package systemd-219-67.el7_7.2.x86_64 already installed and latest version
Nothing to do
新建scrapyd.service文件,然后添加一些内容(需要root权限)我是以root账户操作的。
vim /lib/systemd/system/scrapyd.service
系统可能默认没有安装vim,安装或者改用vi等即可。
添加内容:
[Unit]
Description=scrapyd
After=network.target
Documentation=http://scrapyd.readthedocs.org/en/latest/api.html
[Service]
User=root
ExecStart=/usr/local/bin/scrapyd --logfile /var/scrapyd/scrapyd.log
[Install]
WantedBy=multi-user.target
启动服务
systemctl start scrapyd
service scrapyd start
使用curl工具检测scrapyd服务器状态:
[root@VM_0_6_centos ~]# curl http://localhost:6800/daemonstatus.json
{"node_name": "VM_0_6_centos", "status": "ok", "pending": 0, "running": 0, "finished": 1}
可以通过下面的指令来检查服务器的状态:
[root@VM_0_6_centos ~]# systemctl status scrapyd
● scrapyd.service - scrapyd
Loaded: loaded (/usr/lib/systemd/system/scrapyd.service; enabled; vendor preset: disabled)
Active: active (running) since Fri 2020-01-10 22:46:46 CST; 18h ago
Docs: http://scrapyd.readthedocs.org/en/latest/api.html
Main PID: 12072 (scrapyd)
CGroup: /system.slice/scrapyd.service
└─12072 /usr/bin/python3 /usr/local/bin/scrapyd --logfile /var/scr...
Jan 10 22:46:46 VM_0_6_centos systemd[1]: Started scrapyd.
通过下面的指令让Scrapyd随同操作系统一同启动
systemctl enable scrapyd
以Nginx为例,在Scrapyd前面添加一层反向代理来实现用户的认证
安装Nginx
yum install nginx
配置Nginx
vim /etc/nginx/nginx.conf
我们在http的大括号中添加一个server
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 {
}
}
# 以下是新添加的内容
server {
listen 6801;
location / {
proxy_pass http://127.0.0.1:6800;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/conf.d/.htpasswd;
}
}
这里我们监听的是6801端口,也就是通过6801端口的访问传到Scrapyd的6800,也就是我们只暴露了6801端口
切换到/etc/nginx/conf.d
目录下,如果没有这个目录就新建一个,创建用户认证
[root@VM_0_6_centos ~]# htpasswd -c .htpasswd ray
New password:
Re-type new password:
两次输入密码之后,我们成功创建了ray用户。
我们前面已经开启了scrapyd服务,必须先停止掉
killall scrapyd
修改Scrapyd的配置文件,以防止可以从外面绕过Nginx,直接访问6800端口。
Scrapyd启动时会自动搜索配置文件,最后加载的配置文件会覆盖前面的配置文件,配置文件的加载顺序为:
/etc/scrapyd/scrapyd.conf /etc/scrapyd/conf.d/* scrapyd.con ~/.scrapyd.con
现在我们除了默认的配置文件之外没有其他的配置文件,所以修改默认的配置文件:
vim /etc/scrapyd/scrapyd.conf
修改如下:
字段blind_address必须改为127.0.0.1以防止绕过Nginx直接访问6800端口
[scrapyd]
eggs_dir = eggs
logs_dir = logs
items_dir =
jobs_to_keep = 5
dbs_dir = dbs
max_proc = 0
max_proc_per_cpu = 4
finished_to_keep = 100
poll_interval = 5.0
bind_address = 127.0.0.1
http_port = 6800
debug = off
runner = scrapyd.runner
application = scrapyd.app.application
launcher = scrapyd.launcher.Launcher
webroot = scrapyd.website.Root
[services]
schedule.json = scrapyd.webservice.Schedule
cancel.json = scrapyd.webservice.Cancel
addversion.json = scrapyd.webservice.AddVersion
listprojects.json = scrapyd.webservice.ListProjects
listversions.json = scrapyd.webservice.ListVersions
listspiders.json = scrapyd.webservice.ListSpiders
delproject.json = scrapyd.webservice.DeleteProject
delversion.json = scrapyd.webservice.DeleteVersion
listjobs.json = scrapyd.webservice.ListJobs
daemonstatus.json = scrapyd.webservice.DaemonStatus
配置完成之后,开启Nginx与Scrapyd并测试,步骤如下:
开启scrapyd服务
service scrapyd start
开启Nginx服务
切换到/etc/nginx
目录然后nginx -t
检错,无误之后nginx
开启服务
服务器IP地址已做处理
(venv) F:\Crawl>curl http://***.***.***.**:6801
<html>
<head><title>401 Authorization Required</title></head>
<body>
<center><h1>401 Authorization Required</h1></center>
<hr><center>nginx/1.16.1</center>
</body>
</html>
上面的信息告诉我们需要认证,我们所有的配置都已成功
试一下直接访问6800端口会出现Time out错误
(venv) F:\Crawl>curl http://***.***.***.**:6800
curl: (7) Failed to connect to ***.***.***.** port 6800: Timed out
使用curl工具身份验证,加上参数-u 用户:密码
即可
(venv) F:\Crawl>curl http://***.***.***.**:6801/daemonstatus.json -u ray:*******
{"node_name": "VM_0_6_centos", "status": "ok", "pending": 0, "running": 0, "finished": 0}
标签:enable 才有 web group int 通过 cgroup err start
原文地址:https://www.cnblogs.com/1328497946TS/p/12180538.html