Archlinux Running PhearJS

本文形成日期是 2016-10-27 ,目前 PhearJS 的版本是 0.6.1 。本文始发于 http://blog.csdn.net/pythonshell

Install PhearJS

Archlinux 官方库中有 nodejs npm memcached 和 phantomjs ,为了后期下载 phearjs.git ,需要安装 git 。后期安装 phearjs 需要 base-devel 软件包支持。

$ sudo pacman -S nodejs npm memcached git wget phantomjs base-devel

用国内淘宝 NPM 镜像替换 npm:

$ sudo npm install -g cnpm --registry=https://registry.npm.taobao.org

下载 phearjs 并使用 CNPM 安装:

$ git clone https://github.com/Tomtomgo/phearjs.git
$ cd phearjs
$ cnpm install

启动 memcached

$ sudo systemctl start memcached

如果要开机自动启动 memcached

$ sudo systemctl enable memcached

Product Environment

安装 nginx 和 supervisor 程序。

$ sudo pacman -S nginx supervisor

Config supervisor

配置 supervisor 管理 phearjs ,在目录/etc/supervisord.conf 中,最后的 section 如下:

[include]
files = /etc/supervisor.d/*.ini

所以,在/etc/supervisor.d/ 目录内新建一个 phearjs.ini 文件,假定在前面拷贝 phearjs 的过程中,拷贝在自己的用户目录~内,下文用 $HOME 表示读者的 home 目录(一般情况下,如果读者的用户名是 username 那么读者的 home 目录就是 /home/*username*) 读者请自行替换 $HOME 的内容:

$ cat /etc/supervisor.d/phearjs.ini
[group:phears]
programs=phear

[program:phear]
process_name="phears"
# process_name="%(program_name)s"
command=node $HOME/phearjs/phear.js
# command=node $HOME/phearjs/phear.js -e production
autorestart=true
redirect_stderr=true
stdout_logfile_maxbytes=500MB
stdout_logfile_backups=50
stdout_capture_maxbytes=1MB
stdout_events_enabled=false
loglevel=warn
user=root
directory=$HOME/phearjs

使用 supervisorctl 软件,可以运行 phearjs :

$ supervisorctl start all

或者用 systemctl 启动 supervisord.service :

$ systemctl start supervisord.service

可以使用 systemctl 让 supervisord.service 自动启动:

$ systemctl enable supervisord.service
Created symlink /etc/systemd/system/multi-user.target.wants/supervisord.service → /usr/lib/systemd/system/supervisord.service.

Config nginx

编辑 /etc/nginx/nginx.conf 之前请做好备份:

$ cp /etc/nginx/nginx.conf{,.bak}
$ vim /etc/nginx/nginx.conf

用以下内容替换,同样,读者需要替换 $HOME 为具体的值:

user                root;
worker_processes    1;

events {
    worker_connections      200;
    multi_accept            on;
}

http {
    # Mime types
    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;
    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;
    # Logging
    access_log          /var/log/nginx/access.log;
    error_log           /var/log/nginx/error.log;
    # Gzip Settings
    gzip                on;
    server {
        listen          80;
        root            $HOME/phearjs;
        location / {
            proxy_pass        http://0.0.0.0:8100;
            proxy_set_header  real-ip  $remote_addr; # Forward requester's IP.
        }
    }
}

使用如下的命令运行 nginx ,nginx 需要在 phearjs 启动后再执行:

$ systemctl start nginx.service

或者开机自动执行:

$ systemctl enable nginx.service

Attentions

1 PhearJS real production environment

真正的生产环境下, PhearJS 的启动命令应该如下:

$ node $HOME/phearjs/phear.js -e production

该命令运行的 PhearJS 需要使用用户名密码来访问,比较麻烦,暂时还没有弄清楚怎么用。

2 systemd service startup order

memcached -> supervisord -> nginx

systemd 的启动顺序设置,可以参看 ArchWiki: https://wiki.archlinux.org/index.php/Systemd#Handling_dependencies

References

  1. PhearJS Official: http://phear.io/
  2. PhearJS Github: https://github.com/Tomtomgo/phearjs
  3. CNPM: https://npm.taobao.org/
  4. supervisor: http://supervisord.org/index.html
  5. supervisor - Python进程管理工具: http://chenxiaoyu.org/2011/05/31/python-supervisor.html
  6. Example configs: https://github.com/Tomtomgo/phearjs/blob/master/INSTALLATION.md#production
  7. systemd - ArchWiki: https://wiki.archlinux.org/index.php/Systemd
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值