发布于 2014-12-22 00:40:55 | 210 次阅读 | 评论: 0 | 来源: PHPERZ

这里有新鲜出炉的精品教程,程序狗速度看过来!

Sphinx 全文检索引擎

Sphinx是一个基于SQL的全文检索引擎,可以结合MySQL,PostgreSQL做全文搜索,它可以提供比数据库本身更专业的搜索功能,使得应用程序更容易实现专业化的全文检索。Sphinx特别为一些脚本语言设计搜索API接口,如PHP,Python,Perl,Ruby等,同时为MySQL也设计了一个存储引擎插件。


本文为大家提供的是一份sphinx的启动关闭管理脚本,功能包括启动,停止,重建索引等功能,感兴趣的同学拿去使用。 

sphinx启动关闭管理脚本

#!/bin/sh  
#/usr/local/sphinx/bin/  
#  
#ocpyang@126.com  
  
sphinx_pidfile=/usr/local/sphinx/var/log/searchd.pid  
if [ -e "${sphinx_pidfile}"   ] ; then  
    sphinx_active=1  #runing  
    #echo ${sphinx_active}  
else  
    sphinx_active=0   #close   
    #echo ${sphinx_active}  
fi  
  
  
  
stop(){  
if [  "${sphinx_active}" -eq 0 ];then  
    echo -e '\e[31m SPHINX  Has been turned off  \e[m' #红色  
    exit 1  
else  
    /usr/local/sphinx/bin/searchd   --config  /usr/local/sphinx/etc/sphinx.conf --stop   > /dev/null 2>&1   
        resu=$?  
        if [  "${resu}" -eq 0  ];  then  
             echo -e '\e[32m******************************************************************** \e[m' #绿色  
        echo -e '\e[32m( ^_^ ) Sphinx stop SUCESS( ^_^ ) \e[m' #绿色  
         echo -e '\e[32m******************************************************************** \e[m' #绿色  
        else  
             echo -e '\e[31m******************************************************************** \e[m' #红色  
        echo -e '\e[31m !o(︶︿︶)o!Sphinx stop FAIL! ~~~~(>_<)~~~~ \e[m' #红色  
         echo -e '\e[31m******************************************************************** \e[m' #红色  
        fi  
    return ${resu}  
fi  
}  
  
  
  
start(){  
if [  "${sphinx_active}" -eq 1 ];then  
    echo -e '\e[31m SPHINX  Is already running  \e[m' #红色  
    exit 1  
else  
    /usr/local/sphinx/bin/searchd  --config  /usr/local/sphinx/etc/sphinx.conf > /dev/null 2>&1   
       resu=$?  
        if [  "${resu}" -eq 0  ];  then  
             echo -e '\e[32m******************************************************************** \e[m' #绿色  
        echo -e '\e[32m ( ^_^ )Sphinx start SUCESS( ^_^ ) \e[m' #绿色  
         echo -e '\e[32m******************************************************************** \e[m' #绿色  
        else  
              echo -e '\e[31m******************************************************************** \e[m' #红色  
            echo -e '\e[31m !o(︶︿︶)o!Sphinx start FAIL! ~~~~(>_<)~~~~ \e[m' #红色  
         echo -e '\e[31m******************************************************************** \e[m' #红色  
  
        fi  
    return ${resu}  
fi  
}  
  
  
  
indexer_all(){  
if [  "${sphinx_active}" -eq 0 ];then  
    echo -e '\e[31m SPHINX  Has been turned off  \e[m' #红色  
    exit 1  
else  
  
    /usr/local/sphinx/bin/indexer --config  /usr/local/sphinx/etc/sphinx.conf    --all > /dev/null 2>&1  
    resu=$?  
        if [  "${resu}" -eq 0  ];  then  
             echo -e '\e[32m******************************************************************** \e[m' #绿色  
        echo -e '\e[32m ( ^_^ )Sphinx indexer_all SUCESS( ^_^ ) \e[m' #绿色  
         echo -e '\e[32m******************************************************************** \e[m' #绿色  
        else  
              echo -e '\e[31m******************************************************************** \e[m' #红色  
            echo -e '\e[31m  !o(︶︿︶)o!Sphinx indexer_all FAIL! ~~~~(>_<)~~~~ \e[m' #红色  
         echo -e '\e[31m******************************************************************** \e[m' #红色  
  
        fi  
        return ${resu}  
fi  
}  
  
  
  
indexer_online(){  
if [  "${sphinx_active}" -eq 0 ];then  
    echo -e '\e[31m SPHINX  Has been turned off  \e[m' #红色  
    exit 1  
else  
    /usr/local/sphinx/bin/indexer --config  /usr/local/sphinx/etc/sphinx.conf   --rotate --all  > /dev/null 2>&1  
    resu=$?  
       if [  "${resu}" -eq 0  ];  then  
             echo -e '\e[32m******************************************************************** \e[m' #绿色  
        echo -e '\e[32m ( ^_^ )Sphinx indexer_online SUCESS( ^_^ ) \e[m' #绿色  
         echo -e '\e[32m******************************************************************** \e[m' #绿色  
        else  
              echo -e '\e[31m******************************************************************** \e[m' #红色  
            echo -e '\e[31m  !o(︶︿︶)o!Sphinx indexer_online FAIL! ~~~~(>_<)~~~~ \e[m' #红色  
         echo -e '\e[31m******************************************************************** \e[m' #红色  
  
        fi  
        return ${resu}  
fi  
}  
  
  
status(){  
if [  "${sphinx_active}" -eq 0 ];then  
    echo -e '\e[31m SPHINX  Has been turned off  \e[m' #红色  
    exit 1  
else  
        /usr/local/sphinx/bin/searchd  --config  /usr/local/sphinx/etc/sphinx.conf --status  
        resu=$?  
        if [  "${resu}" -eq 0  ];  then  
        #echo "sphinx status ok"  
        echo -e '\e[32m******************************************************************** \e[m' #绿色  
        echo -e '\e[32m ( ^_^ )Sphinx status ok( ^_^ ) \e[m' #绿色  
        echo -e '\e[32m******************************************************************** \e[m' #绿色  
        else  
         #echo "sphinx status unknow"  
        echo -e '\e[31m*********************************************************************  \e[m' #红色  
        echo -e '\e[31m  !o(︶︿︶)o!Sphinx  status unknown ~~~~(>_<)~~~~  \e[m' #红色  
        echo -e '\e[31m********************************************************************* \e[m' #红色  
        fi  
        return ${resu}  
fi  
}  
  
  
case $1 in  
    restart)  
    stop  
    start  
    ;;  
  
    stop)  
    stop  
    ;;  
      
    start)  
    start  
    ;;  
  
    indexer_all)  
    indexer_all  
    ;;  
  
    indexer_online)  
    indexer_online  
    ;;  
  
    status)  
        status  
        ;;  
  
esac  
  
exit 0  


最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务