Xunsearch 安装、启动

源码安装

1、运行下面指令下载、解压安装包

wget http://www.xunsearch.com/download/xunsearch-full-latest.tar.bz2
tar -xjf xunsearch-full-latest.tar.bz2

执行安装脚本,根据提示进行操作,主要是输入 xunsearch 软件包的安装目录,强烈建议单独 规划一个目录,而不是混到别的软件目录中。

建议使用目录:

/usr/local/xunsearch

2、执行安装 命令

cd xunsearch-full-1.4.14/
sh setup.sh

第一次安装的话,过程可能会稍显漫长,请不必着急,您大可泡杯茶一边喝一边等待即可。

待命令运行结束后,如果没有出错中断,则表示顺利安装完成,然后就可以启动/重新启动 xunsearch 的后台服务

3、服务启动

出于性能和多数需求考虑 xunsearch 服务端和 SDK API 通讯时没有加密和验证处理, 并且默认情况 xs-ctl.sh 启动的服务程序是绑定并监听在 127.0.0.1 上。

如果您的 SDK 调用和 xunsearch 服务端不在同一服务器,请使用 -b inet 方式启动脚本, 并注意借助类似 iptables 的防火墙来控制 xunsearch 的 8383/8384 两个端口的访问权限。 启动脚本用法举例如下,以下均为合法使用方式:

启动命令 语法

Usage: ./xs-ctl.sh [OPTION] COMMAND
OPTION:
  -b <local|unix|inet>      bind address or path
  -L <log_level>            log level, 1-7
  -s <index|search|both>    server type
  -n <num>                  number of search worker process
  -p <port>                 port number of index server
                            port number of search is <port+1>
COMMAND:
  {start|stop|restart|faststop|fastrestart|reload}

服务启动

sudo /usr/local/xunsearch/bin/xs-ctl.sh -b local start    // 监听在本地回环地址 127.0.0.1 上
sudo /usr/local/xunsearch/bin/xs-ctl.sh -b inet start     // 监听在所有本地 IP 地址上 0.0.0.0
sudo /usr/local/xunsearch/bin/xs-ctl.sh -b a.b.c.d start  // 监听在指定 IP 上
sudo /usr/local/xunsearch/bin/xs-ctl.sh -b unix start     // 分别监听在 tmp/indexd.sock 和 tmp/searchd.sock

4、设置开机自启

强烈建议您将启动命令添加到开机启动脚本中,以便每次服务器重启后能自动启动搜索服务程序, 在 Linux 系统中您可以将脚本指令写进 /etc/rc.local 即可。

vim /etc/rc.local

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# xunsearch 开机自启
/usr/local/xunsearch/bin/xs-ctl.sh -b local restart

exit 0

设置文件执行权限

sudo chmod +x /etc/rc.local

有必要指出的是,关于搜索项目的数据目录规划。搜索系统将所有数据保存在 $prefix/data 目录中。 如果您希望数据目录另行安排或转移至其它分区,请将 $prefix/data 作为软链接指向真实目录。

使用 docker 安装

docker run --name xunsearch -d -p 8383:8383 -p 8384:8384 -v /Users/wml/data/xunsearch/:/usr/local/xunsearch/data hightman/xunsearch:latest