Resque/Redis 的套接字权限问题

Socket permission problems with Resque/Redis

我正尝试在带有 Passenger/Apache 的简单 Sinatra 应用程序中使用 Resque,但每当 Resque 尝试访问 Redis 时都会出现权限错误。同样的错误发生在各种方法中,包括 Resque.info 和 Resque.enqueue,并且无论 redis-server 是否实际上是 运行

都会发生

如果我在 irb 或 ruby 脚本中编写相同的代码,它运行良好。

我试过切换哪些用户是 运行 apache/passenger 和 redis,包括 root。

App 31099 stdout: 
App 31082 stderr: 2015-10-01 12:23:52 - Errno::EACCES - Permission denied - connect(2):
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/connection/ruby.rb:122:in `connect_nonblock'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/connection/ruby.rb:122:in `connect_addrinfo'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/connection/ruby.rb:162:in `block in connect'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/connection/ruby.rb:160:in `each'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/connection/ruby.rb:160:in `each_with_index'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/connection/ruby.rb:160:in `connect'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/connection/ruby.rb:211:in `connect'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:322:in `establish_connection'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:94:in `block in connect'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:279:in `with_reconnect'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:93:in `connect'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:350:in `ensure_connected'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:207:in `block in process'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:292:in `logging'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:206:in `process'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb:112:in `call'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis.rb:1320:in `block in smembers'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis.rb:37:in `block in synchronize'
App 31082 stderr:       /usr/share/ruby/monitor.rb:211:in `mon_synchronize'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis.rb:37:in `synchronize'
App 31082 stderr:       /usr/local/share/gems/gems/redis-3.2.1/lib/redis.rb:1319:in `smembers'
App 31082 stderr:       /usr/local/share/gems/gems/redis-namespace-1.5.2/lib/redis/namespace.rb:393:in `call_with_namespace'
App 31082 stderr:       /usr/local/share/gems/gems/redis-namespace-1.5.2/lib/redis/namespace.rb:290:in `method_missing'
App 31082 stderr:       /usr/local/share/gems/gems/resque-1.25.2/lib/resque.rb:259:in `queues'
App 31082 stderr:       /usr/local/share/gems/gems/resque-1.25.2/lib/resque.rb:431:in `info'
App 31082 stderr:       /var/www/html/app.rb:29:in `block in <class:App>'

在这里找到了解决方案: Troubleshooting "Permission denied" when attempting to connect to Redis from PHP script

SELinux 要求您明确允许 Apache 建立套接字连接。

/usr/sbin/setsebool httpd_can_network_connect=1