服务器重启后设置思维sphinx(Rails项目)

时间:2012-11-16 19:47:48

标签: ruby-on-rails thinking-sphinx thin unicorn

问题: 我想在服务器重启后再次运行sphinx。当我尝试启动它时似乎没有sphinx.conf文件:

>searchd

Sphinx 2.0.4-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

FATAL: no readable config file (looked in /etc/sphinxsearch/sphinx.conf, ./sphinx.conf).

我跑了:

rake thinking_sphinx:configure
rake thinking_sphinx:index
rake thinking_sphinx:start

问题是由于某种原因没有创建etc / sphinxsearch / sphinx.conf 文件...我是Thinking_sphinx的新手,这可能不是唯一的问题(使用该网站),但它似乎没有完全建立。有关输出和更多信息,请阅读以下内容:

背景信息 我正在开展一个我最初没有设置的项目。我们重新启动服务器以查看我们在常量文件中所做的一些更改。但重启后,当您导航到该站点时,项目不再显示。当你输入直接的IP地址时,它只是说“欢迎来到Nginx”。

端口已打开并通过我们的托管服务器工作,因此我被告知必须重新启动某些服务。我遇到的一个问题是think_sphinx。这是我引用的rake tasks for sphinx网站。以及common configuration issues for sphinx

我设置了sphinx.yml开发路径(我们没有使用生产)。然后我跑了

>rake thinking_sphinx:index

即使输出一些警告似乎也有效:

Generating Configuration to /home/potato/streetpotato/config/development.sphinx.conf
   (0.2ms)  SELECT @@global.sql_mode, @@session.sql_mode;
Sphinx 2.0.4-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

using config file '/home/potato/streetpotato/config/development.sphinx.conf'...
indexing index 'bar_core'...
WARNING: collect_hits: mem_limit=0 kb too low, increasing to 14080 kb
collected 249 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 249 docs, 32394 bytes
total 0.254 sec, 127298 bytes/sec, 978.49 docs/sec
indexing index 'bar_delta'...
WARNING: collect_hits: mem_limit=0 kb too low, increasing to 14080 kb
collected 0 docs, 0.0 MB
total 0 docs, 0 bytes
total 0.003 sec, 0 bytes/sec, 0.00 docs/sec
skipping non-plain index 'bar'...
indexing index 'synonym_core'...
WARNING: collect_hits: mem_limit=0 kb too low, increasing to 13568 kb
collected 3 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 3 docs, 103 bytes
total 0.003 sec, 30356 bytes/sec, 884.17 docs/sec
indexing index 'synonym_delta'...
WARNING: collect_hits: mem_limit=0 kb too low, increasing to 13568 kb
collected 0 docs, 0.0 MB
total 0 docs, 0 bytes
total 0.002 sec, 0 bytes/sec, 0.00 docs/sec
skipping non-plain index 'synonym'...
indexing index 'user_core'...
WARNING: collect_hits: mem_limit=0 kb too low, increasing to 13568 kb
collected 100 docs, 0.0 MB
sorted 0.0 Mhits, 100.0% done
total 100 docs, 3146 bytes
total 0.013 sec, 239348 bytes/sec, 7608.03 docs/sec
skipping non-plain index 'user'...
total 11 reads, 0.000 sec, 3.8 kb/call avg, 0.0 msec/call avg
total 37 writes, 0.000 sec, 2.5 kb/call avg, 0.0 msec/call avg

然后我跑了

>rake thinking_sphinx:configure

Generating Configuration to /home/potato/streetpotato/config/development.sphinx.conf
(0.2ms)  SELECT @@global.sql_mode, @@session.sql_mode;

最后运行:

>rake thinking_sphinx:start

Started successfully (pid 29623).

现在即使我的日志说:

[Fri Nov 16 19:34:29.820 2012] [29623] accepting connections

仍然没有生成sphinx.conf文件,当我尝试使用searchd命令时,它仍然给我错误...

>searchd --stop

Sphinx 2.0.4-release (r3135)
Copyright (c) 2001-2012, Andrew Aksyonoff
Copyright (c) 2008-2012, Sphinx Technologies Inc (http://sphinxsearch.com)

FATAL: no readable config file (looked in /etc/sphinxsearch/sphinx.conf, ./sphinx.conf).

我很茫然,我知道这是超长的,但这只是因为我迷失了并试图提供尽可能多的信息。我得到了更多,然后我昨天做了这个,但它似乎仍然没有完全工作。我可能还需要做更多设置与独角兽或薄。我只想弄清楚如何让网站重新启动并再次运行...如果任何人遇到类似的问题,他们的网站在重新启动后关闭并重新启动(特别是Nginx和独角兽的铁轨项目或使用sphinx瘦身)任何见解都将受到赞赏。

谢谢,

艾伦

3 个答案:

答案 0 :(得分:0)

冷静下来!! : - )

首先,您不需要/etc/sphinxsearch/sphinx.conf个文件;这只是searchd在未指定任何配置文件时尝试使用的默认文件。

正如您的日志输出所示,您的rails应用程序在启动/home/potato/streetpotato/config/development.sphinx.conf进程时正在使用searchd文件。

在您的开发计算机上运行ps -fe | grep searchd;你应该看到这样的东西作为输出:

501 14128     1   0   0:00.00 ttys004    0:00.00 searchd --pidfile --config /home/potato/streetpotato/config/development.sphinx.conf
501 14130 13546   0   0:00.00 ttys004    0:00.01 grep searchd

所以rails app使用searchd参数调用--config /home/potato/streetpotato/config/development.sphinx.conf,以指定不同的conf文件。

从您的日志中可以清楚地看到thinkingsphinx正常运行。您可以登录rails console并在其中定义了thinking_sphinx indexes的其中一个模型上运行search方法,以进一步确认。

例如:如果您的应用具有Article模型,如上面的链接所示,则以下命令将显示其中包含National Parks的所有文章:

$ rails console
> Article.search( "National Parks" )
=> [#<Article id: 15,... >, #<Article id: 22,...>,...]

真正的问题是重启服务器后应用程序没有显示。这与运行良好的thinking sphinx无关。

尝试回滚上面提到的常量文件中所做的所有更改,并确保应用程序正常运行。然后开始逐个进行更改,并隔离一个破坏应用程序的更改。

答案 1 :(得分:0)

所以是的,这是ThinkingSphinx(恕我直言)中的一个漏洞 - 您可以使用各种rake任务(根据需要生成配置)启动sphinxd服务器...但这不起作用生产

在我去年工作的项目(在Linux服务器上运行)上,我们创建了一个/etc/init.d脚本来启动sphinxd - 它包含选项,包括配置文件的路径。我们使用capistrano进行了部署,并将生成的代码放在app/shared - 源树之外的目录中。我相信有一些预定义的capistrano任务会在模型改变时重建特定于Rails的配置文件,否则会影响Sphinx的功能(与你提到的rake任务相同)。

对于我们来说,这是我们长时间推迟网站搜索的案例之一,我们的一位开发人员在一个下午“全部设置”了。部署它需要做更多的工作。

(刚刚看到来自@ prakash-murthy的回答 - 他提供了一些有关如何在初始化sphinxd时指定配置路径的详细信息)。但诀窍是让它在系统启动时启动并指向ThinkingSphinx生成的配置。)

答案 2 :(得分:0)

好的,所以在一天半之后,我终于把它全部搞定了并让它运行起来(它更像是狮身人面像)。我还必须在后台启动并运行nginx和unicorn,因为我们没有设置脚本以在重新启动服务器时重新启动它们...

重新启动服务器时,您必须重新启动某些服务才能访问该应用程序:

1)thinking_sphinx
参考网站
http://pat.github.com/ts/en/rake_tasks.html
http://www.claytonlz.com/2010/09/thinkingsphinx-conf-problems/

a)create/modify  app/config/sphinx.yml

    development:
      morphology: stem_en
      port: 9312
      bin_path: "/usr/bin"             # set up the path to binary for searchd
      searchd_binary_name: searchd
      indexer_binary_name: indexer
      #mem_limit: 128M
    test:
      morphology: stem_en
      port: 9312
      mem_limit: 128M
    production:
      morphology: stem_en
      port: 9312
      mem_limit: 512M
    # the searchd ip, in case it's not on localhost
    # address: 10.10.0.0
    # this is by default included in db/sphinx
    # searchd_file_path: "/path/to/shared/folder/sphinx"

b)rake thinking_sphinx:index
c)rake thinking_sphinx:configure       # creates config/development.sphinx.conf which helps define sphinx's indexing

d)# then you have to start sphinx, there are 2 ways to do this

    rake thinking_sphinx:start
    rake thinking_sphinx:stop

    OR

    searchd
    searchd --stop

    # only the rake commands worked for me, when I tried to run searchd
    # I got an error FATAL: no readable config file (looked in /etc/sphinxsearch/sphinx.conf, ./sphinx.conf).
    # for some reason we dont have a sphinx.conf file, but the rake commands work without it

e)# once you start thinking_sphinx check log/searchd.log file for the line
    [Fri Nov 16 19:34:29.820 2012] [29623] accepting connections

2)nginx
参考网站:
http://wiki.nginx.org/CommandLine

a) check that nginx is up and running
    i) start server 
        # to check where nginx resides type in this into server console
        which nginx
        # whatever path it gives you is how you start the server this is my path
        /usr/sbin/nginx 
    ii) stop server
        /usr/sbin/nginx -s stop # use the path given by which command

3)独角兽(启动应用程序服务器)
参考网站:
http://codelevy.com/2010/02/09/getting-started-with-unicorn.html

a) test if unicorn will run after previous changes
    unicorn_rails -p 3000
    # the site should now be up and running, check that it is
    # console should now log the different actions you do on the site 

b) create unicorn.rb in config folder (if none is there)
    # only start this step if the step above got the site running
    # close the console or exit the process you started above
    # contents of unicorn.rb 
    worker_processes 2      #(starts 2 child processes, not completely neccissary)
    preload_app true
    timeout 30
    listen 3000

    after_fork do |server, worker|
      ActiveRecord::Base.establish_connection
    end

c) run unicorn in the background
    # make sure you exited the process above before running this
    unicorn_rails -c config/unicorn.rb -D

    # this was giving me an error that it said was logged by stderr
    # I got the command to run by adding a command to the front
    http://stackoverflow.com/questions/2325152/check-for-stdout-or-stderr

    exec 2> /dev/null unicorn_rails -c config/unicorn.rb -D


d) (optional) check stats from starting unicorn

    i) pgrep -lf unicorn_rails
        #sample output
        5374 unicorn_rails master -c config/unicorn.rb -D             
        5388 unicorn_rails worker[0] -c config/unicorn.rb -D    # not needed currently  
        5391 unicorn_rails worker[1] -c config/unicorn.rb -D    # not needed currently

    ii) cat tmp/pids/unicorn.pid # from inside the streetpotato folder
        #sample output
        5374
相关问题