Open Semantic Search
摘要
本文介绍企业级文档搜索引擎Open Semantic Search的安装、配置与维护。
功能描述
OSDS是一个全文搜索引擎,支持绝大部分格式类型的文件。除索引文件外,还能完成其它诸如数据分析、OCR识别、语法检查、推测联想等功能,本文主要介绍其索引功能。
Lucene是 Apache 软件基金会的一个开放源代码的全文检索引擎工具包,是一个全文检索引擎的架构,提供了完整的查询引擎和索引引擎,部分文本分析引擎。Lucene 的目的是为软件开发人员提供一个简单易用的工具包,以方便的在目标系统中实现全文检索的功能,或者是以此为基础建立起完整的全文检索引擎。
Solr是一个基于Lucene的Java搜索引擎服务器。Solr 提供了层面搜索、命中醒目显示并且支持多种输出格式(包括 XML/XSLT 和 JSON 格式)。它易于安装和配置,而且附带了一个基于 HTTP 的管理界面。Solr已经在众多大型的网站中使用,较为成熟和稳定。Solr 包装并扩展了 Lucene,所以Solr的基本上沿用了Lucene的相关术语。更重要的是,Solr 创建的索引与 Lucene 搜索引擎库完全兼容。通过对Solr 进行适当的配置,某些情况下可能需要进行编码,Solr 可以阅读和使用构建到其他 Lucene 应用程序中的索引。
通过Apache Solr项目建立文件索引,OSDS支持且不限于以下格式
- doc docx ppt pptx xls xlsx
- html xml txt csv
安装简介
1. Doc-Server基本信息:
全文索引非常消耗计算资源,索引建立非常耗时,所以,硬件配置尽量高,减少索引建立的时间。
系统平台:
Ubuntu 16.04.2 LTS(GNU/Linux 4.4.0-62-generic x86_64)
安装软件包:
2. 安装
Ubuntu的安装本维护手册未描述,请参照https://www.opensemanticsearch.org/doc/admin/install/search_server安装.系统平台搭建好后上传软件安装包,然后使用指令进行软件安装。服务器的访问请参考章节4 b),安装指令:
su - dpkg --installopen-semantic-search_17.07.13.deb
Tips:如果由于安装失败,使用以下指令进行修复依赖关系。
apt-get -f install
3. 配置:
1) 创建文件路径
该路径用于存储上传的文档。指令如下:
mkdir /home/vsftp/Doc-Server
2) 创建软link
在路径/var/www/html/下创建软link将上传文档路径link到网页访问的路径。指令如下:
ln -s /home/vsftp/Doc-Server /var/www/html/Doc-Server
3) 修改配置文件
Open Semantic Search的配置文件主要是/etc/opensemanticsearch/connector-files,对文件进行配置的命令如下:
vi /etc/opensemanticsearch/connector-files
在配置文件中添加下面两条配置(其中IP为Doc-Server Web界面IP)
config['mappings'] = {"/var/www/html/Doc-Server/":"http://10.140.82.101/Doc-Server/" } config['facet_path_strip_prefix']= [ "http://10.140.82.101/", "/" ]
4) 使用命令创建索引
创建索引需要使用root权限,需要了解到Doc-Server添加索引的方式为增量添加,每次执行命令只增加指定文档中新增的文档。
su - opensemanticsearch-index-dir /var/www/html/Doc-Server
5) 设置定时任务,用于定时添加索引,保持Doc-Server可查询的文档及时更新命令如下:
用于定时添加索引,确保Doc-Server可查询的文档能够及时更新。目前暂定为每3小时添加一次索引。
crontab -e
也可以通过下面命令对文件做monitor
opensemanticsearch-filemonitoring pathname
6) 上传用户创建、设置
使用如下命令创建上传用户uftp:
sudo useradd -d/home/uftp -s /bin/bash uftp
配置uftp的相关权限
cp -p /etc/vsftpd.conf/etc/vsftpd.conf.bak
设置vsftpd.conf中以下内容:
#listen=YES anonymous_enable=NO write_enable=YES local_umask=022 anon_upload_enable=NO anon_mkdir_write_enable=NO xferlog_file=/var/log/vsftpd.log xferlog_std_format=YES idle_session_timeout=600 chroot_local_user=YES chroot_list_file=/etc/vsftpd.chroot_list userlist_deny=NO userlist_enable=YES userlist_file=/etc/allowed_users seccomp_sandbox=NO allow_writeable_chroot=YES cmds_allowed=FEAT,REST,CWD,LIST,MDTM,MKD,NLST,PASS,PASV,PORT,PWD,QUIT,RMD,SIZE,RETR,STOR,TYPE,USER,ACCT,APPE,CDUP,HELP,MODE,NOOP,REIN,STAT,STOU,STRU,SYST #anon_root=/home/Doc-Server-backup #local_root=/home/Doc-Server-backup #anon_upload_enable=yes #anon_mkdir_write_enable=yes #anon_other_write_enable=no
/etc/vsftpd.chroot_list中添加用户uftp
/etc/allowed_users中添加用户uftp
7) 测试:
在PC上打开浏览器,可以正常访问http://10.140.82.101/search 可以正常搜索文件。
Tips:目前IE11显示网页排版不正常,其他浏览器均可正常访问。
系统维护:
1) 使用软件
SecureCRT、Xshell、winscp等软件。
2) 登录方式
使用ssh2对server进行登录,使用命令行进行维护
使用winscp等软件管理已上传文件。
3) 常用维护指令
查看系统资源使用情况:top
当前Doc-Server的CPU使用率较高,持续高于65%,可能需要增强CPU性能(增加CPU数量):
检查定时任务:crontab -l
执行结果如下截图。
4. 脚本及log
1) 脚本介绍
编写的脚本存放路径为:/homt/tool
build-dir.sh 创建索引 daily_report.sh 定时日报 diff_list.sh 比对Doc-Server与Backup-Server文件列表(Backup-Server上部署) inotify_bak.sh 实时触发 list-file.sh 获取已上传文件列表 replace_space.sh 替换已上传文件名中的空格
2) log介绍
生成的log主用路径有
OpenSemanticSearch相关在/var/log/opensemanticsearch/
daily_report_201711.log 日报 list-files/ 已上传文件列表 build-dir.sh.20171123.log 创建index的log rsync.log 自动同步的log
网页访问相关在/var/log/apache2/
2017_11_23_access_log 网页访问记录 2017_11_23_error_log 网页error记录
创建索引监控:
Open-semantic-search新版本(18及以上)在创建索引的时候使用了队列,管理队列的软件是Celery. 我们可以通过软件rabbitmq-server来监测队列的进行情况,并且可以通过软件flower显示出图形界面。
1. 安装
rabbitmq-server为自带软件
celery命令无法直接使用需要安装python-celery-common
[email protected]:~# apt install python-celery-common
flower需要安装
[email protected]:~#pip install flower
2. 使用
rabbitmq-server的使用
[email protected]:~# rabbitmqctl list_queues namemessages messages_ready Listing queues ... celery 17448 17320 [email protected] 0 0 celeryev.f45630cb-6e96-44eb-b5f1-976a65207593 0 0 [email protected]:~#
flower的使用:
[email protected]:~# celery -A celery flower [I 180222 16:49:34 command:139] Visit me athttp://localhost:5555 [I 180222 16:49:34 command:144] Broker:amqp://guest:**@localhost:5672// [I 180222 16:49:34 command:147] Registered tasks: ['celery.backend_cleanup', 'celery.chain', 'celery.chord', 'celery.chord_unlock', 'celery.chunks', 'celery.group', 'celery.map', 'celery.starmap'] [I 180222 16:49:34 mixins:231] Connected toamqp://guest:**@127.0.0.1:5672// [E 180222 16:49:45 broker:82] RabbitMQ management API callfailed: [Errno 111] Connection refused [E 180222 16:51:19 broker:82] RabbitMQ management API callfailed: [Errno 111] Connection refused [E 180222 16:51:33 broker:82] RabbitMQ management API callfailed: [Errno 111] Connection refused
执行上述命令后,在网页中打开以下网页,可以监测index创建统计。
http://192.168.1.230:5555
如果需要删除已开始创建的索引的队列可以使用命令;
[email protected]:~# celery-A celery purge WARNING: This will remove all tasks from queue: celery. There is noundo for this operation! (to skip this prompt use the -f option) Are you sure you want to delete all tasks (yes/NO)? yes No messages purged from 1 queue [email protected]:~# rabbitmqctllist_queues name messages Listing queues ... celery 113 [email protected] 0 celeryev.f45630cb-6e96-44eb-b5f1-976a65207593 0 celeryev.fd66aa58-7197-4e2b-b108-96706f43c32f 0 [email protected]:~#
查看索引状态:
[email protected]:~# celery -A celery events