boyaa 接入ES搜索服务方案
1、申请服务器权限
http://it.oa.com/needs_apply/index?typeId=2&type=opm&yw=0&rand=834325577
测试环境: 192.168.202.100
线上环境: 视实际IP
2、先部署好后面的服务再来更新文件
cmslib/inc.php
cmslib/lib/es.class.php
cmslib/bylib/fun.class.php
cmslib/app/logses/index.html
cmslib/app/logses/logses.php
cmslib/app/logses/logses.js
cms/crontab/doudp.php
cms/crontab/es.sh.php
cms/crontab/crontab.sh.php
3、安装JDK
说明:
ElasticSearch和Logstash依赖于JDK,所以需要安装JDK
对于JDK 版本一定要大于等于1.7.0
# yum -y install java-1.7.0-openjdk*
# java -version
4 安装ElasticSearch
说明:ElasticSearch默认的对外服务的HTTP端口是9200,节点间交互的TCP端口是9300。
4.1下载ElasticSearch:
# mkdir -p /opt/software && cd /opt/software
# sudo wget https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/2.3.4/elasticsearch-2.3.4.tar.gz
或者上传 #rz 回车 或 #rz -bye 命令选择文件不要鼠标选择文件
# sudo tar -zxvf elasticsearch-2.3.4.tar.gz -C /usr/local/
# ln -s /usr/local/elasticsearch-2.3.4 /usr/local/elasticsearch
软连
4.2 设置elasticsearch 配置文件
#vim /usr/local/elasticsearch/config/elasticsearch.yml
需要修改如下:
...
# cluster.name: my-application
cluster.name: cms-cluster
...
# node.name: node-1
node.name: cms_node1
...
# network.host: 192.168.0.1
network.host: 192.168.202.100,127.0.0.1
#注意 192.168.202.100 是测试环境IP 线上则修改成对应IP
...
# http.port: 9200
http.port: 9200
...
#path.data: /path/to/data
path.data: /data/wwwroot/cms/data/es/data
...
#path.logs: /path/to/logs
path.logs: /data/wwwroot/cms/data/es/logs
...
#以下配置 等安装elasticfence 插件后才配置
#elasticfence 是 elasticsearch http auth 认证
#行首要空格 ,否则会报错
elasticfence.disabled: false
elasticfence.root.password: boyaaPWD
elasticfence.whitelist: ["127.0.0.1", "192.168.202.100"]
#elasticfence.blacklist: ["127.0.0.2", "10.0.0.99"]
4.3启动服务用于测试
# cd elasticsearch
# bin/elasticsearch
如果root 启动,则用
bin/elasticsearch -Des.insecure.allow.root=true
4.4测试ElasticSearch服务是否正常,预期返回200的状态码:
# curl -X GET http://localhost:9200
返回一个例子
{
"name" : "cms_node1",
"cluster_name" : "cms-cluster",
"version" : {
"number" : "2.3.4",
"build_hash" : "e455fd0c13dceca8dbbdbb1665d068ae55dabe3f",
"build_timestamp" : "2016-06-30T11:24:31Z",
"build_snapshot" : false,
"lucene_version" : "5.5.0"
},
"tagline" : "You Know, for Search"
}
5.ElasticSearch-Head,ElasticSearch-Kopf 插件安装
a.命令安装
a.1 cd /usr/local/elasticsearch
a.2 执行命令 ./bin/plugin install mobz/elasticsearch-head 即可。
a.3 详细信息请看:https://github.com/mobz/elasticsearch-head下面的README.md文件。
a.4测试是否成功 open http://localhost:9200/_plugin/head
b.ElasticSearch-Kopf
说明:Kopf是一个ElasticSearch的管理工具,它也提供了对ES集群操作的API。
b.1安装
./elasticsearch/bin/plugin install lmenezes/elasticsearch-kopf/
b.2 测试是否成功 open http://localhost:9200/_plugin/kopf
6、Elasticfence 插件安装
说明:Elasticsearch HTTP Basic User Auth plugin
Elasticsearch user authentication plugin with http basic auth and IP ACL
This plugin provides user authentication APIs and a User management web console.
6.1 安装
#cd /usr/local/elasticsearch
#bin/plugin install https://raw.githubusercontent.com/elasticfence/elasticsearch-http-user-auth/2.3.x/jar/elasticfence-2.3.4-SNAPSHOT.zip
6.2 修改配置文件 elasticsearch.yml 在后面添加如下内容:
...
#elasticfence 是 elasticsearch http auth 认证
#行首要空格 ,否则会报错
elasticfence.disabled: false
elasticfence.root.password: boyaaPWD
elasticfence.whitelist: ["127.0.0.1", "192.168.202.100"]
#elasticfence.blacklist: ["127.0.0.2", "10.0.0.99"]
...
注意:
行首要空格 ,否则会报错
http auth
用户名是 root 密码是 boyaaPWD (注意,代码中也使用了此密码)
6.3 重启 elasticsearch
启动服务用于测试
# cd elasticsearch
# bin/elasticsearch
如果root 启动,则用
bin/elasticsearch -Des.insecure.allow.root=true
6.4 测试验证是否生效
http://your.elasticsearch.hostname:9200/_plugin/elasticfence/index.html
eg:测试环境IP
http://192.168.202.100:9200/_plugin/elasticfence/index.html
7、设置 crontab.sh.php 与添加 es.sh.php
7.1 、 在 cms/crontab/crontab.sh.php 后添加
#es server 日志搜索服务
source ${path}es.sh.php
7.2、在cms/crontab/ 目录下 添加 es.sh.php 文件
#!/bin/sh
#<?php die()?>
#此处 es server 不设置开机启动,是因crontab.sh.php 会每分钟都在检查,然而下面会启动es 服务
ps -fe|grep elasticsearch |grep -v grep
if [ $? -ne 0 ];then
/usr/local/elasticsearch/bin/elasticsearch -Des.insecure.allow.root=true &
fi
7.3、 重启 crontab.sh.php
8、重启 udp
/data/wwwroot/cms/data
# rm -f doudpdemo.run
# /usr/local/php/bin/php -f /data/wwwroot/cms/crontab/doudp.php > /data/wwwroot/cms/doudp.log 2>&1 &
# /usr/local/php/bin/php -f /data/wwwroot/cms/crontab/udp.php 45541 > /dev/null 2>&1 &
------全文完-----