Skip to content

音乐搜索系统部署说明

工作日志,转载请保留出处:唐福林 博客雨 音乐搜索系统部署说明 http://blog.fulin.org/2009/11/pcsearch_deploy.html

PC 客户端搜索系统部署说明

唐福林 <tangfulin AT gmail.com>

PC 客户端搜索系统主要由 负责建索引的 IndexServer 和负责提供搜索服务的 SearchServer 两部分组成。
IndexServer (目前是 98)负责接收资源库发过来的xml原始文件,解析原始文件,更新索引,并将更新后的索引推送到 SearchServer 上的指定目录供搜索使用。当前架构中,IndexServer 不支持分布式和负载均衡,只能部署在一台机器上。因为索引更新并不频繁,所以这里并不会带来性能瓶颈。如果是为了消除单点故障,可以在另外一台机器上起一个备份进程,当主 IndexServer 故障的时候接收资源库发过来的xml原始文件,但为了保持索引一致,建议不做实际的索引更新操作。这样 IndexServer 故障带来的唯一影响是索引更新延迟。只要做了必要的监控措施,延迟的时间是可以控制在可接受范围内的。IndexServer 主要消耗磁盘IO,也会有一些 cpu 和内存消耗。
SearchServer (目前是 221)负责对外提供搜索服务。SearchServer 当前使用 Resin 提供的 Servlet 环境,以 HTTP 协议提供 Rest 风格的服务。SearchServer 会定期查看工作目录下是否有新的索引到达,如果有,则打开新索引,关闭旧索引。已关闭的旧索引随后会被脚本删除。SearchServer 主要消耗内存和网络IO。

一。部署之前的服务器检查:

1. 确认操作系统发行版本: cat /etc/redhat-release
Red Hat Enterprise Linux Server release 5.3 (Tikanga) 或以上
2. 确认系统安装的 java 版本:java -version
java version “1.5.0_15″ 或以上
3. 确认系统安装的 rsync 版本: rsync –version
rsync version 3.0.5 protocol version 30 或以上
4. 确认磁盘空间:df -h
确保有超过 2G 的剩余空间,建议预留 5G,方便打log。如果/home下磁盘空间不够,可以使用软链接
5. 确认svn客户端版本:svn –version
确保含有 https 模块:
ra_dav : Module for accessing a repository via WebDAV (DeltaV) protocol.
- handles ‘http’ scheme
- handles ‘https’ scheme
6. 确认 ant 版本:ant -version
Apache Ant version 1.6.2 或以上
7. 确认 resin 版本:
3.1.9 或以上

二。建立目录结构

项目根目录设置为 /home/yyjd,以下的相对路径,如无特殊说明,都是相对于项目的根目录

mkdir /home/yyjd && cd /home/yyjd && mkdir code data software && cd data && mkdir -p backup dict indexes indexserver logs pids webapps/search xml

三。取得文件数据

1. 取得必要的软件
如果 “一” 中的检查不满足,或者希望安装 Hudson 或 JIRA,可以从 98 的 /home/yyjd/software 中取得软件,并进行安装。安装的时候,如果是 rpm 包,可以使用 rpm -ivh xxx.rpm 进行安装,如果是zip或tgz压缩包,解压缩即可,Hudson 是一个 war 包,可以直接运行,参考 code/PCSearcher/trunk/shell/server-start.sh 里的运行命令说明。
注意,在安装 rpm 包的时候,可能会有一些依赖问题,按照提示先安装依赖包即可;安装 rpm 包如果报冲突,在命令行上加一个 –force 参数即可。

2. 取得代码
cd /home/yyjd/code && svn checkout https://*.*.*.254/svn/PCSearch

四。相关软件设置

1. rsync 设置:在搜索机上 vi /etc/rsyncd.conf

uid = root
gid = root
max connections = 200
timeout = 600
use chroot = no
read only = no
pid file=/var/run/rsyncd.pid
hosts allow=*.*.*.98

[search]
path=/home/yyjd
comment = PCsearch project sync model

保存退出,然后运行 rsync –daemon

在 IndexServer 上测试 rsync 是否畅通:
rsync -vn 搜索机ip::search/data/indexes .
如果不通,则再测试一下使用 ssh 协议是否畅通:
首先将 IndexServer 的 /root/.ssh/id_rsa.pub (如果没有该文件,运行一下 ssh-keygen 命令)的内容添加到搜索机 /root/.ssh/authorized_keys 文件的末尾(注意不要引入多余的换行符),然后测试:
rsync -vn root@搜索机ip:/home/yyjd/data/indexes .

测试正常之后,将测试成功的地址添加到 IndexServer 的 /home/yyjd/code/PCSearcher/trunk/shell/trans-dest.conf 文件末尾

2. resin 设置:
将 data/webapps/search 目录添加到 resin app 目录列表,也可以在 resin 的 webapps 目录下建一个到 data/webapps/search 的软链接

五。编译代码

cd /home/yyjd/code/PCSearcher/trunk && svn up && ant && ant indexserver

六。启动进程
进入 /home/yyjd/code/PCSearcher/trunk/shell 目录
参考 server-start.sh
1. IndexServer:
a. 启动 resin (仅作测试,非必要)
b. 启动 IndexServer: ./indexUpdater.sh restart
c. 启动 trans 索引传输脚本:
(nohup ./trans-indexsnap.sh songs 2>&1 >> /home/yyjd/data/logs/trans-songs.log &)
(nohup ./trans-indexsnap.sh albums 2>&1 >> /home/yyjd/data/logs/trans-albums.log &)
(nohup ./trans-indexsnap.sh keywords 2>&1 >> /home/yyjd/data/logs/trans-keywords.log &)
d. 启动 clean 索引清除脚本(如果启用了 resin,就必须启动这些清除脚本):
(nohup ./clean-indexsnap.sh songs 2>&1 >> /home/yyjd/data/logs/clean-songs.log &)
(nohup ./clean-indexsnap.sh albums 2>&1 >> /home/yyjd/data/logs/clean-albums.log &)
(nohup ./clean-indexsnap.sh keywords 2>&1 >> /home/yyjd/data/logs/clean-keywords.log &)
e. 检查 /home/yyjd/data/logs 下的日志是否都正常

2. SearchServer:
a. 启动 resin
b. 启动 IndexServer: ./indexUpdater.sh restart (可以作为 IndexServer 接收xml原始文件的功能的备份,非必要)
c. 启动 clean 索引清除脚本:
(nohup ./clean-indexsnap.sh songs 2>&1 >> /home/yyjd/data/logs/clean-songs.log &)
(nohup ./clean-indexsnap.sh albums 2>&1 >> /home/yyjd/data/logs/clean-albums.log &)
(nohup ./clean-indexsnap.sh keywords 2>&1 >> /home/yyjd/data/logs/clean-keywords.log &)
d. 检查 /home/yyjd/data/logs 下的日志是否都正常

七。日常管理

1. shell 脚本介绍:code/PCSearcher/trunk/shell
build.sh : Hudson 使用的编译,重启 IndexServer 进程的脚本,不建议使用
clean-indexsnap.sh : 无用索引清除脚本,SearchServer 使用
indexUpdater.sh : 索引更新 daemon 进程,接受 {start|stop|restart} 参数调用
initKeyword.sh : 关键词索引初始化脚本,平常不用
processManager.sh : 底层的进程启动,停止管理脚本,由其他脚本调用
rebuild.sh : 模拟发送重建歌曲,专辑索引的xml原始数据的脚本,重建索引时使用
server-start.sh : 记录了新部署机器时可能会用到的启动命令,不建议直接运行
trans-dest.conf : 传输脚本的目的地址配置文件
trans-indexsnap.sh : 索引传输脚本,IndexServer 使用

2. logs 日志介绍:data/logs
classpath.log : 索引更新 daemon 进程启动的时候的 classpath,debug 使用
clean-*.log : 索引清除日志
trans-*.log : 索引传输日志
search.log : 搜索日志
indexserver.log : 索引更新日志
另外,resin 的日志也需要留意观察。

八。常见错误及修正方法

1. svn 不支持 https
2. ant 编译出错
3. indexUpdater.sh 启动 索引更新 daemon 进程 出错
4. rsync 传输出错
5. 搜索出错,出白页面或 404
6. 搜索出错,报 Exception:确认一下 data/indexes/ 下面的每个子目录下面都有索引文件

Post a Comment

Your email is never published nor shared. Required fields are marked *