Ruby on rails 如何从.yml配置精简以使用tcp套接字?
我这里有一个RoR应用程序,我正在使用瘦appserver 其配置在.yml文件中,因此:Ruby on rails 如何从.yml配置精简以使用tcp套接字?,ruby-on-rails,sockets,tcp,thin,unix-socket,Ruby On Rails,Sockets,Tcp,Thin,Unix Socket,我这里有一个RoR应用程序,我正在使用瘦appserver 其配置在.yml文件中,因此: --- pid: /srv/cica/tmp/pids/thin.pid group: cica wait: 30 timeout: 30 log: /srv/cica/log/thin.log max_conns: 1024 require: [] environment: production max_persistent_conns: 512 servers: 4 daemonize: true
---
pid: /srv/cica/tmp/pids/thin.pid
group: cica
wait: 30
timeout: 30
log: /srv/cica/log/thin.log
max_conns: 1024
require: []
environment: production
max_persistent_conns: 512
servers: 4
daemonize: true
user: cica
socket: /srv/cica/tmp/thin.sock
chdir: /srv/cica
如何使用TCP套接字而不是unix套接字进行侦听
我所找到的文档不知何故从未提及这种可能性,尽管间接引用说这是可能的
问题的原因是前端web(apache2)不太适合将http请求代理到unix路径。nginx不会有问题。理论上,您可以简单地使用IP:ADDR而不是套接字路径:
socket: 127.0.0.1:3000
会有用的。但是,如果使用多个精简进程,则会出现问题
(这很有可能,因为整个ruby都是单线程的。考虑到IO等待时间,甚至可能会有更高的进程数作为CPU内核数)
不知何故,瘦配置解释器的套接字地址解码器足够智能,可以使用普通的IP地址,但它增加了IP,而不是额外套接字的端口。因此,您将有多个精简实例在侦听
# thin will listen on these addresses
127.0.0.1:3000
127.0.0.2:3000
127.0.0.3:3000
127.0.0.4:3000
# it would be okay, but not this happens
127.0.0.1:3000
127.0.0.1:3001
127.0.0.1:3002
127.0.0.1:3003
他们宁愿听
# thin will listen on these addresses
127.0.0.1:3000
127.0.0.2:3000
127.0.0.3:3000
127.0.0.4:3000
# it would be okay, but not this happens
127.0.0.1:3000
127.0.0.1:3001
127.0.0.1:3002
127.0.0.1:3003
这种超现实的行为可能不是你想要的。(尽管如果所有IP上都有活动接口,它也可以工作。)
然而,这个ruby东西有一个很好的特性,即它的命令行选项和配置文件选项之间有一个直接的赋值。一个thin--help
命令将向您显示它们。您可以使用地址
和端口
选项强制TCP侦听:
#socket: /srv/cica/tmp/thin.sock
address: 127.0.0.1
port: 3000
因此,您将得到正确的结果
默认值为0.0.0.0
和3000
由于apache只想使用其最常见的设置(ProxyPass
,ProxyPassReverse
指令)代理单个tcp端口,因此您还需要一些小技巧,即负载平衡代理集群。相关配置代码段:
<Proxy balancer://cicas>
BalancerMember http://localhost:3000 disablereuse=On route=cica1
BalancerMember http://localhost:3001 disablereuse=On route=cica2
BalancerMember http://localhost:3002 disablereuse=On route=cica3
BalancerMember http://localhost:3003 disablereuse=On route=cica4
ProxySet lbmethod=byrequests
</Proxy>
ProxyPass / balancer://cicas/
平衡员http://localhost:3000 禁用重用=路由上=cica1
平衡员http://localhost:3001 禁用重用=路由上=cica2
平衡员http://localhost:3002 禁用重用=在路线上=cica3
平衡员http://localhost:3003 禁用重用=路由上=cica4
ProxySet lbmethod=byrequests
ProxyPass/balancer://cicas/