【问题标题】:Setting up thinking sphinx after server reboot (Rails project)服务器重启后设置思考狮身人面像(Rails 项目)
【发布时间】:2012-11-16 19:47:47
【问题描述】:

问题: 服务器重新启动后,我试图让 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”。

端口已打开并通过我们的托管服务器工作,所以我被告知我必须重新启动一些服务。我遇到的问题之一是thinking_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 和 unicorn 上的 Rails 项目)或瘦身使用狮身人面像)任何见解将不胜感激。

谢谢,

艾伦

【问题讨论】:

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


    【解决方案1】:

    冷静点!! :-)

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

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

    在你的开发机器上运行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 应用程序使用 --config /home/potato/streetpotato/config/development.sphinx.conf 参数调用 searchd,以指定不同的 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 无关。

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

    【讨论】:

      【解决方案2】:

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

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

      这是我们长期推迟网站搜索的案例之一,而我们的一位开发人员在一个下午就将其“全部设置”完毕。部署它需要更多的工作。

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

      【讨论】:

        【解决方案3】:

        好的,所以在一天半之后,我终于把它全部设置好并让它运行(它不仅仅是狮身人面像)。我还必须让 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) unicorn(启动应用服务器)
        参考站点:
        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
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2014-10-03
          • 2012-03-17
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多