UBUNTU 14.04 LTS 安装 elasticseach
同步MYSQL表
并实现中文搜索

===========================================================================================

1、下载
wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.4.1.deb

===========================================================================================

2、安装
dpkg -i elasticsearch-1.4.1.deb

===========================================================================================

3、启动脚本
Selecting previously unselected package elasticsearch.
(Reading database ... 90313 files and directories currently installed.)
Preparing to unpack elasticsearch-1.4.1.deb ...
Unpacking elasticsearch (1.4.1) ...
Setting up elasticsearch (1.4.1) ...
Adding system user `elasticsearch' (UID 107) ...
Adding new user `elasticsearch' (UID 107) with group `elasticsearch' ...
Not creating home directory `/usr/share/elasticsearch'.
### NOT starting elasticsearch by default on bootup, please execute
 sudo update-rc.d elasticsearch defaults 95 10
### In order to start elasticsearch, execute
 sudo /etc/init.d/elasticsearch start
Processing triggers for ureadahead (0.100.0-16) ...

===========================================================================================

4、安装JAVA
wget http://119.254.108.84:8080/jdk.tar.gz
tar zxvf jdk.tar.gz

sudo update-alternatives --install /usr/bin/java java /opt/jdk/bin/java 300
sudo update-alternatives --install /usr/bin/javac javac /opt/jdk/bin/javac 300
sudo update-alternatives --install /usr/bin/jar jar /opt/jdk/bin/jar 300
sudo update-alternatives --config java

vim /etc/profile
export JAVA_HOME=/opt/jdk
export CLASSPATH=.:$JAVA_HOME/jre/lib/rt.jar:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export PATH=$PATH:$JAVA_HOME/bin

source /etc/profile

验证
java -version

===========================================================================================

5、校验是否启动

netstat -nlp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 690/sshd
tcp6 0 0 :::9200 :::* LISTEN 10610/java
tcp6 0 0 :::9300 :::* LISTEN 10610/java
tcp6 0 0 :::22 :::* LISTEN 690/sshd
tcp6 0 0 :::3000 :::* LISTEN 1584/pm2: Daemon
udp 0 0 0.0.0.0:43449 0.0.0.0:* 1149/dhclient
udp 0 0 0.0.0.0:68 0.0.0.0:* 1149/dhclient
udp6 0 0 :::12563 :::* 1149/dhclient
udp6 0 0 :::54328 :::* 10610/java
Active UNIX domain sockets (only servers)
Proto RefCnt Flags Type State I-Node PID/Program name Path
unix 2 [ ACC ] STREAM LISTENING 8720 1584/pm2: Daemon /root/.pm2/pub.sock
unix 2 [ ACC ] STREAM LISTENING 8721 1584/pm2: Daemon /root/.pm2/rpc.sock
unix 2 [ ACC ] SEQPACKET LISTENING 5391670 17731/systemd-udevd /run/udev/control
unix 2 [ ACC ] STREAM LISTENING 10362 1/init @/com/ubuntu/upstart
unix 2 [ ACC ] STREAM LISTENING 1641 833/acpid /var/run/acpid.socket
unix 2 [ ACC ] STREAM LISTENING 9453 619/dbus-daemon /var/run/dbus/system_bus_socket

===========================================================================================

6、与MYSQL之间完成同步
http://blog.csdn.net/alen1985/article/details/41356361

官方地址:
https://github.com/jprante/elasticsearch-river-jdbc

6.1 去安装目录安装

cd /usr/share/elasticsearch/bin/

./plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.3.4.4/elasticsearch-river-jdbc-1.3.4.4-plugin.zip

root@node1:/usr/share/elasticsearch/bin# ./plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.3.4.4/elasticsearch-river-jdbc-1.3.4.4-plugin.zip
-> Installing jdbc...
Trying http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.3.4.4/elasticsearch-river-jdbc-1.3.4.4-plugin.zip...
Downloading ......................................................................DONE
Installed jdbc into /usr/share/elasticsearch/plugins/jdbc

---------------------------------------

6.2 下载mysql的driver

curl -o mysql-connector-java-5.1.33.zip -L 'http://dev.mysql.com/get/Downloads/Connector-J/mysql-connector-java-5.1.33.zip/from/http://cdn.mysql.com/'

---------------------------------------

6.3 拷贝jar包到指定目录
cp mysql-connector-java-5.1.33-bin.jar /usr/share/elasticsearch/plugins/jdbc/
cd /usr/share/elasticsearch/plugins/jdbc/
chmod 644 *

6.4 重启elasticsearch
sudo /etc/init.d/elasticsearch restart

6.5 出现主机名解析问题

改/etc/hostname

---------------------------------------

6.6 出现了插件错误

[2014-11-27 23:26:52,838][INFO ][node ] [Powderkeg] initializing ...
[2014-11-27 23:26:52,859][INFO ][plugins ] [Powderkeg] loaded [jdbc-1.3.4.4-d2e33c3], sites []
[2014-11-27 23:26:52,905][ERROR][bootstrap ] {1.4.1}: Initialization Failed ...
- IncompatibleClassChangeError[Implementing class]

./plugin --install jdbc --url http://xbib.org/repository/org/xbib/elasticsearch/plugin/elasticsearch-river-jdbc/1.4.0.3.Beta1/elasticsearch-river-jdbc-1.4.0.3.Beta1-plugin.zip

./plugin -r jdbc

service elasticsearch restart

OK,解决了
---------------------------------------

6.7 搞定同步

curl -XPUT 'localhost:9200/_river/my_jdbc_river/_meta' -d '{
    "type" : "jdbc",
    "jdbc" : {
        "url" : "jdbc:mysql://192.168.60.5:3306/heike_product",
        "user" : "。。。。。。",
        "password" : "。。。。。",
        "sql" : "select * from product"
    }
}'

6.8 安装head插件
tail -f /var/log/elasticsearch/elasticsearch.log
cd /usr/share/elasticsearch/bin/
./plugin -install mobz/elasticsearch-head

6.9 卸载
service elasticsearch stop
apt-get remove elasticsearch

wget https://download.elasticsearch.org/elasticsearch/elasticsearch/elasticsearch-1.3.4.deb
dpkg -i elasticsearch-1.3.4.deb
service elasticsearch restart

===================================================

7. node.js封装

http://www.elasticsearch.org/guide/en/elasticsearch/client/javascript-api/current/quick-start.html

var pageNum = request.param('page', 1);
var perPage = request.param('per_page', 15);
var userQuery = request.param('search_query');
var userId = request.session.userId;

client.search({
  index: 'posts',
  from: (pageNum - 1) * perPage,
  size: perPage,
  body: {
    filtered: {
      query: {
        match: {
          // match the query agains all of
          // the fields in the posts index
          _all: userQuery
        }
      },
      filter: {
        // only return documents that are
        // public or owned by the current user
        or: [
          {
            term: { privacy: "public" }
          },
          {
            term: { owner: userId }
          }
        ]
      }
    }
  }
}, function (error, response) {
  if (err) {
    // handle error
    return;
  }

response.render('search_results', {
    results: response.hits.hits,
    page: pageNum,
    pages: Math.ceil(response.hits.total / perPage)
  })
});

elasticsearch installation guide的更多相关文章

  1. Arch Linux Installation Guide

    Arch Linux Installation Guide   timedatectl set-ntp true   sed -i '/Score/{/China/!{n;s/^/#/}}' /etc ...

  2. P6 EPPM Manual Installation Guide (Oracle Database)

    P6 EPPM Manual Installation Guide (Oracle Database) P6 EPPM Manual Installation Guide (Oracle Databa ...

  3. .NET Core installation guide

      .NET Core installation guide 1.Download Visual Studio 2015 Make sure you have Visual Studio 2015 U ...

  4. 【英文文档】Solidifier for Windows Installation Guide

    Page 1Solidifier for Windows  Installation Guide Page 2McAfee, Inc.McAfee® Solidifier for Windows In ...

  5. Installation Guide Ubuntu 16.04

    Beside the installation guide on the main page, here is a guide to install GenieACS off a freshly in ...

  6. Ubuntu14.04 clang3.8 Installation Guide

    Reference Installing clang 3.8 on Ubuntu 14.04.3. Ubuntu14.04 clang3.8 Installation Guide 1.add the ...

  7. Installation Guide of Ubuntu 14.04, 64bit on Dell Server

    Installation Guide of Ubuntu 14.04, 64bit on Dell Server 准备:U盘(已通过ultraiso刻录ISO镜像). 1.插入U盘: 2.启动服务器, ...

  8. Oracle Grid Infrastructure Installation Guide for Linux 以debug模式安装并记录日志

    最新文章:Virson's Blog 使用如下命令能够以debug模式安装Oracle Grid并将日志记录到文件 [grid@vdb1 11ggrid]$ ./runInstaller -debug ...

  9. Installation Guide for Appium 1.6.3

    A.) System Requirements : - Require node 4 or above Xcode 8 iOS 10 B.) Open terminal and type follow ...

随机推荐

  1. SpringMVC从入门到精通之第四章

    第一个知识点:@Controller注解,用于标识这个类是一个后端控制器(类似struts中的action),主要作用就是接受页面的参数,转发页面.中间的业务逻辑是调用业务类处理的这个就是MVC设计模 ...

  2. Strcmp(字符串1,字符串2)函数 Sizeof && strlen() Substr(a,b)

    Strcmp(字符串1,字符串2)函数 { strcmp函数是比较两个字符串的大小,返回比较的结果.一般形式是:  i=strcmp(字符串,字符串); 其中,字符串1.字符串2均可为字符串常量或变量 ...

  3. AC日记——验证字串 openjudge 1.7 18

    18:验证子串 总时间限制:  1000ms 内存限制:   65536kB 描述 输入两个字符串,验证其中一个串是否为另一个串的子串. 输入 输入两个字符串, 每个字符串占一行,长度不超过200且不 ...

  4. windows 如何查看端口占用情况?

    原文来自:http://www.iteye.com/topic/1117270 开始--运行--cmd 进入命令提示符 输入netstat -ano 即可看到所有连接的PID 之后在任务管理器中找到这 ...

  5. jsonobject 遍历 org.json.JSONObject

    import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; public static  ...

  6. Spring JPA Junit 关闭自动回滚

    因为用了JPA配合Hibernate ,采用注解默认是开启了LayzLoad也就是懒加载,所以不得不在Junit的单元测试上加上@Transactional注解 这样Spring会自动为当前线程开启S ...

  7. ajax设置自定义请求头信息

    客户端请求 $.ajax({ type:"post", url:urlstr, dataType:'json', async:true, headers:{token:'abck' ...

  8. wk_04

    函数 函数是对程序逻辑进行结构化或过程化的一直编程方法.能将整块代码巧妙的隔离成易于管理的小块,把重复代码放到函数中而不是进行大量的拷贝--这样既能节省空间,也有助于保持一致性,因为你只需要改变单个的 ...

  9. PHP中调用move_uploaded_file函数提示failed to open stream和 Unable to move

    在做一个PHP文件上传系统的时候,使用move_uploaded_file进行文件上传,提示下面两个warning,不能成功上传文件 Warning: move_uploaded_file(uploa ...

  10. PAT 1015. 德才论 (25)

    宋代史学家司马光在<资治通鉴>中有一段著名的"德才论":"是故才德全尽谓之圣人,才德兼亡谓之愚人,德胜才谓之君子,才胜德谓之小人.凡取人之术,苟不得圣人,君子 ...